Skip to content

Commit

Permalink
Dont check for Locations on local Ip's. (#3894)
Browse files Browse the repository at this point in the history
  • Loading branch information
underdarknl authored Dec 4, 2024
1 parent d3ef9a6 commit c3eb1ce
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion boefjes/boefjes/plugins/kat_maxmind_geoip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import tarfile
from datetime import datetime, timezone
from ipaddress import ip_address
from os import getenv
from pathlib import Path

Expand All @@ -25,8 +26,13 @@

def run(boefje_meta: BoefjeMeta) -> list[tuple[set, bytes | str]]:
input_ = boefje_meta.arguments["input"]
ip = input_["address"]
hash_algorithm = getenv("HASHFUNC", HASHFUNC)

# if the address is private, we do not need a Location
if not ip_address(ip).is_global:
return [(set(), json.dumps("IP address is private, no location possible"))]

if not geoip_file_exists() or cache_out_of_date():
geoip_meta = refresh_geoip(hash_algorithm)
else:
Expand All @@ -36,7 +42,7 @@ def run(boefje_meta: BoefjeMeta) -> list[tuple[set, bytes | str]]:
geoip_path = find_geoip_path()

with maxminddb.open_database(geoip_path) as reader:
results = reader.get(input_["address"])
results = reader.get(ip)

return [({"maxmind-geoip/geo_data"}, json.dumps(results)), ({"maxmind-geoip/cache-meta"}, json.dumps(geoip_meta))]

Expand Down

0 comments on commit c3eb1ce

Please sign in to comment.