Path: blob/master/tools/exploit/pdf2xdp.rb
19669 views
#!/usr/bin/env ruby12#3# This script converts a PDF file to an equivalent XML Data Package file,4# which can be opened by Adobe Reader as well and typically escapes AV5# detection better than a "normal" PDF6#7# Alexander 'alech' Klink, 20118# public domain / CC-09#10begin11require 'base64'1213pdf = ARGV.shift14xdp = ARGV.shift1516if ! xdp then17STDERR.puts " Usage: #{$0} input.pdf output.xdp"18exit 119end2021pdf_content = begin22File.read(pdf)23rescue24STDERR.puts "Could not read input PDF file: #{$!}"25exit 226end2728xdp_out = begin29open xdp, 'w'30rescue31STDERR.puts "Could not open output XDP file: #{$!}"32exit 333end3435xdp_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>'36xdp_out.print Base64.encode64(pdf_content)37xdp_out.print '</chunk></document></pdf></xdp:xdp>'38rescue SignalException => e39puts("Aborted! #{e}")40end414243