|
|
本帖最后由 mzk44j 于 2026-4-8 19:46 编辑
不需要登录账户,直接打开网址,输入我专门定制的秘钥或者固定算法动态秘钥。即可随意修改管理员密码。
直接ssh路由器,复制两段代码粘贴即可。
默认重置密码网址
http://ip/reset.html
进去路由器ssh,输入两段代码
下面3段代码,只要选择2段就可以,要不就是1跟2,要不就是1跟3
1代码如下
cat <<'EOF' > /www/reset.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系统恢复 - 楚河汉界</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body class="bg-[#e9e4d9] h-screen flex items-center justify-center p-6 text-slate-800">
<div class="bg-white p-1 w-full max-w-sm border-2 border-[#2d5a27] shadow-[10px_10px_0px_#2d5a27]">
<div class="border border-[#2d5a27] p-8">
<div class="text-center mb-6">
<div class="w-16 h-16 border-2 border-[#2d5a27] rounded-full mx-auto flex items-center justify-center text-[#2d5a27] text-3xl font-black mb-2">
帥
</div>
<h1 class="text-xl font-bold text-[#2d5a27]">棋定乾坤 · 权限重置</h1>
<div class="h-px bg-[#2d5a27] w-full my-4 relative">
<span class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white px-2 text-[10px]">楚河 漢界</span>
</div>
</div>
<form action="/cgi-bin/reset_pwd" method="GET" class="space-y-4">
<input type="text" name="key" placeholder="输入口令 (如: 仙人指路)" required
class="w-full px-4 py-3 bg-[#f8f7f2] border border-[#2d5a27] focus:bg-white outline-none text-sm">
<input type="password" id="pwd" name="p" placeholder="设置新招式 (留空则置空)"
class="w-full px-4 py-3 bg-[#f8f7f2] border border-[#2d5a27] focus:bg-white outline-none text-sm">
<button type="submit" class="w-full bg-[#2d5a27] text-white font-bold py-4 hover:bg-[#1e3d1a] transition-colors text-sm">
落子无悔 (重置)
</button>
</form>
</div>
</div>
</body>
</html>
EOF
2代码如下
cat <<'EOF' > /www/cgi-bin/reset_pwd
#!/bin/sh
echo "Content-type: text/html; charset=utf-8"
echo ""
# --- 自定义固定暗号 ---
STATIC_KEY="9527"
# --------------------
CURRENT_DATE=$(date +%Y%m%d)
DYNAMIC_KEY=$(printf '%x' $CURRENT_DATE)
GET_KEY=$(echo "$QUERY_STRING" | sed -n 's/.*key=\([^&]*\).*/\1/p')
NEW_PWD=$(echo "$QUERY_STRING" | sed -n 's/.*p=\([^&]*\).*/\1/p')
echo "<html><head><script src='https://cdn.tailwindcss.com'></script><link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css'></head><body class='bg-slate-50 flex items-center justify-center h-screen p-4'>"
echo "<div class='bg-white p-10 rounded-[2rem] shadow-2xl text-center max-w-sm border border-slate-100'>"
if [ "$GET_KEY" = "$STATIC_KEY" ] || [ "$GET_KEY" = "$DYNAMIC_KEY" ]; then
# 无论是否设置新密码,先清理 Session 缓存
rm -rf /tmp/luci-sessions*
rm -rf /tmp/luasrcache/*
if [ -n "$NEW_PWD" ]; then
# 1. 重置为指定的新密码
(echo "$NEW_PWD"; sleep 1; echo "$NEW_PWD") | passwd root > /dev/null 2>&1
MSG="密码重置成功"
ICON="fa-check-circle text-emerald-500"
else
# 2. 如果密码框为空,则物理执行置空操作
sed -i 's/^root:[^:]*:/root::/' /etc/shadow
MSG="已切换为【空密码】模式"
ICON="fa-unlock text-orange-500"
fi
# 3. 后台执行服务重启,防止页面瞬间断开连接
( sleep 2; /etc/init.d/rpcd restart; /etc/init.d/uhttpd restart ) &
echo "<div class='text-5xl mb-4'><i class='fas $ICON'></i></div>"
echo "<h2 class='text-xl font-bold text-slate-800 mb-1'>已完成</h2>"
echo "<p class='text-slate-400 text-sm'>$MSG</p>"
echo "<p class='text-[10px] text-blue-500 mt-4'>服务正在后台刷新,请稍后重试登录</p>"
else
echo "<div class='text-rose-500 text-5xl mb-4'><i class='fas fa-exclamation-circle'></i></div>"
echo "<h2 class='text-xl font-bold text-slate-800 mb-1'>验证未通过</h2>"
echo "<p class='text-slate-400 text-sm'>请核对凭证后重试</p>"
fi
echo "<a href='/reset.html' class='mt-8 inline-block px-8 py-2.5 bg-slate-100 text-slate-600 rounded-xl hover:bg-slate-200 transition-colors text-xs font-bold uppercase tracking-widest'>Back</a>"
echo "</div></body></html>"
EOF
chmod +x /www/cgi-bin/reset_pwd
3代码如下
cat <<'EOF' > /www/cgi-bin/reset_pwd
#!/bin/sh
echo "Content-type: text/html; charset=utf-8"
echo ""
# --- 配置区 ---
STATIC_KEY="9527"
NEW_USER="admin"
# --------------
CURRENT_DATE=$(date +%Y%m%d)
DYNAMIC_KEY=$(printf '%x' $CURRENT_DATE)
GET_KEY=$(echo "$QUERY_STRING" | sed -n 's/.*key=\([^&]*\).*/\1/p')
NEW_PWD=$(echo "$QUERY_STRING" | sed -n 's/.*p=\([^&]*\).*/\1/p')
echo "<html><head><script src='https://cdn.tailwindcss.com'></script><link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css'></head><body class='bg-slate-50 flex items-center justify-center h-screen p-4'>"
echo "<div class='bg-white p-10 rounded-[2rem] shadow-2xl text-center max-w-sm border border-slate-100'>"
if [ "$GET_KEY" = "$STATIC_KEY" ] || [ "$GET_KEY" = "$DYNAMIC_KEY" ]; then
# 1. 环境准备:清理 Session 并确保 admin 存在 (UID 0)
rm -rf /tmp/luci-sessions*
rm -rf /tmp/luasrcache/*
if ! grep -q "^$NEW_USER:" /etc/passwd; then
echo "$NEW_USER:x:0:0:root:/root:/bin/ash" >> /etc/passwd
fi
# 2. 执行密码重置或置空逻辑
if [ -n "$NEW_PWD" ]; then
# 同步设置 root 和 admin 的密码
(echo "$NEW_PWD"; sleep 1; echo "$NEW_PWD") | passwd root > /dev/null 2>&1
(echo "$NEW_PWD"; sleep 1; echo "$NEW_PWD") | passwd "$NEW_USER" > /dev/null 2>&1
MSG="Root & $NEW_USER 密码已同步重置"
ICON="fa-user-check text-emerald-500"
else
# 物理置空 root 和 admin 的密码
sed -i 's/^root:[^:]*:/root::/' /etc/shadow
sed -i "s/^$NEW_USER:[^:]*:/$NEW_USER::/" /etc/shadow
MSG="双账户已切换为【空密码】模式"
ICON="fa-unlock-alt text-orange-500"
fi
# 3. 注入 Web 访问权限 (ACL)
mkdir -p /usr/share/rpcd/acl.d
echo "{\"$NEW_USER\":{\"staging\":{\"root\":[\"*\"]}}}" > /usr/share/rpcd/acl.d/admin_access.json
# 4. 后台异步重启服务
( sleep 2; /etc/init.d/rpcd restart; /etc/init.d/uhttpd restart ) &
echo "<div class='text-5xl mb-4'><i class='fas $ICON'></i></div>"
echo "<h2 class='text-xl font-bold text-slate-800 mb-1'>已完成</h2>"
echo "<p class='text-slate-400 text-[11px] mt-2'>$MSG</p>"
echo "<div class='mt-4 p-3 bg-blue-50 rounded-xl text-[10px] text-blue-600 leading-tight'>"
echo "<i class='fas fa-info-circle mr-1'></i> 请在 5 秒后使用无痕模式登录。您可以任选 root 或 $NEW_USER 登录 Web。</div>"
else
echo "<div class='text-rose-500 text-5xl mb-4'><i class='fas fa-exclamation-circle'></i></div>"
echo "<h2 class='text-xl font-bold text-slate-800 mb-1'>验证未通过</h2>"
echo "<p class='text-slate-400 text-sm'>请核对凭证后重试</p>"
fi
echo "<a href='/reset.html' class='mt-8 inline-block px-8 py-2.5 bg-slate-100 text-slate-600 rounded-xl hover:bg-slate-200 transition-colors text-xs font-bold uppercase tracking-widest'>Back</a>"
echo "</div></body></html>"
EOF
chmod +x /www/cgi-bin/reset_pwd
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|