自动给ssh输入密码(python使用pty模块,或者script命令)

准备环境:

cp /etc/passwd /etc/passwd.bak
tail /etc/passwd
echo "tee:\$1\$123456\$wOSEtcyiP2N/IfIl15W6Z0:229:2:toor:/tmp:/bin/bash" >>/etc/passwd 
echo "yes:\$1\$123\$EKWAR30..wEKERDtzOQUv/:200:2:toor:/tmp:/bin/bash" >>/etc/passwd 
tail /etc/passwd
((sleep 0.4;echo yes;sleep 0.2;echo yes;sleep 0.2;echo exit;)|python -c 'import pty;pty.spawn(["bash","-c","ssh -f -N -D 0.0.0.0:1304 yes@127.0.0.1"]);')&


netstat -anlp| grep 1302 

使用( xxx) & ,切换到后台,是因ssh或者bash不会自动退出,但是可以使用ctrl +C 结束.

原因不明.

ssh -f -N -D 0.0.0.0:1304 yes@127.0.0.1

这句话就是在本地起socks5代理,端口号1304,

  • -f:后台执行ssh指令

pty模块基本都是python自带的,

使用socat的pty功能 ,没有成功,也不会使用c语言静态编写一个elf文件,

只能使用pty了

使用script命令如下:

(sleep 0.5;echo "ssh -f -o StrictHostKeyChecking=no -N -D 0.0.0.0:40079 yes@127.0.0.1";sleep 0.5;echo yes;sleep 0.5;echo exit;)|script /dev/null 

root@out:~# (echo id ;sleep 2;echo "ssh -f -o StrictHostKeyChecking=no -N -D 0.0.0.0:60079 yes@127.2.0.6";sleep 1;echo yes;sleep 1;echo exit;)| script /dev/null
Script started, file is /dev/null
id
root@out:~# id
uid=0(root) gid=0(root) groups=0(root)
Warning: Permanently added '127.2.0.6' (ECDSA) to the list of known hosts..2.0.6 
yes@127.2.0.6's password: 
root@out:~# exit
exit
Script done, file is /dev/null
root@out:~# which script
/usr/bin/script
root@out:~# ls -al /usr/bin/script
-rwxr-xr-x 1 root root 23200 Jun 14  2017 /usr/bin/script
root@out:~# 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值