Skip to content

Commit 469dc49

Browse files
authored
Merge pull request #2193 from wagner-intevation/fix-ctip-payload
bug: fix ctip parser handling JSON Payload content
2 parents 236e2fd + 95d486e commit 469dc49

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ CHANGELOG
6060
- `intelmq.bots.parsers.microsoft.parser_ctip`:
6161
- New parameter `overwrite` (PR#2112 by Sebastian Wagner, fixes #2022).
6262
- Fix handling of field `Payload.domain` if it contains the same IP address as `Payload.serverIp` (PR#2144 by Mikk Margus Möll and Sebastian Wagner).
63+
- Handle Payload field with non-base64-encoded JSON content and numbered dictionaries (PR#2193 by Sebastian Wagner)
6364
- `intelmq.bot.parsers.shodan.parser` (PR#2117 by Mikk Margus Möll):
6465
- Instead of keeping track of `extra.ftp.<something>.parameters`, FTP parameters are collected together into `extra.ftp.features` as a list of said features, reducing field count.
6566
- Shodan field `rsync.modules` is collected.

intelmq/bots/parsers/microsoft/parser_ctip.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"CustomField4": "",
6060
"CustomField5": ""
6161
},
62-
"Payload": base64 encoded json
62+
"Payload": base64 encoded json with meaningful dictionary keys or JSON-string with numbered dictionary keys
6363
}
6464
6565
"""
@@ -267,14 +267,23 @@ def parse_azure(self, line, report):
267267

268268
for key, value in line.copy().items():
269269
if key == 'Payload':
270+
# empty
270271
if value == 'AA==': # NULL
271272
del line[key]
272273
continue
273-
try:
274-
value = json.loads(utils.base64_decode(value))
275-
# continue unpacking in next loop
276-
except json.decoder.JSONDecodeError:
277-
line[key] = utils.base64_decode(value)
274+
275+
# JSON string
276+
if value.startswith('{'):
277+
for payload_key, payload_value in json.loads(value).items():
278+
event[f'extra.payload.{payload_key}'] = payload_value
279+
del line[key]
280+
else:
281+
# base64-encoded JSON
282+
try:
283+
value = json.loads(utils.base64_decode(value))
284+
# continue unpacking in next loop
285+
except json.decoder.JSONDecodeError:
286+
line[key] = utils.base64_decode(value)
278287
elif key == 'TLP' and value.lower() == 'unknown':
279288
del line[key]
280289
if isinstance(value, dict):

intelmq/etc/feeds.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ providers:
17561756
parser:
17571757
module: intelmq.bots.parsers.microsoft.parser_ctip
17581758
parameters:
1759-
revision: 2020-05-29
1759+
revision: 2022-06-01
17601760
documentation: https://docs.microsoft.com/en-us/security/gsp/informationsharingandexchange http://www.dcuctip.com/
17611761
public: false
17621762
CTIP C2 via Azure:

intelmq/tests/bots/parsers/microsoft/ctip_azure.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
{"DataFeed":"Microsoft.DCU.CTIP.Infected","SourcedFrom":"Microsoft.DCU.CTIP.Gov.0001","DateTimeReceivedUtc":132622667720000000,"DateTimeReceivedUtcTxt":"Wednesday April 07 2021 10:59:32.0000","Malware":"Emotet","ThreatCode":"B77-GV","ThreatConfidence":"High","TotalEncounters":1,"TLP":"Unknown","SourceIp":"224.0.5.8","SourcePort":33587,"DestinationIp":"10.0.0.1","DestinationPort":8080,"SourceIpInfo":{"SourceIpAsnNumber":"64496","SourceIpAsnOrgName":"Example AS","SourceIpCountryCode":"AT","SourceIpRegion":"Styria","SourceIpCity":"Graz","SourceIpPostalCode":"8042","SourceIpLatitude":47.1298,"SourceIpLongitude":15.466,"SourceIpMetroCode":0,"SourceIpAreaCode":6,"SourceIpConnectionType":"","SourceIpv4Int":0},"HttpInfo":{"HttpHost":"","HttpRequest":"","HttpMethod":"","HttpReferrer":"","HttpUserAgent":"","HttpVersion":""},"CustomInfo":{"CustomField1":"bot-id-data","CustomField2":"comp-name","CustomField3":"","CustomField4":"","CustomField5":""},"Payload":"eyJ0aW1lc3RhbXBfdXRjIjoiMjAyMS0wNC0wN1QxMDo1OTozMiIsInNvdXJjZV9pcCI6IjEwLjAuMC4xIiwic291cmNlX3BvcnQiOiIzMzU4NyIsImRlc3RpbmF0aW9uX2lwIjoiMTAuMC4wLjEiLCJkZXN0aW5hdGlvbl9wb3J0IjoiODA4MCIsImNvbXB1dGVyX25hbWUiOiJjb21wLW5hbWUiLCJib3RfaWQiOiJib3QtaWQtZGF0YSJ9"}
44
{"DataFeed":"Microsoft.DCU.CTIP.Infected","SourcedFrom":"Microsoft.DCU.CTIP.Sinkhole","DateTimeReceivedUtc":132651352622420000,"DateTimeReceivedUtcTxt":"Monday May 10 2021 15:47:42.2420","Malware":"Avalanche","ThreatCode":"B67-SS-Gamarue","ThreatConfidence":"Low","TotalEncounters":2,"TLP":"Green","SourceIp":"224.0.5.8","SourcePort":28285,"DestinationIp":"10.0.0.1","DestinationPort":80,"SourceIpInfo":{"SourceIpAsnNumber":"64496","SourceIpAsnOrgName":"Example AS","SourceIpCountryCode":"AT","SourceIpRegion":"","SourceIpCity":"","SourceIpPostalCode":"","SourceIpLatitude":48.2,"SourceIpLongitude":16.3667,"SourceIpMetroCode":0,"SourceIpAreaCode":0,"SourceIpConnectionType":"Cellular","SourceIpv4Int":3758097672},"HttpInfo":{"HttpHost":"","HttpRequest":"","HttpMethod":"","HttpReferrer":"","HttpUserAgent":"","HttpVersion":""},"CustomInfo":{"CustomField1":"andromeda210","CustomField2":"","CustomField3":"","CustomField4":"","CustomField5":""},"Payload":"eyJ0cyI6MTYyMDY2MTY2Mi4yNDIzMTYsImlwIjoiMjI0LjAuNS44IiwicG9ydCI6MjgyODUsInNlcnZlcklwIjoiMTAuMC4wLjEiLCJzZXJ2ZXJQb3J0Ijo4MCwiZG9tYWluIjoiZXhhbXBsZS5jb20iLCJmYW1pbHkiOiJhbmRyb21lZGEiLCJtYWx3YXJlIjp7fSwicmVzcG9uc2UiOiJIdHRwT2siLCJoYW5kbGVyIjoiaGFuZGxlcjEiLCJ0eXBlIjoiSHR0cCJ9"}
55
{"DataFeed":"Microsoft.DCU.CTIP.Infected","SourcedFrom":"Microsoft.DCU.CTIP.Sinkhole","DateTimeReceivedUtc":132651352622420000,"DateTimeReceivedUtcTxt":"Monday May 10 2021 15:47:42.2420","Malware":"Avalanche","ThreatCode":"B67-SS-Gamarue","ThreatConfidence":"Low","TotalEncounters":2,"TLP":"Green","SourceIp":"224.0.5.8","SourcePort":28285,"DestinationIp":"10.0.0.1","DestinationPort":80,"SourceIpInfo":{"SourceIpAsnNumber":"64496","SourceIpAsnOrgName":"Example AS","SourceIpCountryCode":"AT","SourceIpRegion":"","SourceIpCity":"","SourceIpPostalCode":"","SourceIpLatitude":48.2,"SourceIpLongitude":16.3667,"SourceIpMetroCode":0,"SourceIpAreaCode":0,"SourceIpConnectionType":"Cellular","SourceIpv4Int":3758097672},"HttpInfo":{"HttpHost":"","HttpRequest":"","HttpMethod":"","HttpReferrer":"","HttpUserAgent":"","HttpVersion":""},"CustomInfo":{"CustomField1":"andromeda210","CustomField2":"","CustomField3":"","CustomField4":"","CustomField5":""},"Payload":"eyJ0cyI6MTYyMDY2MTY2Mi4yNDIzMTYsImlwIjoiMjI0LjAuNS44IiwicG9ydCI6MjgyODUsInNlcnZlcklwIjoiMTAuMC4wLjEiLCJzZXJ2ZXJQb3J0Ijo4MCwiZG9tYWluIjoiMTAuMC4wLjEiLCJmYW1pbHkiOiJhbmRyb21lZGEiLCJtYWx3YXJlIjp7fSwicmVzcG9uc2UiOiJIdHRwT2siLCJoYW5kbGVyIjoiaGFuZGxlcjEiLCJ0eXBlIjoiSHR0cCJ9"}
6+
{"DataFeed":"Microsoft.DCU.CTIP.Infected","SourcedFrom":"Microsoft.DCU.CTIP.Sinkhole","DateTimeReceivedUtc":132990083418030000,"DateTimeReceivedUtcTxt":"Wednesday June 01 2022 13:33:13.3713","Malware":"Malware","ThreatCode":"B00-Leet","ThreatConfidence":"High","TotalEncounters":137,"TLP":"Green","SourceIp":"10.0.0.15","SourcePort":10000,"DestinationIp":"10.0.0.2","DestinationPort":443,"SourceIpInfo":{"SourceIpAsnNumber":"64496","SourceIpAsnOrgName":"My ISP","SourceIpCountryCode":"DE","SourceIpRegion":"Saarland","SourceIpCity":"Saarbrücken","SourceIpPostalCode":"66111","SourceIpLatitude":49.2367,"SourceIpLongitude":6.9794,"SourceIpMetroCode":0,"SourceIpAreaCode":0,"SourceIpConnectionType":"Cable/DSL","SourceIpv4Int":167772175},"HttpInfo":{"HttpHost":"example.com","HttpRequest":"/index.php","HttpMethod":"POST","HttpReferrer":"","HttpUserAgent":"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36","HttpVersion":"HTTP/1.1"},"CustomInfo":{"CustomField1":"v1.6","CustomField2":"14758f1afd44c09b7992073ccf00b43d","CustomField3":"my PC name","CustomField4":"personal","CustomField5":""},"Payload":"{\"10001\":\"my PC name\",\"10002\":\"personal\",\"10022\":\"00000000\",\"10029\":157,\"10006\":\"00\"}"}

intelmq/tests/bots/parsers/microsoft/test_parser_ctip_azure.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,46 @@
189189
'tlp': 'GREEN',
190190
'extra.source.connection_type': 'Cellular',
191191
},
192+
{'__type': 'Event',
193+
'classification.type': 'infected-system',
194+
'destination.ip': '10.0.0.2',
195+
'destination.port': 443,
196+
'event_description.text': 'Microsoft.DCU.CTIP.Sinkhole',
197+
'extra.custom_field1': 'v1.6',
198+
'extra.custom_field2': '14758f1afd44c09b7992073ccf00b43d',
199+
'extra.custom_field3': 'my PC name',
200+
'extra.custom_field4': 'personal',
201+
'extra.http.host': 'example.com',
202+
'extra.http.method': 'POST',
203+
'extra.http.request': '/index.php',
204+
'extra.http.version': 'HTTP/1.1',
205+
'extra.malware': 'Malware',
206+
'extra.payload.10001': 'my PC name',
207+
'extra.payload.10002': 'personal',
208+
'extra.payload.10006': '00',
209+
'extra.payload.10022': '00000000',
210+
'extra.payload.10029': 157,
211+
'extra.source.connection_type': 'Cable/DSL',
212+
'extra.source.geolocation.postal_code': '66111',
213+
'extra.total_encounters': 137,
214+
'extra.user_agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) '
215+
'AppleWebKit/537.36 (KHTML, like Gecko) '
216+
'Chrome/79.0.3945.88 Safari/537.36',
217+
'feed.accuracy': 100.0,
218+
'feed.name': 'ctip',
219+
'malware.name': 'b00-leet',
220+
'raw': base64_encode(EXAMPLE_LINES[5]),
221+
'source.as_name': 'My ISP',
222+
'source.asn': 64496,
223+
'source.geolocation.cc': 'DE',
224+
'source.geolocation.city': 'Saarbrücken',
225+
'source.geolocation.latitude': 49.2367,
226+
'source.geolocation.longitude': 6.9794,
227+
'source.geolocation.region': 'Saarland',
228+
'source.ip': '10.0.0.15',
229+
'source.port': 10000,
230+
'time.source': '2022-06-06T16:59:01.802999+00:00',
231+
'tlp': 'GREEN'},
192232
]
193233

194234

0 commit comments

Comments
 (0)