Skip to content

Commit 9a5d17f

Browse files
bug: fix ctip parser handling JSON Payload content
Handle Payload field with non-base64-encoded JSON content and numbered dictionaries
1 parent cef39c1 commit 9a5d17f

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ CHANGELOG
5858
- `intelmq.bots.parsers.microsoft.parser_ctip`:
5959
- New parameter `overwrite` (PR#2112 by Sebastian Wagner, fixes #2022).
6060
- 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).
61+
- Handle Payload field with non-base64-encoded JSON content and numbered dictionaries (PR#2193 by Sebastian Wagner)
6162
- `intelmq.bot.parsers.shodan.parser` (PR#2117 by Mikk Margus Möll):
6263
- 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.
6364
- Shodan field `rsync.modules` is collected.

intelmq/bots/parsers/microsoft/parser_ctip.py

+15-6
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
"""
@@ -263,14 +263,23 @@ def parse_azure(self, line, report):
263263

264264
for key, value in line.copy().items():
265265
if key == 'Payload':
266+
# empty
266267
if value == 'AA==': # NULL
267268
del line[key]
268269
continue
269-
try:
270-
value = json.loads(utils.base64_decode(value))
271-
# continue unpacking in next loop
272-
except json.decoder.JSONDecodeError:
273-
line[key] = utils.base64_decode(value)
270+
271+
# JSON string
272+
if value.startswith('{'):
273+
for payload_key, payload_value in json.loads(value).items():
274+
event[f'extra.payload.{payload_key}'] = payload_value
275+
del line[key]
276+
else:
277+
# base64-encoded JSON
278+
try:
279+
value = json.loads(utils.base64_decode(value))
280+
# continue unpacking in next loop
281+
except json.decoder.JSONDecodeError:
282+
line[key] = utils.base64_decode(value)
274283
elif key == 'TLP' and value.lower() == 'unknown':
275284
del line[key]
276285
if isinstance(value, dict):

intelmq/etc/feeds.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -723,21 +723,21 @@ providers:
723723
services on the router or tried to gain access to them. The list also
724724
contains a list of tags for each address which
725725
indicate what behaviour of the address was observed.
726-
726+
727727
The Turris Greylist feed provides PGP signatures for the provided files.
728728
You will need to import the public PGP key from the linked documentation
729729
page, currently available at
730730
https://pgp.mit.edu/pks/lookup?op=vindex&search=0x10876666
731731
or from below.
732732
See the URL Fetcher Collector documentation for more information on
733733
PGP signature verification.
734-
734+
735735
PGP Public key:
736736
```
737737
-----BEGIN PGP PUBLIC KEY BLOCK-----
738738
Version: SKS 1.1.6
739739
Comment: Hostname: pgp.mit.edu
740-
740+
741741
mQINBFRl7D8BEADaRFoDa/+r27Gtqrdn8sZL4aSYTU4Q3gDr3TfigK8H26Un/Y79a/DUL1o0
742742
o8SRae3uwVcjJDHZ6KDnxThbqF7URfpuCcCYxOs8p/eu3dSueqEGTODHWF4ChIh2japJDc4t
743743
3FQHbIh2e3GHotVqJGhvxMmWqBFoZ/mlWvhjs99FFBZ87qbUNk7l1UAGEXeWeECgz9nGox40
@@ -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:
@@ -1887,10 +1887,10 @@ providers:
18871887
listen 443 ssl http2;
18881888
server_name [your host name];
18891889
client_max_body_size 50M;
1890-
1890+
18911891
ssl_certificate [path to your key];
18921892
ssl_certificate_key [path to your certificate];
1893-
1893+
18941894
location /[your private url] {
18951895
if ($http_authorization != '[your private password]') {
18961896
return 403;

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

+1
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

+40
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)