-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_call.py
67 lines (61 loc) · 2.11 KB
/
api_call.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
# coding: utf-8
import hashlib
import hmac
import json
import requests
import js2py
import texttable as tt
import sys
password = 'CHANGE ME'
def getChallenge():
r = s.get(url, headers=headers)
j = json.loads(r.text)
parts = j['result']['challenge']
password_salt = j['result']['password_salt']
challenge = ''
for letter in parts:
challenge += js2py.eval_js(letter)
return(password_salt, challenge)
def sendPassword(password_salt, challenge, password):
sha1 = hashlib.sha1((password_salt+password).encode('utf-8')).hexdigest()
if (sys.version_info > (3, 0)):
sha1 = bytes(sha1, 'utf-8')
challenge = bytes(challenge, 'utf-8')
mac = hmac.new(sha1, challenge, hashlib.sha1).hexdigest()
data = {"password": mac}
r = s.post(url, data=data, headers=headers)
return(r.status_code == 200)
def doWhatever():
base = 'http://mafreebox.freebox.fr/api/v6/'
apis = ['api_version', 'wifi/config/', 'connection/config/', 'system/', 'lcd/config', 'lan/config/']
for api in apis:
r = s.get(base+api, headers=headers)
j = json.loads(r.text)
tab = tt.Texttable()
title = ['API', api]
tab.header(title)
if api == 'api_version':
for key in j:
tab.add_row([key, j[key]])
else:
for key in j['result']:
tab.add_row([key, j['result'][key]])
print(tab.draw()+'\n')
def reboot():
r = s.post('http://mafreebox.freebox.fr/api/v6/system/reboot', headers=headers)
j = json.loads(r.text)
if j['success'] == True: print('Rebooting')
else: print('Reboot failed')
if __name__ == '__main__':
if password.encode('utf-8').hex() == '4348414e4745204d45':
print('Set your password on line 10')
s = requests.session()
url = 'http://mafreebox.freebox.fr/api/v6/login/'
headers = {'X-FBX-FREEBOX0S': '1', 'X-Requested-With': 'XMLHttpRequest'}
password_salt, challenge = getChallenge()
success = sendPassword(password_salt, challenge, password)
if success:
doWhatever()
#reboot()
else:
print('Failed')