Skip to content

Commit

Permalink
Listen for all types by default
Browse files Browse the repository at this point in the history
  • Loading branch information
M4t7e committed Mar 28, 2020
1 parent 48e0511 commit 2384a1b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 0 additions & 5 deletions pytlssniff/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ def cli():
args = parse_args()
handshake_sniffer = TLSHandshakeSniffer(args.interface, args.input_file, args.bpf_filter, args.display_filter)

if not (args.sni or args.cn or args.san):
args.sni = True
args.cn = True
args.san = True

for message in handshake_sniffer.listen(args.sni, args.cn, args.san, args.packet_count, args.debug):
dns_name = ''

Expand Down
19 changes: 12 additions & 7 deletions pytlssniff/sniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class TLSHandshakeMessage(NamedTuple):


class TLSHandshakeSniffer():
def __init__(self, interface='any', input_file=None, custom_bpf_filter='', custom_display_filter=''):
def __init__(self, interface='any', input_file=None, bpf_filter='', display_filter=''):
self.interface = interface
self.input_file = input_file
self.custom_bpf_filter = custom_bpf_filter
self.custom_display_filter = custom_display_filter
self.bpf_filter = bpf_filter
self.display_filter = display_filter

@classmethod
def _extract_certificate_san(cls, x509cert: X509) -> Optional[List[str]]:
Expand Down Expand Up @@ -144,10 +144,10 @@ def listen(self, sniff_sni=False, sniff_cn=False, sniff_san=False, packet_count:
bpf_filter = 'tcp'
display_filter = f'(ssl.record.content_type == 22 && ssl.handshake.type)'

if self.custom_bpf_filter != '':
bpf_filter += f' && {self.custom_bpf_filter.strip()}'
if self.custom_display_filter != '':
display_filter += f' && {self.custom_display_filter.strip()}'
if self.bpf_filter != '':
bpf_filter += f' && {self.bpf_filter.strip()}'
if self.display_filter != '':
display_filter += f' && {self.display_filter.strip()}'

if packet_count is not None and packet_count <= 0:
packet_count = None
Expand All @@ -157,6 +157,11 @@ def listen(self, sniff_sni=False, sniff_cn=False, sniff_san=False, packet_count:
else:
capture = LiveCapture(interface=self.interface, bpf_filter=bpf_filter, display_filter=display_filter, debug=debug)
packet_iterator = capture.sniff_continuously()

if not (sniff_sni or sniff_cn or sniff_san):
sniff_sni = True
sniff_cn = True
sniff_san = True

for packet in packet_iterator:
handshake_message = self._get_handshake_message(packet, sniff_sni=sniff_sni, sniff_cn=sniff_cn, sniff_san=sniff_san)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name="PyTLSSniff",
version="0.0.4",
version="0.0.5",
author="M4t7e",
license='MIT License',
description="Python TLS handshake sniffer to extract domain names",
Expand Down

0 comments on commit 2384a1b

Please sign in to comment.