A few days ago, i released an obfuscated Tk YAPH, where most of it was Base64 encoded in some sort of figlet code.
Turning the program into the base64 figlet text was done by a... you guessed it: Perl script. Since i though that writing a Perl script to obfuscate another Perl script was kinda cool, it would be sad to let it rot on my harddisk. So i rewrote it to make it more useable and even added comments for your reading pleasure.
And here it is:
#!/usr/bin/perl # This is the legendary figlet encoder that turns every text file # into a BIIIIG base64 encoded message. # # It works, because MIME::Base64 ignores whitespace and anything after # the end-character (which is an equal sign) on decoding. use strict; use warnings; use MIME::Base64; # Change this if you don't like Edgar Allan Poe my $bigtext = "Once upon a midnight dreary, while I pondered weak and +weary, Over many a quaint and curious volume of forgotten lore, While + I nodded, nearly napping, suddenly there came a tapping, As of some +one gently rapping, rapping at my chamber door. 'Tis some visitor,' I + muttered, 'tapping at my chamber door - Only this, and nothing more. +' Ah, distinctly I remember it was in the bleak December, And each se +parate dying ember wrought its ghost upon the floor. If you can read +this text, you did not change the BIGTEXT variable in the figlet enco +der example as instructed."; # Check the command line options and use some named variables for the +filenames if((scalar @ARGV) != 2) { die("Usage: figencode_full.pl inpufile outputfile"); } my ($infile, $outfile) = @ARGV; # Turn our text into "figlines" my @figlines = `figlet -w 70 -f banner "$bigtext"`; # Slurp and base64-encode our file open(my $ffh, "<", $infile) or die($!); my $figtext = encode_base64(join('', <$ffh>), ''); close $ffh; # split the base64 encoded file into single characters # for easier handling my @figparts = split//, $figtext; # We'll need some "simbytes" to fill up unneeded space with simulated +base64 my @simbytes = split//, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS +TUVWXYZ0123456789"; # Let's also count "wasted" bytes my $overbytes = 0; # Now, we're nearly ready to go open(my $ofh, ">", $outfile) or die($!); # Iterate through all "figlines" foreach my $line (@figlines) { chomp $line; # Work on the lines byte-by-byte my @parts = split//,$line; foreach my $part (@parts) { # whitespace will stay whitespace if($part eq " ") { print $ofh " "; } else { if(@figparts) { # if we still have some real base64 values, output tha +t my $tmp = shift @figparts; print $ofh $tmp; } else { # else just simulate raw data to confuse the reader my $tmp = $simbytes[int(rand(scalar @simbytes))]; print $ofh $tmp; $overbytes++; } } } # at the end of the line we print out an end-of-line character. We +ird, huh? print $ofh "\n"; } # Yeah, we're done writing close $ofh; # Now, let's inform the user, if it actually works # (and how much figlet-bytes (s)he wasted with simulated bytes) if(@figparts) { print "Lost " . (scalar @figparts) . "bytes in translation!!!\n"; } elsif($overbytes) { print "Wasted $overbytes figlet bytes!\n"; } else { print "Length is perfect.\n"; }
|
|---|