Skip to content

Commit e1a5d44

Browse files
p0rtL6p0rtL6
andauthored
[enhancement] Add windows support and windows binary build to Coercer (#97)
* split task preparation and execution into seperate functions * Update debug + verbose printing * Refactor reporter, standardize print formatting, and add logging * Initial Windows Support * Create windows binary installer script * Add small snippet to README for using the installer script * Update installer to install C++ Build Tools * Fix bug with coerce mode and packet redirection * Update URL in installer.ps1 --------- Co-authored-by: p0rtL6 <[email protected]>
1 parent aba43d3 commit e1a5d44

File tree

13 files changed

+395
-672
lines changed

13 files changed

+395
-672
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<br>
1111
</p>
1212

13+
## Windows Support
14+
To build a binary for Windows, download the `installer.ps1` script from this repository. Run it simply with no arguments to create a binary in the working directory. Use `-h` or `--help` for the help menu with options.
15+
1316
## Features
1417

1518
- Core:

coercer/__main__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import argparse
99
import os
1010
import sys
11+
import threading
1112
from sectools.network.domains import is_fqdn
1213
from sectools.network.ip import is_ipv4_cidr, is_ipv4_addr, is_ipv6_addr, expand_cidr, expand_port_range
13-
from coercer.core.Reporter import create_reporter
1414

1515
VERSION = "2.4.3"
1616

@@ -187,6 +187,8 @@ def parseArgs():
187187

188188
def main():
189189
lmhash, nthash, options = parseArgs()
190+
191+
from coercer.core.Reporter import create_reporter
190192
create_reporter(options, options.verbose)
191193

192194
from coercer.core.Reporter import reporter
@@ -195,11 +197,19 @@ def main():
195197
from coercer.core.modes.coerce import action_coerce
196198
from coercer.core.modes.fuzz import action_fuzz
197199
from coercer.network.smb import try_login
198-
from coercer.network.utils import can_listen_on_port
200+
from coercer.network.utils import can_listen_on_port, redirect_smb_packets
199201
from coercer.core.loader import find_and_load_coerce_methods
200202

201203
available_methods = find_and_load_coerce_methods()
202-
204+
205+
if options.smb_port == 445 and sys.platform == "win32" and (options.mode == "scan" or options.mode == "fuzz"):
206+
reporter.print_info("Redirecting packets between port 445 <-> 4445")
207+
options.redirecting_smb_packets = True
208+
redirector = threading.Thread(target=redirect_smb_packets)
209+
redirector.start()
210+
else:
211+
options.redirecting_smb_packets = False
212+
203213
# Parsing targets
204214
targets = []
205215
if options.target_ip is not None:
@@ -265,8 +275,8 @@ def main():
265275
reporter.print_info("Starting scan mode")
266276
if credentials.is_anonymous():
267277
reporter.print_info("No credentials provided, trying to connect with a NULL session.")
268-
if not can_listen_on_port("0.0.0.0", 445):
269-
reporter.print_error("Cannot listen on port tcp/%d. Are you root or are other servers running?" % 445)
278+
if not can_listen_on_port("0.0.0.0", 4445 if options.redirecting_smb_packets else options.smb_port):
279+
reporter.print_error("Cannot listen on port tcp/%d. Are you root or are other servers running?" % 4445 if options.redirecting_smb_packets else options.smb_port)
270280
else:
271281
for target in targets:
272282
reporter.print_info("Scanning target %s" % target)
@@ -289,8 +299,8 @@ def main():
289299
reporter.print_info("Starting fuzz mode")
290300
if credentials.is_anonymous():
291301
reporter.print_info("No credentials provided, trying to connect with a NULL session.")
292-
if not can_listen_on_port("0.0.0.0", 445):
293-
reporter.print_error("Cannot listen on port tcp/%d. Are you root or are other servers running?" % 445)
302+
if not can_listen_on_port("0.0.0.0", 4445 if options.redirecting_smb_packets else options.smb_port):
303+
reporter.print_error("Cannot listen on port tcp/%d. Are you root or are other servers running?" % 4445 if options.redirecting_smb_packets else options.smb_port)
294304
else:
295305
for target in targets:
296306
reporter.print_info("Fuzzing target %s" % target)

coercer/core/Reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def report_test_result(self, target, uuid, version, namedpipe, msprotocol_rpc_in
213213
sys.stdout.write(EscapeCodes.ERASE_LINE)
214214

215215
if self.options.mode in ["scan", "fuzz"]:
216-
if result == TestResult.SMB_AUTH_RECEIVED:
216+
if result == TestResult.SMB_AUTH_RECEIVED or result == TestResult.SMB_AUTH_RECEIVED_NTLMv1 or result == TestResult.SMB_AUTH_RECEIVED_NTLMv2:
217217
self.print_result("+", "SMB Auth", msprotocol_rpc_instance, EscapeCodes.BOLD_BRIGHT_GREEN)
218218
elif result == TestResult.HTTP_AUTH_RECEIVED:
219219
self.print_result("+", "HTTP Auth", msprotocol_rpc_instance, EscapeCodes.BOLD_BRIGHT_GREEN)

coercer/core/tasks/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ def connect_function(dcerpc, target, taskEntry):
155155
if options.verbose:
156156
reporter.print_error(" ", "Cannot bind to interface (%s, %s)!" % (uuid, version))
157157
else:
158-
reporter.print(transportType.value, " '", (taskEntry, EscapeCodes.BOLD_BRIGHT_BLUE), "' ", ("closed", EscapeCodes.BOLD_BRIGHT_RED), "!", symbol=("!", EscapeCodes.BRIGHT_RED), verbose=True)
158+
reporter.print(transportType.value, " '", (taskEntry, EscapeCodes.BOLD_BRIGHT_BLUE), "' ", ("closed", EscapeCodes.BOLD_BRIGHT_RED), "!", symbol=("!", EscapeCodes.BRIGHT_RED), verbose=True)

0 commit comments

Comments
 (0)