Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This is the shell of what I use. I actually build %replace_key manually. This version only works if you ensure that all subs and vars are unlikely to appear as words (or part of word) you print. Eg, don't use a var called $time if your script outputs something like:
print "The time is $time\n";
OK, here's the meat (unobfuscated, and well commented :)...
#!/usr/bin/perl use strict; print "Enter path to script: "; my $script_path = (<STDIN>); # read in script open (SCRIPT, $script_path) || die("Can't find script $script_path - $ +!"); my $script_text = join '', (&lt;SCRIPT&gt;); close(SCRIPT); my %replace_key; # read in vars of at least 2 chars - well, I always use $i anyway :) while ($script_text =~ /\$(\w\w+)/gs) { $replace_key{$1} = 1; } # read in subs while ($script_text =~ /sub (\w+)/gs) { $replace_key{$1} = 1; } my $i=1; for (keys %replace_key) { my $replace = unpack ("B32", pack("N", $i)); # get binary of $i $replace =~ s/^0+(?=\d)//; # remove trailing zer +oes $replace =~ s/0/I/g; # change 0 -> I $replace =~ s/1/l/g; # change 1 -> l (lowe +rcase L) $i++; $script_text =~ s/$_/$replace/gs; # obfuscate } # remove extraneous CRs $script_text =~ s/;\s*\n\s*/;\n/gis; # now screw up tab spacing $script_text =~ s/\t+/"\t" x (int(rand 6))/ges; # take a look at your handywork print $script_text; exit(0);
Depending on the consistancy of your coding style, you can add other obfuscations. EG, I always mark comments as:
# ## comment
so I can rip them all out with
s/# ##[^\n]+\n\s*/\n/g;
I also use the following:
s/\{/n/ /g; s/\}\s+elsif/} elsif/g; s/;\s+my/; my/g;
That leaves your code totally readable, but when you run it through the obfuscater and let it loose... ;-)

Any othet s/obfuscation/pattern/ suggestions welcomed :)

later

cLive ;-)


In reply to Re: Writing highly obfuscated code in Perl by cLive ;-)
in thread Writing highly obfuscated code in Perl by marko

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-28 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found