Hide keyboard shortcuts

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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved. 

# 

# This software is provided under under a slightly modified version 

# of the Apache Software License. See the accompanying LICENSE file 

# for more information. 

# 

# A Socks Proxy for the HTTPS Protocol 

# 

# Author: 

# Dirk-jan Mollema (@_dirkjan) / Fox-IT (https://www.fox-it.com) 

# 

# Description: 

# A simple SOCKS server that proxies a connection to relayed HTTPS connections 

# 

# ToDo: 

# 

 

from impacket import LOG 

from impacket.examples.ntlmrelayx.servers.socksplugins.http import HTTPSocksRelay 

from impacket.examples.ntlmrelayx.utils.ssl import SSLServerMixin 

from OpenSSL import SSL 

 

# Besides using this base class you need to define one global variable when 

# writing a plugin: 

PLUGIN_CLASS = "HTTPSSocksRelay" 

EOL = '\r\n' 

 

class HTTPSSocksRelay(SSLServerMixin, HTTPSocksRelay): 

PLUGIN_NAME = 'HTTPS Socks Plugin' 

PLUGIN_SCHEME = 'HTTPS' 

 

def __init__(self, targetHost, targetPort, socksSocket, activeRelays): 

HTTPSocksRelay.__init__(self, targetHost, targetPort, socksSocket, activeRelays) 

 

@staticmethod 

def getProtocolPort(): 

return 443 

 

def skipAuthentication(self): 

LOG.debug('Wrapping client connection in TLS/SSL') 

self.wrapClientConnection() 

if not HTTPSocksRelay.skipAuthentication(self): 

# Shut down TLS connection 

self.socksSocket.shutdown() 

return False 

return True 

 

def tunnelConnection(self): 

while True: 

try: 

data = self.socksSocket.recv(self.packetSize) 

except SSL.ZeroReturnError: 

# The SSL connection was closed, return 

return 

# Pass the request to the server 

tosend = self.prepareRequest(data) 

self.relaySocket.send(tosend) 

# Send the response back to the client 

self.transferResponse()