-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsaw-ctf-2014-forensics-200-obscurity.html
286 lines (241 loc) · 14.4 KB
/
csaw-ctf-2014-forensics-200-obscurity.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSAW CTF 2014 - Forensics 200: "Obscurity"</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Marina von Steinkirch">
<!-- Le styles -->
<link rel="stylesheet" href="./theme/css/bootstrap.dark.css" type="text/css" />
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.tag-1 {
font-size: 13pt;
}
.tag-2 {
font-size: 11pt;
}
.tag-2 {
font-size: 10pt;
}
.tag-4 {
font-size: 8pt;
}
</style>
<link href="./theme/css/bootstrap-responsive.dark.css" rel="stylesheet">
<link href="./theme/css/font-awesome.css" rel="stylesheet">
<link href="./theme/css/pygments.css" rel="stylesheet">
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="./theme/images/favicon.ico">
<link rel="apple-touch-icon" href="./theme/images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="./theme/images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="./theme/images/apple-touch-icon-114x114.png">
<link href="./feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="chmod +x singularity.sh ATOM Feed" />
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="./index.html">chmod +x singularity.sh </a>
<div class="nav-collapse">
<ul class="nav">
<li class="divider-vertical"></li>
<ul class="nav pull-right">
<li><a href="./authors.html">About</a></li>
<li><a href="./archives.html"><b>Archives</b></a></li>
<li>
<a href="https://github.com/bt3gl">github
<!--<i class="icon-github-sign icon-large" ></i>-->
</a></li>
<li>
<a href="https://twitter.com/1bt337">
<!--<i class="icon-twitter-sign icon-large"></i> -->
twitter
</a></li>
<li><a href="http://bt3gl.github.io/projects_page/index.html">Bygone Playful Times
</a></li>
</ul>
</ul>
<!--<p class="navbar-text pull-right">Logged in as <a href="#">username</a></p>-->
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="span9" id="content">
<section id="content">
<article>
<header>
<h1>
<a href=""
rel="bookmark"
title="Permalink to CSAW CTF 2014 - Forensics 200: "Obscurity"">
CSAW CTF 2014 - Forensics 200: "Obscurity"
</a>
</h1>
</header>
<div class="entry-content">
<div class="well">
<footer class="post-info">
<abbr class="published" title="2014-09-22T07:20:00">
Mon 22 September 2014 </abbr>
<span class="label"> Category</span>
<a href="./category/forensics.html"><i class="icon-folder-open"></i>Forensics</a>
<span class="label">Tags</span>
<a href="./tag/ctf.html"><i class="icon-tag"></i>CTF</a>
<a href="./tag/csaw.html"><i class="icon-tag"></i>CSAW</a>
<a href="./tag/pdf-parser.html"><i class="icon-tag"></i>pdf-parser</a>
<a href="./tag/pdftotext.html"><i class="icon-tag"></i>pdftotext</a>
</footer><!-- /.post-info --> </div>
<p>The third forensics challenge starts with the following text:</p>
<blockquote>
<p>see or do not see</p>
<p>Written by marc</p>
<p><a href="https://ctf.isis.poly.edu/static/uploads/883c7046854e04138c55680ffde90a61/pdf.pdf">pdf.pdf</a></p>
</blockquote>
<p>Hacking PDFs, what fun!</p>
<p>In general, when dealing with reverse-engineering malicious documents, we follow these steps:</p>
<div class="highlight"><pre> <span class="mf">1.</span> <span class="n">We</span> <span class="n">search</span> <span class="k">for</span> <span class="n">malicious</span> <span class="n">embedded</span> <span class="n">code</span> <span class="p">(</span><span class="n">shell</span> <span class="n">code</span><span class="p">,</span> <span class="n">JavaScript</span><span class="p">).</span>
<span class="mf">2.</span> <span class="n">We</span> <span class="n">extract</span> <span class="n">any</span> <span class="n">suspicious</span> <span class="n">code</span> <span class="n">segments</span>
<span class="mf">3.</span> <span class="n">If</span> <span class="n">we</span> <span class="n">see</span> <span class="n">shell</span> <span class="n">code</span><span class="p">,</span> <span class="n">we</span> <span class="n">disassemble</span> <span class="n">or</span> <span class="n">debug</span> <span class="n">it</span><span class="p">.</span> <span class="n">If</span> <span class="n">we</span> <span class="n">see</span> <span class="n">JavaScript</span> <span class="p">(</span><span class="n">or</span> <span class="n">ActionScript</span> <span class="n">or</span> <span class="n">VB</span> <span class="n">macro</span> <span class="n">code</span><span class="p">),</span> <span class="n">we</span> <span class="n">try</span> <span class="n">to</span> <span class="n">examine</span> <span class="n">it</span><span class="p">.</span>
</pre></div>
<p>However, this problem turned out to be very simple...</p>
<hr />
<h2>Finding the Flag in 10 Seconds</h2>
<p>Yeap, this easy:</p>
<div class="highlight"><pre><span class="mf">1.</span> <span class="n">Download</span> <span class="n">the</span> <span class="n">PDF</span> <span class="n">file</span><span class="p">.</span>
<span class="mf">2.</span> <span class="n">Open</span> <span class="n">it</span> <span class="n">in</span> <span class="n">any</span> <span class="n">PDF</span> <span class="n">viewer</span><span class="p">.</span>
<span class="mf">3.</span> <span class="n">CTRL</span><span class="o">+</span><span class="n">A</span> <span class="p">(</span><span class="n">select</span> <span class="n">all</span> <span class="n">the</span> <span class="n">contend</span><span class="p">).</span>
<span class="mf">4.</span> <span class="n">You</span> <span class="n">see</span> <span class="n">the</span> <span class="n">flag</span><span class="o">!</span>
</pre></div>
<p><img alt="" src="http://i.imgur.com/b03EehK.png" /></p>
<p>OK, we were luck. Keep reading if you think this was too easy.</p>
<hr />
<h2>Analyzing the ID and the Streams in a PDF File</h2>
<p>Let's suppose we had no clue that the flag would just be a text in the file. In this case, we would want to examine the file's structure. For this task we use the <a href="http://blog.didierstevens.com/programs/pdf-tools/">PDF Tool</a> suite, which is written in Python.</p>
<h4>pdfid</h4>
<p>We start with <em>pdfid.py</em>, which parses the PDF looking for certain keywords. We download and unzip that script, and then we make it an executable:</p>
<div class="highlight"><pre><span class="nv">$ </span>unzip pdfid_v0_1_2.zip
<span class="nv">$ </span>chmod a+x pdfid.py
</pre></div>
<p>Running over our file gives:</p>
<div class="highlight"><pre><span class="nv">$ </span>./pdfid.py pdf.pdf
PDFiD 0.1.2 pdf.pdf
PDF Header: %PDF-1.3
obj 20
endobj 19
stream 10
endstream 10
xref 1
trailer 1
startxref 1
/Page 1
/Encrypt 0
/ObjStm 0
/JS 0
/JavaScript 0
/AA 0
/OpenAction 0
/AcroForm 0
/JBIG2Decode 0
/RichMedia 0
/Launch 0
/EmbeddedFile 0
/XFA 0
/Colors > 2^24 0
</pre></div>
<p>All right, no funny stuff going on here. We need to look deeper into each of the these streams.</p>
<h4>pdf-parser</h4>
<p>We download <em>pdf-parser.py</em>, which is used to search for all the fundamental elements in a PDF file. Let's take a closer look:</p>
<div class="highlight"><pre><span class="nv">$ </span>unzip pdf-parser_V0_4_3.zip
<span class="nv">$ </span>chmod a+x pdf-parser.py
<span class="nv">$ </span>./pdf-parser.py
Usage: pdf-parser.py <span class="o">[</span>options<span class="o">]</span> pdf-file|zip-file|url
pdf-parser, use it to parse a PDF document
Options:
--version show program<span class="err">'</span>s version number and <span class="nb">exit</span>
-s SEARCH, --search<span class="o">=</span>SEARCH
string to search in indirect objects <span class="o">(</span>except streams<span class="o">)</span>
-f, --filter pass stream object through filters <span class="o">(</span>FlateDecode,
ASCIIHexDecode, ASCII85Decode, LZWDecode and
RunLengthDecode only<span class="o">)</span>
-o OBJECT, --object<span class="o">=</span>OBJECT
id of indirect object to <span class="k">select</span> <span class="o">(</span>version independent<span class="o">)</span>
-r REFERENCE, --reference<span class="o">=</span>REFERENCE
id of indirect object being referenced <span class="o">(</span>version
independent<span class="o">)</span>
-e ELEMENTS, --elements<span class="o">=</span>ELEMENTS
<span class="nb">type </span>of elements to <span class="k">select</span> <span class="o">(</span>cxtsi<span class="o">)</span>
-w, --raw raw output <span class="k">for </span>data and filters
-a, --stats display stats <span class="k">for </span>pdf document
-t TYPE, --type<span class="o">=</span>TYPE <span class="nb">type </span>of indirect object to <span class="k">select</span>
-v, --verbose display malformed PDF elements
-x EXTRACT, --extract<span class="o">=</span>EXTRACT
filename to extract malformed content to
-H, --hash display <span class="nb">hash </span>of objects
-n, --nocanonicalizedoutput
<span class="k">do </span>not canonicalize the output
-d DUMP, --dump<span class="o">=</span>DUMP filename to dump stream content to
-D, --debug display debug info
-c, --content display the content <span class="k">for </span>objects without streams or
with streams without filters
--searchstream<span class="o">=</span>SEARCHSTREAM
string to search in streams
--unfiltered search in unfiltered streams
--casesensitive <span class="k">case </span>sensitive search in streams
--regex use regex to search in streams
</pre></div>
<p>Very interesting! We run it with our file, searching for the string <em>/ProcSet</em>:</p>
<div class="highlight"><pre><span class="nv">$ </span>./pdf-parser.py pdf.pdf | grep /ProcSet
/ProcSet <span class="o">[</span> /ImageC /Text /PDF /ImageI /ImageB <span class="o">]</span>
</pre></div>
<p>Awesome! Even though we don't see any text in the file (when we opened it in the PDF viewer), there is text somewhere!</p>
<hr />
<h2>Getting Text from PDF</h2>
<p>A good way to extract text from a pdf is using <a href="http://en.wikipedia.org/wiki/Pdftotext">pdftotext</a>:</p>
<div class="highlight"><pre><span class="nv">$ </span>pdftotext pdf.pdf
</pre></div>
<p>You should get a <code>pdf.txt</code> file. Reading it with Linux's commands <code>cat</code> or <code>strings</code>gives you the flag:</p>
<div class="highlight"><pre><span class="nv">$ </span>strings pdf.txt
flag<span class="o">{</span>security_through_obscurity<span class="o">}</span>
</pre></div>
<p>As a note, there are several other PDF forensics tools that are worth to be mentioned: <a href="http://esec-lab.sogeti.com/pages/Origami">Origami</a> (pdfextract extracts JavaScript from PDF files), <a href="http://blog.zeltser.com/post/3235995383/pdf-stream-dumper-malicious-file-analysis">PDF Stream Dumper</a> (several PDF analysis tools), <a href="http://blog.zeltser.com/post/6780160077/peepdf-malicious-pdf-analysis">Peepdf</a> (command-line shell for examining PDF), <a href="https://github.com/9b/pdfxray_lite">PDF X-RAY Lite</a> (creates an HTML report with decoded file structure and contents), <a href="http://blog.zeltser.com/post/12615013257/extracting-swf-from-pdf-using-swf-mastah">SWF mastah</a> (extracts SWF objects), <a href="for examining and decoding structure and content of PDF files">Pyew</a>.</p>
<p><strong>Hack all the things!</strong></p>
</div><!-- /.entry-content -->
<div class="comments">
<h2>Comments !</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_identifier = "csaw-ctf-2014-forensics-200-obscurity.html";
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://bt3gl.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</div>
</article>
</section>
</div><!--/span-->
</div><!--/row-->
<footer>
<address id="about">
</address><!-- /#about -->
</footer>
</div><!--/.fluid-container-->
<script src="./theme/js/jquery-1.7.2.min.js"></script>
<script src="./theme/js/bootstrap.min.js"></script>
</body>
</html>