好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

SQL Server 高阶应用.doc

10页
  • 卖家[上传人]:汽***
  • 文档编号:530481422
  • 上传时间:2023-09-19
  • 文档格式:DOC
  • 文档大小:63.50KB
  • / 10 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • SQL Server 高阶应用 Posted on 2005-06-06 12:51 Let's DotNet 阅读(413) 评论(1) 编辑 收藏 网摘 所属分类: tech 一、统计功能[查看当前SQLServer的使用人员列表]select count(distinct loginame) from sysprocesses注- sysprocesses 是系统表,在默认数据库master中[查看当前SQLServer的使用人数]select distinct loginame from sysprocesses[过滤查询]新建一张专门用于监视数据连接使用情况的临时表CREATE table MonitorUser ( spid int, ecid int, status varchar(200), loginame varchar(200), hostname varchar(200), --根据sp_who的结果新建表结构 blk varchar(200), dbname varchar(200), cmd varchar(200), [DateTime] [datetime] NOT NULL ) ALTER TABLE [dbo].[MonitorUser] WITH NOCHECK ADD CONSTRAINT [DateTime] DEFAULT (getdate()) for[DateTime] --自动获取时间插到datetime列中 GO insert into MonitorUser(spid,ecid,status,loginame,hostname,blk,dbname,cmd) exec ('sp_who') 例:select * from MonitorUser where hostname='XXX-DAVID-J-GU' and dbname='PRJ2' [Status解释]Background: 后台执行(SPID is performing a background task.)Sleeping: 休眠(SPID is not currently executing. This usually indicates that the SPID is awaiting a command from the application).Runnable: 正在执行(SPID is currently executing).Dormant: 休眠并清除资源(Same as Sleeping, except Dormant also indicates that the SPID has been reset after completing an RPC event. The reset cleans up resources used during the RPC event. This is a normal state and the SPID is available and waiting to execute further commands).Rollback: 回滚(The SPID is in rollback of a transaction).Defwakeup: 等待资源(Indicates that a SPID is waiting on a resource that is in the process of being freed. The waitresource field should indicate the resource in question).Spinloop: 等待解锁(Process is waiting while attempting to acquire a spinlock used for concurrency control on SMP systems).二、SQL注入[xp_cmdshell] 许多存储过程被创建在SQLSERVER中,执行各种各样的功能,例如发送电子邮件和与注册表交互。

      Xp_cmdshell是一个允许执行任意的命令行命令的内置的存储过程例如: Exec master..xp_cmdshell ’dir’ 将获得SQLSERVER进程的当前工作目录中的目录列表 Exec master..xp_cmdshell ’net user’ 将提供服务器上所有用户的列表当SQLSERVER正常以系统帐户或域帐户运行时,攻击者可以做出更严重的危害 [xp_regread] 另一个有用的内置存储过程是xp_regXXXX类的函数集合 Xp_regaddmultistring Xp_regdeletekey Xp_regdeletevalue Xp_regenumkeys Xp_regenumvalues Xp_regread Xp_regremovemultistring Xp_regwrite 这些函数的使用方法举例如下: exec xp_regread HKEY_LOCAL_MACHINE,’SYSTEM\CurrentControlSet\Services\lanmanserver\parameters’, ’nullsessionshares’ 这将确定什么样的会话连接在服务器上是可以使用的 exec xp_regenumvalues HKEY_LOCAL_MACHINE,’SYSTEM\CurrentControlSet\Services\snmp\parameters\validcommunities’ 这将显示服务器上所有SNMP团体配置。

      在SNMP团体很少被更改和在许多主机间共享的情况下,有了这些信息,攻击者或许会重新配置同一网络中的网络设备 这很容易想象到一个攻击者可以利用这些函数读取SAM,修改系统服务的配置,使它下次机器重启时启动,或在下次任何用户登陆时执行一条任意的命令 [其他存储过程] xp_servicecontrol过程允许用户启动,停止,暂停和继续服务: exec master..xp_servicecontrol ’start’,’schedule’ exec master..xp_servicecontrol ’start’,’server’ 下表中列出了少量的其他有用的存储过程: Xp_availablemedia 显示机器上有用的驱动器 Xp_dirtree 允许获得一个目录树 Xp_enumdsn 列举服务器上的ODBC数据源 Xp_loginconfig Reveals information about the security mode of the server Xp_makecab 允许用户在服务器上创建一个压缩文件 Xp_ntsec_enumdomains 列举服务器可以进入的域 Xp_terminate_process 提供进程的进程ID,终止此进程 [Linked Servers] SQL SERVER提供了一种允许服务器连接的机制,也就是说允许一台数据库服务器上的查询能够操作另一台服务器上的数据。

      这个链接存放在master.sysservers表中如果一个连接的服务器已经被设置成使用’sp_addlinkedsrvlogin’过程,当前可信的连接不用登陆就可以访问到服务器’openquery’函数允许查询脱离服务器也可以执行 [Custom extended stored procedures] 扩展存储过程应用程序接口是相当简单的,创建一个携带恶意代码的扩展存储过程动态连接库是一个相当简单的任务使用命令行有几个方法可以上传动态连接库到SQL服务器上,还有其它包括了多种自动通讯的通讯机制,比如HTTP下载和FTP脚本 一旦动态连接库文件在机器上运行即SQL服务器能够被访问——这不需要它自己是SQL服务器——攻击者就能够使用下面的命令添加扩展存储过程(这种情况下,我们的恶意存储过程就是一个能输出服务器的系统文件的小的木马): Sp_addextendedproc ’xp_webserver’,’c:\temp\xp_foo.dll’ 在正常的方式下,这个扩展存储过程可以被运行: exec xp_webserver 一旦这个程序被运行,可以使用下面的方法将它除去: xp_dropextendedproc ’xp_webserver’ [将文本文件导入表] 使用’bulk insert’语法可以将一个文本文件插入到一个临时表中。

      简单地创建这个表: create table foo( line varchar(8000) ) 然后执行bulk insert操作把文件中的数据插入到表中,如: bulk insert foo from ’c:\inetpub\wwwroot\process_login.asp’ 可以使用上述的错误消息技术,或者使用’union’选择,使文本文件中的数据与应用程序正常返回的数据结合,将数据取回这个用来获取存放在数据库服务器上的脚本源代码或者ASP脚本代码是非常有用的 [使用bcp建立文本文件] 使用’bulk insert’的相对技术可以很容易建立任意的文本文件不幸的是这需要命令行工具’bcp’,即’bulk copy program’ 既然 bcp可以从SQL服务进程外访问数据库,它需要登陆这代表获得权限不是很困难,既然攻击者能建立,或者利用整体安全机制(如果服务器配置成可以使用它) 命令行格式如下: bcp "select * from text..foo" queryout c:\inetpub\wwwroot\runcommand.asp –c -Slocalhost –Usa –Pfoobar ’S’参数为执行查询的服务器,’U’参数为用户名,’P’参数为密码,这里为’foobar’ [ActiveX automation scripts in SQL SERVER] SQL SERVER中提供了几个内置的允许创建ActiveX自动执行脚本的存储过程。

      这些脚本和运行在windows脚本解释器下的脚本,或者ASP脚本程序一样——他们使用VBScript或javascript书写,他们创建自动执行对象并和它们交互一个自动执行脚本使用这种方法书写可以在Transact-SQL中做任何在ASP脚本中,或者WSH脚本中可以做的任何事情为了阐明这些,这里提供了几个例子: (Ⅰ)这个例子使用’wscript.shell’对象建立了一个记事本的实例: wscript.shell example declare @o int exec sp_oacreate ’wscript.shell’,@o out exec sp_oamethod @o,’run’,NULL,’notepad.exe’ 我们可以通过指定在。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.