Skip to content

Instantly share code, notes, and snippets.

@nipotan
Created June 24, 2009 06:23
Show Gist options
  • Save nipotan/135048 to your computer and use it in GitHub Desktop.
Save nipotan/135048 to your computer and use it in GitHub Desktop.
XXE precaution
#!perl
use strict;
use XML::Simple;
use Data::Dumper;
my $xml = do { local $/ = undef; <DATA> };
my @entities = $xml =~ /<!ENTITY\s+(\w+)\s+.+?>/sg;
my $entities_re = '&(?:' . join('|', @entities) . ');';
$xml =~ s/$entities_re//g;
my $ref = XMLin($xml);
warn Dumper $ref;
__DATA__
<?xml version="1.0"?>
<!DOCTYPE str [
<!ENTITY pass SYSTEM "/etc/passwd">
]>
<str><data1>&pass;</data1><data2></data2></str>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment