Last active
June 29, 2017 16:41
-
-
Save cedriczirtacic/47230ce05d8bf4783a8d384f34f688e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
my $bin = $ARGV[0]; | |
my $func= $ARGV[1]; | |
die("./$0 <binary> <function>") if (!defined $bin or !defined $func); | |
my @shellcode; | |
open(H,"objdump -D $bin |"); | |
while(<H>){ | |
if(/<$func>:/){ | |
while(<H>){ | |
last if(/^\n*$/); | |
my($ops) = $_ =~ m/[0-9a-f]+:[\s]+?((?:[^\s]{2}\s)+)+\s+/g; | |
if ($ops){ | |
foreach ($ops =~ m/(?:([a-z0-9]+)\s)/g) { | |
push @shellcode, $_ | |
} | |
} | |
} | |
last; | |
} | |
} | |
close(H); | |
printf "\tsubq \$%d, %%rsp\n", ($#shellcode+1); | |
print "shellcode:\n\t"; | |
for( my $i = $#shellcode, my $j=1; $i >= 0; $i--,$j++ ) { | |
printf "movb \$0x%2s, -%d(%%rbp)\n\t", $shellcode[$i], $j; | |
} | |
print $/ and exit(0); | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment