Skip to content

Commit a539034

Browse files
committed
f
1 parent 886bd7b commit a539034

1 file changed

Lines changed: 184 additions & 0 deletions

File tree

src/pentesting-cloud/azure-security/az-enumeration-tools.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,190 @@ $env:HTTP_PROXY="http://127.0.0.1:8080"
122122
{{#endtab }}
123123
{{#endtabs }}
124124

125+
<details>
126+
<summary><strong>Fixing “CA cert does not include key usage extension”</strong></summary>
127+
128+
### Why the error happens
129+
130+
When Azure CLI authenticates, it makes HTTPS requests (via MSAL → Requests → OpenSSL). If you’re intercepting TLS with Burp, Burp generates “on the fly” certificates for sites like `login.microsoftonline.com` and signs them with Burp’s CA.
131+
132+
On newer stacks (Python 3.13 + OpenSSL 3), CA validation is stricter:
133+
134+
- A CA certificate must include **Basic Constraints: `CA:TRUE`** and a **Key Usage** extension permitting certificate signing (**`keyCertSign`**, and typically **`cRLSign`**).
135+
136+
Burp’s default CA (PortSwigger CA) is old and typically lacks the Key Usage extension, so OpenSSL rejects it even if you “trust it”.
137+
138+
That produces errors like:
139+
140+
- `CA cert does not include key usage extension`
141+
- `CERTIFICATE_VERIFY_FAILED`
142+
- `self-signed certificate in certificate chain`
143+
144+
So you must:
145+
146+
1. Create a modern CA (with proper Key Usage).
147+
2. Make Burp use it to sign intercepted certs.
148+
3. Trust that CA in macOS.
149+
4. Point Azure CLI / Requests to that CA bundle.
150+
151+
### Step-by-step: working configuration
152+
153+
#### 0) Prereqs
154+
155+
- Burp running locally (proxy at `127.0.0.1:8080`)
156+
- Azure CLI installed (Homebrew)
157+
- You can `sudo` (to trust the CA in the system keychain)
158+
159+
#### 1) Create a standards-compliant Burp CA (PEM + KEY)
160+
161+
Create an OpenSSL config file that explicitly sets CA extensions:
162+
163+
```bash
164+
mkdir -p ~/burp-ca && cd ~/burp-ca
165+
166+
cat > burp-ca.cnf <<'EOF'
167+
[ req ]
168+
default_bits = 2048
169+
prompt = no
170+
default_md = sha256
171+
distinguished_name = dn
172+
x509_extensions = v3_ca
173+
174+
[ dn ]
175+
C = US
176+
O = Burp Custom CA
177+
CN = Burp Custom Root CA
178+
179+
[ v3_ca ]
180+
basicConstraints = critical,CA:TRUE
181+
keyUsage = critical,keyCertSign,cRLSign
182+
subjectKeyIdentifier = hash
183+
authorityKeyIdentifier = keyid:always,issuer
184+
EOF
185+
```
186+
187+
Generate the CA certificate + private key:
188+
189+
```bash
190+
openssl req -x509 -new -nodes \
191+
-days 3650 \
192+
-keyout burp-ca.key \
193+
-out burp-ca.pem \
194+
-config burp-ca.cnf
195+
```
196+
197+
Sanity check (you MUST see Key Usage):
198+
199+
```bash
200+
openssl x509 -in burp-ca.pem -noout -text | egrep -A3 "Basic Constraints|Key Usage"
201+
```
202+
203+
Expected to include something like:
204+
205+
- `CA:TRUE`
206+
- `Key Usage: ... Certificate Sign, CRL Sign`
207+
208+
#### 2) Convert to PKCS#12 (Burp import format)
209+
210+
Burp needs certificate + private key, easiest as PKCS#12:
211+
212+
```bash
213+
openssl pkcs12 -export \
214+
-out burp-ca.p12 \
215+
-inkey burp-ca.key \
216+
-in burp-ca.pem \
217+
-name "Burp Custom Root CA"
218+
```
219+
220+
You’ll be prompted for an export password (set one; Burp will ask for it).
221+
222+
#### 3) Import the CA into Burp and restart Burp
223+
224+
In Burp:
225+
226+
- Proxy → Options
227+
- Find Import / export CA certificate
228+
- Click Import CA certificate
229+
- Choose PKCS#12
230+
- Select `burp-ca.p12`
231+
- Enter the password
232+
- Restart Burp completely (important)
233+
234+
Why restart? Burp may keep using the old CA until restart.
235+
236+
#### 4) Trust the new CA in macOS system keychain
237+
238+
This allows system apps and many TLS stacks to trust the CA.
239+
240+
```bash
241+
sudo security add-trusted-cert \
242+
-d -r trustRoot \
243+
-k /Library/Keychains/System.keychain \
244+
~/burp-ca/burp-ca.pem
245+
```
246+
247+
(If you prefer GUI: Keychain Access → System → Certificates → import → set “Always Trust”.)
248+
249+
#### 5) Configure proxy env vars
250+
251+
```bash
252+
export HTTPS_PROXY="http://127.0.0.1:8080"
253+
export HTTP_PROXY="http://127.0.0.1:8080"
254+
```
255+
256+
#### 6) Configure Requests/Azure CLI to trust your Burp CA
257+
258+
Azure CLI uses Python Requests internally; set both of these:
259+
260+
```bash
261+
export REQUESTS_CA_BUNDLE="$HOME/burp-ca/burp-ca.pem"
262+
export SSL_CERT_FILE="$HOME/burp-ca/burp-ca.pem"
263+
```
264+
265+
Notes:
266+
267+
- `REQUESTS_CA_BUNDLE` is used by Requests.
268+
- `SSL_CERT_FILE` helps for other TLS consumers and edge cases.
269+
- You typically do not need the old `ADAL_PYTHON_SSL_NO_VERIFY` / `AZURE_CLI_DISABLE_CONNECTION_VERIFICATION` once the CA is correct.
270+
271+
#### 7) Verify Burp is actually signing with your new CA (critical check)
272+
273+
This confirms your interception chain is correct:
274+
275+
```bash
276+
openssl s_client -connect login.microsoftonline.com:443 \
277+
-proxy 127.0.0.1:8080 </dev/null 2>/dev/null \
278+
| openssl x509 -noout -issuer
279+
```
280+
281+
Expected issuer contains your CA name, e.g.:
282+
283+
`O=Burp Custom CA, CN=Burp Custom Root CA`
284+
285+
If you still see PortSwigger CA, Burp is not using your imported CA → re-check import and restart.
286+
287+
#### 8) Verify Python Requests works through Burp
288+
289+
```bash
290+
python3 - <<'EOF'
291+
import requests
292+
requests.get("https://login.microsoftonline.com")
293+
print("OK")
294+
EOF
295+
```
296+
297+
Expected: `OK`
298+
299+
#### 9) Azure CLI test
300+
301+
```bash
302+
az account get-access-token --resource=https://management.azure.com/
303+
```
304+
305+
If you’re already logged in, it should return JSON with an `accessToken`.
306+
307+
</details>
308+
125309
### Az PowerShell
126310

127311
Azure PowerShell is a module with cmdlets for managing Azure resources directly from the PowerShell command line.

0 commit comments

Comments
 (0)