-
-
Notifications
You must be signed in to change notification settings - Fork 832
Expand file tree
/
Copy pathinstall.ps1
More file actions
314 lines (278 loc) · 10.9 KB
/
Copy pathinstall.ps1
File metadata and controls
314 lines (278 loc) · 10.9 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# PhoneSploit Pro — dependency installer for Windows (Chocolatey + official Metasploit MSI).
# Run from an elevated PowerShell when installing system-wide tools: "Run as administrator".
[CmdletBinding()]
param(
[string] $Components = "",
[switch] $NonInteractive,
[switch] $Interactive,
[switch] $SkipPip,
[switch] $SkipChocolateyInstall
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir
function Write-Info($msg) { Write-Host "[install] $msg" -ForegroundColor Cyan }
function Write-Warn($msg) { Write-Host "[install] $msg" -ForegroundColor Yellow }
function Test-IsAdmin {
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object Security.Principal.WindowsPrincipal($id)
return $p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Get-ChocoExe {
$c = Get-Command choco -ErrorAction SilentlyContinue
if ($c) { return $c.Source }
$guess = "$env:ProgramData\chocolatey\bin\choco.exe"
if (Test-Path $guess) { return $guess }
return $null
}
function Install-Chocolatey {
if ($SkipChocolateyInstall) {
throw "Chocolatey is not installed. Install from https://chocolatey.org/install or re-run without -SkipChocolateyInstall."
}
if (-not (Test-IsAdmin)) {
throw "Chocolatey installation requires Administrator PowerShell. Right-click PowerShell → Run as administrator."
}
Write-Info "Installing Chocolatey (official script)…"
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
function Ensure-Chocolatey {
$choco = Get-ChocoExe
if ($choco) { return $choco }
if ($SkipChocolateyInstall) {
throw "Chocolatey is not installed. Install from https://chocolatey.org/install or re-run without -SkipChocolateyInstall."
}
if ($Interactive) {
$ans = Read-Host "Chocolatey is not installed. Install it now? [y/N]"
if ($ans -notmatch '^[yY]') {
throw "Chocolatey is required for automatic installs on Windows. Install manually and re-run."
}
}
elseif (-not (Test-IsAdmin)) {
throw "Chocolatey is not installed. Run PowerShell as Administrator to install Chocolatey automatically, or install from https://chocolatey.org/install"
}
Install-Chocolatey
$choco = Get-ChocoExe
if (-not $choco) { throw "Chocolatey install finished but choco.exe was not found. Restart PowerShell and try again." }
return $choco
}
function Refresh-PathFromMachine {
$machine = [Environment]::GetEnvironmentVariable("Path", "Machine")
$user = [Environment]::GetEnvironmentVariable("Path", "User")
$env:Path = "$machine;$user"
}
function Test-CommandAvailable([string] $Name) {
return $null -ne (Get-Command $Name -ErrorAction SilentlyContinue)
}
function Test-AdbPresent {
if (Test-CommandAvailable "adb") { return $true }
$local = Join-Path $ScriptDir "adb.exe"
return Test-Path $local
}
function Test-MetasploitPresent {
return (Test-CommandAvailable "msfconsole") -and (Test-CommandAvailable "msfvenom")
}
function Test-ScrcpyPresent {
if (Test-CommandAvailable "scrcpy") { return $true }
if (Test-CommandAvailable "scrcpy.exe") { return $true }
$local = Join-Path $ScriptDir "scrcpy.exe"
return Test-Path $local
}
function Test-NmapPresent {
return Test-CommandAvailable "nmap"
}
function Test-PipReqsPresent {
$req = Join-Path $ScriptDir "requirements.txt"
$venv = Join-Path $ScriptDir ".venv"
$pip = Join-Path $venv "Scripts\pip.exe"
if (-not (Test-Path $req)) { return $true }
if (-not (Test-Path $pip)) { return $false }
$missing = $false
foreach ($line in Get-Content $req) {
$line = ($line -split '#', 2)[0].Trim()
if ($line -eq "") { continue }
$pkg = ($line -split '[<>=!~]', 2)[0].Trim()
if ($pkg -eq "") { continue }
& $pip show $pkg 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) { $missing = $true; break }
}
return -not $missing
}
function Skip-ComponentsAlreadyPresent([hashtable] $Want) {
if ($Want.adb -and (Test-AdbPresent)) {
Write-Info "ADB already installed; skipping."
$Want.adb = $false
}
if ($Want.nmap -and (Test-NmapPresent)) {
Write-Info "Nmap already installed; skipping."
$Want.nmap = $false
}
if ($Want.scrcpy -and (Test-ScrcpyPresent)) {
Write-Info "scrcpy already installed; skipping."
$Want.scrcpy = $false
}
if ($Want.metasploit -and (Test-MetasploitPresent)) {
Write-Info "Metasploit already installed (msfconsole, msfvenom); skipping."
$Want.metasploit = $false
}
if ($Want.pip -and (Test-PipReqsPresent)) {
Write-Info "Python dependencies already installed in .venv; skipping pip."
$Want.pip = $false
}
}
function Install-MetasploitMsi {
param([string] $DownloadUrl = "https://windows.metasploit.com/metasploitframework-latest.msi")
if (-not (Test-IsAdmin)) {
throw "Metasploit Framework MSI install requires Administrator PowerShell."
}
$dlRoot = Join-Path $env:APPDATA "Metasploit"
if (-not (Test-Path $dlRoot)) { New-Item -Path $dlRoot -ItemType Directory | Out-Null }
$msi = Join-Path $dlRoot "metasploitframework-latest.msi"
$log = Join-Path $dlRoot "metasploit-install.log"
Write-Info "Downloading Metasploit Framework MSI…"
Invoke-WebRequest -UseBasicParsing -Uri $DownloadUrl -OutFile $msi
Write-Info "Running MSI (quiet). This may take several minutes…"
$p = Start-Process -FilePath "msiexec.exe" -ArgumentList @(
"/i", $msi,
"/qn", "/norestart",
"/L*v", $log
) -Wait -PassThru -NoNewWindow
if ($p.ExitCode -ne 0) {
Write-Warn "msiexec exit code: $($p.ExitCode). Log: $log"
} else {
Write-Info "Metasploit Framework installed. You may need a new terminal for PATH updates."
}
}
# --- Parse components ---
$want = @{
adb = $false
metasploit = $false
scrcpy = $false
nmap = $false
pip = $false
}
# Default: installs all components (adb, metasploit, scrcpy, nmap, pip) without prompts.
# Use -Components to limit what is installed, or -Interactive for per-component and Chocolatey prompts.
# -NonInteractive is kept for backward compatibility (default behavior is already non-interactive).
if ($Components -ne "") {
foreach ($p in $Components.Split(",")) {
$k = $p.Trim().ToLowerInvariant()
if ($k -eq "") { continue }
switch ($k) {
"adb" { $want.adb = $true }
"metasploit" { $want.metasploit = $true }
"scrcpy" { $want.scrcpy = $true }
"nmap" { $want.nmap = $true }
"pip" { $want.pip = $true }
default { Write-Warn "Unknown component ignored: $k" }
}
}
} elseif ($Interactive) {
Write-Host ""
Write-Host "PhoneSploit Pro — Windows dependency installer" -ForegroundColor Green
Write-Host "Detected: Windows $([Environment]::OSVersion.Version)" -ForegroundColor Gray
Write-Host ""
function Ask([string]$q) {
$a = Read-Host "$q [y/N]"
return ($a -match '^[yY]')
}
$want.adb = Ask "Install ADB (Chocolatey package: adb)?"
$want.metasploit = Ask "Install Metasploit Framework (official MSI, large download)?"
$want.scrcpy = Ask "Install scrcpy (Chocolatey)?"
$want.nmap = Ask "Install Nmap (Chocolatey)?"
$want.pip = Ask "Run pip install -r requirements.txt?"
}
else {
$want.adb = $true
$want.metasploit = $true
$want.scrcpy = $true
$want.nmap = $true
$want.pip = $true
}
if (-not ($want.Values -contains $true)) {
Write-Host "Nothing selected. Exiting."
exit 0
}
Write-Host ""
Write-Host "PhoneSploit Pro — Windows dependency installer" -ForegroundColor Green
Write-Host ""
# Python 3.10+ (prefer `python`, else Windows `py -3`)
$pythonExe = $null
$usePyLauncher = $false
$pyCmd = Get-Command python -ErrorAction SilentlyContinue
if ($pyCmd) {
& $pyCmd.Source -c "import sys; raise SystemExit(0 if sys.version_info >= (3,10) else 1)" 2>$null
if ($LASTEXITCODE -eq 0) { $pythonExe = $pyCmd.Source }
}
if (-not $pythonExe) {
$pyLauncher = Get-Command py -ErrorAction SilentlyContinue
if ($pyLauncher) {
& py -3 -c "import sys; raise SystemExit(0 if sys.version_info >= (3,10) else 1)" 2>$null
if ($LASTEXITCODE -eq 0) { $usePyLauncher = $true }
}
}
if (-not $pythonExe -and -not $usePyLauncher) {
throw "Python 3.10+ is required. Install from https://www.python.org/ and re-run."
}
Skip-ComponentsAlreadyPresent $want
$any = $want.Values -contains $true
if (-not $any) {
Write-Host "Everything requested is already installed. Exiting."
exit 0
}
$chocoExe = $null
$needChoco = $want.adb -or $want.scrcpy -or $want.nmap
if ($needChoco) {
$chocoExe = Ensure-Chocolatey
if (-not (Test-IsAdmin)) {
Write-Warn "Chocolatey installs usually need Administrator rights. If install fails, re-run PowerShell as Administrator."
}
Refresh-PathFromMachine
}
$chocoArgs = @()
if ($want.adb) { $chocoArgs += "adb" }
if ($want.nmap) { $chocoArgs += "nmap" }
if ($want.scrcpy) { $chocoArgs += "scrcpy" }
if ($chocoArgs.Count -gt 0) {
Write-Info "Installing via Chocolatey: $($chocoArgs -join ', ') …"
$argList = @("install") + $chocoArgs + @("-y", "--no-progress")
$proc = Start-Process -FilePath $chocoExe -ArgumentList $argList -Wait -PassThru -NoNewWindow
if ($proc.ExitCode -ne 0) {
Write-Warn "choco install exited with code $($proc.ExitCode). Try running this script as Administrator."
}
Refresh-PathFromMachine
}
if ($want.metasploit) {
try {
Install-MetasploitMsi
} catch {
Write-Warn $_.Exception.Message
Write-Warn "You can install Metasploit manually: https://www.metasploit.com/download"
}
}
if ($want.pip -and -not $SkipPip) {
if (Test-Path (Join-Path $ScriptDir "requirements.txt")) {
$venv = Join-Path $ScriptDir ".venv"
if (-not (Test-Path $venv)) {
Write-Info "Creating virtual environment at .venv…"
if ($usePyLauncher) {
& py -3 -m venv $venv
} else {
& $pythonExe -m venv $venv
}
}
Write-Info "Installing Python dependencies into .venv…"
$pip = Join-Path $venv "Scripts\pip.exe"
$req = Join-Path $ScriptDir "requirements.txt"
& $pip install -r $req
} else {
Write-Warn "requirements.txt not found; skipping pip."
}
}
Write-Host ""
Write-Info "Done. If tools are still not found, close this window and open a new terminal (PATH refresh)."
Write-Info "Activate the virtual environment and run:"
Write-Info " .\.venv\Scripts\activate"
Write-Info " python phonesploitpro.py"
Write-Host ""