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 Windows Support and Installer for Examples #1907

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b61f76c
Add packet redirection for port 445 and init build script and instruc…
Oct 23, 2024
d0eaa10
Update install script, update install instructions, and add indicatio…
Oct 23, 2024
7abc07e
update install script to check existing python installs and remove af…
Oct 23, 2024
adfdffe
Fix formatting
Oct 23, 2024
d8cc4d5
Add installer for secretsdump
Oct 23, 2024
9702497
Update README
Oct 23, 2024
cbbd514
Update Installer and README
Oct 24, 2024
e186676
Update Help message
Oct 24, 2024
b28c5a0
Add list of available scripts in help message
Oct 24, 2024
13d2e22
Fix issue with command description
Oct 24, 2024
6278ec7
update readme and install script
Oct 24, 2024
0bf50c5
Patch pyreadline3
Oct 26, 2024
4d8b670
Individualize requirements
Oct 26, 2024
6d3d2ea
Init Modules
Oct 27, 2024
41c964a
Update readme
Oct 30, 2024
128ce07
Fix installer url
p0rtL6 Nov 4, 2024
50eb26a
Fix cleanup of Npcap module
Nov 4, 2024
380bc68
Add -a & fix error for requirements install
Nov 4, 2024
8beec68
Add module for ntlmrelayx
Nov 4, 2024
23d2027
Update installer to use ntlmrelayx module
Nov 4, 2024
598edc2
capitalize all flag
Nov 14, 2024
f504888
Optimizations & Docs update
Nov 15, 2024
fa73d0d
Patch Readline
Nov 15, 2024
db86eae
Fix packet redirection bug
Jan 18, 2025
428f13d
Fix readline patch for SQLSHELL
Feb 6, 2025
7a9f25b
Allow installer to pull from different repos/branches as well as buil…
Feb 13, 2025
5d829be
Add temp dir and extract dir options
Feb 17, 2025
346a34b
Rewrite installer to use Powershell framework
Feb 20, 2025
696bfc9
Update Documentation
p0rtL6 Feb 25, 2025
c84f3b1
remove pyinstaller from requirements
p0rtL6 Feb 26, 2025
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
Impacket
========

Windows Branch
-----------------------

This branch contains modifications to make impacket examples work on Windows as
well as adding a helpful installer to build examples into standalone binaries.

**To build a tool into an executable:**
> You may have to disable Windows AV
Download `impacket-installer.ps1` and run the script as administrator in Powershell.

```
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
impacket-exe-installer.ps1 --help
```

> Use Ctrl+Pause/Break to exit scripts.
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)

Expand Down
4 changes: 4 additions & 0 deletions examples/dcomexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def run(self, addr, silentCommand=False):

class RemoteShell(cmd.Cmd):
def __init__(self, share, quit, executeShellCommand, smbConnection, shell_type, silentCommand=False):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self)
self._share = share
self._output = '\\' + OUTPUT_FILENAME
Expand Down
4 changes: 4 additions & 0 deletions examples/goldenPac.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ def run(self):

class RemoteShell(cmd.Cmd):
def __init__(self, server, port, credentials, tid, fid, TGS, share):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self, False)
self.prompt = '\x08'
self.server = server
Expand Down
4 changes: 4 additions & 0 deletions examples/mimikatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@

class MimikatzShell(cmd.Cmd):
def __init__(self, dce):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self)
self.shell = None

Expand Down
4 changes: 4 additions & 0 deletions examples/ntfs-read.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@ def getINode(self, iNodeNum):

class MiniShell(cmd.Cmd):
def __init__(self, volume):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self)
self.volumePath = volume
self.volume = NTFS(volume)
Expand Down
25 changes: 25 additions & 0 deletions examples/ntlmrelayx.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import sys
import logging
import cmd

try:
from urllib.request import ProxyHandler, build_opener, Request
except ImportError:
Expand All @@ -50,6 +51,8 @@
from time import sleep
from threading import Thread

import pydivert

from impacket import version
from impacket.examples import logger
from impacket.examples.ntlmrelayx.servers import SMBRelayServer, HTTPRelayServer, WCFRelayServer, RAWRelayServer
Expand All @@ -61,6 +64,10 @@

class MiniShell(cmd.Cmd):
def __init__(self, relayConfig, threads, api_address):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self)

self.prompt = 'ntlmrelayx> '
Expand Down Expand Up @@ -236,6 +243,14 @@ def start_servers(options, threads):
continue

elif server is SMBRelayServer:
if options.smb_port == 445:
print("[*] SMB Server port set to 445 - redirecting to port 4445")
redirect_thread = Thread(target=redirect_smb_packets)
redirect_thread.start()
threads.add(redirect_thread)

options.smb_port = 4445

c.setListeningPort(options.smb_port)
elif server is WCFRelayServer:
c.setListeningPort(options.wcf_port)
Expand All @@ -258,6 +273,16 @@ def stop_servers(threads):
threads.remove(thread)
del thread

def redirect_smb_packets():
with pydivert.WinDivert("tcp.DstPort == 445 or tcp.SrcPort == 4445") as w:
for packet in w:
if packet.dst_port == 445 and packet.is_inbound:
packet.dst_port = 4445
if packet.src_port == 4445 and packet.is_outbound:
packet.src_port = 445
w.send(packet)


# Process command-line arguments.
if __name__ == '__main__':

Expand Down
4 changes: 4 additions & 0 deletions examples/psexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ def run(self):

class RemoteShell(cmd.Cmd):
def __init__(self, server, port, credentials, tid, fid, share, transport):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self, False)
self.prompt = '\x08'
self.server = server
Expand Down
4 changes: 4 additions & 0 deletions examples/raiseChild.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ def run(self):

class RemoteShell(cmd.Cmd):
def __init__(self, server, port, credentials, tid, fid, TGS, share):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self, False)
self.prompt = '\x08'
self.server = server
Expand Down
4 changes: 4 additions & 0 deletions examples/smbexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def run(self, remoteName, remoteHost):

class RemoteShell(cmd.Cmd):
def __init__(self, share, rpc, mode, serviceName, shell_type):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self)
self.__share = share
self.__mode = mode
Expand Down
12 changes: 12 additions & 0 deletions examples/sniff.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@
# ImpactDecoder
#

import os
import sys
import subprocess

try:
if not "RUNNING" in subprocess.run(['sc', 'query', 'npcap'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode():
raise
except:
print("Npcap not found. Running installer.")
installer_path = os.path.join(sys._MEIPASS, 'npcap.exe')
subprocess.run(installer_path, check=True)


from threading import Thread
import pcapy
from pcapy import findalldevs, open_live
Expand Down
14 changes: 13 additions & 1 deletion examples/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@
# pcapy: open_offline, pcapdumper
# ImpactDecoder
#

from __future__ import division
from __future__ import print_function


import os
import sys
import subprocess

try:
if not "RUNNING" in subprocess.run(['sc', 'query', 'npcap'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode():
raise
except:
print("Npcap not found. Running installer.")
installer_path = os.path.join(sys._MEIPASS, 'npcap.exe')
subprocess.run(installer_path, check=True)

import pcapy
from pcapy import open_offline

Expand Down
4 changes: 4 additions & 0 deletions examples/wmiexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def run(self, addr, silentCommand=False):

class RemoteShell(cmd.Cmd):
def __init__(self, share, win32Process, smbConnection, shell_type, silentCommand=False):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self)
self.__share = share
self.__output = '\\' + OUTPUT_FILENAME
Expand Down
4 changes: 4 additions & 0 deletions examples/wmiquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

class WMIQUERY(cmd.Cmd):
def __init__(self, iWbemServices):

import readline
readline.backend = 'readline'

cmd.Cmd.__init__(self)
self.iWbemServices = iWbemServices
self.prompt = 'WQL> '
Expand Down
Loading