-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
23 additions
and
508 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
import struct | ||
from socket import inet_aton | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from contextlib import suppress | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from base64 import b64encode, b64decode | ||
from contextlib import suppress | ||
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from contextlib import suppress | ||
from random import choice | ||
from tempfile import TemporaryDirectory | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
from __future__ import annotations | ||
|
||
import json | ||
|
@@ -36,7 +25,7 @@ | |
import psutil | ||
from OpenSSL import crypto | ||
from psutil import process_iter | ||
from psycopg2 import connect as psycopg2_connect, sql | ||
#from psycopg2 import connect as psycopg2_connect, sql | ||
|
||
|
||
def set_up_error_logging(): | ||
|
@@ -260,17 +249,17 @@ def __init__( # noqa: PLR0913 | |
self.logs = logs | ||
self.uuid = uuid | ||
self.custom_filter = custom_filter | ||
if config and "db_postgres" in self.logs: | ||
if config and "db_postgres_removed" in self.logs: | ||
parsed = urlparse(config["postgres"]) | ||
self.db["db_postgres"] = PostgresClass( | ||
host=parsed.hostname, | ||
port=parsed.port, | ||
username=parsed.username, | ||
password=parsed.password, | ||
db=parsed.path[1:], | ||
uuid=self.uuid, | ||
drop=drop, | ||
) | ||
#self.db["db_postgres"] = PostgresClass( | ||
# host=parsed.hostname, | ||
# port=parsed.port, | ||
# username=parsed.username, | ||
# password=parsed.password, | ||
# db=parsed.path[1:], | ||
# uuid=self.uuid, | ||
# drop=drop, | ||
#### | ||
if config and "db_sqlite" in self.logs: | ||
self.db["db_sqlite"] = SqliteClass( | ||
file=config["sqlite_file"], drop=drop, uuid=self.uuid | ||
|
@@ -314,136 +303,6 @@ def emit(self, record: LogRecord): # noqa: C901,PLR0912 | |
stdout.write(f"{json.dumps(log_entry, sort_keys=True, cls=ComplexEncoder)}\n") | ||
stdout.flush() | ||
|
||
|
||
class PostgresClass: | ||
def __init__( # noqa: PLR0913 | ||
self, | ||
host=None, | ||
port=None, | ||
username=None, | ||
password=None, | ||
db=None, | ||
drop=False, | ||
uuid=None, | ||
): | ||
self.host = host | ||
self.port = port | ||
self.username = username | ||
self.password = password | ||
self.db = db | ||
self.uuid = uuid | ||
self.mapped_tables = ["errors", "servers", "sniffer", "system"] | ||
self.wait_until_up() | ||
if drop: | ||
self.con = psycopg2_connect( | ||
host=self.host, | ||
port=self.port, | ||
user=self.username, | ||
password=self.password, | ||
) | ||
self.con.set_isolation_level(0) | ||
self.cur = self.con.cursor() | ||
self.drop_db() | ||
self.drop_tables() | ||
self.create_db() | ||
self.con.close() | ||
else: | ||
self.con = psycopg2_connect( | ||
host=self.host, | ||
port=self.port, | ||
user=self.username, | ||
password=self.password, | ||
) | ||
self.con.set_isolation_level(0) | ||
self.cur = self.con.cursor() | ||
if not self.check_db_if_exists(): | ||
self.create_db() | ||
self.con.close() | ||
self.con = psycopg2_connect( | ||
host=self.host, | ||
port=self.port, | ||
user=self.username, | ||
password=self.password, | ||
database=self.db, | ||
) | ||
self.con.set_isolation_level(0) | ||
self.con.set_client_encoding("UTF8") | ||
self.cur = self.con.cursor() | ||
self.create_tables() | ||
|
||
def wait_until_up(self): | ||
test = True | ||
while test: | ||
with suppress(Exception): | ||
logger.info(f"{self.uuid} - Waiting on postgres connection") | ||
stdout.flush() | ||
conn = psycopg2_connect( | ||
host=self.host, | ||
port=self.port, | ||
user=self.username, | ||
password=self.password, | ||
connect_timeout=1, | ||
) | ||
conn.close() | ||
test = False | ||
sleep(1) | ||
logger.info(f"{self.uuid} - postgres connection is good") | ||
|
||
def addattr(self, x, val): | ||
self.__dict__[x] = val | ||
|
||
def check_db_if_exists(self): | ||
exists = False | ||
with suppress(Exception): | ||
self.cur.execute( | ||
"SELECT exists(SELECT 1 from pg_catalog.pg_database where datname = %s)", | ||
(self.db,), | ||
) | ||
if self.cur.fetchone()[0]: | ||
exists = True | ||
return exists | ||
|
||
def drop_db(self): | ||
with suppress(Exception): | ||
logger.warning(f"Dropping {self.db} db") | ||
if self.check_db_if_exists(): | ||
self.cur.execute( | ||
sql.SQL("drop DATABASE IF EXISTS {}").format(sql.Identifier(self.db)) | ||
) | ||
sleep(2) | ||
self.cur.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(self.db))) | ||
|
||
def create_db(self): | ||
logger.info("Creating PostgreSQL database") | ||
self.cur.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(self.db))) | ||
|
||
def drop_tables( | ||
self, | ||
): | ||
for x in self.mapped_tables: | ||
self.cur.execute( | ||
sql.SQL("drop TABLE IF EXISTS {}").format(sql.Identifier(x + "_table")) | ||
) | ||
|
||
def create_tables(self): | ||
for table in self.mapped_tables: | ||
self.cur.execute( | ||
sql.SQL( | ||
"CREATE TABLE IF NOT EXISTS {} " | ||
"(id SERIAL NOT NULL,date timestamp with time zone DEFAULT now(),data json)" | ||
).format(sql.Identifier(table + "_table")) | ||
) | ||
|
||
def insert_into_data_safe(self, table, obj): | ||
with suppress(Exception): | ||
self.cur.execute( | ||
sql.SQL("INSERT INTO {} (id,date, data) VALUES (DEFAULT ,now(), %s)").format( | ||
sql.Identifier(table + "_table") | ||
), | ||
[obj], | ||
) | ||
|
||
|
||
class SqliteClass: | ||
def __init__(self, file=None, drop=False, uuid=None): | ||
self.file = file | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
from __future__ import annotations | ||
|
||
from contextlib import suppress | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from contextlib import suppress | ||
|
||
from twisted.internet import reactor | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from contextlib import suppress | ||
|
||
from twisted.internet import reactor, ssl | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from contextlib import suppress | ||
from random import choice | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
from __future__ import annotations | ||
|
||
from contextlib import suppress | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from contextlib import suppress | ||
|
||
from twisted.internet import reactor | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
from __future__ import annotations | ||
|
||
import struct | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
""" | ||
// ------------------------------------------------------------- | ||
// author Giga | ||
// project qeeqbox/honeypots | ||
// email [email protected] | ||
// description app.py (CLI) | ||
// licensee AGPL-3.0 | ||
// ------------------------------------------------------------- | ||
// contributors list qeeqbox/honeypots/graphs/contributors | ||
// ------------------------------------------------------------- | ||
""" | ||
|
||
from contextlib import suppress | ||
from random import randint, uniform | ||
from time import time | ||
|
Oops, something went wrong.