def __init__(self): self.proxy_on = False self.interceptor_on = False self.interceptor = interceptor.Interceptor() # Running this ensures iptables-save returns the correct output subprocess.run(['iptables', '-L'], stdout=DEVNULL, stderr=DEVNULL)
def __init__(self, learningmode=True): self._ipt_handler = IPTablesHandler() self._ictor_out = interceptor.Interceptor() self._ictor_in = interceptor.Interceptor() self._state_active = False # Rule format: b"1234A" b"1234ABB" self._rules_ip_proto_wl_out = set() self._rules_ip_proto_bl_out = set() self._rules_ip_proto_wl_in = set() self._rules_ip_proto_bl_in = set() # hashes of known apps, stored non volatile (PID is dynamic) self._app_wl = set() self._app_bl = set() self._rulefile_wl_out = "fw_rules_wl_out.txt" self._rulefile_bl_out = "fw_rules_bl_out.txt" self._rulefile_wl_in = "fw_rules_wl_in.txt" self._rulefile_bl_in = "fw_rules_bl_in.txt" self._inputlock = threading.Lock() self._learningmode = learningmode
from pypacker import interceptor from pypacker.layer3 import ip, icmp # ICMP Echo request intercepting def verdict_cb(data, ll_proto_id, ctx): ip1 = ip.IP(data) icmp1 = ip1[icmp.ICMP] if icmp1 is None or icmp1.type != icmp.ICMP_TYPE_ECHO_REQ: return data, interceptor.NF_ACCEPT echo1 = icmp1[icmp.ICMP.Echo] if echo1 is None: return data, interceptor.NF_ACCEPT pp_bts = b"PYPACKER" print("changing ICMP echo request packet") echo1.body_bytes = echo1.body_bytes[:len(pp_bts)] + pp_bts return ip1.bin(), interceptor.NF_ACCEPT ictor = interceptor.Interceptor() ictor.start(verdict_cb) print("sleeping") try: time.sleep(999) except KeyboardInterrupt: pass ictor.stop()
import time from pypacker import interceptor from pypacker.layer3 import ip, icmp # ICMP Echo request intercepting def verdict_cb(data): ip1 = ip.IP(data) icmp1 = ip1[icmp.ICMP] if icmp1 is None or icmp1.type != icmp.ICMP_TYPE_ECHO_REQ: return data, interceptor.NF_ACCEPT echo1 = icmp1[icmp.ICMP.Echo] if echo1 is None: return data, interceptor.NF_ACCEPT pp_bts = b"PYPACKER" print("changing ICMP echo request packet") echo1.body_bytes = echo1.body_bytes[:len(pp_bts)] + pp_bts return ip1.bin(), interceptor.NF_ACCEPT ictor = interceptor.Interceptor(verdict_cb) ictor.start() print("sleeping") time.sleep(999) ictor.stop()