tag:blogger.com,1999:blog-8889285000186294932.post1387205765250603939..comments2024-03-17T02:45:18.077-07:00Comments on Ken Felix Security Blog: Understanding HTTP redirect traces analysisUnknownnoreply@blogger.comBlogger2125tag:blogger.com,1999:blog-8889285000186294932.post-73364143689474963182017-02-24T19:35:51.370-08:002017-02-24T19:35:51.370-08:00Thanks
I haven't ran the perl script yet but ...Thanks<br /><br />I haven't ran the perl script yet but this might come in handy on my day job. We have a lot web engineer that place http.redirects, but really have no insight on redirect traces & on what they are redirecting and any broken redirects.<br />socpuppetshttps://www.blogger.com/profile/13096043188091774607noreply@blogger.comtag:blogger.com,1999:blog-8889285000186294932.post-46122770988062760142017-02-24T10:34:08.094-08:002017-02-24T10:34:08.094-08:00If you want to do the same thing in Perl from the ...If you want to do the same thing in Perl from the CLI, try this.<br /><br />#!/usr/bin/perl<br />#Author: Lance Vermilion<br />#Purpose: Map redirects for webpages<br />#Date: Feb 24, 2017<br />####################################<br />use strict;<br /><br />my $url = $ARGV[0];<br />chomp($url);<br />my $origurl = $url;<br /><br />\$/;;/g'`;tput = `curl -s -L -I -X GET $url | sed 's/^<br />my @sections = split(/;;/, $curloutput);<br /><br />my $loop = 1;<br />my $redirects = 0;<br />my $href = {};<br /><br />for my $section (@sections)<br />{<br /> my @lines = split(/\n/, $section);<br /> for my $line (@lines)<br /> {<br /> chomp($line);<br /> $line =~ s/\r//g if ( $line !~ /^$/ ); # remove annoying ^M<br /> $redirects++ if ( $line =~ /^$/ ); # Count redirect because there is a blank line between redirects<br /> push(@{$href->{$redirects}->{'header'}}, $line) if ( $line !~ /^$/ );<br /> my (undef, $LOCATION) = split(/ /, $line) if ( $line =~ /Location: / ); # split line to get location so we can construct complete URL for display<br /> $href->{$redirects}->{'fulllocation'} = $line if ( $line =~ /^Location: / );<br /> <br /> if ( $line =~ m/^Location:/i )<br /> {<br /> if ( $line =~ m/^Location: (http.*)/i )<br /> {<br /> $url = $1;<br /> $href->{$redirects}->{'redirectlocation'} = $url;<br /> }<br /> elsif ( $line =~ m/^Location: (\/.*)/i )<br /> {<br /> my $uri = $1;<br /> $url =~ s/\/$//;<br /> $href->{$redirects}->{'redirectlocation'} = $url . $uri;<br /> }<br /> else<br /> {<br /> $href->{$redirects}->{'redirectlocation'} = "null";<br /> }<br /> }<br /> }<br />}<br /><br />print "### REDIRECT MAPPER ###\n";<br />print "There are $redirects redirects for the URL: $origurl\n";<br /><br />if ( $redirects > 0 )<br />{<br /> #use Data::Dumper;<br /> #print Dumper($href);<br /> print "\nOriginal URL: $origurl\n";<br /> for my $key ( sort keys %$href )<br /> {<br /> print "Header:\n";<br /> for my $line (@{$href->{$key}->{'header'}})<br /> {<br /> print " $line\n";<br /> }<br /> print "\nRedirected to: " . $href->{$key}->{'redirectlocation'} . "\n" if ( $href->{$key}->{'redirectlocation'} );<br /> }<br />}<br />else<br />{<br /> print "\nOriginal URL: $origurl\n";<br /> print "Header:\n";<br /> for my $section (@sections)<br /> {<br /> my @lines = split(/\n/, $section);<br /> for my $line (@lines)<br /> {<br /> print " $line\n";<br /> }<br /> }<br />}Anonymoushttps://www.blogger.com/profile/12132370161582580449noreply@blogger.com