Exemple #1
0
 def start(self):
     """Start monitoring DHCP"""
     LOGGER.info(
         'DHCP monitor %s waiting for replies...',
         self.name,
     )
     if self.log_file:
         LOGGER.debug('Logging results to %s', self.log_file)
         self.dhcp_log = open(self.log_file, "w")
     self.scan_start = int(time.time())
     # Because there's buffering somewhere, can't reliably filter out DHCP with "src port 67"
     tcp_filter = ""
     flags = "-v -l"  # use line buffering
     helper = tcpdump_helper.TcpdumpHelper(self.host,
                                           tcp_filter,
                                           packets=None,
                                           vflags=flags,
                                           timeout=None,
                                           blocking=False,
                                           intf_name=self.intf_name)
     self.dhcp_traffic = helper
     self.runner.monitor_stream(self.name,
                                self.dhcp_traffic.stream(),
                                self._dhcp_line,
                                hangup=self._dhcp_hangup,
                                error=self._dhcp_error)
Exemple #2
0
 def _monitor_scan(self):
     self._state_transition(_STATE.MONITOR, _STATE.BASE)
     self.record_result('monitor', time=self._MONITOR_SCAN_SEC, state='run')
     monitor_file = os.path.join(self.scan_base, 'monitor.pcap')
     LOGGER.info('Target port %d background scan for %d seconds...',
                 self.target_port, self._MONITOR_SCAN_SEC)
     network = self.runner.network
     tcp_filter = ''
     intf_name = self._mirror_intf_name
     assert not self._tcp_monitor, 'tcp_monitor already active'
     LOGGER.debug(
         'Target port %d background scan intf %s filter %s output in %s',
         self.target_port, intf_name, tcp_filter, monitor_file)
     helper = tcpdump_helper.TcpdumpHelper(network.pri,
                                           tcp_filter,
                                           packets=None,
                                           intf_name=intf_name,
                                           timeout=self._MONITOR_SCAN_SEC,
                                           pcap_out=monitor_file,
                                           blocking=False)
     self._tcp_monitor = helper
     self.runner.monitor_stream('tcpdump',
                                self._tcp_monitor.stream(),
                                self._tcp_monitor.next_line,
                                hangup=self._monitor_complete,
                                error=self._monitor_error)
Exemple #3
0
 def _startup_scan(self):
     assert not self._tcp_monitor, 'tcp_monitor already active'
     self._startup_file = os.path.join(self.scan_base, 'startup.pcap')
     self._startup_time = datetime.now()
     LOGGER.info('Target port %d startup pcap capture', self.target_port)
     network = self.runner.network
     tcp_filter = ''
     LOGGER.debug(
         'Target port %d startup scan intf %s filter %s output in %s',
         self.target_port, self._mirror_intf_name, tcp_filter,
         self._startup_file)
     helper = tcpdump_helper.TcpdumpHelper(network.pri,
                                           tcp_filter,
                                           packets=None,
                                           intf_name=self._mirror_intf_name,
                                           timeout=None,
                                           pcap_out=self._startup_file,
                                           blocking=False)
     self._tcp_monitor = helper
     hangup = lambda: self._monitor_error(Exception('startup scan hangup'))
     self.runner.monitor_stream('tcpdump',
                                self._tcp_monitor.stream(),
                                self._tcp_monitor.next_line,
                                hangup=hangup,
                                error=self._monitor_error)
Exemple #4
0
 def _startup_scan(self, host):
     assert not self._scan_monitor, 'startup_scan already active'
     startup_file = '/tmp/gateway.pcap'
     LOGGER.info('Gateway %s startup capture %s in container\'s %s', self.port_set,
                 self.host_intf, startup_file)
     tcp_filter = ''
     helper = tcpdump_helper.TcpdumpHelper(host, tcp_filter, packets=None,
                                           intf_name=self.host_intf, timeout=None,
                                           pcap_out=startup_file, blocking=False)
     self._scan_monitor = helper
     self.runner.monitor_stream('start%d' % self.port_set, helper.stream(),
                                helper.next_line, hangup=self._scan_complete,
                                error=self._scan_error)
Exemple #5
0
 def start(self):
     """Start monitoring DHCP"""
     LOGGER.info('Set %d waiting for dhcp reply from %s...', self.port_set,
                 self.networking.name)
     self.test_start = int(time.time())
     # Because there's buffering somewhere, can't reliably filter out DHCP with "src port 67"
     tcp_filter = ""
     helper = tcpdump_helper.TcpdumpHelper(self.networking,
                                           tcp_filter,
                                           packets=None,
                                           timeout=self.DHCP_TIMEOUT_SEC,
                                           blocking=False)
     self.dhcp_traffic = helper
     self.runner.monitor_stream(self.networking.name,
                                self.dhcp_traffic.stream(),
                                self._dhcp_line,
                                hangup=self._dhcp_hangup,
                                error=self._dhcp_error)
Exemple #6
0
 def _startup_scan(self):
     assert not self.tcp_monitor, 'tcp_monitor already active'
     LOGGER.debug('Set %d startup pcap start', self.port_set)
     startup_file = os.path.join('/tmp', 'startup.pcap')
     tcp_filter = ''
     helper = tcpdump_helper.TcpdumpHelper(self.networking,
                                           tcp_filter,
                                           packets=None,
                                           timeout=None,
                                           pcap_out=startup_file,
                                           blocking=False)
     self.tcp_monitor = helper
     hangup = lambda: self._monitor_error(Exception('startup scan hangup'))
     self.runner.monitor_stream('tcpdump',
                                self.tcp_monitor.stream(),
                                self.tcp_monitor.next_line,
                                hangup=hangup,
                                error=self._monitor_error)
Exemple #7
0
 def _monitor_scan(self, output_file, timeout=None):
     assert not self._monitor_ref, 'tcp_monitor already active'
     network = self.runner.network
     tcp_filter = ''
     LOGGER.info('Target port %d pcap intf %s for %ss output in %s',
                 self.target_port, self._mirror_intf_name, timeout,
                 output_file)
     helper = tcpdump_helper.TcpdumpHelper(network.pri,
                                           tcp_filter,
                                           packets=None,
                                           intf_name=self._mirror_intf_name,
                                           timeout=timeout,
                                           pcap_out=output_file,
                                           blocking=False)
     self._monitor_ref = helper
     self._monitor_start = datetime.now()
     self.runner.monitor_stream('tcpdump',
                                self._monitor_ref.stream(),
                                self._monitor_ref.next_line,
                                error=self._monitor_error,
                                hangup=functools.partial(
                                    self._monitor_timeout, timeout))
Exemple #8
0
 def _monitor_scan(self, output_file, timeout=None):
     assert not self._monitor_ref, 'tcp_monitor already active'
     network = self.runner.network
     tcp_filter = ''
     self.logger.info(
         'Target device %s pcap intf %s for %s seconds output in %s', self,
         self._mirror_intf_name, timeout if timeout else 'infinite',
         self._shorten_filename(output_file))
     helper = tcpdump_helper.TcpdumpHelper(network.pri,
                                           tcp_filter,
                                           packets=None,
                                           intf_name=self._mirror_intf_name,
                                           timeout=timeout,
                                           pcap_out=output_file,
                                           blocking=False)
     self._monitor_ref = helper
     self._monitor_start = datetime.now()
     self.runner.monitor_stream('tcpdump',
                                self._monitor_ref.stream(),
                                self._monitor_ref.next_line,
                                error=self._monitor_error,
                                hangup=functools.partial(
                                    self._monitor_timeout, timeout))
Exemple #9
0
 def _monitor_scan(self):
     self._state_transition(_STATE.MONITOR, _STATE.BASE)
     self.record_result('monitor', time=self.MONITOR_SCAN_SEC, state='run')
     LOGGER.info('Set %d background scan for %d seconds...', self.port_set,
                 self.MONITOR_SCAN_SEC)
     network = self.runner.network
     intf_name = network.sec_name
     monitor_file = os.path.join(self.scan_base, 'monitor.pcap')
     tcp_filter = 'vlan %d' % self.pri_base
     assert not self.tcp_monitor, 'tcp_monitor already active'
     helper = tcpdump_helper.TcpdumpHelper(network.pri,
                                           tcp_filter,
                                           packets=None,
                                           intf_name=intf_name,
                                           timeout=self.MONITOR_SCAN_SEC,
                                           pcap_out=monitor_file,
                                           blocking=False)
     self.tcp_monitor = helper
     self.runner.monitor_stream('tcpdump',
                                self.tcp_monitor.stream(),
                                self.tcp_monitor.next_line,
                                hangup=self._monitor_complete,
                                error=self._monitor_error)