comparison decrypt.py @ 0:fee51ab07d09

blanket publication of all existing python files in lib/python on maritain
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 09 Mar 2020 14:58:04 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fee51ab07d09
1 #!/usr/bin/env python
2 # decrypt tp-link config.bin file
3 # coded by root@kev7n.com
4
5 from Crypto.Cipher import DES
6 from hashlib import md5
7 import sys
8
9 # backup your config.bin from 192.168.x.1
10 # usage find PPPOE account
11 # ./run.py wan_ppp_usr
12 # keys: wan_ppp_usr,wan_ppp_pwd
13
14
15 key = '\x47\x8D\xA5\x0B\xF9\xE3\xD2\xCF'
16 crypto = DES.new(key, DES.MODE_ECB)
17
18 if len(sys.argv)>1:
19 f=sys.argv[1]
20 else:
21 f='conf.bin'
22
23 data = open(f, 'rb').read()
24 data_decrypted = crypto.decrypt(data).rstrip('\0')
25 assert data_decrypted[:16] == md5(data_decrypted[16:]).digest()
26 data_decrypted_finally = data_decrypted[16:]
27 data_decrypted_dict = {}
28 data_decrypted_array = data_decrypted_finally.split('\r\n')
29 for item in data_decrypted_array:
30 if not item:
31 continue
32 item_array = item.split(' ', 1)
33 item_key = item_array[0]
34 item_value = item_array[1]
35 data_decrypted_dict[item_key] = item_value
36
37 sys.stdout.write(data_decrypted_finally)