nopasaran 0.2.97__py3-none-any.whl → 0.2.99__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.
@@ -40,7 +40,7 @@ class HTTPSimpleClientPrimitives:
40
40
  try:
41
41
  if use_https == "1":
42
42
  scheme = "HTTPS"
43
- context = ssl.create_default_context()
43
+ context = ssl._create_unverified_context()
44
44
  conn = http.client.HTTPSConnection(ip_address, 443, context=context, timeout=5)
45
45
  elif use_https == "0":
46
46
  scheme = "HTTP"
@@ -17,21 +17,45 @@ class HTTP1SocketServer:
17
17
  self.client_socket = None
18
18
  self.TIMEOUT = 5.0
19
19
 
20
- def handle_client_connection(self, client_socket):
20
+ def handle_client_connection(self, client_socket, timeout):
21
21
  """
22
22
  Handle a client connection by processing the incoming request and sending the appropriate response.
23
23
  """
24
- request = client_socket.recv(4096)
25
- request_str = request.decode('utf-8')
24
+ client_socket.setblocking(False)
25
+ ready_to_read, _, _ = select.select([client_socket], [], [], timeout)
26
+
27
+ if not ready_to_read:
28
+ client_socket.close()
29
+ return None, EventNames.TIMEOUT.name
30
+
31
+ try:
32
+ request = client_socket.recv(4096)
33
+ except socket.timeout:
34
+ client_socket.close()
35
+ return None, EventNames.TIMEOUT.name
36
+ except ConnectionResetError as e:
37
+ client_socket.close()
38
+ return str(e), EventNames.ERROR.name
39
+
40
+ if not request:
41
+ client_socket.close()
42
+ return None, EventNames.TIMEOUT.name
43
+
44
+ request_str = request.decode('utf-8', errors='ignore')
45
+
26
46
  # Extract request line and headers
27
47
  headers_end_index = request_str.find("\r\n\r\n")
28
48
  headers_part = request_str[:headers_end_index] if headers_end_index != -1 else request_str
29
49
  request_line = headers_part.split("\r\n")[0]
30
- method, path, _ = request_line.split(" ", 2)
50
+
51
+ try:
52
+ method, path, _ = request_line.split(" ", 2)
53
+ except ValueError:
54
+ method, path = "GET", "/"
31
55
 
32
56
  route_key = (path, method)
33
57
  route_info_list = self.routes.get(route_key)
34
-
58
+
35
59
  if route_info_list:
36
60
  response = ""
37
61
  for route_info in route_info_list:
@@ -39,42 +63,30 @@ class HTTP1SocketServer:
39
63
  status_code = route_info.get('status', 200)
40
64
  headers = route_info.get('headers', [])
41
65
 
42
- # Construct each part of the response
43
66
  response_part = f"HTTP/1.1 {status_code} OK\r\n"
44
67
  for header_name, header_value in headers:
45
68
  response_part += f"{header_name}: {header_value}\r\n"
46
- response_part += f"\r\n{response_body}\r\n\r\n" # Double CRLF to separate responses
69
+ response_part += f"\r\n{response_body}\r\n\r\n"
47
70
 
48
- # Append the response part to the full response
49
71
  response += response_part
50
72
 
51
- # Send the full combined response to the client
52
73
  client_socket.sendall(response.encode())
53
-
54
74
  else:
55
75
  response_body = 'NoPASARAN HTTP/1.1 Server'
56
76
  status_code = 404
57
- headers = []
58
-
59
- # Construct the HTTP response
60
- response = f"HTTP/1.1 {status_code} OK\r\n"
61
- for header_name, header_value in headers:
62
- response += f"{header_name}: {header_value}\r\n"
63
- response += f"\r\n{response_body}"
64
-
65
- # Send response to client
77
+ response = f"HTTP/1.1 {status_code} Not Found\r\nContent-Length: {len(response_body)}\r\n\r\n{response_body}"
66
78
  client_socket.sendall(response.encode())
67
79
 
68
80
  client_socket.close()
69
81
 
70
- # Store the raw received request data
71
82
  self.received_request_data = request
72
83
 
73
- # Notify that a request has been received
74
84
  if self.request_received:
75
85
  with self.request_received:
76
86
  self.request_received.notify_all()
77
87
 
88
+ return request, EventNames.REQUEST_RECEIVED.name
89
+
78
90
  def wait_for_request(self, port, timeout):
79
91
  """
80
92
  Wait for an HTTP request or timeout.
@@ -84,7 +96,7 @@ class HTTP1SocketServer:
84
96
  timeout (int): The timeout duration in seconds.
85
97
 
86
98
  Returns:
87
- Tuple[bytes, str]: The raw received request data or None if a timeout occurs, and the event name.
99
+ Tuple[bytes or None, str]: The raw received request data or None if a timeout occurs, and the event name.
88
100
  """
89
101
  server_address = ('', port)
90
102
  self.request_received = threading.Condition()
@@ -96,22 +108,18 @@ class HTTP1SocketServer:
96
108
  server_socket.listen(1)
97
109
  server_socket.setblocking(False)
98
110
 
99
- # Initialize the timeout timer
100
111
  start_time = time.time()
101
112
 
102
113
  while True:
103
- # Check if the timeout has elapsed
104
114
  elapsed_time = time.time() - start_time
105
- if elapsed_time > timeout:
115
+ if elapsed_time >= timeout:
106
116
  return None, EventNames.TIMEOUT.name
107
-
108
- # Use select to wait for a connection with a timeout
117
+
109
118
  ready_to_read, _, _ = select.select([server_socket], [], [], timeout - elapsed_time)
110
-
119
+
111
120
  if ready_to_read:
112
121
  client_socket, _ = server_socket.accept()
113
- self.handle_client_connection(client_socket)
114
- return self.received_request_data, EventNames.REQUEST_RECEIVED.name
122
+ return self.handle_client_connection(client_socket, timeout - elapsed_time)
115
123
 
116
124
  def start(self, host, port):
117
125
  """
@@ -121,7 +129,7 @@ class HTTP1SocketServer:
121
129
  self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
122
130
  self.sock.bind((host, port))
123
131
  self.sock.listen(5)
124
-
132
+
125
133
  return EventNames.SERVER_STARTED.name, f"Server successfully started at {host}:{port}."
126
134
 
127
135
  def close(self):
@@ -131,11 +139,10 @@ class HTTP1SocketServer:
131
139
  self.client_socket.close()
132
140
  if self.sock:
133
141
  self.sock.close()
134
-
135
- # Clear references
142
+
136
143
  self.client_socket = None
137
144
  self.sock = None
138
-
145
+
139
146
  return EventNames.CONNECTION_ENDING.name
140
147
  except Exception as e:
141
148
  return EventNames.CONNECTION_ENDING.name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nopasaran
3
- Version: 0.2.97
3
+ Version: 0.2.99
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
@@ -40,7 +40,7 @@ nopasaran/primitives/action_primitives/http_1_request_primitives.py,sha256=ov4OL
40
40
  nopasaran/primitives/action_primitives/http_1_response_primitives.py,sha256=0wS61tl1KSAlIkYkPXMjbbnY5LqKzl9UtuoK56S4IHQ,7947
41
41
  nopasaran/primitives/action_primitives/http_2_client_primitives.py,sha256=s8QVm_vBvX8mFfq6a2Yz9tszToyOThp620HQThMzoL0,9306
42
42
  nopasaran/primitives/action_primitives/http_2_server_primitives.py,sha256=g6RfKuXVNSDBlyYCJeokgntM5AXLfNBUUSLciLaQYyU,9310
43
- nopasaran/primitives/action_primitives/http_simple_client_primitives.py,sha256=KBo6HsfY73-MTK7RAJrDcmiVSrQqmLMmZUqelD0jUL4,2534
43
+ nopasaran/primitives/action_primitives/http_simple_client_primitives.py,sha256=Tx9qAzplMZIlvVJsvGYmacgch1qVK1_JGLiXEGR3Sug,2538
44
44
  nopasaran/primitives/action_primitives/https_1_request_primitives.py,sha256=lW1DMab0CNuUtG0Z_oRXJXz5d8SBZcPEcJhSzSQzwbc,2060
45
45
  nopasaran/primitives/action_primitives/https_1_response_primitives.py,sha256=rj01Co2Pa9Daxrl15SZoKuvJvsVflxWB63WYHvhy5wk,7797
46
46
  nopasaran/primitives/action_primitives/icmp_primitives.py,sha256=56hfho9cjZR9kbk6bsI1fsJTyTt-7LGR5LNFAk2cdMQ,5967
@@ -68,7 +68,7 @@ nopasaran/sniffers/sniffer.py,sha256=rmUlW4_IvLurz_qelpFFSdIaiyWXBljFZ2Cdec3ohSE
68
68
  nopasaran/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
69
69
  nopasaran/tools/checks.py,sha256=-Y5gOm0f8ZIkOdiViCCrTR9jC1MTt8IbnOrLp5tBzVo,1299
70
70
  nopasaran/tools/echo_socket_server.py,sha256=_a6bcDq4pXVjeEnNqPuulipgfH2bddf-N-ExXBTuQiE,3748
71
- nopasaran/tools/http_1_socket_server.py,sha256=400VpzPVrX7RO1m4JigmSR_Xx8pOZbMcFb0hjyYNLqA,5220
71
+ nopasaran/tools/http_1_socket_server.py,sha256=jZTxZdRutDnPwxvAiC4GM2gCBgWhwv1by2bzgxCXZFc,5162
72
72
  nopasaran/tools/http_2_overwrite.py,sha256=vKJzAwbisK9qkN3GCp7FuFfSaPAiUGPwZD9ABYi6eIs,25177
73
73
  nopasaran/tools/http_2_socket_base.py,sha256=KDfkU4Nr_TXxqzp1-ZHec_UawfDZ5oIIj-JysEhi0Q0,11233
74
74
  nopasaran/tools/http_2_socket_client.py,sha256=5mmc8FuT2dNVAihbMdvyytVwME_xSc7mez_jwU3YZOA,6256
@@ -76,9 +76,9 @@ nopasaran/tools/http_2_socket_server.py,sha256=8W-bxmdoGyK5moxpC87V1EGuZ9jJpIKho
76
76
  nopasaran/tools/https_1_socket_server.py,sha256=ytLVYdH5je4L6ElCKKhhsbU_53gT6QF9l5ym7q5TMmo,8162
77
77
  nopasaran/tools/tcp_dns_socket_server.py,sha256=UKOgyhCXj-u9KJoP8qsQLbyyIkjOhyG7-_3GSP8e0DM,7908
78
78
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
79
- nopasaran-0.2.97.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
80
- nopasaran-0.2.97.dist-info/METADATA,sha256=1ucCuOtDePr7NIaMpi-JUyl6QqOEgfilYObb0fV4iX0,5496
81
- nopasaran-0.2.97.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
82
- nopasaran-0.2.97.dist-info/entry_points.txt,sha256=LaOz5GlWuMLjzg4KOEB5OVTattCXVW6a4nSW-WQajCw,55
83
- nopasaran-0.2.97.dist-info/top_level.txt,sha256=60R1FzpprzU8iiJ1cBMNOA0F083_lYoctFo7pzOpMwY,16
84
- nopasaran-0.2.97.dist-info/RECORD,,
79
+ nopasaran-0.2.99.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
80
+ nopasaran-0.2.99.dist-info/METADATA,sha256=SEjkQMlAxalgmDx6zn_5ydkbwVVI5oCy2inxEkKZ3eI,5496
81
+ nopasaran-0.2.99.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
82
+ nopasaran-0.2.99.dist-info/entry_points.txt,sha256=LaOz5GlWuMLjzg4KOEB5OVTattCXVW6a4nSW-WQajCw,55
83
+ nopasaran-0.2.99.dist-info/top_level.txt,sha256=60R1FzpprzU8iiJ1cBMNOA0F083_lYoctFo7pzOpMwY,16
84
+ nopasaran-0.2.99.dist-info/RECORD,,