nopasaran 0.2.110__py3-none-any.whl → 0.2.111__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import socket
2
2
  from dnslib import DNSRecord, RR, QTYPE, A, CNAME, MX, TXT, NS, SOA, PTR, AAAA, SRV, DS, RRSIG, NSEC, DNSKEY
3
3
  from nopasaran.definitions.events import EventNames
4
4
  import logging
5
+ import time
5
6
 
6
7
  class UDPDNSSocketServer:
7
8
  def __init__(self):
@@ -18,31 +19,46 @@ class UDPDNSSocketServer:
18
19
  self.sock.settimeout(timeout)
19
20
  logging.info(f"Waiting for UDP packets on port {self.sock.getsockname()[1]} with timeout {timeout} seconds")
20
21
 
21
- try:
22
- data, client_addr = self.sock.recvfrom(512) # max size of a DNS UDP packet
23
- logging.debug(f"Received {len(data)} bytes from {client_addr}")
22
+ start_time = time.time()
24
23
 
25
- logging.debug("Parsing DNS query...")
26
- parsed_query = DNSRecord.parse(data)
27
- logging.info(f"Parsed query:\n{parsed_query.toZone()}")
24
+ while True:
25
+ try:
26
+ remaining_time = timeout - (time.time() - start_time)
27
+ if remaining_time <= 0:
28
+ logging.warning("Timeout reached while waiting for a valid DNS query.")
29
+ return {"received": None}, EventNames.TIMEOUT.name
28
30
 
29
- logging.debug("Building DNS response...")
30
- response = self.build_response(parsed_query, response_spec)
31
+ self.sock.settimeout(remaining_time)
32
+ data, client_addr = self.sock.recvfrom(512) # max size of a DNS UDP packet
33
+ logging.debug(f"Received {len(data)} bytes from {client_addr}")
31
34
 
32
- logging.debug("Sending DNS response...")
33
- self.send_dns_response(client_addr, response)
34
- logging.info("DNS response sent successfully.")
35
+ logging.debug("Parsing DNS query...")
36
+ parsed_query = DNSRecord.parse(data)
35
37
 
36
- return {
37
- "received": str(parsed_query.q)
38
- }, EventNames.REQUEST_RECEIVED.name
38
+ # Check if query section is empty
39
+ if not parsed_query.questions:
40
+ logging.debug("Received DNS packet with no query section. Continuing to wait...")
41
+ continue
39
42
 
40
- except socket.timeout:
41
- logging.warning("Timeout reached with no packet received.")
42
- return {"received": None}, EventNames.TIMEOUT.name
43
- except Exception as e:
44
- logging.error(f"Error while handling DNS query: {e}", exc_info=True)
45
- return {"received": None}, EventNames.ERROR.name
43
+ logging.info(f"Parsed query:\n{parsed_query.toZone()}")
44
+
45
+ logging.debug("Building DNS response...")
46
+ response = self.build_response(parsed_query, response_spec)
47
+
48
+ logging.debug("Sending DNS response...")
49
+ self.send_dns_response(client_addr, response)
50
+ logging.info("DNS response sent successfully.")
51
+
52
+ return {
53
+ "received": str(parsed_query.q)
54
+ }, EventNames.REQUEST_RECEIVED.name
55
+
56
+ except socket.timeout:
57
+ logging.warning("Timeout reached while waiting for a valid DNS query.")
58
+ return {"received": None}, EventNames.TIMEOUT.name
59
+ except Exception as e:
60
+ logging.error(f"Error while handling DNS query: {e}", exc_info=True)
61
+ return {"received": None}, EventNames.ERROR.name
46
62
 
47
63
  def build_response(self, query_record, response_spec=None):
48
64
  qname = str(query_record.q.qname)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nopasaran
3
- Version: 0.2.110
3
+ Version: 0.2.111
4
4
  Summary: NoPASARAN is an advanced network tool designed to detect, fingerprint, and locate network middleboxes in a unified framework.
5
5
  Home-page: https://github.com/BenIlies/NoPASARAN
6
6
  Author: Ilies Benhabbour
@@ -77,11 +77,11 @@ nopasaran/tools/http_2_socket_client.py,sha256=5mmc8FuT2dNVAihbMdvyytVwME_xSc7me
77
77
  nopasaran/tools/http_2_socket_server.py,sha256=8W-bxmdoGyK5moxpC87V1EGuZ9jJpIKhokvZrDV84kk,5551
78
78
  nopasaran/tools/https_1_socket_server.py,sha256=ytLVYdH5je4L6ElCKKhhsbU_53gT6QF9l5ym7q5TMmo,8162
79
79
  nopasaran/tools/tcp_dns_socket_server.py,sha256=fZl2ujE3C_1iqyz8qquWnePPAj8n2uzWfk3DUEDlgho,7924
80
- nopasaran/tools/udp_dns_socket_server.py,sha256=N6_27OTo3aKlihu1YqWfgYeCpdR3Xfo2o7ZE2db9Vuw,5568
80
+ nopasaran/tools/udp_dns_socket_server.py,sha256=BrtuddDgfeCZEt11IZ9wb1uJO4cW0KtlQahfyVrY9sg,6283
81
81
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
- nopasaran-0.2.110.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
83
- nopasaran-0.2.110.dist-info/METADATA,sha256=B6RitCFp4VAB_AUhU8_oIVRb2mqrFZIquCBmb_ofg04,5497
84
- nopasaran-0.2.110.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
85
- nopasaran-0.2.110.dist-info/entry_points.txt,sha256=LaOz5GlWuMLjzg4KOEB5OVTattCXVW6a4nSW-WQajCw,55
86
- nopasaran-0.2.110.dist-info/top_level.txt,sha256=60R1FzpprzU8iiJ1cBMNOA0F083_lYoctFo7pzOpMwY,16
87
- nopasaran-0.2.110.dist-info/RECORD,,
82
+ nopasaran-0.2.111.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
83
+ nopasaran-0.2.111.dist-info/METADATA,sha256=w6Rc4eHoaI8z17mrzBX4R-zdesq02iY5XFK1lJ1kQy4,5497
84
+ nopasaran-0.2.111.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
85
+ nopasaran-0.2.111.dist-info/entry_points.txt,sha256=LaOz5GlWuMLjzg4KOEB5OVTattCXVW6a4nSW-WQajCw,55
86
+ nopasaran-0.2.111.dist-info/top_level.txt,sha256=60R1FzpprzU8iiJ1cBMNOA0F083_lYoctFo7pzOpMwY,16
87
+ nopasaran-0.2.111.dist-info/RECORD,,