Created
January 31, 2021 05:51
-
-
Save steelywing/bdfe5a72a7fa4c34e3fa4f74379b156a to your computer and use it in GitHub Desktop.
Enable RedMi 2100 SSH access
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
// Work for RedMi 2100 firmware 2.0.23 | |
// http://cdn.cnbj1.fds.api.mi-img.com/xiaoqiang/rom/rm2100/miwifi_rm2100_all_fb720_2.0.23.bin | |
function getSTOK() { | |
let match = location.href.match(/;stok=(.*?)\//); | |
if (!match) { | |
return null; | |
} | |
return match[1]; | |
} | |
function execute(stok, command) { | |
command = encodeURIComponent(command); | |
let path = `/cgi-bin/luci/;stok=${stok}/api/misystem/set_config_iotdev?bssid=SteelyWing&user_id=SteelyWing&ssid=-h%0A${command}%0A`; | |
console.log(path); | |
return fetch(new Request(location.origin + path)); | |
} | |
function enableSSH() { | |
stok = getSTOK(); | |
if (!stok) { | |
console.error('stok not found in URL'); | |
return; | |
} | |
console.log(`stok = "${stok}"`); | |
password = prompt('Input new SSH password'); | |
if (!password) { | |
console.error('You must input password'); | |
return; | |
} | |
execute(stok, | |
` | |
nvram set ssh_en=1 | |
nvram commit | |
sed -i 's/channel=.*/channel=\\"debug\\"/g' /etc/init.d/dropbear | |
/etc/init.d/dropbear start | |
` | |
) | |
.then((response) => response.text()) | |
.then((text) => console.log(text)); | |
console.log('New SSH password: ' + password); | |
execute(stok, `echo -e "${password}\\n${password}" | passwd root`) | |
.then((response) => response.text()) | |
.then((text) => console.log(text)); | |
} | |
enableSSH(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment