资源描述:
《sql server 高阶应用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、SQLServer高阶应用Postedon2005-06-0612:51Let'sDotNet阅读(413)评论(1)编辑收藏网摘所属分类:tech一、统计功能[查看当前SQLServer的使用人员列表]selectcount(distinctloginame)fromsysprocesses注-sysprocesses是系统表,在默认数据库master中[查看当前SQLServer的使用人数]selectdistinctloginamefromsysprocesses[过滤查询]新建一张专门用于监视数据连接使用情况的临时表CREATEtableMonitorUser(spidint,e
2、cidint,statusvarchar(200),loginamevarchar(200),hostnamevarchar(200),--根据sp_who的结果新建表结构blkvarchar(200),dbnamevarchar(200),cmdvarchar(200),[DateTime][datetime]NOTNULL)ALTERTABLE[dbo].[MonitorUser]WITHNOCHECKADDCONSTRAINT[DateTime]DEFAULT(getdate())for[DateTime]--自动获取时间插到datetime列中GOinsertintoMonito
3、rUser(spid,ecid,status,loginame,hostname,blk,dbname,cmd)exec('sp_who')例:select*fromMonitorUserwherehostname='XXX-DAVID-J-GU'anddbname='PRJ2'[Status解释]Background:后台执行(SPIDisperformingabackgroundtask.)Sleeping:休眠(SPIDisnotcurrentlyexecuting.ThisusuallyindicatesthattheSPIDisawaitingacommandfromtheap
4、plication).Runnable:正在执行(SPIDiscurrentlyexecuting).Dormant:休眠并清除资源(SameasSleeping,exceptDormantalsoindicatesthattheSPIDhasbeenresetaftercompletinganRPCevent.TheresetcleansupresourcesusedduringtheRPCevent.ThisisanormalstateandtheSPIDisavailableandwaitingtoexecutefurthercommands).Rollback:回滚(TheSPI
5、Disinrollbackofatransaction).Defwakeup:等待资源(IndicatesthataSPIDiswaitingonaresourcethatisintheprocessofbeingfreed.Thewaitresourcefieldshouldindicatetheresourceinquestion).Spinloop:等待解锁(ProcessiswaitingwhileattemptingtoacquireaspinlockusedforconcurrencycontrolonSMPsystems).二、SQL注入[xp_cmdshell]许多存储过
6、程被创建在SQLSERVER中,执行各种各样的功能,例如发送电子邮件和与注册表交互。Xp_cmdshell是一个允许执行任意的命令行命令的内置的存储过程。例如:Execmaster..xp_cmdshell’dir’将获得SQLSERVER进程的当前工作目录中的目录列表。Execmaster..xp_cmdshell’netuser’将提供服务器上所有用户的列表。当SQLSERVER正常以系统帐户或域帐户运行时,攻击者可以做出更严重的危害。[xp_regread]另一个有用的内置存储过程是xp_regXXXX类的函数集合。Xp_regaddmultistringXp_regdeletek
7、eyXp_regdeletevalueXp_regenumkeysXp_regenumvaluesXp_regreadXp_regremovemultistringXp_regwrite这些函数的使用方法举例如下:execxp_regreadHKEY_LOCAL_MACHINE,’SYSTEMCurrentControlSetServiceslanmanserverparameters’,’nullsessionshares