Skip to content

Instantly share code, notes, and snippets.

@geekman
Created August 17, 2016 02:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekman/48691ae931b6f54e9a27a1422970e5ee to your computer and use it in GitHub Desktop.
Save geekman/48691ae931b6f54e9a27a1422970e5ee to your computer and use it in GitHub Desktop.
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