Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Native SOCKS Proxy Options for Examples #1903

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Impacket
========

Socks Branch
-----------------------

This branch adds native socks proxy functionality for some examples.
This is done to eliminate the need for an extra tool like
[proxychains](https://github.com/haad/proxychains).

The extra options added are found under the `SOCKS Proxy Options` category in the help menu:

* socks (enables socks)
* socks-address
* socks-port

**Examples updated:**

* atexec.py
* dcomexec.py
* mssqlclient.py
* psexec.py
* secretsdump.py
* smbexec.py
* wmiexec.py

Original README
---

[![Latest Version](https://img.shields.io/pypi/v/impacket.svg)](https://pypi.python.org/pypi/impacket/)
[![Build and test Impacket](https://github.com/fortra/impacket/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/fortra/impacket/actions/workflows/build_and_test.yml)

15 changes: 15 additions & 0 deletions examples/atexec.py
Original file line number Diff line number Diff line change
@@ -271,6 +271,12 @@ def cmd_split(cmdline):
'If omitted it will use the domain part (FQDN) specified in the target parameter')
group.add_argument('-keytab', action="store", help='Read keys for SPN from keytab file')

group = parser.add_argument_group('SOCKS Proxy Options')
group.add_argument('-socks', action='store_true', default=False,
help='Use a SOCKS proxy for the connection')
group.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address')
group.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')

if len(sys.argv)==1:
parser.print_help()
sys.exit(1)
@@ -280,6 +286,15 @@ def cmd_split(cmdline):
# Init the example's logger theme
logger.init(options.ts)

# Relay connections through a socks proxy
if (options.socks):
logging.info('Relaying connections through SOCKS proxy (%s:%s)', options.socks_address, options.socks_port)
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, options.socks_address, options.socks_port)
socket.socket = socks.socksocket

if options.codec is not None:
CODEC = options.codec
else:
15 changes: 15 additions & 0 deletions examples/dcomexec.py
Original file line number Diff line number Diff line change
@@ -589,6 +589,12 @@ def load_smbclient_auth_file(path):
group.add_argument('-A', action="store", metavar = "authfile", help="smbclient/mount.cifs-style authentication file. "
"See smbclient man page's -A option.")
group.add_argument('-keytab', action="store", help='Read keys for SPN from keytab file')

group = parser.add_argument_group('SOCKS Proxy Options')
group.add_argument('-socks', action='store_true', default=False,
help='Use a SOCKS proxy for the connection')
group.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address')
group.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')

if len(sys.argv)==1:
parser.print_help()
@@ -599,6 +605,15 @@ def load_smbclient_auth_file(path):
# Init the example's logger theme
logger.init(options.ts)

# Relay connections through a socks proxy
if (options.socks):
logging.info('Relaying connections through SOCKS proxy (%s:%s)', options.socks_address, options.socks_port)
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, options.socks_address, options.socks_port)
socket.socket = socks.socksocket

if options.codec is not None:
CODEC = options.codec
else:
14 changes: 14 additions & 0 deletions examples/mssqlclient.py
Original file line number Diff line number Diff line change
@@ -64,6 +64,11 @@
'This is useful when target is the NetBIOS name and you cannot resolve it')
group.add_argument('-port', action='store', default='1433', help='target MSSQL port (default 1433)')

group = parser.add_argument_group('SOCKS Proxy Options')
group.add_argument('-socks', action='store_true', default=False,
help='Use a SOCKS proxy for the connection')
group.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address')
group.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')

if len(sys.argv)==1:
parser.print_help()
@@ -78,6 +83,15 @@
else:
logging.getLogger().setLevel(logging.INFO)

# Relay connections through a socks proxy
if (options.socks):
logging.info('Relaying connections through SOCKS proxy (%s:%s)', options.socks_address, options.socks_port)
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, options.socks_address, options.socks_port)
socket.socket = socks.socksocket

domain, username, password, remoteName = parse_target(options.target)

if domain is None:
15 changes: 15 additions & 0 deletions examples/psexec.py
Original file line number Diff line number Diff line change
@@ -633,6 +633,12 @@ def run(self):
' used to trigger the payload')
group.add_argument('-remote-binary-name', action='store', metavar="remote_binary_name", default = None, help='This will '
'be the name of the executable uploaded on the target')

group = parser.add_argument_group('SOCKS Proxy Options')
group.add_argument('-socks', action='store_true', default=False,
help='Use a SOCKS proxy for the connection')
group.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address')
group.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')

if len(sys.argv)==1:
parser.print_help()
@@ -643,6 +649,15 @@ def run(self):
# Init the example's logger theme
logger.init(options.ts)

# Relay connections through a socks proxy
if (options.socks):
logging.info('Relaying connections through SOCKS proxy (%s:%s)', options.socks_address, options.socks_port)
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, options.socks_address, options.socks_port)
socket.socket = socks.socksocket

if options.codec is not None:
CODEC = options.codec
else:
15 changes: 15 additions & 0 deletions examples/secretsdump.py
Original file line number Diff line number Diff line change
@@ -461,6 +461,12 @@ def cleanup(self):
help='IP Address of the target machine. If omitted it will use whatever was specified as target. '
'This is useful when target is the NetBIOS name and you cannot resolve it')

group = parser.add_argument_group('SOCKS Proxy Options')
group.add_argument('-socks', action='store_true', default=False,
help='Use a SOCKS proxy for the connection')
group.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address')
group.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')

if len(sys.argv)==1:
parser.print_help()
sys.exit(1)
@@ -477,6 +483,15 @@ def cleanup(self):
else:
logging.getLogger().setLevel(logging.INFO)

# Relay connections through a socks proxy
if (options.socks):
logging.info('Relaying connections through SOCKS proxy (%s:%s)', options.socks_address, options.socks_port)
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, options.socks_address, options.socks_port)
socket.socket = socks.socksocket

domain, username, password, remoteName = parse_target(options.target)

if options.just_dc_user is not None or options.ldapfilter is not None:
14 changes: 14 additions & 0 deletions examples/smbexec.py
Original file line number Diff line number Diff line change
@@ -359,6 +359,11 @@ def send_data(self, data):
'(128 or 256 bits)')
group.add_argument('-keytab', action="store", help='Read keys for SPN from keytab file')

group = parser.add_argument_group('SOCKS Proxy Options')
group.add_argument('-socks', action='store_true', default=False,
help='Use a SOCKS proxy for the connection')
group.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address')
group.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')

if len(sys.argv)==1:
parser.print_help()
@@ -369,6 +374,15 @@ def send_data(self, data):
# Init the example's logger theme
logger.init(options.ts)

# Relay connections through a socks proxy
if (options.socks):
logging.info('Relaying connections through SOCKS proxy (%s:%s)', options.socks_address, options.socks_port)
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, options.socks_address, options.socks_port)
socket.socket = socks.socksocket

if options.codec is not None:
CODEC = options.codec
else:
15 changes: 15 additions & 0 deletions examples/wmiexec.py
Original file line number Diff line number Diff line change
@@ -403,6 +403,12 @@ def load_smbclient_auth_file(path):
"See smbclient man page's -A option.")
group.add_argument('-keytab', action="store", help='Read keys for SPN from keytab file')

group = parser.add_argument_group('SOCKS Proxy Options')
group.add_argument('-socks', action='store_true', default=False,
help='Use a SOCKS proxy for the connection')
group.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address')
group.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')

if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
@@ -412,6 +418,15 @@ def load_smbclient_auth_file(path):
# Init the example's logger theme
logger.init(options.ts)

# Relay connections through a socks proxy
if (options.socks):
logging.info('Relaying connections through SOCKS proxy (%s:%s)', options.socks_address, options.socks_port)
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, options.socks_address, options.socks_port)
socket.socket = socks.socksocket

if options.codec is not None:
CODEC = options.codec
else:
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ ldap3>=2.5,!=2.5.2,!=2.5.0,!=2.6
ldapdomaindump>=0.9.0
flask>=1.0
pyreadline3;sys_platform == 'win32'
pysocks