Analyzing PHP Object Injection Vulnerabilities_PHP Tutorial
Analyzing PHP Object Injection Vulnerability
??0. Foreword
I saw an interesting translation while browsing the Wuyun Knowledge Base: www.Bkjia.com
It’s talking about an injection method called object injection. Can objects also be injected?
Yes, nothing is impossible to inject as long as there is tainted data, but this vulnerability is a bit too weird for me to find interesting.
1. Principle
When writing a program, it is often necessary to serialize some runtime data. The so-called serialization is to write the runtime data to a local file in a certain format. In this way, the data can be saved locally. When used, the data generated during runtime can be read out by directly reading the file. In PHP, they are the serialize and unserialize functions.
The principle behind injection is that contaminated data is introduced during deserialization, such as:
$obj = unserialize($_GET[‘injection’]) ;
With this statement, we can construct it ourselves according to the format of the serialized data and get the object $obj we want.
Someone may ask, what is the use of just getting this object $obj? Let’s take a look at the following example first.
2. Scenario
This scene also comes from the demo in the translation, here is a restoration:
<!--?php header(Content-type:text/html;charset=UTF-8); // … 一些include ... class FileClass { // 文件名 public $filename = error.log; //当对象被作为一个字符串会读取这个文件 public function __toString() { echo filename发生了变化==--> . $this->filename ; return file_get_contents($this->filename) ; } } // Main User class class User { // Class data public $age = 0; public $name = ''; // 允许对象作为一个字符串输出上面的data public function __toString() { return 'User ' . $this->name . ' is ' . $this->age . ' years old. '; } } // 用户可控 $obj = unserialize($_GET['usr_serialized']); // 输出 __toString var_dump($obj) ; echo $obj; ?>
The above code obtains a serialized data from user-controllable data, and then calls the unserialize method to deserialize $_GET['usr_serialized'], then this $obj can be controlled by us.
The normal way is to submit:
http://127.0.0.1/code/objin.php?usr_serialized=O:4:User:2:{s:3:age;i:20;s:4:name;s:4:John; }
The above serialized data is an object of User class, where $age=20, $name=John.
At this time, echo $obj; directly echo the object, you can call the magic method __toString. This magic method has been overloaded in the User class, that is, it outputs a string. The operation effect is as follows:
The above code obtains a serialized data from user-controllable data, and then calls the unserialize method to deserialize $_GET['usr_serialized'], then this $obj can be controlled by us.
The normal way is to submit:
http://127.0.0.1/code/objin.php?usr_serialized=O:4:User:2:{s:3:age;i:20;s:4:name;s:4:John; }
The above serialized data is an object of User class, where $age=20, $name=John.
At this time, echo $obj; directly echo the object, you can call the magic method __toString. This magic method has been overloaded in the User class, that is, it outputs a string. The operation effect is as follows:
3. Vulnerability mining
This type of vulnerability is quite hidden, but once it appears, it is very effective. The main purpose of mining is to find out whether the parameters in the unserialize function are contaminated data. Find the corresponding control location, and then see which class can be used to complete our attack, such as the FileClass class in this scenario.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



JSON (JavaScriptObjectNotation) is a lightweight data exchange format that has become a common format for data exchange between web applications. PHP's json_encode() function can convert an array or object into a JSON string. This article will introduce how to use PHP's json_encode() function, including syntax, parameters, return values, and specific examples. Syntax The syntax of the json_encode() function is as follows: st

In less than a minute and no more than 20 steps, you can bypass security restrictions and successfully jailbreak a large model! And there is no need to know the internal details of the model - only two black box models need to interact, and the AI can fully automatically defeat the AI and speak dangerous content. I heard that the once-popular "Grandma Loophole" has been fixed: Now, facing the "Detective Loophole", "Adventurer Loophole" and "Writer Loophole", what response strategy should artificial intelligence adopt? After a wave of onslaught, GPT-4 couldn't stand it anymore, and directly said that it would poison the water supply system as long as... this or that. The key point is that this is just a small wave of vulnerabilities exposed by the University of Pennsylvania research team, and using their newly developed algorithm, AI can automatically generate various attack prompts. Researchers say this method is better than existing

Buffer overflow vulnerabilities in Java and their harm Buffer overflow means that when we write more data to a buffer than its capacity, it will cause data to overflow to other memory areas. This overflow behavior is often exploited by hackers, which can lead to serious consequences such as abnormal code execution and system crash. This article will introduce buffer overflow vulnerabilities and their harm in Java, and give code examples to help readers better understand. The buffer classes widely used in Java include ByteBuffer, CharBuffer, and ShortB

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

Use Python's __contains__() function to define the containment operation of an object. Python is a concise and powerful programming language that provides many powerful features to handle various types of data. One of them is to implement the containment operation of objects by defining the __contains__() function. This article will introduce how to use the __contains__() function to define the containment operation of an object, and give some sample code. The __contains__() function is Pytho

According to news on February 2, Shane Jones, manager of Microsoft’s software engineering department, recently discovered a vulnerability in OpenAI’s DALL-E3 model, which is said to be able to generate a series of inappropriate content. Shane Jones reported the vulnerability to the company, but was asked to keep it confidential. However, he eventually decided to disclose the vulnerability to the outside world. ▲Image source: Report disclosed by ShaneJones. This site noticed that ShaneJones discovered through independent research in December last year that there was a vulnerability in the DALL-E3 model of OpenAI text-generated images. This vulnerability can bypass the AI Guardrail (AIGuardrail), resulting in the generation of a series of NSFW inappropriate content. This discovery attracted widespread attention

Overview of Comma Operator Vulnerabilities and Defense Measures in Java: In Java programming, we often use the comma operator to perform multiple operations at the same time. However, sometimes we may overlook some potential vulnerabilities of the comma operator that may lead to unexpected results. This article will introduce the vulnerabilities of the comma operator in Java and provide corresponding protective measures. Usage of comma operator: The syntax of comma operator in Java is expr1, expr2, which can be said to be a sequence operator. Its function is to first calculate ex

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values are passed and object references are passed.
