|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# encoding: utf-8 |
| 3 | + |
| 4 | +from cortexutils.analyzer import Analyzer |
| 5 | +import dns.resolver |
| 6 | +import time |
| 7 | + |
| 8 | +class TeamCymruMHRAnalyzer(Analyzer): |
| 9 | + def __init__(self): |
| 10 | + Analyzer.__init__(self) |
| 11 | + self.observable = self.get_param('data', None, 'Data missing!') |
| 12 | + |
| 13 | + def summary(self, raw): |
| 14 | + taxonomies = [] |
| 15 | + level = 'info' |
| 16 | + namespace = 'TeamCymruMHR' |
| 17 | + |
| 18 | + # Set predicate for last_seen |
| 19 | + predicate = 'last_seen' |
| 20 | + taxonomies.append(self.build_taxonomy(level, namespace, predicate, raw['last_seen'])) |
| 21 | + |
| 22 | + # Set predicate for detection percentage |
| 23 | + predicate = 'detection_pct' |
| 24 | + taxonomies.append(self.build_taxonomy(level, namespace, predicate, raw['detection_pct'])) |
| 25 | + |
| 26 | + return {"taxonomies": taxonomies} |
| 27 | + |
| 28 | + def run(self): |
| 29 | + lookup = dns.resolver.query(self.observable + '.malware.hash.cymru.com', 'TXT') |
| 30 | + for rdata in lookup: |
| 31 | + for txt_string in rdata.strings: |
| 32 | + last_seen_epoch = str(txt_string).split("\'")[1].split(" ")[0] |
| 33 | + # Make timestamp mor readable for humans, but maintain UTC |
| 34 | + last_seen = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(last_seen_epoch))) |
| 35 | + detection_pct = str(txt_string).split("\'")[1].split(" ")[1] |
| 36 | + self.report({ 'last_seen': last_seen, 'detection_pct': detection_pct }) |
| 37 | + |
| 38 | +if __name__ == '__main__': |
| 39 | + TeamCymruMHRAnalyzer().run() |
0 commit comments