Skip to content

Commit f513ee1

Browse files
authored
Merge pull request #1079 from stratosphereips/alya/fix_db_issues_in_the_web_interface
Fix db issues in the web interface
2 parents e610ccf + 014a1ca commit f513ee1

27 files changed

+697
-466
lines changed

managers/metadata_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def update_slips_stats_in_the_db(self) -> Tuple[int, Set[str]]:
128128
updates the number of processed ips, slips internal time,
129129
and modified tws so far in the db
130130
"""
131-
slips_internal_time = float(self.main.db.getSlipsInternalTime()) + 1
131+
slips_internal_time = float(self.main.db.get_slips_internal_time()) + 1
132132

133133
# Get the amount of modified profiles since we last checked
134134
# this is the modification time of the last timewindow

managers/redis_manager.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class RedisManager:
16-
open_servers_pids: Dict[int, int]
16+
open_servers_pids: Dict[int, dict]
1717

1818
def __init__(self, main):
1919
self.main = main
@@ -240,19 +240,19 @@ def get_pid_of_redis_server(self, port: int) -> int:
240240
return False
241241

242242
@staticmethod
243-
def is_comment(line: str) -> True:
243+
def is_comment(line: str) -> bool:
244244
"""returns true if the given line is a comment"""
245245
return (line.startswith("#") or line.startswith("Date")) or len(
246246
line
247247
) < 3
248248

249-
def get_open_redis_servers(self) -> Dict[int, int]:
249+
def get_open_redis_servers(self) -> Dict[int, dict]:
250250
"""
251251
fills and returns self.open_servers_PIDs
252252
with PIDs and ports of the redis servers started by slips
253253
read from running_slips.info.txt
254254
"""
255-
self.open_servers_pids = {}
255+
self.open_servers_pids: Dict[int, dict] = {}
256256
try:
257257
with open(self.running_logfile, "r") as f:
258258
for line in f.read().splitlines():
@@ -263,8 +263,29 @@ def get_open_redis_servers(self) -> Dict[int, int]:
263263
line = line.split(",")
264264

265265
try:
266-
pid, port = int(line[3]), int(line[2])
267-
self.open_servers_pids[pid] = port
266+
(
267+
timestamp,
268+
file_or_interface,
269+
port,
270+
pid,
271+
zeek_dir,
272+
output_dir,
273+
slips_pid,
274+
is_daemon,
275+
save_the_db,
276+
) = line
277+
278+
self.open_servers_pids[pid] = {
279+
"timestamp": timestamp,
280+
"file_or_interface": file_or_interface,
281+
"port": port,
282+
"pid": pid,
283+
"zeek_dir": zeek_dir,
284+
"output_dir": output_dir,
285+
"slips_pid": slips_pid,
286+
"is_daemon": is_daemon,
287+
"save_the_db": save_the_db,
288+
}
268289
except ValueError:
269290
# sometimes slips can't get the server pid and logs "False"
270291
# in the logfile instead of the PID
@@ -379,7 +400,8 @@ def flush_redis_server(self, pid: int = None, port: int = None):
379400
if not hasattr(self, "open_servers_PIDs"):
380401
self.get_open_redis_servers()
381402

382-
port: int = self.open_servers_pids.get(pid, False)
403+
pid_info: Dict[str, str] = self.open_servers_pids.get(pid, {})
404+
port: int = pid_info.get("port", False)
383405
if not port:
384406
# try to get the port using a cmd
385407
port: int = self.get_port_of_redis_server(pid)

modules/cesnet/cesnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def import_alerts(self):
251251

252252
src_ips.update({srcip: json.dumps(event_info)})
253253

254-
self.db.add_ips_to_IoC(src_ips)
254+
self.db.add_ips_to_ioc(src_ips)
255255

256256
def pre_main(self):
257257
utils.drop_root_privs()

modules/flowalerts/conn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def check_multiple_reconnection_attempts(self, profileid, twid, flow):
227227
# reset the reconnection attempts of this src->dst
228228
current_reconnections[key] = (0, [])
229229

230-
self.db.setReconnections(profileid, twid, current_reconnections)
230+
self.db.set_reconnections(profileid, twid, current_reconnections)
231231

232232
def is_ignored_ip_data_upload(self, ip):
233233
"""

modules/threat_intelligence/threat_intelligence.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,11 @@ def parse_local_ti_file(self, ti_file_path: str) -> bool:
693693
)
694694

695695
# Add all loaded malicious ips to the database
696-
self.db.add_ips_to_IoC(malicious_ips)
696+
self.db.add_ips_to_ioc(malicious_ips)
697697
# Add all loaded malicious domains to the database
698-
self.db.add_domains_to_IoC(malicious_domains)
699-
self.db.add_ip_range_to_IoC(malicious_ip_ranges)
700-
self.db.add_asn_to_IoC(malicious_asns)
698+
self.db.add_domains_to_ioc(malicious_domains)
699+
self.db.add_ip_range_to_ioc(malicious_ip_ranges)
700+
self.db.add_asn_to_ioc(malicious_asns)
701701
return True
702702

703703
def __delete_old_source_ips(self, file):
@@ -724,7 +724,7 @@ def __delete_old_source_ips(self, file):
724724
if data["source"] == file:
725725
old_data.append(ip)
726726
if old_data:
727-
self.db.delete_ips_from_IoC_ips(old_data)
727+
self.db.delete_ips_from_ioc_ips(old_data)
728728

729729
def __delete_old_source_domains(self, file):
730730
"""Deletes all domain indicators of compromise (IoCs) associated with a specific
@@ -748,7 +748,7 @@ def __delete_old_source_domains(self, file):
748748
if data["source"] == file:
749749
old_data.append(domain)
750750
if old_data:
751-
self.db.delete_domains_from_IoC_domains(old_data)
751+
self.db.delete_domains_from_ioc_domains(old_data)
752752

753753
def __delete_old_source_data_from_database(self, data_file):
754754
"""Deletes old indicators of compromise (IoCs) associated with a specific source
@@ -837,7 +837,7 @@ def parse_ja3_file(self, path):
837837
}
838838
)
839839
# Add all loaded JA3 to the database
840-
self.db.add_ja3_to_IoC(ja3_dict)
840+
self.db.add_ja3_to_ioc(ja3_dict)
841841
return True
842842

843843
def parse_jarm_file(self, path):
@@ -901,7 +901,7 @@ def parse_jarm_file(self, path):
901901
"threat_level": threat_level,
902902
}
903903
)
904-
self.db.add_jarm_to_IoC(jarm_dict)
904+
self.db.add_jarm_to_ioc(jarm_dict)
905905
return True
906906

907907
def should_update_local_ti_file(self, path_to_local_ti_file: str) -> bool:
@@ -1206,7 +1206,7 @@ def ip_has_blacklisted_asn(
12061206
if not asn:
12071207
return
12081208

1209-
if asn_info := self.db.is_blacklisted_ASN(asn):
1209+
if asn_info := self.db.is_blacklisted_asn(asn):
12101210
asn_info = json.loads(asn_info)
12111211
self.set_evidence_malicious_asn(
12121212
ip,
@@ -1359,7 +1359,7 @@ def is_malicious_ip(
13591359
# not malicious
13601360
return False
13611361

1362-
self.db.add_ips_to_IoC({ip: json.dumps(ip_info)})
1362+
self.db.add_ips_to_ioc({ip: json.dumps(ip_info)})
13631363
if is_dns_response:
13641364
self.set_evidence_malicious_ip_in_dns_response(
13651365
ip,

modules/update_manager/update_manager.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def parse_ssl_feed(self, url, full_path):
569569
)
570570
continue
571571
# Add all loaded malicious sha1 to the database
572-
self.db.add_ssl_sha1_to_IoC(malicious_ssl_certs)
572+
self.db.add_ssl_sha1_to_ioc(malicious_ssl_certs)
573573
return True
574574

575575
async def update_TI_file(self, link_to_download: str) -> bool:
@@ -693,7 +693,7 @@ def update_riskiq_feed(self):
693693
"source": url,
694694
}
695695
)
696-
self.db.add_domains_to_IoC(malicious_domains_dict)
696+
self.db.add_domains_to_ioc(malicious_domains_dict)
697697
except KeyError:
698698
self.print(
699699
f'RiskIQ returned: {response["message"]}. Update Cancelled.',
@@ -852,7 +852,7 @@ def parse_ja3_feed(self, url, ja3_feed_path: str) -> bool:
852852
continue
853853

854854
# Add all loaded malicious ja3 to the database
855-
self.db.add_ja3_to_IoC(malicious_ja3_dict)
855+
self.db.add_ja3_to_ioc(malicious_ja3_dict)
856856
return True
857857

858858
except Exception:
@@ -895,7 +895,7 @@ def parse_json_ti_feed(self, link_to_download, ti_file_path: str) -> bool:
895895
}
896896
)
897897

898-
self.db.add_ips_to_IoC(malicious_ips_dict)
898+
self.db.add_ips_to_ioc(malicious_ips_dict)
899899
return True
900900

901901
if "hole.cert.pl" in link_to_download:
@@ -932,7 +932,7 @@ def parse_json_ti_feed(self, link_to_download, ti_file_path: str) -> bool:
932932
"tags": tags,
933933
}
934934
)
935-
self.db.add_domains_to_IoC(malicious_domains_dict)
935+
self.db.add_domains_to_ioc(malicious_domains_dict)
936936
return True
937937

938938
def get_description_column_index(self, header):
@@ -1386,9 +1386,9 @@ def parse_ti_feed(self, feed_link: str, ti_file_path: str) -> bool:
13861386
ti_file_name: str = ti_file_path.split("/")[-1]
13871387
handlers[data_type](ioc, ti_file_name, feed_link, description)
13881388

1389-
self.db.add_ips_to_IoC(self.malicious_ips_dict)
1390-
self.db.add_domains_to_IoC(self.malicious_domains_dict)
1391-
self.db.add_ip_range_to_IoC(self.malicious_ip_ranges)
1389+
self.db.add_ips_to_ioc(self.malicious_ips_dict)
1390+
self.db.add_domains_to_ioc(self.malicious_domains_dict)
1391+
self.db.add_ip_range_to_ioc(self.malicious_ip_ranges)
13921392
feed.close()
13931393
return True
13941394

0 commit comments

Comments
 (0)