Esempio n. 1
0
def test_get_display_filter_flag():
    actual = get_tshark_display_filter_flag(version.parse('1.10.0'))
    expected = '-Y'
    assert actual == expected

    actual = get_tshark_display_filter_flag(version.parse('1.6.0'))
    expected = '-R'
    assert actual == expected
Esempio n. 2
0
def test_get_display_filter_flag(mock_get_tshark_version):
    mock_get_tshark_version.return_value = '1.10.0'
    actual = get_tshark_display_filter_flag()
    expected = '-Y'
    assert actual == expected

    mock_get_tshark_version.return_value = '1.6.0'
    actual = get_tshark_display_filter_flag()
    expected = '-R'
    assert actual == expected
Esempio n. 3
0
    def get_parameters(self, packet_count=None):
        """
        Returns the special tshark parameters to be used according to the configuration of this class.
        """
        params = []
        if self.display_filter:
            params += [
                get_tshark_display_filter_flag(self.tshark_path),
                self.display_filter
            ]
        if packet_count:
            params += ['-c', str(packet_count)]
        if all(self.encryption):
            params += [
                '-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' +
                self.encryption[1] + '","' + self.encryption[0] + '"'
            ]
        if self.output_file:
            params += ['-w', self.output_file]

        if self.decode_as:
            for criterion, decode_as_proto in self.decode_as.items():
                params += [
                    '-d',
                    ','.join([criterion.strip(),
                              decode_as_proto.strip()])
                ]
        return params
Esempio n. 4
0
    def get_parameters(self, packet_count=None):
        """
        Returns the special tshark parameters to be used according to the configuration of this class.
        """
        params = []
        if self.display_filter:
            params += [get_tshark_display_filter_flag(self.tshark_path), self.display_filter]
        if packet_count:
            params += ['-c', str(packet_count)]
        if all(self.encryption):
            params += ['-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' + self.encryption[1] + '","' +
                                                                  self.encryption[0] + '"']
        if self.sslkey_path:
            params += ['-o', 'ssl.desegment_ssl_records:TRUE', '-o', 'ssl.desegment_ssl_application_data:TRUE',
                            '-o','tcp.desegment_tcp_streams:TRUE', '-o', 'ssl.keylog_file:'+self.sslkey_path]
        if self.http_only:
            params += ['-Y', 'tcp.port == 80 || tcp.port == 443']

        if self.output_file:
            params += ['-w', self.output_file]

        if self.decode_as:
            for criterion, decode_as_proto in self.decode_as.items():
                params += ['-d', ','.join([criterion.strip(), decode_as_proto.strip()])]
        if self.other_paras:
            params += self.other_paras
        return params
Esempio n. 5
0
    def get_parameters(self, packet_count=None):
        """
        Returns the special tshark parameters to be used according to the configuration of this class.
        """
        params = []
        if self._capture_filter:
            params += ['-f', self._capture_filter]
        if self._display_filter:
            params += [get_tshark_display_filter_flag(self.tshark_path), self._display_filter]
        if packet_count:
            params += ['-c', str(packet_count)]
        if all(self.encryption):
            params += ['-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' + self.encryption[1] + '","' +
                                                                  self.encryption[0] + '"']
        if self._override_prefs:
            for preference_name, preference_value in self._override_prefs.items():
                if all(self.encryption) and preference_name in ('wlan.enable_decryption', 'uat:80211_keys'):
                    continue  # skip if override preferences also given via --encryption options
                params += ['-o', '{0}:{1}'.format(preference_name, preference_value)]

        if self._output_file:
            params += ['-w', self._output_file]

        if self._decode_as:
            for criterion, decode_as_proto in self._decode_as.items():
                params += ['-d', ','.join([criterion.strip(), decode_as_proto.strip()])]

        if self._disable_protocol:
            params += ['--disable-protocol', self._disable_protocol.strip()]

        return params
Esempio n. 6
0
    def get_parameters(self, packet_count=None):
        """
        Returns the special tshark parameters to be used according to the configuration of this class.
        """
        params = []
        if self.capture_filter:
            params += ['-f', self.capture_filter]
        if self.display_filter:
            params += [get_tshark_display_filter_flag(self.tshark_path), self.display_filter]
        if packet_count:
            params += ['-c', str(packet_count)]
        if all(self.encryption):
            params += ['-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' + self.encryption[1] + '","' +
                                                                  self.encryption[0] + '"']
        if self.override_prefs:
            for preference_name, preference_value in self.override_prefs.items():
                if all(self.encryption) and preference_name in ('wlan.enable_decryption', 'uat:80211_keys'):
                    continue  # skip if override preferences also given via --encryption options
                params += ['-o', '{0}:{1}'.format(preference_name, preference_value)]

        if self.output_file:
            params += ['-w', self.output_file]

        if self.decode_as:
            for criterion, decode_as_proto in self.decode_as.items():
                params += ['-d', ','.join([criterion.strip(), decode_as_proto.strip()])]
        return params
Esempio n. 7
0
    def get_parameters(self, packet_count=None):
        """
        Returns the special tshark parameters to be used according to the configuration of this class.
        """
        params = []
        if self._capture_filter:
            params += ['-f', self._capture_filter]
        if self._display_filter:
            params += [
                get_tshark_display_filter_flag(self.tshark_path),
                self._display_filter
            ]
        # Raw is only enabled when JSON is also enabled.
        if self.include_raw:
            params += ["-x"]
        if packet_count:
            params += ['-c', str(packet_count)]

        if self._custom_parameters:
            if isinstance(self._custom_parameters, list):
                params += self._custom_parameters
            elif isinstance(self._custom_parameters, dict):
                for key, val in self._custom_parameters.items():
                    params += [key, val]
            else:
                raise Exception("Custom parameters type not supported.")

        if all(self.encryption):
            params += [
                '-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' +
                self.encryption[1] + '","' + self.encryption[0] + '"'
            ]
        if self._override_prefs:
            for preference_name, preference_value in self._override_prefs.items(
            ):
                if all(self.encryption) and preference_name in (
                        'wlan.enable_decryption', 'uat:80211_keys'):
                    continue  # skip if override preferences also given via --encryption options
                params += [
                    '-o', '{0}:{1}'.format(preference_name, preference_value)
                ]

        if self._output_file:
            params += ['-w', self._output_file]

        if self._decode_as:
            for criterion, decode_as_proto in self._decode_as.items():
                params += [
                    '-d',
                    ','.join([criterion.strip(),
                              decode_as_proto.strip()])
                ]

        if self._disable_protocol:
            params += ['--disable-protocol', self._disable_protocol.strip()]

        return params
Esempio n. 8
0
 def get_parameters(self, packet_count=None):
     """
     Returns the special tshark parameters to be used according to the configuration of this class.
     """
     params = []
     if self.display_filter:
         params += [get_tshark_display_filter_flag(), self.display_filter]
     if packet_count:
         params += ['-c', str(packet_count)]
     if all(self.encryption):
         params += ['-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' + self.encryption[1] + ' ","' +
                                                               self.encryption[0] + '"']
     return params
Esempio n. 9
0
 def get_parameters(self, packet_count=None):
     """
     Returns the special tshark parameters to be used according to the configuration of this class.
     """
     params = []
     if self.display_filter:
         params += [get_tshark_display_filter_flag(), self.display_filter]
     if packet_count:
         params += ['-c', str(packet_count)]
     if all(self.encryption):
         params += [
             '-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' +
             self.encryption[1] + '","' + self.encryption[0] + '"'
         ]
     return params
Esempio n. 10
0
    def get_parameters(self, packet_count=None):
        """
        Returns the special tshark parameters to be used according to the configuration of this class.
        """
        params = []
        if self.display_filter:
            params += [get_tshark_display_filter_flag(self.tshark_path), self.display_filter]
        if packet_count:
            params += ['-c', str(packet_count)]
        if all(self.encryption):
		params += ['-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:\"' + self.encryption[1] + '\",\"' + self.encryption[0] + '\"']
        if self.output_file:
            params += ['-w', self.output_file]

        if self.decode_as:
            for criterion, decode_as_proto in self.decode_as.items():
                params += ['-d', ','.join([criterion.strip(), decode_as_proto.strip()])]
        return params
Esempio n. 11
0
    def get_parameters(self, packet_count=None):
        """
        Returns the special tshark parameters to be used according to the configuration of this class.
        """
        params = []
        if self._capture_filter:
            params += ['-f', self._capture_filter]
        if self._display_filter:
            params += [get_tshark_display_filter_flag(self.tshark_path), self._display_filter]
        # Raw is only enabled when JSON is also enabled.
        if self.include_raw:
            params += ["-x"]
        if packet_count:
            params += ['-c', str(packet_count)]

        if self._custom_parameters:
            if isinstance(self._custom_parameters, list):
                params += self._custom_parameters
            elif isinstance(self._custom_parameters, dict):
                for key, val in self._custom_parameters.items():
                    params += [key, val]
            else:
                raise Exception("Custom parameters type not supported.")

        if all(self.encryption):
            params += ['-o', 'wlan.enable_decryption:TRUE', '-o', 'uat:80211_keys:"' + self.encryption[1] + '","' +
                                                                  self.encryption[0] + '"']
        if self._override_prefs:
            for preference_name, preference_value in self._override_prefs.items():
                if all(self.encryption) and preference_name in ('wlan.enable_decryption', 'uat:80211_keys'):
                    continue  # skip if override preferences also given via --encryption options
                params += ['-o', '{0}:{1}'.format(preference_name, preference_value)]

        if self._output_file:
            params += ['-w', self._output_file]

        if self._decode_as:
            for criterion, decode_as_proto in self._decode_as.items():
                params += ['-d', ','.join([criterion.strip(), decode_as_proto.strip()])]

        if self._disable_protocol:
            params += ['--disable-protocol', self._disable_protocol.strip()]

        return params
Esempio n. 12
0
 def _get_dumpcap_parameters(self):
     # Don't report packet counts.
     params = ["-q"]
     if self._get_tshark_version() < LooseVersion("2.5.0"):
         # Tshark versions older than 2.5 don't support pcapng. This flag forces dumpcap to output pcap.
         params += ["-P"]
     if self.bpf_filter:
         params += ["-f", self.bpf_filter]
     if self.monitor_mode:
         params += ["-I"]
     if self._capture_filter:
         params += ["-f", self._capture_filter]
     if self._display_filter:
         params += [
             get_tshark_display_filter_flag(self._get_tshark_version(), ),
             self._display_filter
         ]
     for interface in self.interfaces:
         params += ["-i", interface]
     # Write to STDOUT
     params += ["-w", "-"]
     return params