Skip to content

Commit 32a18ab

Browse files
committed
refactor
1 parent 4c6b2bd commit 32a18ab

File tree

2 files changed

+63
-55
lines changed

2 files changed

+63
-55
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# ENV
2+
3+
```
4+
python3 -m venv .venv
5+
source ./.venv/bin/activate
6+
pip install -r requirements.txt
7+
```
8+
19
# zte_factroymode.py
210

311
open telnet(use embed user/pass to 192.168.1.1 80):
@@ -9,7 +17,7 @@ or custom args
917
`python3 zte_factroymode.py --user CUAdmin --pass CUAdmin -- 192.168.1.1 80 telnet open`
1018

1119
```shell
12-
$ python3 zte_factroymode.py -h
20+
$ python3 zte_factroymode.py -h
1321
usage: zte_factroymode [-h] [--user USER [USER ...]] [--pass PASS [PASS ...]] [ip] [port] {telnet,serial} ...
1422

1523
positional arguments:
@@ -38,6 +46,7 @@ https://github.com/douniwan5788/zte_modem_tools
3846
# zte_hardcode_dump.py
3947
4048
decrypt /etc/hardcodefile
49+
4150
`./zte_hardcode_dump.py test/hardcode test/hardcodefile/*`
4251
4352
```shell

zte_factroymode.py

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def sendInfo(self):
114114
try:
115115
resp = self.S.post(f"http://{self.ip}:{self.port}/webFacEntry",
116116
data=self.chiper.encrypt(pad(f'SendInfo.gch?info=6|'.encode(), 16)))
117-
print(resp.status_code, repr(resp.text))
117+
# print(resp.status_code, repr(resp.text))
118118
if resp.status_code == 200:
119119
return True
120120
elif resp.status_code == 400:
@@ -136,6 +136,7 @@ def checkLoginAuth(self):
136136
# print(repr(resp.text))
137137
if resp.status_code == 200:
138138
# checkLoginAuth use wrong function strlen to calc response size, so we may need to pad ciphertext first
139+
# but ciphertext can still be truncated prematurely,resulting in undecryptable data
139140
ciphertext = resp.content
140141
# print(len(ciphertext))
141142
if len(ciphertext) % 16:
@@ -165,7 +166,7 @@ def serialSlience(self, action):
165166
data=self.chiper.encrypt(
166167
pad(f'SerialSlience.gch?action={action}'.encode(), 16)
167168
))
168-
print(repr(resp.text))
169+
# print(repr(resp.text))
169170
if resp.status_code == 200:
170171
return True
171172
elif resp.status_code == 400:
@@ -191,7 +192,7 @@ def factoryMode(self, action):
191192
resp = self.S.post(
192193
f"http://{self.ip}:{self.port}/webFacEntry",
193194
data=self.chiper.encrypt(
194-
pad(f'FactoryMode.gch?mode=2&user=notused'.encode(), 16)
195+
pad('FactoryMode.gch?mode=2&user=notused'.encode(), 16)
195196
))
196197
# print(repr(resp.text))
197198
if resp.status_code == 200:
@@ -210,73 +211,71 @@ def factoryMode(self, action):
210211
return False
211212

212213

213-
def dealSerial(ip, port, users, pws, action):
214+
def dealFacAuth(Class: WebFac, ip, port, users, pws):
214215
for user in users:
215216
for pw in pws:
216-
serial = WebFacSerial(ip, port, user, pw)
217+
print(f"trying user:\"{user}\" pass:\"{pw}\" ")
218+
webfac = Class(ip, port, user, pw)
217219
print("reset facTelnetSteps:")
218-
if serial.reset():
219-
print("reset OK")
220+
if webfac.reset():
221+
print("reset OK!\n")
220222

221-
print("\nfacStep 1:")
222-
serial.requestFactoryMode()
223+
print("facStep 1:")
224+
webfac.requestFactoryMode()
225+
print("OK!\n")
223226

224-
print("\nfacStep 2:")
225-
version = serial.sendSq()
227+
print("facStep 2:")
228+
version = webfac.sendSq()
229+
print("OK!\n")
226230

227231
if version == 1:
228-
print("\nfacStep 3:")
229-
serial.checkLoginAuth()
232+
print("facStep 3:")
233+
print("OK!\n")
234+
if webfac.checkLoginAuth():
235+
print("facStep 4:")
236+
print("OK!\n")
230237
elif version == 2:
231-
print("\nfacStep 3:")
232-
if not serial.sendInfo():
238+
print("facStep 3:")
239+
if not webfac.sendInfo():
233240
print("sendInfo error")
234241
return
235-
print("\nfacStep 4:")
236-
serial.checkLoginAuth()
242+
print("OK!\n")
237243

238-
print("\nfacStep 5:")
239-
serial.serialSlience(action)
244+
print("facStep 4:")
245+
url = webfac.checkLoginAuth()
246+
if not url:
247+
print("try next...\n")
248+
continue
249+
print("OK!\n")
250+
print(repr(url))
251+
return webfac
252+
return False
240253

241254

242-
def dealTelnet(ip, port, users, pws, action):
243-
for user in users:
244-
for pw in pws:
245-
print(f"trying user:\"{user}\" pass:\"{pw}\" ")
246-
telnet = WebFacTelnet(ip, port, user, pw)
247-
print("reset facTelnetSteps:")
248-
if telnet.reset():
249-
print("reset OK")
255+
def dealSerial(ip, port, users, pws, action):
256+
serial = dealFacAuth(WebFacSerial, ip, port, users, pws)
257+
if not serial:
258+
return
250259

251-
print("\nfacStep 1:")
252-
telnet.requestFactoryMode()
260+
print("facStep 5:")
261+
if serial.serialSlience(action):
262+
print("OK!\n")
263+
print('done')
264+
return
253265

254-
print("\nfacStep 2:")
255-
version = telnet.sendSq()
256266

257-
if version == 1:
258-
print("\nfacStep 3:")
259-
if telnet.checkLoginAuth():
260-
print("\nfacStep 4:")
261-
elif version == 2:
262-
print("\nfacStep 3:")
263-
if not telnet.sendInfo():
264-
print("sendInfo error")
265-
return
266-
print("\nfacStep 4:")
267-
url = telnet.checkLoginAuth()
268-
if not url:
269-
print("try next...\n")
270-
continue
271-
print(repr(url))
272-
else:
273-
pass
267+
def dealTelnet(ip, port, users, pws, action):
268+
telnet = dealFacAuth(WebFacTelnet, ip, port, users, pws)
269+
if not telnet:
270+
return
274271

275-
print("\nfacStep 5:")
276-
url = telnet.factoryMode(action)
277-
if url:
278-
print(repr(url))
279-
return
272+
print("facStep 5:")
273+
url = telnet.factoryMode(action)
274+
if url:
275+
print("OK!\n")
276+
print(repr(url))
277+
print('done')
278+
return
280279

281280

282281
def parseArgs():
@@ -289,7 +288,7 @@ def parseArgs():
289288
"user", "admin", "cuadmin", "lnadmin", "useradmin"])
290289
parser.add_argument('--pass', '-p', metavar='PASS', dest='pw', nargs='+', help='factorymode auth password', default=[
291290
'nE%jA@5b', "aDm8H%MdA", "CUAdmin", "nE7jA%5m", "cqunicom",
292-
"1620@CTCC", "1620@CUcc", "admintelecom", "cuadmin", "lnadmin",])
291+
"1620@CTCC", "1620@CUcc", "admintelecom", "cuadmin", "lnadmin"])
293292
subparsers = parser.add_subparsers(dest='cmd', title='subcommands',
294293
description='valid subcommands',
295294
help='supported commands')

0 commit comments

Comments
 (0)