2018-07-23 08:55:15 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import datetime, time
|
|
|
|
import sqlite3
|
|
|
|
from sqlite3 import Error
|
2019-02-11 21:00:56 +00:00
|
|
|
from Config import Database
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def initializedb():
|
|
|
|
create_implants = """CREATE TABLE IF NOT EXISTS Implants (
|
|
|
|
ImplantID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
|
|
|
RandomURI VARCHAR(20),
|
|
|
|
User TEXT,
|
|
|
|
Hostname TEXT,
|
|
|
|
IpAddress TEXT,
|
|
|
|
Key TEXT,
|
|
|
|
FirstSeen TEXT,
|
|
|
|
LastSeen TEXT,
|
|
|
|
PID TEXT,
|
|
|
|
Proxy TEXT,
|
|
|
|
Arch TEXT,
|
|
|
|
Domain TEXT,
|
|
|
|
Alive TEXT,
|
|
|
|
Sleep TEXT,
|
|
|
|
ModsLoaded TEXT,
|
2018-12-31 11:15:13 +00:00
|
|
|
Pivot TEXT,
|
|
|
|
Label TEXT);"""
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
create_autoruns = """CREATE TABLE AutoRuns (
|
|
|
|
TaskID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
|
|
|
Task TEXT);"""
|
|
|
|
|
2019-02-06 16:11:18 +00:00
|
|
|
create_tasks = """CREATE TABLE Tasks (
|
|
|
|
TaskID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
2018-07-23 08:55:15 +00:00
|
|
|
RandomURI TEXT,
|
|
|
|
Command TEXT,
|
|
|
|
Output TEXT,
|
2019-02-06 16:11:18 +00:00
|
|
|
User TEXT,
|
|
|
|
SentTime TEXT,
|
2019-02-12 11:21:26 +00:00
|
|
|
CompletedTime TEXT,
|
|
|
|
ImplantID INTEGER,
|
|
|
|
FOREIGN KEY(ImplantID) REFERENCES Implants(ImplantID))"""
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2019-02-06 16:11:18 +00:00
|
|
|
create_newtasks = """CREATE TABLE NewTasks (
|
2018-07-23 08:55:15 +00:00
|
|
|
TaskID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
|
|
|
RandomURI TEXT,
|
2019-02-11 17:05:14 +00:00
|
|
|
Command TEXT,
|
|
|
|
User TEXT);"""
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2018-10-10 07:16:32 +00:00
|
|
|
create_urls = """CREATE TABLE URLs (
|
|
|
|
URLID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
|
|
|
RandomID TEXT,
|
|
|
|
URL TEXT,
|
2019-02-20 16:11:27 +00:00
|
|
|
HostHeader TEXT,
|
2018-10-10 07:16:32 +00:00
|
|
|
ProxyURL TEXT,
|
|
|
|
ProxyUsername TEXT,
|
|
|
|
ProxyPassword TEXT,
|
2019-03-12 20:33:45 +00:00
|
|
|
CredentialExpiry TEXT);"""
|
2018-10-10 07:16:32 +00:00
|
|
|
|
2018-07-23 08:55:15 +00:00
|
|
|
create_creds = """CREATE TABLE Creds (
|
|
|
|
credsID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
|
|
|
Username TEXT,
|
|
|
|
Password TEXT,
|
|
|
|
Hash TEXT);"""
|
|
|
|
|
|
|
|
create_c2server = """CREATE TABLE C2Server (
|
|
|
|
ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
|
|
|
HostnameIP TEXT,
|
|
|
|
EncKey TEXT,
|
|
|
|
DomainFrontHeader TEXT,
|
|
|
|
DefaultSleep TEXT,
|
|
|
|
KillDate TEXT,
|
|
|
|
HTTPResponse TEXT,
|
|
|
|
FolderPath TEXT,
|
|
|
|
ServerPort TEXT,
|
|
|
|
QuickCommand TEXT,
|
|
|
|
DownloadURI TEXT,
|
|
|
|
ProxyURL TEXT,
|
|
|
|
ProxyUser TEXT,
|
|
|
|
ProxyPass TEXT,
|
|
|
|
Sounds TEXT,
|
|
|
|
APIKEY TEXT,
|
|
|
|
MobileNumber TEXT,
|
|
|
|
URLS TEXT,
|
|
|
|
SocksURLS TEXT,
|
|
|
|
Insecure TEXT,
|
|
|
|
UserAgent TEXT,
|
2019-03-11 19:43:29 +00:00
|
|
|
Referrer TEXT,
|
2018-09-07 11:03:57 +00:00
|
|
|
APIToken TEXT,
|
|
|
|
APIUser TEXT,
|
2019-02-20 16:11:27 +00:00
|
|
|
EnableNotifications TEXT);"""
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
create_history = """CREATE TABLE History (
|
|
|
|
ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
2019-02-20 16:11:27 +00:00
|
|
|
Command TEXT);"""
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
if conn is not None:
|
|
|
|
c.execute(create_implants)
|
|
|
|
c.execute(create_autoruns)
|
|
|
|
c.execute(create_tasks)
|
2019-02-06 16:11:18 +00:00
|
|
|
c.execute(create_newtasks)
|
2018-07-23 08:55:15 +00:00
|
|
|
c.execute(create_creds)
|
2018-10-10 07:16:32 +00:00
|
|
|
c.execute(create_urls)
|
2018-07-23 08:55:15 +00:00
|
|
|
c.execute(create_c2server)
|
|
|
|
c.execute(create_history)
|
|
|
|
conn.commit()
|
|
|
|
else:
|
|
|
|
print("Error! cannot create the database connection.")
|
|
|
|
|
2019-03-11 19:43:29 +00:00
|
|
|
def setupserver(HostnameIP,EncKey,DomainFrontHeader,DefaultSleep,KillDate,HTTPResponse,FolderPath,ServerPort,QuickCommand,DownloadURI,ProxyURL,ProxyUser,ProxyPass,Sounds,APIKEY,MobileNumber,URLS,SocksURLS,Insecure,UserAgent,Referrer,APIToken,APIUser,EnableNotifications):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
c = conn.cursor()
|
2019-03-11 19:43:29 +00:00
|
|
|
c.execute("INSERT INTO C2Server (HostnameIP,EncKey,DomainFrontHeader,DefaultSleep,KillDate,HTTPResponse,FolderPath,ServerPort,QuickCommand,DownloadURI,ProxyURL,ProxyUser,ProxyPass,Sounds,APIKEY,MobileNumber,URLS,SocksURLS,Insecure,UserAgent,Referrer,APIToken,APIUser,EnableNotifications) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",(HostnameIP,EncKey,DomainFrontHeader,DefaultSleep,KillDate,HTTPResponse,FolderPath,ServerPort,QuickCommand,DownloadURI,ProxyURL,ProxyUser,ProxyPass,Sounds,APIKEY,MobileNumber,URLS,SocksURLS,Insecure,UserAgent,Referrer,APIToken,APIUser,EnableNotifications))
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
def get_c2server_all():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM C2Server")
|
|
|
|
result = c.fetchone()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_implants_all():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM Implants")
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-02-11 17:05:14 +00:00
|
|
|
def get_newtasks_all():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM NewTasks")
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def new_urldetails(RandomID, URL, HostHeader, ProxyURL, ProxyUsername, ProxyPassword, CredentialExpiry):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-10-10 07:16:32 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("INSERT INTO URLs (RandomID, URL, HostHeader, ProxyURL, ProxyUsername, ProxyPassword, CredentialExpiry) VALUES (?, ?, ?, ?, ?, ?, ?)",(RandomID, URL, HostHeader, ProxyURL, ProxyUsername, ProxyPassword, CredentialExpiry))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-02-11 17:05:14 +00:00
|
|
|
def drop_newtasks():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("DELETE FROM NewTasks ")
|
|
|
|
conn.commit()
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def new_task(task, user, randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
c = conn.cursor()
|
2019-02-11 17:05:14 +00:00
|
|
|
c.execute("INSERT INTO NewTasks (RandomURI, Command, User) VALUES (?, ?, ?)",(randomuri, task, user))
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
def get_lastcommand():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM History ORDER BY ID DESC LIMIT 1")
|
|
|
|
try:
|
|
|
|
result = c.fetchone()[1]
|
|
|
|
except Exception as e:
|
|
|
|
result = None
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def new_commandhistory(command):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("INSERT INTO History (Command) VALUES (?)",(command,))
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
def get_history_dict():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM History")
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def get_history():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM History")
|
|
|
|
result = c.fetchall()
|
|
|
|
history = ""
|
|
|
|
for command in result:
|
|
|
|
history = "%s \r\n %s" % (history, command[1])
|
|
|
|
history = "%s \r\n" % (history)
|
|
|
|
if history:
|
|
|
|
return history
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def get_implants():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM Implants WHERE Alive='Yes'")
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def get_implanttype(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT Pivot FROM Implants WHERE RandomURI=?",(randomuri,))
|
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def get_implantdetails(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM Implants WHERE RandomURI=?",(randomuri,))
|
|
|
|
result = c.fetchone()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def get_hostdetails(implant_id):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM Implants WHERE ImplantID=?",(implant_id,))
|
|
|
|
result = c.fetchone()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def get_randomuri(implant_id):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT RandomURI FROM Implants WHERE ImplantID=?",(implant_id,))
|
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def add_autorun(Task):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("INSERT INTO AutoRuns (Task) VALUES (?)", (Task,))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def update_sleep(sleep, randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("UPDATE Implants SET Sleep=? WHERE RandomURI=?",(sleep, randomuri))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def update_label(label, randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-12-31 11:15:13 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("UPDATE Implants SET Label=? WHERE RandomURI=?",(label, randomuri))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def update_mods(modules, randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("UPDATE Implants SET ModsLoaded=? WHERE RandomURI=?",(modules, randomuri))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def kill_implant(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("UPDATE Implants SET Alive='No' WHERE RandomURI=?",(randomuri,))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def unhide_implant(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("UPDATE Implants SET Alive='Yes' WHERE RandomURI=?",(randomuri,))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-03-12 20:33:45 +00:00
|
|
|
def select_mods(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT ModsLoaded FROM Implants WHERE RandomURI=?", (randomuri,))
|
2019-02-20 16:11:27 +00:00
|
|
|
result = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def select_item(column, table):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT %s FROM %s" % (column, table))
|
2019-02-20 16:11:27 +00:00
|
|
|
result = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def del_newtasks(TaskID):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("DELETE FROM NewTasks WHERE TaskID=?", (TaskID,))
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
def del_autorun(TaskID):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("DELETE FROM AutoRuns WHERE TaskID=?", (TaskID,))
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
def del_autoruns():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("DELETE FROM AutoRuns ")
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
def update_implant_lastseen(time, randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("UPDATE Implants SET LastSeen=? WHERE RandomURI=?", (time,randomuri))
|
|
|
|
conn.commit()
|
|
|
|
|
2018-12-31 11:15:13 +00:00
|
|
|
def new_implant(RandomURI, User, Hostname, IpAddress, Key, FirstSeen, LastSeen, PID, Proxy, Arch, Domain, Alive, Sleep, ModsLoaded, Pivot, Label):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2018-12-31 11:15:13 +00:00
|
|
|
c.execute("INSERT INTO Implants (RandomURI, User, Hostname, IpAddress, Key, FirstSeen, LastSeen, PID, Proxy, Arch, Domain, Alive, Sleep, ModsLoaded, Pivot, Label) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (RandomURI, User, Hostname, IpAddress, Key, FirstSeen, LastSeen, PID, Proxy, Arch, Domain, Alive, Sleep, ModsLoaded, Pivot, Label))
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.commit()
|
2019-02-20 16:11:27 +00:00
|
|
|
return c.lastrowid
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2019-02-06 16:11:18 +00:00
|
|
|
def insert_task(randomuri, command, user):
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
sent_time = now.strftime("%m/%d/%Y %H:%M:%S")
|
2019-02-12 11:21:26 +00:00
|
|
|
implantId = get_implantbyrandomuri(randomuri)[0]
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2019-02-06 16:11:18 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
if user is None:
|
|
|
|
user = ""
|
2019-02-12 11:21:26 +00:00
|
|
|
c.execute("INSERT INTO Tasks (RandomURI, Command, Output, User, SentTime, CompletedTime, ImplantID) VALUES (?, ?, ?, ?, ?, ?, ?)", (randomuri, command, "", user, sent_time, "", implantId))
|
2019-02-06 16:11:18 +00:00
|
|
|
conn.commit()
|
|
|
|
return c.lastrowid
|
|
|
|
|
|
|
|
def update_task(taskId, output):
|
2018-07-23 08:55:15 +00:00
|
|
|
now = datetime.datetime.now()
|
2019-02-06 16:11:18 +00:00
|
|
|
completedTime = now.strftime("%m/%d/%Y %H:%M:%S")
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.text_factory = str
|
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2019-02-11 17:19:54 +00:00
|
|
|
c.execute("UPDATE Tasks SET Output=?, CompletedTime=? WHERE TaskID=?", (output, completedTime, taskId))
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.commit()
|
2019-02-06 16:11:18 +00:00
|
|
|
return c.lastrowid
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2019-02-13 13:12:27 +00:00
|
|
|
def get_task_owner(taskId):
|
|
|
|
conn = sqlite3.connect(Database)
|
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT User FROM Tasks WHERE TaskID=?", (taskId,))
|
|
|
|
result = c.fetchone()
|
|
|
|
if result and result[0] != "":
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2018-07-23 08:55:15 +00:00
|
|
|
def update_item(column, table, value, wherecolumn=None, where=None):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
if wherecolumn is None:
|
|
|
|
c.execute("UPDATE %s SET %s=?" % (table,column), (value,))
|
|
|
|
else:
|
|
|
|
c.execute("UPDATE %s SET %s=? WHERE %s=?" % (table,column,wherecolumn), (value, where))
|
|
|
|
conn.commit()
|
|
|
|
|
2019-02-11 21:24:06 +00:00
|
|
|
def get_implantbyid(implantId):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2019-02-11 21:24:06 +00:00
|
|
|
c.execute("SELECT * FROM Implants WHERE ImplantID=?", (implantId,))
|
2018-07-23 08:55:15 +00:00
|
|
|
result = c.fetchone()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-02-12 11:21:26 +00:00
|
|
|
def get_implantbyrandomuri(RandomURI):
|
|
|
|
conn = sqlite3.connect(Database)
|
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM Implants WHERE RandomURI=?", (RandomURI,))
|
|
|
|
result = c.fetchone()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-02-06 16:11:18 +00:00
|
|
|
def get_tasks():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2019-02-06 16:11:18 +00:00
|
|
|
c.execute("SELECT * FROM Tasks")
|
2018-07-23 08:55:15 +00:00
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-02-11 21:24:06 +00:00
|
|
|
def get_tasksbyid(implantId):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2019-02-11 21:24:06 +00:00
|
|
|
c.execute("SELECT * FROM Tasks WHERE CompletedTaskID=?", (implantId,))
|
2018-07-23 08:55:15 +00:00
|
|
|
result = c.fetchone()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_newtasksbyid(taskid):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2019-02-11 21:24:06 +00:00
|
|
|
c.execute("SELECT * FROM NewTasks WHERE TaskID=?", (taskid,))
|
2018-07-23 08:55:15 +00:00
|
|
|
result = c.fetchone()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_seqcount(table):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2019-02-11 21:24:06 +00:00
|
|
|
c.execute("SELECT seq FROM sqlite_sequence WHERE name=\"?\"", (table,))
|
2018-07-23 08:55:15 +00:00
|
|
|
result = int(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_baseenckey():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT EncKey FROM C2Server")
|
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2018-08-14 20:17:54 +00:00
|
|
|
def get_dfheader():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-08-14 20:17:54 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT DomainFrontHeader FROM C2Server")
|
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-02-06 16:11:18 +00:00
|
|
|
def get_cmd_from_task_id(taskId):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2019-02-06 16:11:18 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
2019-02-11 21:24:06 +00:00
|
|
|
c.execute("SELECT Command FROM Tasks WHERE TaskId=?", (taskId,))
|
2019-02-06 16:11:18 +00:00
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2018-07-23 08:55:15 +00:00
|
|
|
def get_defaultuseragent():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT UserAgent FROM C2Server")
|
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_defaultbeacon():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT DefaultSleep FROM C2Server")
|
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_killdate():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT KillDate FROM C2Server")
|
|
|
|
result = str(c.fetchone()[0])
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_sharpurls():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT SocksURLS FROM C2Server")
|
2019-02-20 16:11:27 +00:00
|
|
|
result = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_allurls():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT URLS FROM C2Server")
|
2019-02-20 16:11:27 +00:00
|
|
|
result1 = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
c.execute("SELECT SocksURLS FROM C2Server")
|
2019-02-20 16:11:27 +00:00
|
|
|
result2 = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
result = result1+","+result2
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_beaconurl():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT URLS FROM C2Server")
|
2019-02-20 16:11:27 +00:00
|
|
|
result = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
if result:
|
|
|
|
url = result.split(",")
|
|
|
|
return url[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_otherbeaconurls():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT URLS FROM C2Server")
|
2019-02-20 16:11:27 +00:00
|
|
|
result = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_newimplanturl():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT URLS FROM C2Server")
|
2019-02-20 16:11:27 +00:00
|
|
|
result = str(c.fetchone()[0])
|
2018-07-23 08:55:15 +00:00
|
|
|
if result:
|
|
|
|
url = result.split(",")
|
|
|
|
return "/"+url[0].replace('"', '')
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_hostinfo(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM Implants WHERE RandomURI=?", (randomuri,))
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
2018-10-10 07:16:32 +00:00
|
|
|
def get_c2urls():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-10-10 07:16:32 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM URLs")
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-10-10 07:16:32 +00:00
|
|
|
|
2018-07-23 08:55:15 +00:00
|
|
|
def get_autoruns():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM AutoRuns")
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def get_autorun():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM AutoRuns")
|
|
|
|
result = c.fetchall()
|
|
|
|
autoruns = ""
|
|
|
|
for autorun in result:
|
|
|
|
autoruns += "%s:%s\r\n" % (autorun[0],autorun[1])
|
|
|
|
if autoruns:
|
|
|
|
return autoruns
|
|
|
|
else:
|
2019-02-20 16:11:27 +00:00
|
|
|
return None
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def get_pid(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT PID FROM Implants WHERE RandomURI=?", (randomuri,))
|
|
|
|
result = c.fetchone()[0]
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_newtasks(randomuri):
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2018-07-23 08:55:15 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM NewTasks WHERE RandomURI=?", (randomuri,))
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
2019-01-02 21:10:01 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def get_keys():
|
2019-02-11 21:00:56 +00:00
|
|
|
conn = sqlite3.connect(Database)
|
2019-01-02 21:10:01 +00:00
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
c = conn.cursor()
|
|
|
|
result = c.execute("SELECT EncKey FROM C2Server")
|
|
|
|
result = c.fetchall()
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|