-
Notifications
You must be signed in to change notification settings - Fork 807
Add T1168 and T1053 attack techniques (job scheduling) #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37b4717
Add techniques' info to attack_schema
shreyamalviya 73c4070
Add T1168 (linux PBA)
shreyamalviya 7588cd8
Add T1053 (windows PBA)
shreyamalviya 9c0c298
Mongo search logic changes + used/scanned/unscanned message changes
shreyamalviya c38875d
Code review changes
shreyamalviya 5bbef83
Linux: delete `TEMP_CRON` file even if command fails
shreyamalviya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
monkey/infection_monkey/post_breach/actions/schedule_jobs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from common.data.post_breach_consts import POST_BREACH_JOB_SCHEDULING | ||
from infection_monkey.post_breach.pba import PBA | ||
from infection_monkey.post_breach.job_scheduling.job_scheduling import\ | ||
get_commands_to_schedule_jobs, remove_scheduled_jobs | ||
|
||
|
||
class ScheduleJobs(PBA): | ||
""" | ||
This PBA attempts to schedule jobs on the system. | ||
""" | ||
|
||
def __init__(self): | ||
linux_cmds, windows_cmds = get_commands_to_schedule_jobs() | ||
|
||
super(ScheduleJobs, self).__init__(name=POST_BREACH_JOB_SCHEDULING, | ||
linux_cmd=' '.join(linux_cmds), | ||
windows_cmd=windows_cmds) | ||
|
||
remove_scheduled_jobs() |
18 changes: 18 additions & 0 deletions
18
monkey/infection_monkey/post_breach/job_scheduling/job_scheduling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import subprocess | ||
from infection_monkey.post_breach.job_scheduling.linux_job_scheduling import\ | ||
get_linux_commands_to_schedule_jobs | ||
from infection_monkey.post_breach.job_scheduling.windows_job_scheduling import\ | ||
get_windows_commands_to_schedule_jobs,\ | ||
get_windows_commands_to_remove_scheduled_jobs | ||
from infection_monkey.utils.environment import is_windows_os | ||
|
||
|
||
def get_commands_to_schedule_jobs(): | ||
linux_cmds = get_linux_commands_to_schedule_jobs() | ||
windows_cmds = get_windows_commands_to_schedule_jobs() | ||
return linux_cmds, windows_cmds | ||
|
||
|
||
def remove_scheduled_jobs(): | ||
if is_windows_os(): | ||
subprocess.run(get_windows_commands_to_remove_scheduled_jobs(), shell=True) # noqa: DUO116 |
12 changes: 12 additions & 0 deletions
12
monkey/infection_monkey/post_breach/job_scheduling/linux_job_scheduling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
TEMP_CRON = "$HOME/monkey-schedule-jobs" | ||
|
||
|
||
def get_linux_commands_to_schedule_jobs(): | ||
return [ | ||
f'touch {TEMP_CRON} &&', | ||
f'crontab -l > {TEMP_CRON} &&', | ||
'echo \"# Successfully scheduled a job using crontab\" |', | ||
f'tee -a {TEMP_CRON} &&', | ||
f'crontab {TEMP_CRON} ;', | ||
f'rm {TEMP_CRON}' | ||
] |
12 changes: 12 additions & 0 deletions
12
monkey/infection_monkey/post_breach/job_scheduling/windows_job_scheduling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SCHEDULED_TASK_NAME = 'monkey-spawn-cmd' | ||
SCHEDULED_TASK_COMMAND = 'C:\windows\system32\cmd.exe' | ||
|
||
# Commands from: https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1053.005/T1053.005.md | ||
|
||
|
||
def get_windows_commands_to_schedule_jobs(): | ||
return f'schtasks /Create /SC monthly /TN {SCHEDULED_TASK_NAME} /TR {SCHEDULED_TASK_COMMAND}' | ||
|
||
|
||
def get_windows_commands_to_remove_scheduled_jobs(): | ||
return f'schtasks /Delete /TN {SCHEDULED_TASK_NAME} /F > nul 2>&1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
monkey/monkey_island/cc/services/attack/technique_reports/T1053.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from monkey_island.cc.services.attack.technique_reports import AttackTechnique | ||
from monkey_island.cc.database import mongo | ||
from common.utils.attack_utils import ScanStatus | ||
from common.data.post_breach_consts import POST_BREACH_JOB_SCHEDULING | ||
|
||
|
||
__author__ = "shreyamalviya" | ||
|
||
|
||
class T1053(AttackTechnique): | ||
tech_id = "T1053" | ||
unscanned_msg = "Monkey did not try scheduling a job on Windows." | ||
scanned_msg = "Monkey tried scheduling a job on the Windows system but failed." | ||
used_msg = "Monkey scheduled a job on the Windows system." | ||
|
||
query = [{'$match': {'telem_category': 'post_breach', | ||
'data.name': POST_BREACH_JOB_SCHEDULING, | ||
'data.command': {'$regex': 'schtasks'}}}, | ||
{'$project': {'_id': 0, | ||
'machine': {'hostname': '$data.hostname', | ||
'ips': ['$data.ip']}, | ||
'result': '$data.result'}}] | ||
|
||
@staticmethod | ||
def get_report_data(): | ||
data = {'title': T1053.technique_title()} | ||
|
||
job_scheduling_info = list(mongo.db.telemetry.aggregate(T1053.query)) | ||
|
||
status = (ScanStatus.USED.value if job_scheduling_info[0]['result'][1] | ||
else ScanStatus.SCANNED.value) if job_scheduling_info else ScanStatus.UNSCANNED.value | ||
|
||
data.update(T1053.get_base_data_by_status(status)) | ||
data.update({'info': job_scheduling_info}) | ||
return data |
35 changes: 35 additions & 0 deletions
35
monkey/monkey_island/cc/services/attack/technique_reports/T1168.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from monkey_island.cc.services.attack.technique_reports import AttackTechnique | ||
from monkey_island.cc.database import mongo | ||
from common.utils.attack_utils import ScanStatus | ||
from common.data.post_breach_consts import POST_BREACH_JOB_SCHEDULING | ||
|
||
|
||
__author__ = "shreyamalviya" | ||
|
||
|
||
class T1168(AttackTechnique): | ||
tech_id = "T1168" | ||
unscanned_msg = "Monkey did not try scheduling a job on Linux." | ||
scanned_msg = "Monkey tried scheduling a job on the Linux system but failed." | ||
used_msg = "Monkey scheduled a job on the Linux system." | ||
|
||
query = [{'$match': {'telem_category': 'post_breach', | ||
'data.name': POST_BREACH_JOB_SCHEDULING, | ||
'data.command': {'$regex': 'crontab'}}}, | ||
{'$project': {'_id': 0, | ||
'machine': {'hostname': '$data.hostname', | ||
'ips': ['$data.ip']}, | ||
'result': '$data.result'}}] | ||
|
||
@staticmethod | ||
def get_report_data(): | ||
data = {'title': T1168.technique_title()} | ||
|
||
job_scheduling_info = list(mongo.db.telemetry.aggregate(T1168.query)) | ||
|
||
status = (ScanStatus.USED.value if job_scheduling_info[0]['result'][1] | ||
else ScanStatus.SCANNED.value) if job_scheduling_info else ScanStatus.UNSCANNED.value | ||
|
||
data.update(T1168.get_base_data_by_status(status)) | ||
data.update({'info': job_scheduling_info}) | ||
return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
monkey/monkey_island/cc/ui/src/components/attack/techniques/T1053.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import ReactTable from 'react-table'; | ||
import {renderMachineFromSystemData, ScanStatus} from './Helpers'; | ||
import MitigationsComponent from './MitigationsComponent'; | ||
|
||
class T1053 extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
static getColumns() { | ||
return ([{ | ||
columns: [ | ||
{ Header: 'Machine', | ||
id: 'machine', | ||
accessor: x => renderMachineFromSystemData(x.machine), | ||
style: {'whiteSpace': 'unset'}}, | ||
{ Header: 'Result', | ||
id: 'result', | ||
accessor: x => x.result, | ||
style: {'whiteSpace': 'unset'}} | ||
] | ||
}]) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<div>{this.props.data.message}</div> | ||
<br/> | ||
{this.props.data.status === ScanStatus.USED ? | ||
<ReactTable | ||
columns={T1053.getColumns()} | ||
data={this.props.data.info} | ||
showPagination={false} | ||
defaultPageSize={this.props.data.info.length} | ||
/> : ''} | ||
<MitigationsComponent mitigations={this.props.data.mitigations}/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default T1053; |
45 changes: 45 additions & 0 deletions
45
monkey/monkey_island/cc/ui/src/components/attack/techniques/T1168.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import ReactTable from 'react-table'; | ||
import {renderMachineFromSystemData, ScanStatus} from './Helpers'; | ||
import MitigationsComponent from './MitigationsComponent'; | ||
|
||
class T1168 extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
static getColumns() { | ||
return ([{ | ||
columns: [ | ||
{ Header: 'Machine', | ||
id: 'machine', | ||
accessor: x => renderMachineFromSystemData(x.machine), | ||
style: {'whiteSpace': 'unset'}}, | ||
{ Header: 'Result', | ||
id: 'result', | ||
accessor: x => x.result, | ||
style: {'whiteSpace': 'unset'}} | ||
] | ||
}]) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<div>{this.props.data.message}</div> | ||
<br/> | ||
{this.props.data.status === ScanStatus.USED ? | ||
<ReactTable | ||
columns={T1168.getColumns()} | ||
data={this.props.data.info} | ||
showPagination={false} | ||
defaultPageSize={this.props.data.info.length} | ||
/> : ''} | ||
<MitigationsComponent mitigations={this.props.data.mitigations}/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default T1168; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, all imports should follow the same structure:
If not sure about why, look up PEP8.
You can automatically achieve this on pycharm with ctrl + alt + o.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add https://pypi.org/project/flake8-import-order/