Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
LabyREnth 2016 bowie.pl Solver
#
# Perl debugger module to deal with bowie.pl (LabyREnth CTF)
# save this under ./Devel/Tracer.pm,
# then run `perl -d:Tracer bowie.pl < /dev/null`
#
# 2016.07.22 @zxcvgm
#
package DB;
my (@saved, $ctx, $evalarg);
BEGIN {
@saved = ();
$ctx = '';
$evalarg = '';
}
sub DB {
my ($p, $f, $l) = caller;
my $code = \@{"::_<$f"};
my $codeline = $code->[$l];
&save;
$ctx = "package $p; ";
# don't show the base64 crap
$codeline =~ s/MIME::Base64::decode\([^)]+\)/MIME::Base64::decode(...)/;
# if it's looking for some input, let's give it to him!
if ($codeline =~ /\$input eq/) {
print STDERR "$codeline\n";
# strip out the if (...) and make it into a statement
(my $newcode = $codeline) =~ s/if \((.*)\) {/$1/;
$newcode =~ s/$input eq /$input = /;
$newcode .= ';';
# add code to print out what we just gave him
$newcode .= qq|print "\$input\n";|;
# set this as the $evalarg and eval it
$evalarg = $newcode;
&evalcode;
# pause here
#scalar <STDIN>;
} else {
#print STDERR "$codeline\n";
}
($@, $!, $,, $/, $\, $^W) = @saved;
();
}
sub evalcode {
($@, $!, $,, $/, $\, $^W) = @saved;
eval "$ctx $evalarg; &DB::save";
}
use strict;
sub save {
@saved = ($@, $!, $,, $/, $\, $^W);
$, = ""; $/ = "\n"; $\ = ""; $^W = 0;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment