Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this Perl code work?

I found this Perl program:

''=~('(?{'.(']])@+}'^'-/@._]').'"'.('/<[*-_<+>?}{>]@}+@}]])@+}@<[*-_<+>?}{>]@^'^'`^=_^<]_[[]+[/,]_/]-/@._]/^=_^<]_[[]+[/,|').',$/})')

It prints "Obfuscated Perl to print obfuscated Perl"

I want to know how it actually prints this.

like image 318
Umair Ayub Avatar asked Jul 26 '16 13:07

Umair Ayub


People also ask

How does a Perl script work?

Perl is a fairly straightforward, widely known and well-respected scripting language. It is used for a variety of tasks (for example, you can use it to create the equivalent of DOS batch files or C shell scripts), but in the context of Web development it is used to develop CGI scripts.

What is Perl coding used for?

Perl is a high-level, interpreted, general-purpose programming language originally developed for text manipulation. It borrows many features from C and Shell script and is used for system administration, networking, and other applications that involve user interfaces.

How does Perl interpreter work?

Perl is InterpretedTraditional compilers convert programs into machine language. When you run a Perl program, it's first compiled into a byte code, which is then converted ( as the program runs) into machine instructions.


1 Answers

It is making good use of the bitwise string XOR operator ^.

']])@+}' ^ '-/@._]'

evaluates to print,

'/<[*-_<+>?}{>]@}+@}]])@+}@<[*-_<+>?}{>]@^' 
    ^ '`^=_^<]_[[]+[/,]_/]-/@._]/^=_^<]_[[]+[/,|'

evaluates to Obfuscated Perl to print obfuscated Perl" and the whole program reduces to

$ perl -MO=Deparse ...
'' =~ m[(?{print "Obfuscated Perl to print obfuscated Perl",$/})];
... syntax OK

Related: Acme::EyeDrops

like image 127
mob Avatar answered Sep 29 '22 12:09

mob