def set_dns_servers(dns_server_info): field = {1: 'primary', 2: 'secondary'} with ConfigurationManager('dns_server') as dnx: dns_server_settings = dnx.load_configuration() public_resolvers = dns_server_settings['dns_server']['resolvers'] for i, (server_name, ip_address) in enumerate(dns_server_info.items(), 1): if (not server_name and ip_address): continue public_resolvers[field[i]].update({ 'name': server_name, 'ip_address': ip_address }) dnx.write_configuration(dns_server_settings) wan_information = load_configuration('config')['settings'] interface = wan_information['interfaces'] wan_dhcp = interface['wan']['dhcp'] wan_int = interface['wan']['ident'] if (not wan_dhcp): wan_ip = interface.get_ip_address(wan_int) wan_dfg = Interface.default_gateway(wan_int) cidr = System.standard_to_cidr(wan_netmask) # TODO: convert this to new module wan_netmask = Interface.netmask(wan_int) set_wan_interface({ 'ip_address': wan_ip, 'cidr': cidr, 'default_gateway': wan_dfg })
def ShowIPAddress(self, initial_load=False): Inter = Int() with open(f'{HOME_DIR}/data/config.json', 'r') as settings: setting = json.load(settings) interface_settings = setting['settings']['interface'] default_wan_mac = interface_settings['wan']['default_mac'] configured_wan_mac = interface_settings['wan']['configured_mac'] dhcp = interface_settings['wan']['dhcp'] wan_int = interface_settings['outside'] if (not configured_wan_mac): configured_wan_mac = default_wan_mac if (dhcp): wan_mode = 'dhcp' else: wan_mode = 'static' wan_ip = Inter.IP(wan_int) wan_netmask = Inter.Netmask(wan_int) wan_dfg = Inter.DefaultGateway(wan_int) if (initial_load): self.interface_settings_pending['mode'].update( {'setting': wan_mode}) else: self.Standard.ShowSend('ip-address', wan_ip) self.Standard.ShowSend('netmask', wan_netmask) self.Standard.ShowSend('default-gateway', wan_dfg) self.Standard.ShowSend('mode', wan_mode)
def set_dns_servers(dns_server_info): with ConfigurationManager('dns_server') as dnx: dns_server_settings = dnx.load_configuration() dns = dns_server_settings['dns_server']['resolvers'] for i, (server_name, ip_address) in enumerate(dns_server_info.items(), 1): if (server_name and ip_address): server = dns[f'server{i}'] server.update({'name': server_name, 'ip_address': ip_address}) dnx.write_configuration(dns_server_settings) wan_information = load_configuration('config') interface = wan_information['settings']['interface'] wan_dhcp = interface['wan']['dhcp'] wan_int = interface['outside'] if (not wan_dhcp): wan_ip = interface.get_ip_address(wan_int) wan_netmask = Interface.netmask(wan_int) wan_dfg = Interface.default_gateway(wan_int) cidr = System.standard_to_cidr(wan_netmask) wan_settings = { 'ip_address': wan_ip, 'cidr': cidr, 'default_gateway': wan_dfg } set_wan_interface(wan_settings)
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
def InterfaceInfo(self): Interface = Int() insideip = Interface.IP(self.lan_int) netmask = Interface.Netmask(self.lan_int) broadcast = Interface.Broadcast(self.lan_int) mtu = Interface.MTU(self.lan_int) 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
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
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))
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
def __init__(self): with open(f'{HOME_DIR}/data/config.json', 'r') as configs: config = json.load(configs) lan_int = config['settings']['interface']['inside'] Interface = Int() self.lan_ip = Interface.IP(lan_int) self.syslog_queue = deque() self.tls_retry = 0 self.tcp_retry = 0 self.tcp_fallback = False self.tcp_fallback = False self.queue_lock = threading.Lock()
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': {}}
def _load_interfaces(self): interface = load_configuration('config.json') self.IPS.wan_int = interface['settings']['interfaces']['wan'] self.IPS.broadcast = Interface.broadcast_address( self.IPS.wan_int['ident'])
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 = []
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
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()
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 = []
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 = {}
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 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 _load_interfaces(self): dnx_settings = load_configuration('config')['settings'] wan_ident = dnx_settings['interfaces']['wan']['ident'] self.IPS.broadcast = Interface.broadcast_address(wan_ident)
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