Merge pull request #117 from stufus/add_egress_busting
Add Egress Checking Traffic Generator Module1.6
commit
c6ff79d7b8
|
@ -0,0 +1,156 @@
|
|||
<#
|
||||
|
||||
This module aims to offer the ability to generate arbitrary traffic on the ports specified, using the protocol specified.
|
||||
Author: Stuart Morgan (@ukstufus)
|
||||
Web: https://github.com/stufus
|
||||
|
||||
#>
|
||||
|
||||
function Invoke-EgressCheck {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
|
||||
Generates arbitrary traffic on the ports specified, using the protocol specified.
|
||||
|
||||
.DESCRIPTION
|
||||
|
||||
This will attempt to asynchronously generate a connection on each port specified, using the
|
||||
protocol specified, to a target. This is most useful when attempting to identify breaches
|
||||
in a firewall from an egress perspective. Note that it is quite noisy, but it may be
|
||||
appropriate in some situations.
|
||||
|
||||
A listener on the destination IP address will be required. The EgressChecker tool could
|
||||
be useful for this (accessible at https://github.com/stufus/egresscheck-framework) or any
|
||||
other method of identifying incoming connections will be fine.
|
||||
|
||||
.PARAMETER ip
|
||||
|
||||
The IP address of the target endpoint.
|
||||
Example: -ip "10.0.0.1"
|
||||
|
||||
.PARAMETER portrange
|
||||
|
||||
The ports to try. This accepts comma-separated individual port numbers, ranges
|
||||
or both.
|
||||
Example: -portrange "22-25,53,80,443,445,3306,3389"
|
||||
Default: "22-25,53,80,443,445,3306,3389"
|
||||
|
||||
.PARAMETER protocol
|
||||
|
||||
The IP protocol to use. This can be one of TCP, UDP or ALL.
|
||||
Example: -protocol "TCP"
|
||||
Default: TCP
|
||||
|
||||
.PARAMETER verbose
|
||||
|
||||
The verbosity of the console output.
|
||||
If this is unset, there is no intentional verbosity.
|
||||
If this is set, it will output:
|
||||
't/port' - Sending a TCP packet
|
||||
'u/port' - Sending a UDP packet
|
||||
'W/tcp' - Waiting (i.e. sleep/delay) after a TCP connection was attempted
|
||||
'W/udp' - Waiting (i.e. sleep/delay) after a UDP connection was attempted
|
||||
Example: -verbose
|
||||
Default: Not verbose
|
||||
|
||||
.PARAMETER delay
|
||||
|
||||
The delay between sending packets. This injects a delay in milliseconds between
|
||||
packets generated on a per-port per-protocol basis.
|
||||
Example: -delay 100
|
||||
Default: 100
|
||||
|
||||
.EXAMPLE
|
||||
Invoke-EgressCheck -ip 1.2.3.4 -portrange "22-25,53,80,443,445,3306,3389" -protocol ALL -delay 100 -verbose
|
||||
|
||||
.LINK
|
||||
|
||||
https://github.com/stufus/egresscheck-framework
|
||||
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param([string] $ip, [string] $portrange = "22-25,53,80,443,445,3306,3389", [string] $protocol = "TCP", [int] $delay=100)
|
||||
|
||||
if ($ip -NotMatch '^([0-9]{1,3}\.){3}[0-9]{1,3}$') {
|
||||
Write-Error "IP not specified"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Output "EgressCheck started"
|
||||
|
||||
$pr_split = $portrange -split ','
|
||||
foreach ($p in $pr_split) {
|
||||
if ($p -match '^[0-9]+-[0-9]+$') {
|
||||
$prange = $p -split '-'
|
||||
$s = [convert]::ToInt32($prange[0])
|
||||
$e = [convert]::ToInt32($prange[1])
|
||||
Write-Verbose "Now generating traffic on ports $s - $e"
|
||||
for ($c = $s;$c -le $e;$c++) {
|
||||
egress -ip $ip -port $c -delay $delay -protocol $protocol
|
||||
}
|
||||
} elseif ($p -match '^[0-9]+$') {
|
||||
$c = [convert]::ToInt32($p)
|
||||
Write-Verbose "Now generating traffic on port $c"
|
||||
egress -ip $ip -port $c -delay $delay -protocol $protocol
|
||||
} else {
|
||||
Write-Error "Bad port range"
|
||||
return
|
||||
}
|
||||
}
|
||||
Write-Output "EgressCheck completed"
|
||||
}
|
||||
|
||||
function egress {
|
||||
[CmdletBinding()]
|
||||
param([string]$ip, [int]$port, [int]$delay, [string]$protocol)
|
||||
|
||||
$protocol_case = $protocol.ToUpper()
|
||||
|
||||
if ($protocol_case -eq "TCP" -Or $protocol_case -eq "ALL") {
|
||||
generate_tcp -ip $ip -port $port
|
||||
if ($delay -gt 0) {
|
||||
Start-Sleep -m ($delay)
|
||||
Write-Verbose "W/tcp"
|
||||
}
|
||||
}
|
||||
|
||||
if ($protocol_case -eq "UDP" -Or $protocol_case -eq "ALL") {
|
||||
generate_udp -ip $ip -port $port
|
||||
if ($delay -gt 0) {
|
||||
Start-Sleep -m ($delay)
|
||||
Write-Verbose "W/udp"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Send the TCP packet
|
||||
function generate_tcp {
|
||||
[CmdletBinding()]
|
||||
param([string]$ip, [int]$port)
|
||||
|
||||
try {
|
||||
$t = New-Object System.Net.Sockets.TCPClient
|
||||
$t.BeginConnect($ip, $port, $null, $null) | Out-Null
|
||||
$t.Close()
|
||||
Write-Verbose "t/$port"
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
# Send the UDP packet
|
||||
function generate_udp {
|
||||
[CmdletBinding()]
|
||||
param([string]$ip, [int]$port)
|
||||
|
||||
$d = [system.Text.Encoding]::UTF8.GetBytes(".")
|
||||
try {
|
||||
$t = New-Object System.Net.Sockets.UDPClient
|
||||
$t.Send($d, $d.Length, $ip, $port) | Out-Null
|
||||
$t.Close()
|
||||
Write-Verbose "u/$port"
|
||||
}
|
||||
catch { }
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
from lib.common import helpers
|
||||
|
||||
class Module:
|
||||
|
||||
def __init__(self, mainMenu, params=[]):
|
||||
|
||||
# metadata info about the module, not modified during runtime
|
||||
self.info = {
|
||||
# name for the module that will appear in module menus
|
||||
'Name': 'Invoke-EgressCheck',
|
||||
|
||||
# list of one or more authors for the module
|
||||
'Author': ['Stuart Morgan <stuart.morgan@mwrinfosecurity.com>'],
|
||||
|
||||
# more verbose multi-line description of the module
|
||||
'Description': ('This module will generate traffic on a provided range of ports '
|
||||
'and supports both TCP and UDP. Useful to identify direct egress channels.'),
|
||||
|
||||
# True if the module needs to run in the background
|
||||
'Background' : False,
|
||||
|
||||
# File extension to save the file as
|
||||
'OutputExtension' : None,
|
||||
|
||||
# True if the module needs admin rights to run
|
||||
'NeedsAdmin' : False,
|
||||
|
||||
# True if the method doesn't touch disk/is reasonably opsec safe
|
||||
# Disabled - this can be a relatively noisy module but sometimes useful
|
||||
'OpsecSafe' : False,
|
||||
|
||||
# The minimum PowerShell version needed for the module to run
|
||||
'MinPSVersion' : '2',
|
||||
|
||||
# list of any references/other comments
|
||||
'Comments': [
|
||||
'https://github.com/stufus/egresscheck-framework'
|
||||
]
|
||||
}
|
||||
|
||||
# any options needed by the module, settable during runtime
|
||||
self.options = {
|
||||
# format:
|
||||
# value_name : {description, required, default_value}
|
||||
'Agent' : {
|
||||
# The 'Agent' option is the only one that MUST be in a module
|
||||
'Description' : 'Agent to generate the source traffic on',
|
||||
'Required' : True,
|
||||
'Value' : ''
|
||||
},
|
||||
'ip' : {
|
||||
'Description' : 'Target IP Address',
|
||||
'Required' : True,
|
||||
'Value' : ''
|
||||
},
|
||||
'protocol' : {
|
||||
'Description' : 'The protocol to use. This can be TCP or UDP',
|
||||
'Required' : True,
|
||||
'Value' : 'TCP'
|
||||
},
|
||||
'portrange' : {
|
||||
'Description' : 'The range of ports to connect on. This can be a comma separated list or dash-separated ranges.',
|
||||
'Required' : True,
|
||||
'Value' : '22-25,53,80,443,445,3306,3389'
|
||||
},
|
||||
'delay' : {
|
||||
'Description' : 'Delay, in milliseconds, between ports being tested',
|
||||
'Required' : True,
|
||||
'Value' : '50'
|
||||
}
|
||||
}
|
||||
|
||||
# save off a copy of the mainMenu object to access external functionality
|
||||
# like listeners/agent handlers/etc.
|
||||
self.mainMenu = mainMenu
|
||||
|
||||
# During instantiation, any settable option parameters
|
||||
# are passed as an object set to the module and the
|
||||
# options dictionary is automatically set. This is mostly
|
||||
# in case options are passed on the command line
|
||||
if params:
|
||||
for param in params:
|
||||
# parameter format is [Name, Value]
|
||||
option, value = param
|
||||
if option in self.options:
|
||||
self.options[option]['Value'] = value
|
||||
|
||||
|
||||
def generate(self):
|
||||
# if you're reading in a large, external script that might be updates,
|
||||
# use the pattern below
|
||||
# read in the common module source code
|
||||
moduleSource = self.mainMenu.installPath + "/data/module_source/exfil/Invoke-EgressCheck.ps1"
|
||||
try:
|
||||
f = open(moduleSource, 'r')
|
||||
except:
|
||||
print helpers.color("[!] Could not read module source path at: " + str(moduleSource))
|
||||
return ""
|
||||
|
||||
moduleCode = f.read()
|
||||
f.close()
|
||||
|
||||
script = moduleCode
|
||||
|
||||
# Need to actually run the module that has been loaded
|
||||
script += 'Invoke-EgressCheck'
|
||||
|
||||
# add any arguments to the end execution of the script
|
||||
for option,values in self.options.iteritems():
|
||||
if option.lower() != "agent":
|
||||
if values['Value'] and values['Value'] != '':
|
||||
if values['Value'].lower() == "true":
|
||||
# if we're just adding a switch
|
||||
script += " -" + str(option)
|
||||
else:
|
||||
script += " -" + str(option) + " \"" + str(values['Value']) + "\""
|
||||
|
||||
return script
|
Loading…
Reference in New Issue