-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows_crowdstrike_deploy_method_2.ps1
More file actions
180 lines (157 loc) · 8.91 KB
/
Copy pathwindows_crowdstrike_deploy_method_2.ps1
File metadata and controls
180 lines (157 loc) · 8.91 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
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
171
172
173
174
175
176
177
178
179
180
#========================== CONFIGURATION (EDIT THESE) ==========================#
$Operation = "" # "Split" or "Deploy"
$Parts = 0 # Number of parts for split (e.g., 5)
$OriginalFilePath = "" # Full path to original installer to split
$SplittedFilesLocation = "" # Folder for file_split_part_* (used by Split & Deploy)
$CrowdstrikeCID = "" # Falcon Tenant CID (e.g., 1234567890ABCDEFGHIJKLMN-12)
$TenantName = "" # Friendly display name for messages
$RebuiltFileName = "RebuiltCrowdStrikeSensor.exe" # Output filename when rebuilding (can rename if wanted)
#===============================================================================#
#---------------------------- Safety & Environment -----------------------------#
$ErrorActionPreference = 'Stop'
function Require-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error "Please run this script in an elevated PowerShell (Run as Administrator)."
}
}
Require-Admin
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
if (-not (Test-Path $ScriptDir)) { $ScriptDir = (Get-Location).Path }
#------------------------------ Banner ------------------------------------------#
Write-Output ""
Write-Output " ██████╗██████╗ ██████╗ ██╗ ██╗██████╗ ███████╗████████╗██████╗ ██╗██╗ ██╗███████╗"
Write-Output " ██╔════╝██╔══██╗██╔═══██╗██║ ██║██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██║██║ ██╔╝██╔════╝"
Write-Output " ██║ ██████╔╝██║ ██║██║ █╗ ██║██║ ██║███████╗ ██║ ██████╔╝██║█████╔╝ █████╗"
Write-Output " ██║ ██╔══██╗██║ ██║██║███╗██║██║ ██║╚════██║ ██║ ██╔══██╗██║██╔═██╗ ██╔══╝"
Write-Output " ╚██████╗██║ ██║╚██████╔╝╚███╔███╔╝██████╔╝███████║ ██║ ██║ ██║██║██║ ██╗███████╗"
Write-Output " ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚══════╝"
Write-Output ""
Write-Output " ██████╗ ███████╗██████╗ ██╗ ██████╗ ██╗ ██╗"
Write-Output " ██╔══██╗██╔════╝██╔══██╗██║ ██╔═══██╗╚██╗ ██╔╝"
Write-Output " ██║ ██║█████╗ ██████╔╝██║ ██║ ██║ ╚████╔╝"
Write-Output " ██║ ██║██╔══╝ ██╔═══╝ ██║ ██║ ██║ ╚██╔╝"
Write-Output " ██████╔╝███████╗██║ ███████╗╚██████╔╝ ██║"
Write-Output " ╚═════╝ ╚══════╝╚═╝ ╚══════╝ ╚═════╝ ╚═╝"
Write-Output ""
Write-Output " Created & Maintained by: Eilay Yosfan"
Write-Output " GitHub.com/YosfanEilay"
Write-Output " Method: 2"
Write-Output ""
#------------------------------- Split Function --------------------------------#
function Split-File {
param(
[Parameter(Mandatory=$true)][string]$Path,
[Parameter(Mandatory=$true)][int]$Parts,
[Parameter(Mandatory=$false)][string]$OutputFolder = $null
)
if (-not (Test-Path $Path -PathType Leaf)) {
throw "Error: File not found: $Path"
}
if ($Parts -lt 1) {
throw "Error: Parts must be a positive integer."
}
if ([string]::IsNullOrWhiteSpace($OutputFolder)) {
if (-not [string]::IsNullOrWhiteSpace($SplittedFilesLocation)) {
$OutputFolder = $SplittedFilesLocation
} else {
$OutputFolder = $ScriptDir
}
}
if (-not (Test-Path $OutputFolder -PathType Container)) {
Write-Host "Output folder not found, creating: $OutputFolder"
New-Item -ItemType Directory -Path $OutputFolder -Force | Out-Null
}
$fileInfo = Get-Item $Path
$fileSize = $fileInfo.Length
$chunk = [long][math]::Ceiling($fileSize / [double]$Parts)
Write-Host "Splitting '$Path' ($fileSize bytes) into $Parts parts in '$OutputFolder'..."
$in = [System.IO.File]::OpenRead($Path)
try {
for ($i = 1; $i -le $Parts; $i++) {
$outFile = Join-Path $OutputFolder ("file_split_part_{0}" -f $i)
$remaining = [math]::Min($chunk, $fileSize - $in.Position)
if ($remaining -le 0) { break }
$buffer = New-Object byte[] $remaining
$read = $in.Read($buffer, 0, $remaining)
if ($read -gt 0) {
[System.IO.File]::WriteAllBytes($outFile, $buffer)
Write-Host "Created: $outFile"
}
}
Write-Host "Split complete."
} finally {
$in.Dispose()
}
}
#------------------------------- Rebuild Function ------------------------------#
function Rebuild-FromParts {
param(
[Parameter(Mandatory=$true)][string]$PartsFolder,
[Parameter(Mandatory=$true)][string]$OutputFile
)
if (-not (Test-Path $PartsFolder -PathType Container)) {
throw "Error: Parts folder not found: $PartsFolder"
}
$outputPath = Join-Path $PartsFolder $OutputFile
if (Test-Path $outputPath) { Remove-Item -Force $outputPath }
$parts = Get-ChildItem -Path (Join-Path $PartsFolder "file_split_part_*") -File |
Sort-Object { [int]($_.Name -replace 'file_split_part_','') }
if (-not $parts) { throw "Error: No parts found in $PartsFolder" }
Write-Host "Rebuilding original file from parts in: $PartsFolder"
$out = [System.IO.File]::OpenWrite($outputPath)
try {
foreach ($p in $parts) {
$bytes = [System.IO.File]::ReadAllBytes($p.FullName)
$out.Write($bytes, 0, $bytes.Length)
Write-Host "Appended: $($p.FullName)"
}
} finally {
$out.Dispose()
}
if (-not (Test-Path $outputPath)) {
throw "Error: Reconstructed file not found."
}
Write-Host "CrowdStrike sensor file reconstructed as: $outputPath"
return $outputPath
}
#----------------------- Install Function ---------------------------#
function Install-CrowdStrikeSimple {
param(
[Parameter(Mandatory=$true)][string]$InstallerPath,
[Parameter(Mandatory=$true)][string]$CID,
[Parameter(Mandatory=$true)][string]$TenantName
)
$DstPath = $InstallerPath
$TenantCID = $CID
$Hostname = $env:COMPUTERNAME
Write-Host "`n[+] Starting CrowdStrike installation..."
& $DstPath /install /quiet CID=$TenantCID
Start-Sleep -Seconds 60
Write-Output "[+] Done. $Hostname will be available on host management under the tenant $TenantName in 5-10 minutes."
Write-Output ""
}
#---------------------------------- Driver -------------------------------------#
try {
switch ($Operation) {
"Split" {
if ([string]::IsNullOrWhiteSpace($SplittedFilesLocation)) {
$SplittedFilesLocation = $ScriptDir
}
Split-File -Path $OriginalFilePath -Parts $Parts -OutputFolder $SplittedFilesLocation
}
"Deploy" {
if ([string]::IsNullOrWhiteSpace($SplittedFilesLocation)) {
throw "Please set `$SplittedFilesLocation to the folder containing file_split_part_*."
}
$rebuilt = Rebuild-FromParts -PartsFolder $SplittedFilesLocation -OutputFile $RebuiltFileName
Install-CrowdStrikeSimple -InstallerPath $rebuilt -CID $CrowdstrikeCID -TenantName $TenantName
}
Default {
throw "Error: Unknown Operation: $Operation (use 'Split' or 'Deploy')"
}
}
}
catch {
Write-Error $_.Exception.Message
}