Skip to content

Instantly share code, notes, and snippets.

@dap
Created July 18, 2009 13:37
Show Gist options
  • Save dap/149564 to your computer and use it in GitHub Desktop.
Save dap/149564 to your computer and use it in GitHub Desktop.
Store PHP code in a JPEG
#!/usr/bin/perl
# write_jpg.pl - Store PHP code inside of a JPEG
# Darian Anthony Patrick <[email protected]>
#
# Demonstration of masquerading PHP code inside
# of a file identifiable as JPEG format
use perl5i;
use IO::All;
#Create "JPEG image data" and "JFIF standard" magic patterns
my $pat = pack('H4xxxxa*', 'ffd8', 'JFIF');
# Output magic patterns followed by PHP code
io('/tmp/this_contains_php.jpg')->print(
$pat,
'<?php echo "\nThis output is from PHP code stored inside of a \"JPEG\".\n"; ?>'
);
say 'Completed "JPEG" creation.';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment