PX: A quick and silly Ruby obfuscation system
For the fun of it, I developed a quick Ruby obfuscation tool a few weeks ago. It's not a proper obfuscater that changes variable names and such, but it'll keep your code from being immediately understood. Here's the library, px.rb:
class PX; def self.method_missing(m, *args); m = m.to_s; eval $c.join if m == '-@'; m.scan(/(w)(w)/).each { |t| ($c ||= []) << (((t[0][0] - 97) * 26) + (t[1][0] - 97)).chr }; end; end
And here's a demonstration program, using the px.rb decoder, that displays some text on the screen:
require 'px' PX.bxbwbuemebefdxelbgdwehakeienemelbgbndjdxeedvehefdxbgemehbgdudtdwbgdeenduerbg PX.ehdudyeneldvdtemebehegbhbnakdxegdwak -PX
Pretty incomprehensible, right? Here's a program that will help you create your own encoded / obfuscated Ruby scripts called pxcode.rb:
require 'px' PX.eienemelbgbiekdxejenebekdxbgbneieqbnbiakdueebgcjbgdndpakebbgcjbgbwakbkelemdw PX.ebegbudxdtdveabgetbgeueeebegdxeuakeeebegdxbuelendubhbobvdqdoelbrbvbsbgbnbnbp PX.akeeebegdxbudxdtdveadrdueremdxbgetbgeudueuakdubgcjbgdubuemehdrebakebbgbrcjbg PX.bxbgebdybgdueednebdpbgbmbmbgdueednebdpbueedxegdzemeabgckbgcdcbakdueednebdpbg PX.eueucjbgbnbnakdueednebdpbgbrcjbgbodubgbvbgbyccbgbrbgcfcdbpbudveaekbgbrbgbodu PX.bgblbgbyccbgbrbgcfcdbpbudveaekakevakevakdueebudxdtdveabgetbgeueeeuakeienemel PX.bgbidcdkbubjeteeevbiakevakeienemelbgbibtdcdkbi -PX
To use it, you'll run.. ruby pxcode.rb < your_source_file.rb > output_file.rb where your_source_file.rb is the file you want to encode and output_file.rb is the output file. A PX encrypted Ruby file is created and can be run immediately in the normal way.
Technorati Tags: obfuscation, ruby
June 3, 2006 at 5:26 pm
It's too easy to decode a file :
1. replace eval by puts in the px.rb file
2. run the obfuscated script
3. you got the original source code