Worker process that floods the target.
(self, q: Any, chosen_alg: str, gex_modulus_size: int)
| 902 | |
| 903 | |
| 904 | def _worker_process(self, q: Any, chosen_alg: str, gex_modulus_size: int) -> None: |
| 905 | '''Worker process that floods the target.''' |
| 906 | |
| 907 | |
| 908 | def _close_socket(s: socket.socket) -> None: |
| 909 | try: |
| 910 | s.shutdown(socket.SHUT_RDWR) |
| 911 | s.close() |
| 912 | except OSError: |
| 913 | pass |
| 914 | |
| 915 | |
| 916 | # Copy variables from the object (which might exist in another process?). This might cut down on inter-process overhead. |
| 917 | connect_timeout = self.connect_timeout |
| 918 | target_ip_address = self.target_ip_address |
| 919 | target_address_family = self.target_address_family |
| 920 | port = self.port |
| 921 | |
| 922 | # Determine if we are attacking with a GEX. |
| 923 | gex_mode = False |
| 924 | if chosen_alg in DHEat.gex_algs: |
| 925 | gex_mode = True |
| 926 | self.debug("Setting GEX mode to True; gex_modulus_size: %u" % gex_modulus_size) |
| 927 | |
| 928 | # Attack statistics local to this process. |
| 929 | num_attempted_tcp_connections = 0 |
| 930 | num_successful_tcp_connections = 0 |
| 931 | num_successful_dh_kex = 0 |
| 932 | num_failed_dh_kex = 0 |
| 933 | num_bytes_written = 0 |
| 934 | num_connect_timeouts = 0 |
| 935 | num_read_timeouts = 0 |
| 936 | num_socket_exceptions = 0 |
| 937 | num_openssh_throttled_connections = 0 |
| 938 | |
| 939 | num_loops_since_last_statistics_sync = 0 |
| 940 | while True: |
| 941 | num_loops_since_last_statistics_sync += 1 |
| 942 | |
| 943 | # Instead of flooding the parent process with statistics, report our stats only every 5 connections. |
| 944 | if num_loops_since_last_statistics_sync > 5: |
| 945 | num_loops_since_last_statistics_sync = 0 |
| 946 | |
| 947 | q.put({ |
| 948 | 'num_attempted_tcp_connections': num_attempted_tcp_connections, |
| 949 | 'num_successful_tcp_connections': num_successful_tcp_connections, |
| 950 | 'num_successful_dh_kex': num_successful_dh_kex, |
| 951 | 'num_failed_dh_kex': num_failed_dh_kex, |
| 952 | 'num_bytes_written': num_bytes_written, |
| 953 | 'num_connect_timeouts': num_connect_timeouts, |
| 954 | 'num_read_timeouts': num_read_timeouts, |
| 955 | 'num_socket_exceptions': num_socket_exceptions, |
| 956 | 'num_openssh_throttled_connections': num_openssh_throttled_connections, |
| 957 | }) |
| 958 | |
| 959 | # Since we sent our statistics, reset them all back to zero. |
| 960 | num_attempted_tcp_connections = 0 |
| 961 | num_successful_tcp_connections = 0 |
no test coverage detected