def load_page():
    interface_settings = load_configuration('config')['settings']

    wan_int = interface_settings['interfaces']['wan']
    default_wan_mac = wan_int['default_mac']
    configured_wan_mac = wan_int['configured_mac']
    dhcp = wan_int['dhcp']
    wan_int = wan_int['ident']

    # TODO: migrate away from instace
    Int = Interface()
    wan_ip = Int.ip_address(wan_int)
    wan_netmask = Int.netmask(wan_int)
    wan_dfg = Int.default_gateway(wan_int)

    current_wan_mac = default_wan_mac if not configured_wan_mac else configured_wan_mac

    interface_settings = {
        'mac': {
            'default': default_wan_mac,
            'current': current_wan_mac
        },
        'ip': {
            'dhcp': dhcp,
            'ip_address': wan_ip,
            'netmask': wan_netmask,
            'default_gateway': wan_dfg
        }
    }

    return interface_settings
Esempio n. 2
0
    def __init__(self, action):
        TLSRelay.action = action
        self.path = os.environ['HOME_DIR']

        with open(f'{self.path}/data/config.json', 'r') as settings:
            self.setting = json.load(settings)

        self.lan_int = self.setting['Settings']['Interface']['Inside']
        TLSRelay.wan_int = self.setting['Settings']['Interface']['Outside']
        self.dnsserver = self.setting['Settings']['DNSServers']

        Int = Interface()
        self.lan_ip = Int.IP(self.lan_int)
        self.wan_ip = Int.IP(self.wan_int)
        dfg = Int.DefaultGateway()
        dfg_mac = Int.IPtoMAC(dfg)
        self.wan_mac = Int.MAC(self.wan_int)
        self.lan_mac = Int.MAC(self.lan_int)
        wan_subnet = Int.WANSubnet(self.wan_int, dfg)
        self.wan_info = [dfg_mac, wan_subnet]

        TLSRelay.connections = {'Clients': {}}
        TLSRelay.active_connections = {'Clients': {}}
        TLSRelay.tcp_handshakes = {'Clients': {}}
        self.nat_ports = {}

        ## RAW Sockets which actually handle the traffic.
        TLSRelay.lan_sock = socket(AF_PACKET, SOCK_RAW)
        self.lan_sock.bind((self.lan_int, 3))
        self.wan_sock = socket(AF_PACKET, SOCK_RAW)
        self.wan_sock.bind((self.wan_int, 3))

        self.tls_ports = {443}
        TLSRelay.tcp_info = []
Esempio n. 3
0
 def InterfaceInfo(self):
     Int = Interface()
     insideip = Int.IP(self.insideint)
     netmask = Int.Netmask(self.insideint)
     broadcast = Int.Broadcast(self.insideint)
     mtu = Int.MTU(self.insideint)
     
     return(insideip, netmask, broadcast, mtu)
 def AssignValues(self):
     self.l2pro = 0x0800
     Int = Interface()
     self.smac = Int.MAC(self.wan_int)
     self.dmac = self.packet.src_mac
     self.src_ip = Int.IP(self.wan_int)
     self.dst_ip = self.packet.src_ip
     self.icmp_payload = self.packet.ipv4_header + self.packet.udp_header
 def CheckDestination(self):
     if (self.dst_ip in self.wan_subnet):
         Int = Interface()
         dst_mac = Int.IPtoMAC(self.dst_ip)
         if (not dst_mac):
             run(f'ping {self.dst_ip} -c 1', shell=True)
             self.dst_mac = Int.IPtoMAC(self.dst_ip)
         else:
             self.dst_mac = dst_mac
Esempio n. 6
0
    def LoadInterfaces(self):
        with open(f'{HOME_DIR}/data/config.json', 'r') as settings:
            self.setting = json.load(settings)

        self.lan_int = self.setting['settings']['interface']['inside']
        self.wan_int = self.setting['settings']['interface']['outside']

        Int = Interface()
        self.wan_ip = Int.IP(self.wan_int)
        self.broadcast = Int.Broadcast(self.wan_int)
    def AssignValues(self):
        self.l2pro = 0x0800
        Int = Interface()
        self.smac = Int.MAC(self.wan_int)
        self.dmac = self.packet.src_mac
        self.src_ip = Int.IP(self.wan_int)
        self.dst_ip = self.packet.src_ip
        self.src_port = self.packet.dst_port
        self.dst_port = self.packet.src_port

        self.sport = struct.pack('!H', self.src_port)
        #        print(self.packet.seq_number)
        self.ack_number = self.packet.seq_number + 1
Esempio n. 8
0
    def __init__(self, insideint, xid, mac, ciaddr, chaddr, options, Leases):
        Int = Interface()
        self.insideip = Int.IP(insideint)

        self.Leases = Leases

        self.xID = xid
        self.chaddr = chaddr
        self.ciaddr = ciaddr
        self.serveroptions = options

        self.yiaddr = self.Leases.Handout(mac)
        print('Handing Out: {}'.format(self.yiaddr))
Esempio n. 9
0
def load_page():
    with DBConnector() as ProxyDB:
        domain_count = ProxyDB.unique_domain_count(table='dnsproxy',
                                                   action='blocked')
        top_domains = ProxyDB.dashboard_query_top(5,
                                                  table='dnsproxy',
                                                  action='blocked')
        request_count = ProxyDB.total_request_count(table='dnsproxy',
                                                    action='blocked')
        inf_hosts = ProxyDB.query_last(5,
                                       table='infectedclients',
                                       action='all')

    # TODO: see if this is a candidate for a class method
    Int = Interface()
    intstat = Int.bandwidth()

    uptime = System.uptime()
    cpu = System.cpu_usage()
    ram = System.ram_usage()
    dns_servers = System.dns_status()

    # TODO: make this iterable
    dns_proxy = Services.status('dnx-dns-proxy')
    ip_proxy = Services.status('dnx-ip-proxy')
    dhcp_server = Services.status('dnx-dhcp-server')
    dnx_ips = Services.status('dnx-ips')

    mod_status = {
        'dns_proxy': dns_proxy,
        'ip_proxy': ip_proxy,
        'dnx_ips': dnx_ips,
        'dhcp_server': dhcp_server
    }

    dashboard = {
        'domain_count': domain_count,
        'infected_hosts': inf_hosts,
        'top_domains': top_domains,
        'request_count': request_count,
        'interfaces': intstat,
        'uptime': uptime,
        'cpu': cpu,
        'ram': ram,
        'dns_servers': dns_servers,
        'module_status': mod_status
    }

    return dashboard
Esempio n. 10
0
    def __init__(self):
        self.path = os.environ['HOME_DIR']

        with open('{}/data/config.json'.format(self.path), 'r') as settings:
            self.setting = json.load(settings)
                                
        self.iface = self.setting['Settings']['Interface']['Inside']
        self.wface = self.setting['Settings']['Interface']['Outside']
    
        Int = Interface()
        self.insideip = Int.IP(self.iface)
        self.wanip = Int.IP(self.wface)
        self.DEVNULL = open(os.devnull, 'wb')
        self.dns_sigs = {}

        self.session_tracker = {'Clients': {}}
Esempio n. 11
0
    def __init__(self):
        self.path = os.environ['HOME_DIR']
        #        self.System = Sys()
        #        self.Syslog = SyslogService()

        with open(f'{self.path}/data/config.json', 'r') as settings:
            self.setting = json.load(settings)

        self.lan_int = self.setting['Settings']['Interface']['Inside']
        self.wan_int = self.setting['Settings']['Interface']['Outside']

        Int = Interface()
        self.laddr = Int.IP(self.lan_int)
        self.qaddr = Int.IP(self.wan_int)

        self.dns_connection_tracker = {}
        self.dns_tls_queue = []
Esempio n. 12
0
    def __init__(self):
        self.path = os.environ['HOME_DIR']

        with open('{}/data/config.json'.format(self.path), 'r') as settings:
            self.setting = json.load(settings)

        self.iface = self.setting['Settings']['Interface']['Inside']

        Int = Interface()
        self.insideip = Int.IP(self.iface)
        self.DEVNULL = open(os.devnull, 'wb')
        self.dns_sigs = {}
        self.b_list = {}
        self.ent_logging = True
        self.ent_full = False

        self.log_supress = set()
Esempio n. 13
0
    def __init__(self):
        self.path = os.environ['HOME_DIR']

        with open(f'{self.path}/data/config.json', 'r') as settings:
            self.setting = json.load(settings)

        self.iniface = self.setting['Settings']['Interface']['Inside']
        self.waniface = self.setting['Settings']['Interface']['Outside']
        self.dnsserver = self.setting['Settings']['DNSServers']

        Int = Interface()
        self.laddr = Int.IP(self.iniface)
        self.qaddr = Int.IP(self.waniface)
        self.dns1 = [self.dnsserver['Server1']['IP Address'], True]
        self.dns2 = [self.dnsserver['Server2']['IP Address'], True]
        self.dnsList = [self.dns1, self.dns2]
        self.lport = 53
Esempio n. 14
0
    def __init__(self):
        self.path = os.environ['HOME_DIR']
#        self.Syslog = SyslogService()

        with open(f'{self.path}/data/config.json', 'r') as settings:
            setting = json.load(settings)
        self.lan_int = setting['Settings']['Interface']['Inside']

        Int = Interface()
        self.lan_ip = Int.IP(self.lan_int)
        self.DEVNULL = open(os.devnull, 'wb')
        self.full_logging = None
        self.ip_whitelist = None
        self.dns_whitelist = None
        self.dns_blacklist = None
        self.dns_sigs = {}
        self.dns_records = {}

        self.flagged_traffic = {}
Esempio n. 15
0
    def __init__(self):
        self.path = os.environ['HOME_DIR']

        with open(f'{self.path}/data/config.json', 'r') as settings:
            self.setting = json.load(settings)

        self.lan_int = self.setting['Settings']['Interface']['Inside']
        self.wan_int = self.setting['Settings']['Interface']['Outside']

        Int = Interface()
        self.wan_ip = Int.IP(self.wan_int)
        self.broadcast = Int.Broadcast(self.wan_int)

        self.udp_scan_tracker = {}
        self.tcp_scan_tracker = {}
        self.udp_scan_drop = {}
        self.tcp_scan_drop = {}

        self.scan_mitigation = {}
        self.ddos_tracker = {self.wan_ip: {'TCP': {}, 'UDP': {}, 'ICMP': {}}}
        self.active_ddos = False
def load_page():
    with DBConnector() as ProxyDB:
        domain_count = ProxyDB.unique_domain_count(table='dnsproxy',
                                                   action='blocked')
        top_domains = ProxyDB.dashboard_query_top(5,
                                                  table='dnsproxy',
                                                  action='blocked')
        request_count = ProxyDB.total_request_count(table='dnsproxy',
                                                    action='blocked')
        inf_hosts = ProxyDB.query_last(5,
                                       table='infectedclients',
                                       action='all')

    Int = Interface()
    intstat = Int.bandwidth()

    uptime = System.uptime()
    cpu = System.cpu_usage()
    ram = System.ram_usage()
    dns_servers = System.dns_status()

    #----- Services Status ------#
    dns_proxy = Services.status('dnx-dns-proxy')
    ip_proxy = Services.status('dnx-ip-proxy')
    dhcp_server = Services.status('dnx-dhcp-server')
    dnx_ips = Services.status('dnx-ips')

    mod_status = {
        'dns_proxy': dns_proxy,
        'ip_proxy': ip_proxy,
        'dnx_ips': dnx_ips,
        'dhcp_server': dhcp_server
    }

    dnx_license = load_configuration('license')['license']
    updates = load_configuration('updates')['updates']

    notify = False
    if (dnx_license['validated']):
        system_uptodate = updates['system']['current']
        domains_uptodate = updates['signature']['domain']['current']
        ip_uptodate = updates['signature']['ip']['current']

        if not all([system_uptodate, domains_uptodate, ip_uptodate]):
            notify = 'DNX firewall has updates available. Check updates tab for more info.'

    # System/Service Restart pending check
    sys_restart = updates['system']['restart']
    domain_restart = updates['signature']['domain']['restart']
    ip_restart = updates['signature']['ip']['restart']

    if (domain_restart or ip_restart):
        notify = 'One or more DNX Services require a restart after signature updates. Please check the updates page for more information.'

    if (sys_restart):
        notify = 'DNX firewall is pending a system restart after updates.'

    dashboard = {
        'domain_count': domain_count,
        'infected_hosts': inf_hosts,
        'top_domains': top_domains,
        'request_count': request_count,
        'interfaces': intstat,
        'uptime': uptime,
        'cpu': cpu,
        'ram': ram,
        'dns_servers': dns_servers,
        'module_status': mod_status,
        'notify': notify
    }

    return dashboard