Coverage for /root/GitHubProjects/impacket/impacket/examples/ntlmrelayx/servers/socksplugins/https.py : 45%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Impacket - Collection of Python classes for working with network protocols.
2#
3# SECUREAUTH LABS. Copyright (C) 2018 SecureAuth Corporation. All rights reserved.
4#
5# This software is provided under a slightly modified version
6# of the Apache Software License. See the accompanying LICENSE file
7# for more information.
8#
9# Description:
10# Socks Proxy for the HTTPS Protocol
11#
12# A simple SOCKS server that proxies a connection to relayed HTTPS connections
13#
14# Author:
15# Dirk-jan Mollema (@_dirkjan) / Fox-IT (https://www.fox-it.com)
16#
17from impacket import LOG
18from impacket.examples.ntlmrelayx.servers.socksplugins.http import HTTPSocksRelay
19from impacket.examples.ntlmrelayx.utils.ssl import SSLServerMixin
20from OpenSSL import SSL
22# Besides using this base class you need to define one global variable when
23# writing a plugin:
24PLUGIN_CLASS = "HTTPSSocksRelay"
25EOL = '\r\n'
27class HTTPSSocksRelay(SSLServerMixin, HTTPSocksRelay):
28 PLUGIN_NAME = 'HTTPS Socks Plugin'
29 PLUGIN_SCHEME = 'HTTPS'
31 def __init__(self, targetHost, targetPort, socksSocket, activeRelays):
32 HTTPSocksRelay.__init__(self, targetHost, targetPort, socksSocket, activeRelays)
34 @staticmethod
35 def getProtocolPort():
36 return 443
38 def skipAuthentication(self):
39 LOG.debug('Wrapping client connection in TLS/SSL')
40 self.wrapClientConnection()
41 if not HTTPSocksRelay.skipAuthentication(self):
42 # Shut down TLS connection
43 self.socksSocket.shutdown()
44 return False
45 return True
47 def tunnelConnection(self):
48 while True:
49 try:
50 data = self.socksSocket.recv(self.packetSize)
51 except SSL.ZeroReturnError:
52 # The SSL connection was closed, return
53 return
54 # Pass the request to the server
55 tosend = self.prepareRequest(data)
56 self.relaySocket.send(tosend)
57 # Send the response back to the client
58 self.transferResponse()