CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/exploit/pdf2xdp.rb
Views: 11767
1
#!/usr/bin/env ruby
2
3
#
4
# This script converts a PDF file to an equivalent XML Data Package file,
5
# which can be opened by Adobe Reader as well and typically escapes AV
6
# detection better than a "normal" PDF
7
#
8
# Alexander 'alech' Klink, 2011
9
# public domain / CC-0
10
#
11
begin
12
require 'base64'
13
14
pdf = ARGV.shift
15
xdp = ARGV.shift
16
17
if ! xdp then
18
STDERR.puts " Usage: #{$0} input.pdf output.xdp"
19
exit 1
20
end
21
22
pdf_content = begin
23
File.read(pdf)
24
rescue
25
STDERR.puts "Could not read input PDF file: #{$!}"
26
exit 2
27
end
28
29
xdp_out = begin
30
open xdp, 'w'
31
rescue
32
STDERR.puts "Could not open output XDP file: #{$!}"
33
exit 3
34
end
35
36
xdp_out.print '<?xml version="1.0"?><?xfa ?><xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"><pdf xmlns="http://ns.adobe.com/xdp/pdf/"><document><chunk>'
37
xdp_out.print Base64.encode64(pdf_content)
38
xdp_out.print '</chunk></document></pdf></xdp:xdp>'
39
rescue SignalException => e
40
puts("Aborted! #{e}")
41
end
42
43