Advertisement
Guest User

BofPattern.pl

a guest
Dec 13th, 2017
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.04 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # Buffer Overflow Pattern generator v 1.0
  3. # Written by Wireghoul - http://www.justanotherhacker.com
  4. use strict;
  5. use warnings;
  6.  
  7. sub generate {
  8.     my $len=shift;
  9.     my $pattern='Aa0';
  10.     my $out = '';
  11.     while (length($out) < $len) {
  12.         $out.=$pattern;
  13.         $pattern++;
  14.     }
  15.     return substr($out,0,$len);
  16. }
  17.  
  18. sub search {
  19.     my $string = shift;
  20.     # If we get a hex string, decode and reverse it
  21.     if ($string =~ /0x/) {
  22.         $string =~ s/([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/eg;
  23.         $string =~ s/0x//;
  24.         $string = reverse $string;
  25.     }
  26.     my $pat = 'Aa0';
  27.     my $out = '';
  28.     while ($out !~ m/$string/) {
  29.         $out.=$pat;
  30.         $pat++;
  31.     }
  32.     return index($out, $string);
  33. }
  34.  
  35. if (!$ARGV[0]) {
  36.    print "Buffer overflow pattern generator by Wireghoul\n$0 <size> creates pattern of size characters\n$0 string finds offset of string in pattern\n";
  37.    exit 0 ;
  38. }
  39. if ($ARGV[0] =~ m/^\d+$/) {
  40.     print generate($ARGV[0])."\n";
  41. } else {
  42.     print search($ARGV[0])."\n";
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement