-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbinaryRecon.ps1
More file actions
76 lines (71 loc) · 2.66 KB
/
binaryRecon.ps1
File metadata and controls
76 lines (71 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$blackListedProcesses = @("svchost","System","lsass","spoolsv","wininit","services")
function GetListeningProcessesUDP {
$ProcessArray = New-Object System.Collections.Generic.List[System.Object];
Get-NetUdpEndpoint | Select LocalPort,OwningProcess,LocalAddress | ForEach-Object {
if ($_.LocalAddress -eq "0.0.0.0") {
$p = (Get-Process -PID $_.OwningProcess | Select Id,ProcessName)
if ($p.ProcessName -in $blackListedProcesses){
return
}
$ProcessArray.Add((New-Object -TypeName PSObject -Property @{
Id = $p.id
Name = $p.ProcessName
Port = $_.LocalPort
Type = "UDP"
ServiceName = $null
ServiceState = $null
ServiceStartMode = $null
ServiceRunAS = $null
}))
}
}
return $ProcessArray
}
function GetListeningProcessesTCP {
$ProcessArray = New-Object System.Collections.Generic.List[System.Object];
Get-NetTcpConnection | ForEach-Object {
if ($_.State -eq "Listen" -and $_.RemoteAddress -eq "0.0.0.0") {
$p = (Get-Process -PID $_.OwningProcess | Select Id,ProcessName)
if ($p.ProcessName -in $blackListedProcesses){
return
}
$ProcessArray.Add((New-Object -TypeName PSObject -Property @{
Id = $p.id
Name = $p.ProcessName
Port = $_.LocalPort
Type = "TCP"
ServiceName = $null
ServiceState = $null
ServiceStartMode = $null
ServiceRunAS = $null
}))
}
}
return $ProcessArray
}
$tcpProcs = GetListeningProcessesTCP
$udpProcs = GetListeningProcessesUDP
$tcpProcs | ForEach-Object{
try {
$Service = (Get-WmiObject Win32_service -Filter "ProcessId=$($_.Id)" | Select State,StartMode,Name,StartName)
$_.ServiceName = $Service.Name
$_.ServiceStartMode = $Service.StartMode
$_.ServiceState = $Service.State
$_.ServiceRunAS = $Service.StartName
} catch {
return
}
}
$udpProcs | ForEach-Object{
try {
$Service = (Get-WmiObject Win32_service -Filter "ProcessId=$($_.Id)" | Select State,StartMode,Name,StartName)
$_.ServiceName = $Service.Name
$_.ServiceStartMode = $Service.StartMode
$_.ServiceState = $Service.State
$_.ServiceRunAS = $Service.StartName
} catch {
return
}
}
$tcpProcs
$udpProcs