Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.11 KB | None | 0 0
  1. use strict;
  2. no warnings;
  3.          
  4. my $fileName = shift;
  5. if (! -e $fileName) {
  6.      print "\n\t".'obf.pl <filename> <pack1/0> <password>'."\n"; # <modif>
  7.      exit(0);
  8. }
  9.      
  10. my $modif = int(shift) || 0;
  11.    $modif = 1;
  12. my $pack = int(shift) || 0;
  13.    $pack = 1 if $modif==1;
  14. my $usePassw = shift || '';
  15. my $one1 = 0;
  16. my $take_next = 1;
  17.      
  18. open F, '<'.$fileName;
  19. chomp(my @data = <F>);
  20. close F;
  21. my $text = join "\n",@data;
  22. print "\n\t".'input size = '.length($text)."b\n";
  23.      
  24. if ($modif == 1){
  25.         my @vars = $text  =~ /[\$\%\@]{1}([\w_][\w0-9_]{2,})\s{0,}[=;]{1}/gs;
  26.         foreach (@vars) {
  27.              my $new = &rndText(rand(10));
  28.              $text =~ s/$_/$new/eg;
  29.         }
  30.         #$text =~ s/\s{2,}=//g;
  31.         #$text =~ s/=\s{2,}//g;
  32.         #$text =~ s/\n//g;
  33. }
  34.      
  35. my @allow = q[?.,:;"()[]\\/@\]\[|~_@!#$^&-=_+IoOu];
  36. @allow = q[qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVNM1234567890-=@#$%^];
  37.      
  38. @allow = split //,(join '',@allow);
  39. my ($r1,$r2) = &xorText($text);
  40. if ($one1) {
  41.          my @_r1 = split //,$r1;
  42.          $r1 = '';
  43.          foreach (@_r1) {
  44.              my $rnd = int(rand(2));
  45.              if ($rnd>=1) { $rnd = "'"; } else { $rnd = '"'; }
  46.              $r1 .= $rnd.$_.$rnd.".";
  47.          }
  48.          $r1 = "'.".substr($r1,0,-1).".'";
  49.          
  50.          my @_r2 = split //,$r2;
  51.          $r2 = '';
  52.          foreach (@_r2) {
  53.              my $rnd = int(rand(2));
  54.              if ($rnd>=1) { $rnd = "'"; } else { $rnd = '"'; }
  55.              $r2 .= $rnd.$_.$rnd.".";
  56.          }
  57.          $r2 = "'.".substr($r2,0,-1).".'";
  58. }
  59.      
  60. my $tpl = q{''=~('(?{'.('xXxr1xXx'^'xXxr2xXx').'$/})');};
  61. $tpl =~ s/xXxr1xXx/$r1/i;
  62. $tpl =~ s/xXxr2xXx/$r2/i;
  63.      
  64. my @words = 'a'..'z';
  65. if ($usePassw ne '') {
  66.      my $metka; for(my $i=0; $i<rand(10)+5; $i++) { $metka .= $words[rand scalar(@words)].int(rand(9)); }
  67.      my $rndps; for(my $i=0; $i<rand(10)+5; $i++) { $rndps .= $words[rand scalar(@words)].int(rand(9)); }
  68.      my $pform1 = q{$_=shift;goto xXxr4xXx if 0==($_ eq'password');};
  69.         $pform1 = q{$_=shift;goto xXxr4xXx if 0==($_ eq('password'));};
  70.         #$pform1 = q{$_=shift;0?s:;s:s;;$?::s;;$_;;goto xXxr4xXx if (1!=($_ eq('password'))?1:0);};
  71.      
  72.     # $usePassw .= $usePassw;
  73.      my ($r1,$r2) = &xorText($usePassw);
  74.      $usePassw = $r1."'^'".$r2;
  75.      $pform1 =~ s/password/$usePassw/ig;
  76.      
  77.      my $pform2 = q{exit(0);xXxr4xXx:print $0;};
  78.      $tpl = $pform1.$tpl.$pform2;
  79.      $tpl =~ s/xXxr4xXx/$metka/g;
  80.      $tpl =~ s/xXxr5xXx/$rndps/g;
  81. }
  82.      
  83. if ($pack == 1) {
  84.      my $tpl2 = q{$_='xXxr3xXx';s/(.)(.)/pack('C',ord($2)-$1)/eg;xXxr4xXx;};
  85.      $tpl = &packText($tpl);
  86.      $tpl =~  s/'/\\'/g;
  87.      $tpl2 =~ s/xXxr3xXx/$tpl/gi;
  88.          
  89.      my @eval = ('s;;$_;see');#, 'eval'
  90.      $tpl2 =~ s/xXxr4xXx/$eval[rand @eval]/ig;
  91.          
  92.      $tpl = $tpl2;
  93. }
  94.  
  95. print "\t".'output size = '.length($tpl)."b\n\t";
  96. print (int((length($tpl)*100)/length($text)));
  97. print '%'."\n";
  98. open(myFILE,'>_'.$fileName);
  99. print myFILE $tpl;
  100. close(myFILE);
  101. exit(0);
  102.  
  103. my $chars_genered = 0;
  104. sub xorText {
  105.     my ($text) = @_;
  106.     my @a = split //,(join '',$text);
  107.     my $r1 = my $r2 = '';
  108.     foreach (@a) {
  109.          my @c = &getCh($_);
  110.          if (scalar(@c) <= 0) {
  111.              $chars_genered++;
  112.              if ($chars_genered<2) {
  113.                  print "\t".'@allow bad! char ('.$_.') not found! rebuilding table..!'."\n";
  114.                  &genChars(1);
  115.                  return &xorText($text);
  116.                  exit(0);
  117.              } else {
  118.                  $_ = ' ';
  119.              }
  120.          }
  121.          my $h = $c[rand @c];
  122.          my ($i,$j) = $h =~ /^(\S+):(\S+)$/;
  123.          $r1 .= $i;
  124.          $r2 .= $j;
  125.     }
  126.     $r1 =~  s/'/\\'/g;
  127.     $r2 =~  s/'/\\'/g;
  128.     return ($r1,$r2);
  129. }
  130.      
  131. sub rndText {
  132.      $_[0] = rand(20) if (!$_[0]);
  133.      my @words = 'a'..'z';
  134.      my $r;
  135.      for(my $i=0; $i<$_[0]; $i++) {
  136.          $r .= $words[rand scalar(@words)];
  137.      }
  138.      return $r;
  139. }
  140.      
  141. my %CHARS:shared = ();
  142. sub getCh {
  143.     &genChars() if scalar(%CHARS)<=1;
  144.     return split / /,$CHARS{$_[0]};
  145. }
  146.      
  147. sub genChars {
  148.      my @alf = @allow;
  149.      if ($_[0]) {
  150.          @alf = ();
  151.          for(my$i=33;$i<=200;$i++){$alf[@alf]=chr($i);}
  152.      }
  153.      foreach (@alf) {
  154.          my $i = $_;
  155.          $CHARS{$i} = '';
  156.          foreach (@alf) {
  157.              my $j = $_;
  158.              $CHARS{ $i ^ $j } .= $i.':'.$j.' ';
  159.          }
  160.      }
  161.      return 1;
  162. }
  163.      
  164. sub packText {
  165.     my ($text) = @_;
  166.     my $r = '';
  167.     for(my $i=0;$i<length($text);$i++) {
  168.          my $c = substr($text,$i,1);
  169.          my $N = int(rand(9));
  170.          my $nc = chr(ord($c)+$N);
  171.          $r .= $N.$nc;
  172.     }
  173.     return $r;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement