-
Notifications
You must be signed in to change notification settings - Fork 0
/
detonaRE.ps1
executable file
·170 lines (164 loc) · 6.34 KB
/
detonaRE.ps1
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<#
detonaRE.ps1 v1.3
https://github.com/dwmetz/detonaRE
Author: @dwmetz
detonaRE - from the Latin, "to detonate"
Script Functions:
- initiates .etl packet capture
- initiates Process Monitor with a filter applied for the malware to be detonated
- launches malware sample
- terminates packet capture after specified interval
- initiates evidence collection with Magnet RESPONSE (memory, process, and triage capture)
- terminates the malware process
- converts collected .etl file to .pcap with etl2pcapng.
- converts collected .pml to .csv
Prerequisites:
> Magnet RESPONSE
> etl2pcapng.exe
> procmon.exe
## variable configuration example:
$malwspath = "E:" ## malware source path
$malwdpath = "C:\Users\REM\Desktop\Malware\" ## malware destination path
$malware = "redline-76ca4a.exe" ## malware executable
$pcaptime = 180 ## duration in seconds for pcap capture
$toolsdir = "E:\Tools" ## MagnetRESPONSE.exe and etl2pcapng.exe
$procmonconfig = "$toolsdir\redline.pmc" ## Process Monitor configuration
#>
param ([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated) {
} else {
Write-host -fore DarkCyan "
Admin permissions not detected. Exiting.
"
}
exit
}
$version = "1.3"
[console]::ForegroundColor="Cyan"
## variable configuration:
$malwspath = "E:\Malware" ## malware source path
$malwdpath = "~\Desktop\" ## malware destination path on target host
$malware = "mal-847fb-blackcat.exe" ## malware executable
$pcaptime = 180 ## duration in seconds for pcap capture
$toolsdir = "E:\Tools\Windows" # tools directory
$collectiondir = "E:\Collections" ## output directory for collections
$procmonconfig = "$toolsdir\malw.pmc" ## Process Monitor configuration file
##
Clear-Host
Write-Host ""
Write-Host ""
Write-host "
██████╗ ███████╗████████╗ ██████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗
██╔══██╗██╔════╝╚══██╔══╝██╔═══██╗████╗ ██║██╔══██╗██╔══██╗██╔════╝
██║ ██║█████╗ ██║ ██║ ██║██╔██╗ ██║███████║██████╔╝█████╗
██║ ██║██╔══╝ ██║ ██║ ██║██║╚██╗██║██╔══██║██╔══██╗██╔══╝
██████╔╝███████╗ ██║ ╚██████╔╝██║ ╚████║██║ ██║██║ ██║███████╗
╚═════╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════
"
Write-host "
Capture. Detonate. Collect.
"
Write-Host "version $version | @dwmetz | $([char]0x00A9)2023 bakerstreetforensics.com"
Write-Host ""
Write-Host ""
Set-Location $malwspath
Copy-Item $malwspath\$malware $malwdpath
Set-Location $malwdpath
If (Test-Path -Path $collectiondir) {
Write-Host " "
}
Else {
$null = mkdir $collectiondir
If (Test-Path -Path $collectiondir) {
Write-Host " "
}
Else {
Write-Host -For Cyan "Error creating directory."
}
}
$tstamp = (Get-Date -Format "-yyyyMMddHHmm")
$collection = $env:computername+$tstamp
$malproc = [io.path]::GetFileNameWithoutExtension($malware)
If (Test-Path -Path $collectiondir\$collection) {
Write-Host " "
}
Else {
$null = mkdir $collectiondir\$collection
If (Test-Path -Path $collectiondir\$collection) {
Write-Host "Collection directory $collectiondir\$collection"
}
Else {
Write-Host -For Cyan "Error creating directory."
}
}
# PROCESS MONITOR
Set-Location $toolsdir
Write-host "
Initiating Process Monitor" -Fore yellow
.\Procmon.exe /accepteula /quiet /loadconfig $procmonconfig /backingfile $collectiondir\$collection\$collection-$malproc
Write-host "
Initiating PCAP collection" -Fore yellow
#Get the local IPv4 address
$env:HostIP = (
Get-NetIPConfiguration |
Where-Object {
$_.IPv4DefaultGateway -ne $null -and
$_.NetAdapter.Status -ne "Disconnected"
}
).IPv4Address.IPAddress
# Start 'pcap' capture
netsh trace start capture=yes IPv4.Address=$env:HostIP tracefile=$collectiondir\$collection\$collection.etl
Sleep 5
# Malware detonation
Write-host "
Detonating malware sample" -Fore yellow
Set-Location $malwdpath
Start-process -filepath $malware
# Packet capture timer
function Wait-Count($s){
do {
Write-Progress -SecondsRemaining $s -Activity "Malware running" -Status "Time left for packet capture " -Id 1
$s--
Start-Sleep -Seconds 1
} until ($s -eq 0)
}
Wait-Count $pcaptime
Set-Location $toolsdir
# Terminate Process Monitor Capture
Write-host "
Terminating Process Monitor" -Fore yellow
.\Procmon.exe /Terminate
Write-host "
Terminating packet capture" -Fore yellow
# Terminate .etl capture
netsh trace stop
# Magnet RESPONSE evidence triage collection
Write-host "
Initiating Magnet RESPONSE evidence collection" -Fore yellow
.\MagnetRESPONSE.exe /accepteula /unattended /output:$collectiondir\$collection /caseref:$collection /captureram /capturepagefile /capturevolatile /capturesystemfiles /captureextendedprocessinfo /saveprocfiles
Write-host "
[Collecting Evidence]"
Wait-Process -Name "MagnetRESPONSE"
# Terminate malware process
Write-host "
Terminating malware process" -Fore yellow
Get-process $malware | stop-process
# Convert .etl to .pcap
Write-host "
Converting .etl file to .pcap" -Fore yellow
.$toolsdir\etl2pcapng.exe $collectiondir\$collection\$collection.etl $collectiondir\$collection\$collection.pcap
# Convert Process Monitor .pml to CSV
Write-host "
Converting Process Monitor PML to CSV" -Fore yellow
.\Procmon.exe /openlog $collectiondir\$collection\$collection-$malproc.pml /SaveApplyFilter /SaveAs $collectiondir\$collection\$collection-$malproc.csv
Wait-Process -name "Procmon"
Set-Location $collectiondir\$collection
Get-ChildItem
Write-host ""
Write-host "
** End of automation **" -Fore yellow