Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit da4e553

Browse files
author
byt3bl33d3r
committed
Added error handling for CME server in case the port is already in use.
Should resolve #109
1 parent 2c77b0c commit da4e553

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

core/cmeserver.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BaseHTTPServer
22
import threading
33
import ssl
4+
import sys
45
from BaseHTTPServer import BaseHTTPRequestHandler
56
from logging import getLogger
67
from gevent import sleep
@@ -36,7 +37,7 @@ def stop_tracking_host(self):
3637

3738
class CMEServer(threading.Thread):
3839

39-
def __init__(self, module, context, srv_host, port, server_type='https'):
40+
def __init__(self, module, context, logger, srv_host, port, server_type='https'):
4041

4142
try:
4243
threading.Thread.__init__(self)
@@ -51,7 +52,13 @@ def __init__(self, module, context, srv_host, port, server_type='https'):
5152
self.server.socket = ssl.wrap_socket(self.server.socket, certfile='data/cme.pem', server_side=True)
5253

5354
except Exception as e:
54-
print 'Error starting CME Server: {}'.format(e)
55+
errno, message = e.args
56+
if errno == 98 and message == 'Address already in use':
57+
logger.error('Error starting CME server: the port is already in use, try specifying a diffrent port using --server-port')
58+
else:
59+
logger.error('Error starting CME server: '.format(message))
60+
61+
sys.exit(1)
5562

5663
def base_server(self):
5764
return self.server

crackmapexec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
logger.error("I'm sorry {}, I'm afraid I can't let you do that".format(getpass.getuser()))
225225
sys.exit(1)
226226

227-
server = CMEServer(module, context, args.server_host, args.server_port, args.server)
227+
server = CMEServer(module, context, logger, args.server_host, args.server_port, args.server)
228228
server.start()
229229

230230
for target in args.target:

0 commit comments

Comments
 (0)