Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bafebae
user lowercase function names and move hardcoded key names to constan…
AlyaGomaa Nov 19, 2024
d13019e
user lowercase function names
AlyaGomaa Nov 19, 2024
4be77ef
move the rest of redis db constants to constants.py
AlyaGomaa Nov 19, 2024
113f490
fix Changing the database from the web interface
AlyaGomaa Nov 21, 2024
3953886
db: add a function to get_malicious_profiles() for the web interface
AlyaGomaa Nov 21, 2024
6f9d686
analysis.py: use the db manager instead of the web interface's own db
AlyaGomaa Nov 21, 2024
0530973
app.py: use the db manager instead of the web interface's own db
AlyaGomaa Nov 21, 2024
cdc123c
webinterface/database.py : use the database manager instead of initia…
AlyaGomaa Nov 21, 2024
61f4393
webinterface/general.py: use db manager instead of redis directly
AlyaGomaa Nov 21, 2024
8a1edfc
db: add wrappers to be used by the web interface
AlyaGomaa Nov 21, 2024
afa686f
redis_manager.py: return all info from running_slips_info.txt from ge…
AlyaGomaa Nov 21, 2024
256d2fb
webinterface/utils.py: add a function to parse all info from running_…
AlyaGomaa Nov 21, 2024
d01b028
web interface: fix problem changing the db using the button at the to…
AlyaGomaa Nov 25, 2024
a5cf318
analysis.py: refactor
AlyaGomaa Nov 25, 2024
61ff97b
user lowercase function names and move hardcoded key names to constan…
AlyaGomaa Nov 19, 2024
61fc347
user lowercase function names
AlyaGomaa Nov 19, 2024
25d99b9
move the rest of redis db constants to constants.py
AlyaGomaa Nov 19, 2024
4936df0
fix Changing the database from the web interface
AlyaGomaa Nov 21, 2024
43afbf5
db: add a function to get_malicious_profiles() for the web interface
AlyaGomaa Nov 21, 2024
05b52bc
analysis.py: use the db manager instead of the web interface's own db
AlyaGomaa Nov 21, 2024
e8d659c
app.py: use the db manager instead of the web interface's own db
AlyaGomaa Nov 21, 2024
a5badfe
webinterface/database.py : use the database manager instead of initia…
AlyaGomaa Nov 21, 2024
28092f2
webinterface/general.py: use db manager instead of redis directly
AlyaGomaa Nov 21, 2024
7221b8c
db: add wrappers to be used by the web interface
AlyaGomaa Nov 21, 2024
bbf5662
redis_manager.py: return all info from running_slips_info.txt from ge…
AlyaGomaa Nov 21, 2024
cf595bc
webinterface/utils.py: add a function to parse all info from running_…
AlyaGomaa Nov 21, 2024
1196b02
web interface: fix problem changing the db using the button at the to…
AlyaGomaa Nov 25, 2024
bcd2912
analysis.py: refactor
AlyaGomaa Nov 25, 2024
ab42907
ioc_handler: remove trailing-whitespace
AlyaGomaa Nov 25, 2024
b3632de
update cesnet unit tests to use latest db function names
AlyaGomaa Nov 25, 2024
195f995
fix getting the used redis port
AlyaGomaa Nov 25, 2024
86f81a5
module_factory.py: set alert handler constants
AlyaGomaa Nov 25, 2024
a5a0c13
test_redis_manager.py: update unit tests
AlyaGomaa Nov 25, 2024
014a1ca
test_database.py: hardcode redis server ports
AlyaGomaa Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion managers/metadata_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def update_slips_stats_in_the_db(self) -> Tuple[int, Set[str]]:
updates the number of processed ips, slips internal time,
and modified tws so far in the db
"""
slips_internal_time = float(self.main.db.getSlipsInternalTime()) + 1
slips_internal_time = float(self.main.db.get_slips_internal_time()) + 1

# Get the amount of modified profiles since we last checked
# this is the modification time of the last timewindow
Expand Down
36 changes: 29 additions & 7 deletions managers/redis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class RedisManager:
open_servers_pids: Dict[int, int]
open_servers_pids: Dict[int, dict]

def __init__(self, main):
self.main = main
Expand Down Expand Up @@ -240,19 +240,19 @@ def get_pid_of_redis_server(self, port: int) -> int:
return False

@staticmethod
def is_comment(line: str) -> True:
def is_comment(line: str) -> bool:
"""returns true if the given line is a comment"""
return (line.startswith("#") or line.startswith("Date")) or len(
line
) < 3

def get_open_redis_servers(self) -> Dict[int, int]:
def get_open_redis_servers(self) -> Dict[int, dict]:
"""
fills and returns self.open_servers_PIDs
with PIDs and ports of the redis servers started by slips
read from running_slips.info.txt
"""
self.open_servers_pids = {}
self.open_servers_pids: Dict[int, dict] = {}
try:
with open(self.running_logfile, "r") as f:
for line in f.read().splitlines():
Expand All @@ -263,8 +263,29 @@ def get_open_redis_servers(self) -> Dict[int, int]:
line = line.split(",")

try:
pid, port = int(line[3]), int(line[2])
self.open_servers_pids[pid] = port
(
timestamp,
file_or_interface,
port,
pid,
zeek_dir,
output_dir,
slips_pid,
is_daemon,
save_the_db,
) = line

self.open_servers_pids[pid] = {
"timestamp": timestamp,
"file_or_interface": file_or_interface,
"port": port,
"pid": pid,
"zeek_dir": zeek_dir,
"output_dir": output_dir,
"slips_pid": slips_pid,
"is_daemon": is_daemon,
"save_the_db": save_the_db,
}
except ValueError:
# sometimes slips can't get the server pid and logs "False"
# in the logfile instead of the PID
Expand Down Expand Up @@ -379,7 +400,8 @@ def flush_redis_server(self, pid: int = None, port: int = None):
if not hasattr(self, "open_servers_PIDs"):
self.get_open_redis_servers()

port: int = self.open_servers_pids.get(pid, False)
pid_info: Dict[str, str] = self.open_servers_pids.get(pid, {})
port: int = pid_info.get("port", False)
if not port:
# try to get the port using a cmd
port: int = self.get_port_of_redis_server(pid)
Expand Down
2 changes: 1 addition & 1 deletion modules/cesnet/cesnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def import_alerts(self):

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

self.db.add_ips_to_IoC(src_ips)
self.db.add_ips_to_ioc(src_ips)

def pre_main(self):
utils.drop_root_privs()
Expand Down
2 changes: 1 addition & 1 deletion modules/flowalerts/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def check_multiple_reconnection_attempts(self, profileid, twid, flow):
# reset the reconnection attempts of this src->dst
current_reconnections[key] = (0, [])

self.db.setReconnections(profileid, twid, current_reconnections)
self.db.set_reconnections(profileid, twid, current_reconnections)

def is_ignored_ip_data_upload(self, ip):
"""
Expand Down
20 changes: 10 additions & 10 deletions modules/threat_intelligence/threat_intelligence.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,11 @@ def parse_local_ti_file(self, ti_file_path: str) -> bool:
)

# Add all loaded malicious ips to the database
self.db.add_ips_to_IoC(malicious_ips)
self.db.add_ips_to_ioc(malicious_ips)
# Add all loaded malicious domains to the database
self.db.add_domains_to_IoC(malicious_domains)
self.db.add_ip_range_to_IoC(malicious_ip_ranges)
self.db.add_asn_to_IoC(malicious_asns)
self.db.add_domains_to_ioc(malicious_domains)
self.db.add_ip_range_to_ioc(malicious_ip_ranges)
self.db.add_asn_to_ioc(malicious_asns)
return True

def __delete_old_source_ips(self, file):
Expand All @@ -724,7 +724,7 @@ def __delete_old_source_ips(self, file):
if data["source"] == file:
old_data.append(ip)
if old_data:
self.db.delete_ips_from_IoC_ips(old_data)
self.db.delete_ips_from_ioc_ips(old_data)

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

def __delete_old_source_data_from_database(self, data_file):
"""Deletes old indicators of compromise (IoCs) associated with a specific source
Expand Down Expand Up @@ -837,7 +837,7 @@ def parse_ja3_file(self, path):
}
)
# Add all loaded JA3 to the database
self.db.add_ja3_to_IoC(ja3_dict)
self.db.add_ja3_to_ioc(ja3_dict)
return True

def parse_jarm_file(self, path):
Expand Down Expand Up @@ -901,7 +901,7 @@ def parse_jarm_file(self, path):
"threat_level": threat_level,
}
)
self.db.add_jarm_to_IoC(jarm_dict)
self.db.add_jarm_to_ioc(jarm_dict)
return True

def should_update_local_ti_file(self, path_to_local_ti_file: str) -> bool:
Expand Down Expand Up @@ -1206,7 +1206,7 @@ def ip_has_blacklisted_asn(
if not asn:
return

if asn_info := self.db.is_blacklisted_ASN(asn):
if asn_info := self.db.is_blacklisted_asn(asn):
asn_info = json.loads(asn_info)
self.set_evidence_malicious_asn(
ip,
Expand Down Expand Up @@ -1359,7 +1359,7 @@ def is_malicious_ip(
# not malicious
return False

self.db.add_ips_to_IoC({ip: json.dumps(ip_info)})
self.db.add_ips_to_ioc({ip: json.dumps(ip_info)})
if is_dns_response:
self.set_evidence_malicious_ip_in_dns_response(
ip,
Expand Down
16 changes: 8 additions & 8 deletions modules/update_manager/update_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def parse_ssl_feed(self, url, full_path):
)
continue
# Add all loaded malicious sha1 to the database
self.db.add_ssl_sha1_to_IoC(malicious_ssl_certs)
self.db.add_ssl_sha1_to_ioc(malicious_ssl_certs)
return True

async def update_TI_file(self, link_to_download: str) -> bool:
Expand Down Expand Up @@ -693,7 +693,7 @@ def update_riskiq_feed(self):
"source": url,
}
)
self.db.add_domains_to_IoC(malicious_domains_dict)
self.db.add_domains_to_ioc(malicious_domains_dict)
except KeyError:
self.print(
f'RiskIQ returned: {response["message"]}. Update Cancelled.',
Expand Down Expand Up @@ -852,7 +852,7 @@ def parse_ja3_feed(self, url, ja3_feed_path: str) -> bool:
continue

# Add all loaded malicious ja3 to the database
self.db.add_ja3_to_IoC(malicious_ja3_dict)
self.db.add_ja3_to_ioc(malicious_ja3_dict)
return True

except Exception:
Expand Down Expand Up @@ -895,7 +895,7 @@ def parse_json_ti_feed(self, link_to_download, ti_file_path: str) -> bool:
}
)

self.db.add_ips_to_IoC(malicious_ips_dict)
self.db.add_ips_to_ioc(malicious_ips_dict)
return True

if "hole.cert.pl" in link_to_download:
Expand Down Expand Up @@ -932,7 +932,7 @@ def parse_json_ti_feed(self, link_to_download, ti_file_path: str) -> bool:
"tags": tags,
}
)
self.db.add_domains_to_IoC(malicious_domains_dict)
self.db.add_domains_to_ioc(malicious_domains_dict)
return True

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

self.db.add_ips_to_IoC(self.malicious_ips_dict)
self.db.add_domains_to_IoC(self.malicious_domains_dict)
self.db.add_ip_range_to_IoC(self.malicious_ip_ranges)
self.db.add_ips_to_ioc(self.malicious_ips_dict)
self.db.add_domains_to_ioc(self.malicious_domains_dict)
self.db.add_ip_range_to_ioc(self.malicious_ip_ranges)
feed.close()
return True

Expand Down
Loading
Loading