渗透测试DNS重绑定

前言

** SSRF绕过** 的一种思路,就是利用DNS重绑定,它也被广泛用于 ** 绕过同源策略** ,本质就是欺骗客户端请求的IP地址。

但是之前都是用如xip.io等别人搭建好的平台去利用,没有自己搞过,也没能彻底理解其中的原理

** DNS重绑定**

浏览网页过程中,用户在地址栏中输入包含域名的网址,浏览器通过DNS服务器将域名解析为IP地址,然后向对应的IP地址请求资源,最后展现给用户。即 域名 =>
公共DNS服务器 => IP

但是作为域名的所有者,可以随时设置解析IP,举例如下:

用户第一次访问,解析域名test.gm7.org的IP为104.21.26.222

在用户第二次访问前,修改域名解析的IP为127.0.0.1

用户第二次访问,解析域名test.gm7.org的IP为127.0.0.1

[!tip]

一般来说我们的操作系统默认能够将DNS返回来的这个IP地址信息保存60秒,而超过60秒后如果需要再次访问这个域名,就会重新去请求一次dns

对于浏览器来说,两次访问的都是同一域名,是符合浏览器的同源策略的,但是第二次访问解析到其他IP,调用到了其他资源。 **
这样的行为被称之为域名重新绑定攻击(DNS ReBinding)。**

[!tip]

简而言之:当我们发起域名解析请求的时候,第一次访问会返回一个ip地址A,但是当我们发起第二次域名解析请求的时候,却会返回一个不同于A的ip地址B。

** 实现方法**

** ceye**

ceye.io个人信息最下方,可以设置解析IP,具体说明:http://ceye.io/dns-rebinding

有一个注意点:就是每次都是随机返回一个设置的IP,所以可能大概率碰运气

1652076940_6278b18cc4a3894187d2c.png!small?1652076941019

** 验证:**

重绑定使用域名:r.abcdef.ceye.io or *.r.abcdef.ceye.io

1652076950_6278b196926f987755b1e.png!small?1652076952153

** 基础自建**

前提是有域名,然后增加一个A记录和一个NS记录

1652076963_6278b1a3f10a230e9745b.png!small?1652076964123

此时访问dra.gm7.org域名,先解析该域名的DNS域名为dr.gm7.org,指向10开头的这台服务器。

在10开头的这台服务器上,运行如下python脚本

[!tip]

在ubuntu中,可能会遇到53端口被占用情况,可以尝试

service systemd-resolved stop
service named stop

pip2 install twisted

sudo python2 thiss.py

from twisted.internet import reactor, defer
from twisted.names import client, dns, error, server
record={}
** class** DynamicResolver(object):
** def** _doDynamicResponse(self, query):
name = query.name.name
** if** name not ** in** record or record[name]<1:
ip = “114.114.114.114”
** else** :
ip = “127.0.0.1”
** if** name not ** in** record:
record[name] = 0
record[name] += 1
print name + " ===> " + ip
answer = dns.RRHeader(
name = name,
type = dns.A,
cls = dns.IN,
ttl = 0,
payload = dns.Record_A(address = b’%s’ % ip, ttl=0)
)
answers = [answer]
authority = []
additional = []
** return** answers, authority, additional
** def** query(self, query, timeout=None):
** return** defer.succeed(self._doDynamicResponse(query))
** def** main():
factory = server.DNSServerFactory(
clients=[DynamicResolver(), client.Resolver(resolv=‘/etc/resolv.conf’)]
)
protocol = dns.DNSDatagramProtocol(controller=factory)
reactor.listenUDP(53, protocol)
reactor.run()
** if** name == ‘main’:
** raise** SystemExit(main())

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MZIXJUDp-1690686934934)(https://image.3001.net/images/20220509/1652076997_6278b1c5ab0ed0eb1b6f9.png!small?1652076998297)]

** singularity**

A DNS rebinding attack framework. https://github.com/nccgroup/singularity

wiki: https://github.com/nccgroup/singularity/wiki

主要针对绕过SOP,也可用于绕过SSRF

** 安装配置**

[!note]

也需要一个域名,域名配置和上面自建一样,一个A记录一个NS记录

** 安装:** 需要go环境

git clone https://github.com/nccgroup/singularity
cd singularity/cmd/singularity-server
go build

** 部署web界面:**

给二进制文件移动到html目录同级

1652077015_6278b1d77cff7afdc2d99.png!small?1652077016570

直接运行二进制文件即可启动

1652077023_6278b1df4e4735cc5e03e.png!small?1652077023585

访问管理页面:8080端口

1652077030_6278b1e66a13edbaa3d0b.png!small?1652077030803

** 基础使用**

进入管理页面,输入参数,开始攻击后拿到域名

1652077036_6278b1ec32da25e481d2a.png!small?1652077036528

multiple answers策略设置下的效果

1652077047_6278b1f7633be3916fd1a.png!small?1652077047691

其他Rebinding Strategy说明见下方,在multiple
answers策略下,浏览器会拿到多个dns响应,首先会尝试用第一个连接,失败之后就会尝试另一个,这时就实现了DNS重绑定。这个其实算是一个正常功能,也非常常见,可以说是DNS层面的负载均衡技术。

** Manager UI说明**

manager web界面是配置和启动DNS重新绑定攻击的地方。默认情况下,它监听端口8080。下表介绍了管理器界面中的所有表单字段和按钮:

Field Name

|

Description

—|—

Attack Host Domain

|

This is the (sub-)domain where the Singularity web server is running. Default
value: d.rebind.it

Attack Host

|

This is the IP address where the manager and the attack payloads are hosted.
Default value: xxx.xxx.xxx.xxx

Target Host

|

This is the IP address or FQDN (e.g. jenkins.internal.target.com) of the
target system where the victim (target) application is running. Default value:
127.0.0.1

Target Port

|

This is the port where the victim (target) application is listening on.
Default value: 8080

Request New Port

|

This will request Singularity to listen on a new port. This feature is only
available when Singularity has been started with the
-dangerouslyAllowDynamicHTTPServers command line option.

Attack Payload

|

This is where you select the payload, i.e. which application you are trying to
exploit.

Start Attack

|

Start the DNS rebinding attack. Be patient and wait for at least one minute.
Open the browser web console to see debugging logs.

Toggle Advanced Options

|

This button will enable the advanced fields described below.

** Rebinding Strategy**

|

Specify how to respond to DNS queries from a victim client. The following
options are available:

  • First then second (default, conservative): This is the default value. It should work on most if not all platforms in 40 to 60 seconds.
  • Multiple answers: Near instant DNS rebinding attack! Make sure to set the interval option described below to 1 second and the target address if attacking the local host to “0.0.0.0” for Unix-like platforms (e.g. Linux, macOS) and to “127.0.0.1” (or any other valid local host addresses) for Microsoft Windows.
  • Round robin (IPS/filters evasion): Alternate DNS responses between the attack and target host IP addresses.
  • Random (IPS/filters evasion): Randomly alternate DNS responses between the attack and target host IP addresses.

Interval

|

How long to wait between connection attempts to the target application in
seconds. Default value: 20

Flood DNS Cache

|

Perform ~1000 DNS queries to evict cached DNS entries in Google Chrome and to
improve DNS rebind attack speed from ~60s down to ~20s. Useful with the
following DNS rebinding strategies: First then second, Round robin, Random.
Default value: unset

Index Token

|

The index token is used by Singularity to detect if the rebinding has happened
yet. Default value: thisismytesttoken.

** 参考文章**

.aliyun.com/t/7495)

网络安全工程师(白帽子)企业级学习路线

第一阶段:安全基础(入门)

img

第二阶段:Web渗透(初级网安工程师)

img

第三阶段:进阶部分(中级网络安全工程师)

img

如果你对网络安全入门感兴趣,那么你需要的话可以点击这里👉网络安全重磅福利:入门&进阶全套282G学习资源包免费分享!

学习资源分享

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Wvioy43T-1690686934938)(C:\Users\Administrator\Desktop\网络安全资料图\微信截图_20230201105953.png)]

Internet 服务提供商 (ISP) 的技术支持成本不断飞涨。实际上,对于许多 ISP 来说,技术支持的成本已经相当于或甚至超过 WAN 带宽成本,成为服务商们花费最高的单项成本。 随着 ISP 的合并、更多的用户上网、典型用户群从精通技术的用户转变为不太懂技术的用户,ISP 正面对着一场日益艰难的战斗。这场战斗由下列部分组成:使最终用户的连接自动化而无论其地理位置在何处、优化基础结构性能以及管理和配置最终用户系统。 许多寻求 ISP 技术支持的电话,都源自域名服务 (DNS) 问题。DNS 是一个分布式数据库,提供了 IP 地址和主机名之间的映射。 要使网络进行正常运作,就必须为用户的计算机配置正确的 DNS 服务器地址。如果 DNS 服务器地址配置错了(由于用户输入地址时出错、输入被意外更改或其它任何原因),将导致用户失去与 Internet 的连接。几分钟以后,他们寻求 ISP 技术支持的电话就来了。 而且,为用户的计算机正确配置 DNS 服务器地址的需要可能会妨碍 ISP 为满足用户的需求而更改 DNS 的能力。例如,ISP 可能要从一个集中式 DNS 服务器转变为使用许多分散的 DNS 服务器,以适应用户数量的不断增长。 理想情况下,如果使用分散式 DNS 服务器,用户应该访问与之最接近的 DNS 服务器。但是,由于分散式架构中的各 DNS 服务器都具有唯一的 IP 地址,因此,除非每个用户在自己的计算机上重新配置 DNS 服务器地址,否则,是不可能实现这种理想情况的。 对于任何一个 ISP 来说,让用户更改计算机中的 DNS 服务器地址是一项艰巨而耗时、并且蕴涵着各种潜在问题的任务。如果用户在更改过程中由于 DNS 服务器地址配置错误而请求技术支持,则处理起来更加困难。 虽然动态主机控制协议 (DHCP) 可以缓解其中某些问题,但 ISP 必须使他们的所有用户转换成使用这种自动寻址方案。 而在服务器交换机上采用的 DNS 重定向技术可以消除这些问题。服务器交换机是一种新型、特殊的 LAN 交换机,它为单个服务器服务器集群作前端处理。它所提供的定制服务可以提高可伸缩性、可用性和服务器效率。对发往服务器的流量进行重定向或作负载平衡处理的能力就是这类增值服务之一。 通过重定向 DNS 流量,所有 DNS 请求都被引导至 ISP 所选定的 DNS 服务器,而不管这些请求原来指向何处。如果用户的计算机由于任何原因而使用了错误的 DNS 服务器地址,这也没有任何关系。DNS 请求仍被引导至 ISP 所选定的 DNS 服务器,用户的网络连通性也同时得到维持 ? 无需打电话请求 ISP 的技术支持。 此外,ISP 可能希望用户使用另一个 DNS 服务器,而不是原来为用户的计算机配置的那个,即使原来配置的地址对于用户的本地接入点 (PoP) 来说是正确的。这种情况的一个典型例子,是移动用户离开了原住地,而他们的 ISP 又采用了分布式 DNS 架构。 如果不使用 DNS 重定向,DNS 请求将被发送到用户住宅所在地 PoP 的 DNS 服务器,而不是发送到用户拨入的 PoP 的 DNS 服务器。此时 DNS 重定向可以再次发挥作用,因为用户使用的 DNS 服务器地址将被忽略,DNS 请求将被引导至 ISP 指定的 DNS 服务器。 最后,DNS 重定向还允许将 DNS 请求动态地分配给服务器集群中的多个 DNS 服务器。这样可以提高处理能力,减少响应时间,并提高 DNS 的可用性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值