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# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved.
2#
3# This software is provided under under a slightly modified version
4# of the Apache Software License. See the accompanying LICENSE file
5# for more information.
6#
7# A Socks Proxy for the HTTPS Protocol
8#
9# Author:
10# Dirk-jan Mollema (@_dirkjan) / Fox-IT (https://www.fox-it.com)
11#
12# Description:
13# A simple SOCKS server that proxies a connection to relayed HTTPS connections
14#
15# ToDo:
16#
18from impacket import LOG
19from impacket.examples.ntlmrelayx.servers.socksplugins.http import HTTPSocksRelay
20from impacket.examples.ntlmrelayx.utils.ssl import SSLServerMixin
21from OpenSSL import SSL
23# Besides using this base class you need to define one global variable when
24# writing a plugin:
25PLUGIN_CLASS = "HTTPSSocksRelay"
26EOL = '\r\n'
28class HTTPSSocksRelay(SSLServerMixin, HTTPSocksRelay):
29 PLUGIN_NAME = 'HTTPS Socks Plugin'
30 PLUGIN_SCHEME = 'HTTPS'
32 def __init__(self, targetHost, targetPort, socksSocket, activeRelays):
33 HTTPSocksRelay.__init__(self, targetHost, targetPort, socksSocket, activeRelays)
35 @staticmethod
36 def getProtocolPort():
37 return 443
39 def skipAuthentication(self):
40 LOG.debug('Wrapping client connection in TLS/SSL')
41 self.wrapClientConnection()
42 if not HTTPSocksRelay.skipAuthentication(self):
43 # Shut down TLS connection
44 self.socksSocket.shutdown()
45 return False
46 return True
48 def tunnelConnection(self):
49 while True:
50 try:
51 data = self.socksSocket.recv(self.packetSize)
52 except SSL.ZeroReturnError:
53 # The SSL connection was closed, return
54 return
55 # Pass the request to the server
56 tosend = self.prepareRequest(data)
57 self.relaySocket.send(tosend)
58 # Send the response back to the client
59 self.transferResponse()