Skip to content
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

Add registry mappings #117

Merged
merged 7 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion products/microsoft_defender_for_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
'sha256':{'table':'DeviceProcessEvents','field':'SHA256',
'projections':['DeviceName','AccountName','FolderPath','ProcessCommandLine']},
'modload':{'table': 'DeviceImageLoadEvents', 'field':'FolderPath',
'projections':['DeviceName', 'InitiatingProcessAccountName', 'InitiatingProcessFolderPath', 'InitiatingProcessCommandLine']}
'projections':['DeviceName', 'InitiatingProcessAccountName', 'InitiatingProcessFolderPath', 'InitiatingProcessCommandLine']},
'regmod':{'table':'DeviceRegistryEvents','field':'RegistryKey',
'projections':['DeviceName', 'InitiatingProcessAccountName', 'InitiatingProcessFolderPath', 'InitiatingProcessCommandLine', 'RegistryValueName', 'RegistryValueData']}
}

class DefenderForEndpoints(Product):
Expand Down
11 changes: 7 additions & 4 deletions products/sentinel_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Query:
'process_file_description': ['SrcProcDisplayName'],
'md5': ['Md5'],
'sha1':['Sha1'],
'sha256':['Sha256']
'sha256':['Sha256'],
'regmod':['RegistryKeyPath','RegistryValue']
}

PARAMETER_MAPPING_PQ: dict[str, list[str]] = {
Expand All @@ -67,7 +68,8 @@ class Query:
'process_file_description': ['src.process.displayName'],
'md5': ['src.process.image.md5', 'tgt.file.md5', 'module.md5'],
'sha256':['src.process.image.sha256','tgt.file.sha256'],
'sha1':['src.process.image.sha1','tgt.file.sha1','module.sha1']
'sha1':['src.process.image.sha1','tgt.file.sha1','module.sha1'],
'regmod':['registry.keyPath','registry.value']
}

class SentinelOne(Product):
Expand Down Expand Up @@ -530,9 +532,10 @@ def nested_process_search(self, tag: Tag, criteria: dict, base_query: dict) -> N
# play nice with 100 item limit per search field
chunked_terms = list(self.divide_chunks(terms, 100))
for chunk in chunked_terms:
search_value = ', '.join(f'"{x}"' for x in chunk)

search_value_orig = ', '.join(f'"{x}"' for x in chunk)
for param in parameter:
search_value = search_value_orig
if param == 'query':
# Formats queries as (a) OR (b) OR (c) OR (d)
if len(chunk) > 1:
Expand Down
3 changes: 2 additions & 1 deletion products/vmware_cb_enterprise_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
'domain': 'netconn_domain',
'internal_name': 'process_internal_name',
'md5':'hash',
'sha256':'hash'
'sha256':'hash',
'regmod':'regmod_name'
}

def _convert_relative_time(relative_time) -> str:
Expand Down
4 changes: 3 additions & 1 deletion tests/data/cbc_surveyor_testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"domain":["raw.githubusercontent.com"],
"internal_name":["powershell"],
"md5":["asdfasdfasdfasdf"],
"sha256":["zxcvzxcvzxcv"]
"sha256":["zxcvzxcvzxcv"],
"regmod": ["HKLM"],
"ipport": ["80"]
},
"multiple_values":{
"process_name":["svchost.exe", "cmd.exe"]
Expand Down
4 changes: 3 additions & 1 deletion tests/data/cbr_surveyor_testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"modload":["pcwutl.dll"],
"md5":["asdfasdfasdfasdf"],
"sha1":["qwerqwerqwerqwer"],
"sha256":["zxcvzxcvzxcv"]
"sha256":["zxcvzxcvzxcv"],
"regmod": ["HKLM"],
"ipport": ["80"]
},
"multiple_values":{
"process_name":["svchost.exe", "cmd.exe"]
Expand Down
4 changes: 3 additions & 1 deletion tests/data/dfe_surveyor_testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"md5":["asdfasdfasdfasdf"],
"sha1":["qwerqwerqwerqwer"],
"sha256":["zxcvzxcvzxcv"],
"modload":["pcwutl.dll"]
"modload":["pcwutl.dll"],
"regmod":["HKLM"],
"ipport": ["80"]
},
"multiple_values":{
"process_name":["svchost.exe", "cmd.exe"]
Expand Down
4 changes: 3 additions & 1 deletion tests/data/s1_surveyor_testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"process_file_description": ["Evil Stuff Here"],
"md5":["asdfasdfasdfasdf"],
"sha1":["qwerqwerqwerqwer"],
"sha256":["zxcvzxcvzxcv"]
"sha256":["zxcvzxcvzxcv"],
"regmod":["HKLM"],
"ipport": ["80"]
},
"multiple_values":{
"process_name":["svchost.exe", "cmd.exe"]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_microsoft_defender_for_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def test_nested_process_search(dfe_product : DefenderForEndpoints, mocker):
call(Tag('field_translation', data=None), {}, "DeviceProcessEvents | where SHA1 has_any ('qwerqwerqwerqwer') | project Timestamp, DeviceName, AccountName, FolderPath, ProcessCommandLine"),
call(Tag('field_translation', data=None), {}, "DeviceProcessEvents | where SHA256 has_any ('zxcvzxcvzxcv') | project Timestamp, DeviceName, AccountName, FolderPath, ProcessCommandLine"),
call(Tag('field_translation', data=None), {}, "DeviceImageLoadEvents | where FolderPath has_any ('pcwutl.dll') | project Timestamp, DeviceName, InitiatingProcessAccountName, InitiatingProcessFolderPath, InitiatingProcessCommandLine"),
call(Tag('field_translation', data=None), {}, "DeviceRegistryEvents | where RegistryKey has_any ('HKLM') | project Timestamp, DeviceName, InitiatingProcessAccountName, InitiatingProcessFolderPath, InitiatingProcessCommandLine, RegistryValueName, RegistryValueData"),
call(Tag('field_translation', data=None), {}, "DeviceNetworkEvents | where RemotePort has_any ('80') | project Timestamp, DeviceName, InitiatingProcessAccountName, InitiatingProcessFolderPath, InitiatingProcessCommandLine"),
call(Tag('multiple_values', data=None), {}, "DeviceProcessEvents | where FolderPath has_any ('svchost.exe', 'cmd.exe') | project Timestamp, DeviceName, AccountName, FolderPath, ProcessCommandLine"),
call(Tag('single_query', data=None), {}, "DeviceProcessEvents | where FileName contains \"rundll.exe\""),
call(Tag('multiple_query', data=None), {}, "DeviceProcessEvents | where ProcessCommandLine contains \"-enc\""),
Expand Down
14 changes: 10 additions & 4 deletions tests/test_sentinel_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_nested_process_search_dv(s1_product : SentinelOne):

assert len(s1_product._queries) == 4

assert len(s1_product._queries[Tag('field_translation')]) == 13
assert len(s1_product._queries[Tag('field_translation')]) == 16
sdate = s1_product._queries[Tag('field_translation')][0].start_date
edate = s1_product._queries[Tag('field_translation')][0].end_date
assert Query(sdate, edate, 'ProcessName', 'containscis', '"notepad.exe"', None) in s1_product._queries[Tag('field_translation')]
Expand All @@ -160,7 +160,10 @@ def test_nested_process_search_dv(s1_product : SentinelOne):
assert Query(sdate, edate, 'Md5', 'containscis', '"asdfasdfasdfasdf"', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'Sha1', 'containscis', '"qwerqwerqwerqwer"', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'Sha256', 'containscis', '"zxcvzxcvzxcv"', None) in s1_product._queries[Tag('field_translation')]

assert Query(sdate, edate, 'DstPort', 'containscis', '"80"', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'RegistryKeyPath', 'containscis', '"HKLM"', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'RegistryValue', 'containscis', '"HKLM"', None) in s1_product._queries[Tag('field_translation')]

assert len(s1_product._queries[Tag('multiple_values')]) == 1
sdate = s1_product._queries[Tag('multiple_values')][0].start_date
edate = s1_product._queries[Tag('multiple_values')][0].end_date
Expand Down Expand Up @@ -188,7 +191,7 @@ def test_nested_process_search_pq(s1_product : SentinelOne):

assert len(s1_product._queries) == 4

assert len(s1_product._queries[Tag('field_translation')]) == 18
assert len(s1_product._queries[Tag('field_translation')]) == 21
sdate = s1_product._queries[Tag('field_translation')][0].start_date
edate = s1_product._queries[Tag('field_translation')][0].end_date
assert Query(sdate, edate, 'src.process.name', 'in', '("notepad.exe")', None) in s1_product._queries[Tag('field_translation')]
Expand All @@ -209,7 +212,10 @@ def test_nested_process_search_pq(s1_product : SentinelOne):
assert Query(sdate, edate, 'tgt.file.sha1', 'in', '("qwerqwerqwerqwer")', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'module.md5', 'in', '("asdfasdfasdfasdf")', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'module.sha1', 'in', '("qwerqwerqwerqwer")', None) in s1_product._queries[Tag('field_translation')]

assert Query(sdate, edate, 'registry.keyPath', 'in', '("HKLM")', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'registry.value', 'in', '("HKLM")', None) in s1_product._queries[Tag('field_translation')]
assert Query(sdate, edate, 'dst.port.number', 'in', '("80")', None) in s1_product._queries[Tag('field_translation')]

assert len(s1_product._queries[Tag('multiple_values')]) == 1
sdate = s1_product._queries[Tag('multiple_values')][0].start_date
edate = s1_product._queries[Tag('multiple_values')][0].end_date
Expand Down
2 changes: 2 additions & 0 deletions tests/test_vmware_cb_enterprise_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def test_nested_process_search(cbc_product : CbEnterpriseEdr, mocker):
mocker.call(Tag('field_translation'), {}, '(process_internal_name:powershell)'),
mocker.call(Tag('field_translation'), {}, '(hash:asdfasdfasdfasdf)'),
mocker.call(Tag('field_translation'), {}, '(hash:zxcvzxcvzxcv)'),
mocker.call(Tag('field_translation'), {}, '(netconn_port:80)'),
mocker.call(Tag('field_translation'), {}, '(regmod_name:HKLM)'),
mocker.call(Tag('multiple_values'), {}, '(process_name:svchost.exe OR process_name:cmd.exe)'),
mocker.call(Tag('single_query'), {}, '(process_name:rundll.exe)'),
mocker.call(Tag('multiple_query'), {}, '((process_cmdline:-enc) OR (modload_name:malware.dll))')
Expand Down
4 changes: 3 additions & 1 deletion tests/test_vmware_cb_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def test_nested_process_search(cbr_product : CbResponse, mocker):
mocker.call('(sha256:zxcvzxcvzxcv)'),
mocker.call('(process_name:svchost.exe OR process_name:cmd.exe)'),
mocker.call('(process_name:rundll.exe)'),
mocker.call('((cmdline:-enc) OR (modload:malware.dll))')
mocker.call('((cmdline:-enc) OR (modload:malware.dll))'),
mocker.call('(regmod:HKLM)'),
mocker.call('(ipport:80)')
]

for program, criteria in programs.items():
Expand Down