Skip to content

Cheatsheet · Web pentesting

curl for web testing: requests, headers, cookies, TLS and proxy

curl for an authorised web test: methods, headers, cookies, authentication, redirects, timing, Burp proxy, TLS, HTTP/2, JSON and file uploads.

By Steven Carrier Published

Official website: curl

curl is the Swiss army knife for reproducing, isolating and documenting an HTTP request. It complements an intercepting proxy such as Burp: you observe in the graphical tool, then replay cleanly on the command line. Replace https://target.example with a target inside your authorised scope, agreed using the penetration test scoping checklist. To test an API, see the REST API testing methodology.

Methods and headers

# GET with response headers (-i) or headers only (-I, HEAD method)
curl -i https://target.example/
curl -I https://target.example/

# Another HTTP method
curl -X OPTIONS -i https://target.example/api/resource

# Add or change headers
curl -H "Accept: application/json" -H "X-Test-Request: engagement-001" https://target.example/api/resource

# Remove a header sent by default, change the user agent
curl -H "Accept:" -A "Engagement-Test/1.0" https://target.example/

# Ask for a compressed response (curl decompresses it)
curl --compressed -i https://target.example/

A custom header identifying the engagement (such as X-Test-Request above) makes it easier to sort the logs on the client side. With -X, curl does not change method-related behaviour: for a POST, prefer -d, which selects it automatically.

Cookies and authentication

# Send a cookie, or read/write a cookie file
curl -b "session=VALUE" https://target.example/account
curl -c cookies.txt -b cookies.txt https://target.example/login

# HTTP Basic authentication
curl -u username:password https://target.example/admin/

# Bearer token
curl -H "Authorization: Bearer VALUE" https://target.example/api/resource
curl --oauth2-bearer VALUE https://target.example/api/resource

A password passed with -u or -H stays in the shell history and the process list. Prefer -u username (curl prompts for the password) or a protected -K configuration file, and use test accounts supplied for the engagement.

Redirects

# Follow redirects (3xx) with a limit
curl -L --max-redirs 5 -i https://target.example/old-page

# See the destination without following it
curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" https://target.example/old-page

# Keep the POST method on a 301, 302 or 303 redirect
curl -L --post301 --post302 --post303 -d "a=1" https://target.example/form

Without -L, curl stops at the first 3xx response, which is often exactly what you want to observe. With -L, authentication headers are not sent to another host unless you explicitly ask for it (--location-trusted): avoid that option.

Diagnose: verbose, trace and timing

# Detail of the TLS negotiation and headers (> sent, < received)
curl -v https://target.example/

# Full trace, with timestamps, into a file
curl --trace-ascii trace.txt --trace-time https://target.example/

# Breakdown of response time
curl -s -o /dev/null -w "dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} first_byte=%{time_starttransfer} total=%{time_total}\n" https://target.example/

# Summary of a request
curl -s -o /dev/null -w "%{http_code} %{http_version} %{remote_ip} %{size_download} bytes\n" https://target.example/
-w variable Content
%{http_code} status code
%{http_version} HTTP version used
%{remote_ip} IP address contacted
%{redirect_url} destination of a redirect
%{num_redirects} number of redirects followed
%{time_total} total duration in seconds

Compare measurements over several attempts before drawing a conclusion: an isolated gap is network noise, not proof.

Go through Burp

# Send the request to Burp's listener (unrecognised authority: -k)
curl -x http://127.0.0.1:8080 -k https://target.example/

# Better: trust Burp's authority (certificate converted to PEM)
openssl x509 -inform DER -in cacert.der -out burp-ca.pem
curl -x http://127.0.0.1:8080 --cacert burp-ca.pem https://target.example/

The request then appears in Burp’s history, so it can be replayed in Repeater: see the Burp Suite cheatsheet. Keep -k (which disables certificate verification) for throwaway tests and never use it to judge a target’s TLS quality.

TLS and HTTP/2

# Impose a minimum or maximum TLS version
curl --tlsv1.2 --tls-max 1.2 -v https://target.example/

# Force an HTTP version
curl --http1.1 -I https://target.example/
curl --http2 -I https://target.example/

# Reach a specific IP with the intended host name (SNI and Host header kept)
curl --resolve target.example:443:10.0.0.12 -I https://target.example/

# Verify against a particular certificate authority
curl --cacert internal-ca.pem https://target.example/

--resolve is valuable to test a specific server behind a load balancer. Available options (HTTP/3, some TLS versions) depend on how curl was built: curl --version lists features and protocols. For a full TLS audit, use the testssl.sh cheatsheet instead.

Send JSON and files

# JSON body (curl 7.82 and later: --json adds the Content-Type and Accept headers)
curl --json '{"name":"test","quantity":1}' https://target.example/api/resource

# Explicit equivalent (-d already selects POST)
curl -H "Content-Type: application/json" -H "Accept: application/json" -d '{"name":"test"}' https://target.example/api/resource

# Body read from a file
curl -H "Content-Type: application/json" -d @body.json https://target.example/api/resource

# Classic form, with automatic encoding of the value
curl --data-urlencode "query=two words" https://target.example/search

# Multipart upload (file form)
curl -F "file=@example.txt;type=text/plain" -F "description=trial" https://target.example/upload

To test an upload, use harmless files you created for the engagement (text, small image) and then delete what was stored, or report it to the client. Write the engagement’s requests into a script: they become reproducible evidence.

Reproducible script template

#!/usr/bin/env bash
# Evidence 001: security headers of the home page
set -euo pipefail
date -u +"%Y-%m-%dT%H:%M:%SZ"
curl -sS -I --max-time 15 -H "X-Test-Request: engagement-001" https://target.example/

The -s (silent) and -S (still show errors) options work well together; --max-time prevents hangs. Keep the output together with the date, the exact command and the curl version.

Sources

Related resources

  • AI prompt · Web pentesting

    API test plan prompt

    Prompt that builds an API test plan from an OpenAPI excerpt: endpoints by risk, authorisation matrix and tests per OWASP API Top 10 category.

    Published

  • Cheatsheet · Web pentesting

    Burp Suite cheatsheet

    Burp Suite for an authorised web test: proxy and CA certificate, scope, HTTP history, Repeater, careful Intruder use, Decoder and evidence export.

    Published

  • AI prompt · Web pentesting · Infrastructure and AD pentesting

    Critical vulnerability alert prompt

    Prompt that drafts the urgent client notification when a critical vulnerability is found during testing: facts, impact and immediate containment advice.

    Published

BEAROPS

Need a penetration test?

BEAROPS experts test your applications, infrastructure and cloud, black box or grey box, following OWASP, NIST and ANSSI guidance.