Created
September 2, 2020 21:33
-
-
Save IvanBayan/1c83ddbd68dc66062597be7874adfe78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Requires python3 and pexpect_serial | |
# Tha script changes root password to toor1984 and enables dropbear | |
# Should work with dgnwg05lm (lumi.gateway.mieu01) | |
import sys | |
import serial | |
import argparse | |
from pexpect_serial import SerialSpawn | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-p", "--port", required=True, action="store", help="Port of gateway") | |
args = parser.parse_args(sys.argv[1:]) | |
try: | |
ser = serial.Serial(args.port, baudrate=115200) | |
except: | |
print(f'Cant open port {args.port}') | |
exit(1) | |
ss = SerialSpawn(ser) | |
ss.expect('Hit any key to stop autoboot') | |
ss.sendline('0') | |
ss.expect('=>') | |
ss.sendline('printenv') | |
ss.expect('bootargs=([^\r\n]+)') | |
env = ss.match.group(1).decode('utf-8') | |
print(f'Catched ENV: ##{env}##') | |
ss.expect('=>') | |
newenv=f'{env} single rw init=/bin/bash' | |
print(f'Setting new env: {newenv}') | |
ss.sendline(f'setenv bootargs {newenv}') | |
ss.expect('=>') | |
print('Booting...') | |
ss.sendline('boot') | |
ss.expect('bash.*#') | |
print('Changing root password to toor1984') | |
ss.sendline('passwd') | |
ss.expect('New password:') | |
ss.sendline('toor1984') | |
ss.expect('Re-enter new password:') | |
ss.sendline('toor1984') | |
ss.expect('bash.*#') | |
print('Enabling dropbear') | |
ss.sendline('update-rc.d -f dropbear remove') | |
ss.expect('bash.*#') | |
ss.sendline('update-rc.d dropbear defaults') | |
ss.expect('bash.*#') | |
print('Rebooting') | |
ss.sendline('mount -o remount,ro /') | |
ss.expect('bash.*#') | |
ss.sendline('reboot -f') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment