Remote Exploit Forums

Go Back   Remote Exploit Forums > General IT Discussion


General IT Discussion Non BT Related Topics

   

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2009, 06:23 PM
webtrol's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 107
Default PDF file check question

Hi,
I was just wondering... If someone asked you to ensure that a large PDF file is clean of any evil things.
How would you do this.
(assume the file passed virus scanner, and it legitimately contains some JS content - so scanning source for existence of it is not enough).
This is a curiosity/non urgent question for those with time on their hands to share their most secret white hat ways.

Sin-cerely,
Trol (trolling the Forum since OMG ago)
__________________
He either fears his faith too much, or his desserts are small
who dares not put to touch, to win or loose it all.
Reply With Quote
  #2 (permalink)  
Old 12-06-2009, 06:25 PM
streaker69's Avatar
Senior Member
 
Join Date: May 2007
Location: Virginville, BlueBall, Bird In Hand, Intercourse, Paradise, PA
Posts: 3,664
Default

Quote:
Originally Posted by webtrol View Post
Hi,
I was just wondering... If someone asked you to ensure that a large PDF file is clean of any evil things.
How would you do this.
(assume the file passed virus scanner, and it legitimately contains some JS content - so scanning source for existence of it is not enough).
This is a curiosity/non urgent question for those with time on their hands to share their most secret white hat ways.

Sin-cerely,
Trol (trolling the Forum since OMG ago)
There's a GPO template for AD that disables JS on all clients of AD. So far, I haven't found a single PDF that's actually needed JS.
__________________
A 3rd Party Security Audit is the IT equivalent of a Colonoscopy, it's long, intrusive, and when it's done you'll have seen a lot of things you really didn't want to see, and you'd definitely remember that you had it done.

I baby harp seals.
Reply With Quote
  #3 (permalink)  
Old 12-06-2009, 07:20 PM
webtrol's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 107
Default

Quote:
Originally Posted by streaker69 View Post
There's a GPO template for AD that disables JS on all clients of AD. So far, I haven't found a single PDF that's actually needed JS.
Nice, And after reading this, I looked it up and learned new cool thing, thank you .

But that protect you from bad PDF, it doesn't tell you IF PDF was BAD.
Also, if you then forward such PDF into the wild, it could contaminate others.

Soooo, all the great white hats with too much time on your hands, How do you (if you do) ensure that PDF does not contain a new cool exploit?

Sin-cerely,
Trol
__________________
He either fears his faith too much, or his desserts are small
who dares not put to touch, to win or loose it all.
Reply With Quote
  #4 (permalink)  
Old 12-06-2009, 08:12 PM
streaker69's Avatar
Senior Member
 
Join Date: May 2007
Location: Virginville, BlueBall, Bird In Hand, Intercourse, Paradise, PA
Posts: 3,664
Default

Quote:
Originally Posted by webtrol View Post
Nice, And after reading this, I looked it up and learned new cool thing, thank you .

But that protect you from bad PDF, it doesn't tell you IF PDF was BAD.
Also, if you then forward such PDF into the wild, it could contaminate others.

Soooo, all the great white hats with too much time on your hands, How do you (if you do) ensure that PDF does not contain a new cool exploit?

Sin-cerely,
Trol
I know this may not be the answer you want to hear, but my personal opinion is that it is not really my concern about someone else's network and if they're vulnerable to exploit. If it's a 0-day, it's a 0-day, chances are, nothing that I would have available is going to detect it. Eventually, it will be detected as updated definitions are deployed, and the network is scanned during it's normal cycle.

The only real solution to this would be to quarantine all attachments until such time that definitions are available to scan. This of course is disruptive to business workflow, so it's not a real good solution. Of course, you could always manually look at every PDF that comes in, if you have nothing else to do with your time, I really don't have the time to do that myself.
__________________
A 3rd Party Security Audit is the IT equivalent of a Colonoscopy, it's long, intrusive, and when it's done you'll have seen a lot of things you really didn't want to see, and you'd definitely remember that you had it done.

I baby harp seals.
Reply With Quote
  #5 (permalink)  
Old 12-06-2009, 08:32 PM
Senior Member
 
Join Date: Feb 2009
Location: Sofia, Bulgaria
Posts: 356
Default

JS is not the only "bad" think in a PDF. Most dangerous ones out there actually exploit the reader and you can't make sure it's clean unless you open it in a hex editor... and even then, if it's large, you're probably screwed. So no, you can't protect yourself - UPDATE your reader software and hope for the best!!!!
Reply With Quote
  #6 (permalink)  
Old 12-06-2009, 10:27 PM
lupin's Avatar
Moderator
 
Join Date: Mar 2009
Location: Australia
Posts: 1,363
Default

Here's the method that I use in analysing malicious PDFs:

I use the tools pdfid and pdf-parser from here. I the past I have also used pdftk, but Im finding that less useful recently.

The process:
  1. Use pdfid to analyse the pdf document. pdfid can tell you if a pdf has Javascript included as well as autorun functionality and how many pages it has. A one page document with Javascript and autorun functionality is suspicious.
  2. If Javascript is present, extract it from the document to determine its purpose. Sometimes the Javascript is included in plain text, in which case you can just use the strings utility to extract it. Otherwise, you can use pdf-parser to extract certain types of encoded Javascript.
  3. Malicious Javascript often contains obfuscation to disguise its true purpose. To remove this obfuscation I modify the script a little to allow easier debugging (e.g. assign the code from eval statements to a variable instead) and use the Rhino Javascript debugger to show me how the code is transformed as it runs.
  4. Many of the Javascript based PDF exploits often involve buffer overflows, and the shellcode is often in unicode format. I have a perl script that I wrote to convert this type of shellcode to a C program (really just C style shellcode with some wrapper code) which can then be compiled to be further analysed using standard binary analysis techniques. I can post the script if anyone wants it.

I will note that PDF exploits are possible without Javascript, but in practice most of the ones out in the wild seem to use it. Certainly the ones I have seen have it.
__________________
Nancy Astor: If I were your wife I would put poison in your coffee!
Winston Churchill: Madam, if I were your husband I would drink it.

Last edited by lupin; 12-07-2009 at 01:02 AM. Reason: Better layout and clearer instructions
Reply With Quote
  #7 (permalink)  
Old 12-07-2009, 01:10 AM
webtrol's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 107
Default

Thank you Lupin for reply, between your information and that from streaker (xorred also my thanks) my escapade into PDF documents might end up being successful (since it is goal/subject selected for fun - i also define success which is handy)

Quote:
Originally Posted by lupin View Post
I can post the script if anyone wants it.
I would love to see that script


Sin-cerely,
Trol
__________________
He either fears his faith too much, or his desserts are small
who dares not put to touch, to win or loose it all.
Reply With Quote
  #8 (permalink)  
Old 12-07-2009, 02:43 AM
lupin's Avatar
Moderator
 
Join Date: Mar 2009
Location: Australia
Posts: 1,363
Default

Quote:
Originally Posted by webtrol View Post
I would love to see that script
I knocked this together in the middle of an incident and haven't had a chance to tidy it up, so be warned its pretty rough. You basically just run it at the command line with the JS shellcode as a parameter and it spits out a C program that you can compile.

Code:
#!/usr/bin/perl
# Takes shellcode in javascript unicode coded format as a parameter and outputs it to STDOUT into c code that can be compiled into a windows executable (gcc code.c -o code.exe).  Borrows metasploit c code for compiling shellcode.

# shellcode here in format "%uHHHH%uHHHH" where HH is a hexidecimal value
$jsshellcode = $ARGV[0];

if ($jsshellcode eq "") {die("Enter the javascript shellcode as the first parameter to this script in format %uHHHH%uHHHH...\n\n"); }

$code = '';

@array = split "%", $jsshellcode;
foreach $part (@array) {
	if (! $part == "") { # encoding is little endian so we swap order of encoded bytes
		$code = $code . '\x' . substr($part, 3, 2);
		$code = $code . '\x' . substr($part, 1, 2);	
	}
}

print 'char code[] = "' . $code . '";' . "\n\n";

print <<CODE
int main(int argc, char **argv)
{
	int (*funct)();
	funct = (int (*)()) code;
	(int)(*funct)();
}

CODE
__________________
Nancy Astor: If I were your wife I would put poison in your coffee!
Winston Churchill: Madam, if I were your husband I would drink it.
Reply With Quote
  #9 (permalink)  
Old 12-07-2009, 03:37 AM
webtrol's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 107
Default

Thank you kindly good sir!

Sin-cerely,
Trol
__________________
He either fears his faith too much, or his desserts are small
who dares not put to touch, to win or loose it all.
Reply With Quote
  #10 (permalink)  
Old 12-09-2009, 01:44 AM
lupin's Avatar
Moderator
 
Join Date: Mar 2009
Location: Australia
Posts: 1,363
Default

Something relevant that I just found on the Internet Storm Center blog, Lenny Zeltser's guide to analysing malicious documents, including PDFs!

There are some usage command lines for some of the tools I mentioned (not the same command lines I have used, but still useful nonetheless).

There are also a number of tools listed there I hadn't head of before, as well as a guide to analysing Microsoft Office documents, which I haven't had to do so far.

Analyzing Malicious Documents Cheat Sheet by Lenny Zeltser


Edit: Documented my PDF analysis process in more detail on my blog here.
__________________
Nancy Astor: If I were your wife I would put poison in your coffee!
Winston Churchill: Madam, if I were your husband I would drink it.

Last edited by lupin; 01-09-2010 at 01:39 PM. Reason: Added link.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:28 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2