-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpybox3.py
executable file
·152 lines (124 loc) · 4.49 KB
/
pybox3.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
#!/data/data/com.termux/files/usr/bin/python2
### Python interface to some bbox3v user configuration tools
### Sebastien Blaise, 2016
### A file named "userPassword" should be created in the same directory, containing the User bbox3 password
### A file named "hostName" should be created in the same directory, containing the bbox3 password host name without http://
import hashlib
import re
import mechanize
import time
def login(host, user, pwd):
realm = "Technicolor Gateway";
qop = "auth"
uri = "/login.lp"
initPage = browser.open(host+"/login.lp")
for line in initPage.read().split('\n'):
if (line[0:9] == "var nonce"):
nonce = line[13:-3]
md5 = hashlib.md5()
md5.update(user + ":" + realm + ":" + pwd)
HA1 = md5.hexdigest()
md5 = hashlib.md5()
md5.update("GET" + ":" + uri)
HA2 = md5.hexdigest()
md5 = hashlib.md5()
md5.update(HA1 + ":" + nonce + ":" + "00000001" + ":" + "xyz" + ":" + qop + ":" + HA2)
hidepw = md5.hexdigest()
browser.select_form(name = "authform")
browser.form.find_control("hidepw").readonly = False
browser.form['hidepw'] = hidepw
browser.submit()
def antiCSRF(browser, cj):
browser.form.new_control('text','rn',{'value':''})
browser.form.fixup()
browser.form['rn'] = cj[0].value
def reboot(browser, cj):
browser.open(host+"/bbox-maintenance.lp")
browser.select_form(nr = 0)
antiCSRF(browser, cj)
browser.form.find_control("main_reboot").readonly = False
browser.form['main_reboot'] = "1"
browser.submit()
def switchVoice1(browser, cj, state):
browser.open(host+"/voice-line-1.lp")
browser.select_form(name = "voice1")
antiCSRF(browser, cj)
browser.form.find_control("voice1_enable").readonly = False
if (state):
browser.form['voice1_enable'] = "1"
else:
browser.form['voice1_enable'] = "0"
browser.submit()
def setVoice1Port(browser, cj, port):
browser.open(host+"/voice-line-1.lp")
browser.select_form(name = "voice1")
antiCSRF(browser, cj)
oldPort = browser.form['RSPort1']
browser.form['RSPort1'] = port
browser.submit()
return oldPort
def switchPPP(browser, cj, state):
browser.open(host+"/network-global.lp")
browser.select_form(name = "pppform")
antiCSRF(browser, cj)
browser.form.find_control("wan_net").readonly = False
if (state):
browser.form['wan_net'] = "1"
else:
browser.form['wan_net'] = "0"
browser.submit()
def stripHTML(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
def getIP(browser, cj, index):
page = browser.open(host+"/network-global.lp")
found = 0
remaining = 0
for line in page.read().split('\n'):
remaining -= 1
if (remaining == 0):
break
if "IPv4" in line:
found += 1
if (found == index+1):
remaining = 2
return stripHTML(line).strip()
def getInternetIP(browser, cj):
return getIP(browser, cj, 0)
def getVideoIP(browser, cj):
return getIP(browser, cj, 1)
def getVoiceIP(browser, cj):
return getIP(browser, cj, 2)
user = "User"
### Insert your User password in the "userPassword" file
with open('userPassword', 'r') as f:
pwd = f.readline()
### Insert your bbox3 hostname (without http://) in the "hostName" file
with open('hostName', 'r') as f:
host = "http://"+f.readline()
browser = mechanize.Browser()
browser.set_handle_robots(False)
browser.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
cj = mechanize.LWPCookieJar()
browser.set_cookiejar(cj)
logFile = open('/data/data/com.termux/files/home/pybox3/log','a+')
logFile.write("Connecting to "+host+"/login.lp\n")
login(host, user, pwd)
logFile.write(time.strftime("%d/%m/%Y\n"))
logFile.write(time.strftime("%H:%M:%S\n"))
logFile.write("Internet IP: %s\n"%getInternetIP(browser, cj))
logFile.write("Video IP: %s\n"%getVideoIP(browser, cj))
logFile.write("Voice IP: %s\n"%getVoiceIP(browser, cj))
#logFile.write("Rebooting bbox3\n")
#reboot(browser, cj)
logFile.write("Disconnecting ppp\n")
switchPPP(browser, cj, 0)
logFile.write("Reconnecting ppp\n")
switchPPP(browser, cj, 1)
#oldPort = setVoice1Port(browser, cj, "5070")
#goodPort = "5060"
#logFile.write("Switching sip port from %s to 5070\n"%oldPort)
#logFile.write("Switching (back?) sip port from %s to %s\n"%(setVoice1Port(browser, cj, goodPort), goodPort))
logFile.write("XXXXXXXXXXXXXXXXXXXXXXX\n")
logFile.close()
exit(0)