The Chimera Quine; or, the ISO PDF

Inspired by PoC||GTFO, herewith is a (pseudo) quine written in Perl that generates a copy of itself as a PDF which is also a mountable ISO with that PDF as the sole file.

Copy the script as quine.pl, run it, and you'll get a quine.pdf which can also be mounted as a filesystem:

bash$ file quine.pdf 
quine.pdf: # ISO 9660 CD-ROM filesystem data 'CDROM'
bash$ sudo mount -o ro quine.pdf /mnt
bash$ ls /mnt
quine.pdf
bash$ 

quine.pl:

#!/usr/bin/perl
use strict;
use warnings;

our $/ = undef;
open STDERR, ">", "/dev/null";
open STDOUT, ">", "/dev/null";

my $name = "quine";
system "enscript","-p","$name.ps","$name.pl";
system "ps2pdf", "$name.ps", "$name.pdf";
system "genisoimage", "-o", "$name.iso", "$name.pdf";

unlink "$name.ps";

my ($iso, $pdf);
{
    open my $FH, "<", "$name.iso";
    $iso = <$FH>;
    close $FH;
    unlink "$name.iso";
}

{
    open my $FH, "<", "$name.pdf";
    $pdf = <$FH>;
    close $FH;
    unlink "$name.pdf";
}

substr($iso, 0, length($pdf)) = $pdf;
open my $FH, ">", "$name.pdf";
print $FH $iso;
close $FH;

The magic trick? ISO 9660 ignores the first 32K, so we can stuff anything at all we want in there without affecting the integrity of the filesystem.

(Assumes requisite tools are installed and /dev/null exists)

Leave a comment

About Peter Martini

user-pic I like thinking about machines, especially virtual machines like Perl's VM, the Java VM, and kvm/qemu