当前位置:网站首页>PHP code audit and File Inclusion Vulnerability
PHP code audit and File Inclusion Vulnerability
2022-07-01 09:37:00 【The wind is everywhere】
php Code audit and file contain vulnerabilities
One 、 The file contains an introduction to the vulnerability
1. What is a file containing
The same code appears repeatedly in different files, resulting in code redundancy , So there are file containing functions , Is to make the code more efficient . The part that needs to be used will call , And the included documents will be PHP Code execution , Ignore own suffix . File contains are divided into local file contains (Loacl File Inclusion,LFI) And remote files contain (Remote File Inclusion,RFI), Remote files need to be included in php.ini Set in allow_url_include = on and allow_url_fopen = on
2. The file contains the definition of vulnerability
File Inclusion itself is not a vulnerability , The file contained in the program will not form a vulnerability , Almost all vulnerabilities are caused by controllable parameters , Attackers take advantage of the included features , Plus the application itself on the file ( contain ) Control is not strict , Finally, it will cause the attacker to carry out arbitrary file inclusion . Usually the file containing vulnerability occurs in php In language .
3. The file contains the functions that appear
include() function : Use include Reference to external documents , Only the code executes to include Code snippets , The external file called will be referenced and read , When an error occurs in the referenced file , The system will only give a warning error , And the whole php The file will continue to execute .
require() function : stay php Before the file is executed ,php The parser will replace... With the entire contents of the referenced file require Function statement , Then with require Statements other than statements form a new php file , It is better to press the new php File execution program code .
include_once() function : Use include_once It will check whether the file has been referenced in other parts of the file before importing it , If there is , The file will not be referenced again , The program can only reference once .
require_once() function : Function and require() identical , The difference is that when the same file is called repeatedly , The program can only be called once .
Two 、 Examples of vulnerabilities
Yes phpadmin-4.8.1 System code audit
1. First, search globally in the audit system include Function keywords , I found out that there was one request[target] The ginseng .

2. Click in , There are five conditions

Namely
1、target The pass parameter is not empty and 0
2、target The parameter must be a string
3、 Parameter transfer failure index start
4、 The reference cannot be import.php、export.php
Continue to follow up checkPageValidity() function

There are three situations ,checkPageValidity() The function returns ture, And they all require p a g e stay page stay page stay whitelist Array ,

Let's look at the first case , If whitelist It's empty , Then reassign .
To follow up $goto_whitelis Array , Discovery is a white list . Here's the picture

Let's look at the first return ture The place of , The requirement is whether the string passed as a parameter is in the array , You can enter the file name of a whitelist here , But it doesn't make sense , Contains a file that has been written , Unable to achieve any goal .

Looking at the second
mb_substr() function : Intercepting string . grammar :mb_substr( a , 0 , 3 ) , It means thinking yes section take word operator strand a Of front 3、 ... and position m b s t r p o s ( ) Letter Count : sentence break position Set up Of Letter Count , The first First hold Pass on ginseng a,0,3), It means to intercept the string a The top three of mb_strpos() function : Function of judging position , First pass the parameter a,0,3), It means thinking yes section take word operator strand a Of front 3、 ... and position mbstrpos() Letter Count : sentence break position Set up Of Letter Count , The first First hold Pass on ginseng page Connect a question mark , Find the position of the question mark and return , Only the position of the first question mark will be returned , If there is a question mark in our biography , But in php in get An error will be reported if the reference question mark is passed , Because in url The middle question mark means "pass parameter" , It cannot be used as a parameter value . Continue to look at the next judgment
.
See a urldecode() function : Do a decoding . Then we put the ? Do it twice url Just code it , After coding is %25%3f,url Decoded as %3f, The code goes here , The question mark comes out .
Go to a file on the white list server_binlog.php,
structure playload:target=server_binlog.php%253f/…
/1.txt

But how to write webshell Well ,
This 1.txt I write on the server , there phpadmin No upload function
resolvent ,
Find the storage location first ,select @@datadir // Data storage location , The position shown here is the absolute path

Create a new table , Enter a sentence

Find the database storage file .

test phpinfo
边栏推荐
- dotnet 控制台 使用 Microsoft.Maui.Graphics 配合 Skia 进行绘图入门
- SQL learning notes (03) -- data constraint relationship
- 闭包实现迭代器效果
- SDN_简单总结
- nacos服务配置和持久化配置
- Nacos service configuration and persistence configuration
- PHP array functions (merge, split, append, find, delete, etc.)
- 华为帐号多端协同,打造美好互联生活
- Computer USB, HDMI, DP various interfaces and speeds
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
猜你喜欢

吃一个女富豪的瓜。。。

2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder

HMS core audio editing service 3D audio technology helps create an immersive auditory feast

MapReduce programming basics

Dspic30f6014a LCD block display

Implementation and application of queue

Cortex M4 systick details

nacos简易实现负载均衡

Import and export of power platform platform sharepointlist

2.3 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据
随机推荐
Flinkv1.13实现金融反诈骗案例
JS prototype inheritance can only inherit instances, not constructors
【pytorch学习】torch.device
ESP8266 FreeRTOS开发环境搭建
[ESP nanny level tutorial] crazy completion chapter - Case: gy906 infrared temperature measurement access card swiping system based on the Internet of things
How to launch circle of friends marketing and wechat group activities
Huawei accounts work together at multiple ends to create a better internet life
Implementation and application of queue
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DHT11 +nodejs local service + MySQL database
ES6 const essence and completely immutable implementation (object.free)
Dspic30f6014a LCD block display
【无标题】
JS rewrite their own functions
【检测技术课案】简易数显电子秤的设计与制作
NoSQL数据库的安装和使用
Structure de l'arbre - - - arbre binaire 2 traversée non récursive
SQL学习笔记(03)——数据约束关系
Tree structure -- binary tree 2 non recursive traversal
js原型陷阱
Introduction to mt7628k eCos development