Last active
April 13, 2022 16:25
-
-
Save adcar/26b1c6f0477dd52e5966015e3943a197 to your computer and use it in GitHub Desktop.
athena
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import psycopg2 | |
| import json | |
| import re | |
| # head -n -1 output.json > output.fixed.json | |
| # tail -n +2 output.fixed.json > fixed.json | |
| DATA_LOCATION = "results.cringe.large" | |
| conn = psycopg2.connect(dbname="athena", user="alex", password="yoloswag", host="localhost", port="5432") | |
| conn.set_client_encoding('UTF8') | |
| cur = conn.cursor() | |
| counter = 0 | |
| def get_banner(port_obj): | |
| if "service" in port_obj: | |
| if "banner" in port_obj["service"]: | |
| banner = port_obj["service"]["banner"] | |
| banner = banner[:2046] | |
| return re.sub(u'\x00', '', banner) | |
| return None | |
| with open(DATA_LOCATION) as f: | |
| for line in f: | |
| counter += 1 | |
| print('Iteration: %d' | |
| + | |
| format(counter, ",d")) | |
| host = json.loads(line) | |
| ip = host["ip"] | |
| banner = None | |
| port = 0 # Should always be overridden. If I find a zero in the DB there was some kind of error. | |
| for portObj in host["ports"]: | |
| banner = get_banner(portObj) | |
| port = portObj["port"] | |
| cur.execute( | |
| "INSERT INTO internet (ip, port, banner) " | |
| "VALUES (%s, %s, %s)", | |
| (ip, port, banner)) | |
| conn.commit() | |
| cur.close() | |
| conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment