Skip to content

Instantly share code, notes, and snippets.

@cedriczirtacic
Last active June 29, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedriczirtacic/47230ce05d8bf4783a8d384f34f688e5 to your computer and use it in GitHub Desktop.
Save cedriczirtacic/47230ce05d8bf4783a8d384f34f688e5 to your computer and use it in GitHub Desktop.
#!/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