Table of Contents
Analyzing PHP Object Injection Vulnerability
Home Backend Development PHP Tutorial Analyzing PHP Object Injection Vulnerabilities_PHP Tutorial

Analyzing PHP Object Injection Vulnerabilities_PHP Tutorial

Jul 13, 2016 am 10:07 AM
object loopholes

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 = &#39;&#39;;
 
    // 允许对象作为一个字符串输出上面的data
 
    public function __toString()
    {
        return &#39;User &#39; . $this->name . &#39; is &#39; . $this->age . &#39; years old. 
&#39;;
    }
}
 
// 用户可控
 
$obj = unserialize($_GET[&#39;usr_serialized&#39;]);
 
// 输出 __toString
var_dump($obj) ;
echo $obj;

?>
Copy after login

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/953320.htmlTechArticleAnalyzing PHP object injection vulnerabilities?? 0. Preface I saw an interesting translation when browsing the Wuyun Knowledge Base: www.Bkjia.com is talking about an injection method called object injection. Can objects also be injected? ...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Convert an array or object to a JSON string using PHP's json_encode() function Convert an array or object to a JSON string using PHP's json_encode() function Nov 03, 2023 pm 03:30 PM

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

Jailbreak any large model in 20 steps! More 'grandma loopholes' are discovered automatically Jailbreak any large model in 20 steps! More 'grandma loopholes' are discovered automatically Nov 05, 2023 pm 08:13 PM

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 vulnerability in Java and its harm Buffer overflow vulnerability in Java and its harm Aug 09, 2023 pm 05:57 PM

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

How to convert MySQL query result array to object? How to convert MySQL query result array to object? Apr 29, 2024 pm 01:09 PM

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 Use Python's __contains__() function to define the containment operation of an object Aug 22, 2023 pm 04:23 PM

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

The OpenAI DALL-E 3 model has a vulnerability that generates 'inappropriate content.' A Microsoft employee reported it and was slapped with a 'gag order.' The OpenAI DALL-E 3 model has a vulnerability that generates 'inappropriate content.' A Microsoft employee reported it and was slapped with a 'gag order.' Feb 04, 2024 pm 02:40 PM

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

Comma operator vulnerabilities and protective measures in Java Comma operator vulnerabilities and protective measures in Java Aug 10, 2023 pm 02:21 PM

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

What is the difference between arrays and objects in PHP? What is the difference between arrays and objects in PHP? Apr 29, 2024 pm 02:39 PM

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.

See all articles