PHPEverywhere has an interesting link today about self-replicating PHP.
Doug Ross solves this interesting problem in PHP: to write a source program that, when compiled and executed, will produce as output an exact copy of its source. This is trickier than it sounds, because using the file system or intermediate storage is cheating. While showering [... ] I realized that the solution involves dividing the code into replication and payload modules. The payload is the replication code, stored as a string. The replication code will output the payload twice, once as PHP code (the replication code replicated), and once as a PHP string (the payload replicated).
Does the above algorithm sound familiar? It's one that every virus writer knows by heart!
The idea is to create a program that would, when compiled and executed, output an exact copy of its own source. The real trick is to do it without filesystem functions or any other immediate storage options. Sound like enough of a challenge for you?




