|
13 | 13 | from greedybear.cronjobs.base import ElasticJob |
14 | 14 | from greedybear.cronjobs.scoring.scoring_jobs import UpdateScores |
15 | 15 | from greedybear.cronjobs.sensors import ExtractSensors |
16 | | -from greedybear.models import IOC, GeneralHoneypot, MassScanners, Sensors |
| 16 | +from greedybear.models import IOC, GeneralHoneypot, MassScanners, Sensors, WhatsMyIP, iocType |
17 | 17 | from greedybear.settings import EXTRACTION_INTERVAL, LEGACY_EXTRACTION |
18 | 18 |
|
19 | 19 |
|
@@ -68,10 +68,27 @@ def _add_ioc(self, ioc, attack_type: str, general=None): |
68 | 68 | ioc_record.number_of_days_seen = len(ioc_record.days_seen) |
69 | 69 | ioc_record.scanner = attack_type == SCANNER |
70 | 70 | ioc_record.payload_request = attack_type == PAYLOAD_REQUEST |
71 | | - ioc_record.save() |
72 | | - self.ioc_records.append(ioc_record) |
73 | | - self._threatfox_submission(ioc_record, ioc.related_urls) |
74 | | - return ioc_record |
| 71 | + |
| 72 | + filtered = False |
| 73 | + if ioc_record.type == iocType.DOMAIN: |
| 74 | + filtered = self._filter_whatsmyip(ioc_record.name) |
| 75 | + |
| 76 | + if filtered: |
| 77 | + return None |
| 78 | + else: |
| 79 | + ioc_record.save() |
| 80 | + self.ioc_records.append(ioc_record) |
| 81 | + self._threatfox_submission(ioc_record, ioc.related_urls) |
| 82 | + return ioc_record |
| 83 | + |
| 84 | + def _filter_whatsmyip(self, domain): |
| 85 | + try: |
| 86 | + WhatsMyIP.objects.get(domain=domain) |
| 87 | + except WhatsMyIP.DoesNotExist: |
| 88 | + return False |
| 89 | + else: |
| 90 | + self.log.info(f"{domain=} is a whats-my-ip domain. Filtering it.") |
| 91 | + return True |
75 | 92 |
|
76 | 93 | def _threatfox_submission(self, ioc_record: "IOC", related_urls: list): |
77 | 94 | # we submit only payload request IOCs for now because they are more reliable |
@@ -101,7 +118,7 @@ def _threatfox_submission(self, ioc_record: "IOC", related_urls: list): |
101 | 118 | if ioc_record.log4j: |
102 | 119 | seen_honeypots.append("log4pot") |
103 | 120 | for honeypot in ioc_record.general_honeypot.all(): |
104 | | - seen_honeypots.append(honeypot) |
| 121 | + seen_honeypots.append(honeypot.name) |
105 | 122 | seen_honeypots_str = ", ".join(seen_honeypots) |
106 | 123 |
|
107 | 124 | json_data = { |
|
0 commit comments