Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- no warnings;
- my $fileName = shift;
- if (! -e $fileName) {
- print "\n\t".'obf.pl <filename> <pack1/0> <password>'."\n"; # <modif>
- exit(0);
- }
- my $modif = int(shift) || 0;
- $modif = 1;
- my $pack = int(shift) || 0;
- $pack = 1 if $modif==1;
- my $usePassw = shift || '';
- my $one1 = 0;
- my $take_next = 1;
- open F, '<'.$fileName;
- chomp(my @data = <F>);
- close F;
- my $text = join "\n",@data;
- print "\n\t".'input size = '.length($text)."b\n";
- if ($modif == 1){
- my @vars = $text =~ /[\$\%\@]{1}([\w_][\w0-9_]{2,})\s{0,}[=;]{1}/gs;
- foreach (@vars) {
- my $new = &rndText(rand(10));
- $text =~ s/$_/$new/eg;
- }
- #$text =~ s/\s{2,}=//g;
- #$text =~ s/=\s{2,}//g;
- #$text =~ s/\n//g;
- }
- my @allow = q[?.,:;"()[]\\/@\]\[|~_@!#$^&-=_+IoOu];
- @allow = q[qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVNM1234567890-=@#$%^];
- @allow = split //,(join '',@allow);
- my ($r1,$r2) = &xorText($text);
- if ($one1) {
- my @_r1 = split //,$r1;
- $r1 = '';
- foreach (@_r1) {
- my $rnd = int(rand(2));
- if ($rnd>=1) { $rnd = "'"; } else { $rnd = '"'; }
- $r1 .= $rnd.$_.$rnd.".";
- }
- $r1 = "'.".substr($r1,0,-1).".'";
- my @_r2 = split //,$r2;
- $r2 = '';
- foreach (@_r2) {
- my $rnd = int(rand(2));
- if ($rnd>=1) { $rnd = "'"; } else { $rnd = '"'; }
- $r2 .= $rnd.$_.$rnd.".";
- }
- $r2 = "'.".substr($r2,0,-1).".'";
- }
- my $tpl = q{''=~('(?{'.('xXxr1xXx'^'xXxr2xXx').'$/})');};
- $tpl =~ s/xXxr1xXx/$r1/i;
- $tpl =~ s/xXxr2xXx/$r2/i;
- my @words = 'a'..'z';
- if ($usePassw ne '') {
- my $metka; for(my $i=0; $i<rand(10)+5; $i++) { $metka .= $words[rand scalar(@words)].int(rand(9)); }
- my $rndps; for(my $i=0; $i<rand(10)+5; $i++) { $rndps .= $words[rand scalar(@words)].int(rand(9)); }
- my $pform1 = q{$_=shift;goto xXxr4xXx if 0==($_ eq'password');};
- $pform1 = q{$_=shift;goto xXxr4xXx if 0==($_ eq('password'));};
- #$pform1 = q{$_=shift;0?s:;s:s;;$?::s;;$_;;goto xXxr4xXx if (1!=($_ eq('password'))?1:0);};
- # $usePassw .= $usePassw;
- my ($r1,$r2) = &xorText($usePassw);
- $usePassw = $r1."'^'".$r2;
- $pform1 =~ s/password/$usePassw/ig;
- my $pform2 = q{exit(0);xXxr4xXx:print $0;};
- $tpl = $pform1.$tpl.$pform2;
- $tpl =~ s/xXxr4xXx/$metka/g;
- $tpl =~ s/xXxr5xXx/$rndps/g;
- }
- if ($pack == 1) {
- my $tpl2 = q{$_='xXxr3xXx';s/(.)(.)/pack('C',ord($2)-$1)/eg;xXxr4xXx;};
- $tpl = &packText($tpl);
- $tpl =~ s/'/\\'/g;
- $tpl2 =~ s/xXxr3xXx/$tpl/gi;
- my @eval = ('s;;$_;see');#, 'eval'
- $tpl2 =~ s/xXxr4xXx/$eval[rand @eval]/ig;
- $tpl = $tpl2;
- }
- print "\t".'output size = '.length($tpl)."b\n\t";
- print (int((length($tpl)*100)/length($text)));
- print '%'."\n";
- open(myFILE,'>_'.$fileName);
- print myFILE $tpl;
- close(myFILE);
- exit(0);
- my $chars_genered = 0;
- sub xorText {
- my ($text) = @_;
- my @a = split //,(join '',$text);
- my $r1 = my $r2 = '';
- foreach (@a) {
- my @c = &getCh($_);
- if (scalar(@c) <= 0) {
- $chars_genered++;
- if ($chars_genered<2) {
- print "\t".'@allow bad! char ('.$_.') not found! rebuilding table..!'."\n";
- &genChars(1);
- return &xorText($text);
- exit(0);
- } else {
- $_ = ' ';
- }
- }
- my $h = $c[rand @c];
- my ($i,$j) = $h =~ /^(\S+):(\S+)$/;
- $r1 .= $i;
- $r2 .= $j;
- }
- $r1 =~ s/'/\\'/g;
- $r2 =~ s/'/\\'/g;
- return ($r1,$r2);
- }
- sub rndText {
- $_[0] = rand(20) if (!$_[0]);
- my @words = 'a'..'z';
- my $r;
- for(my $i=0; $i<$_[0]; $i++) {
- $r .= $words[rand scalar(@words)];
- }
- return $r;
- }
- my %CHARS:shared = ();
- sub getCh {
- &genChars() if scalar(%CHARS)<=1;
- return split / /,$CHARS{$_[0]};
- }
- sub genChars {
- my @alf = @allow;
- if ($_[0]) {
- @alf = ();
- for(my$i=33;$i<=200;$i++){$alf[@alf]=chr($i);}
- }
- foreach (@alf) {
- my $i = $_;
- $CHARS{$i} = '';
- foreach (@alf) {
- my $j = $_;
- $CHARS{ $i ^ $j } .= $i.':'.$j.' ';
- }
- }
- return 1;
- }
- sub packText {
- my ($text) = @_;
- my $r = '';
- for(my $i=0;$i<length($text);$i++) {
- my $c = substr($text,$i,1);
- my $N = int(rand(9));
- my $nc = chr(ord($c)+$N);
- $r .= $N.$nc;
- }
- return $r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement