tools

Overview

cURL (Client URL) is a command-line tool and library for transferring data using various protocols — primarily HTTP/HTTPS but also FTP, SFTP, SCP, and more. Unlike a web browser, cURL outputs raw responses to STDOUT without rendering HTML, CSS, or JavaScript, making it ideal for scripting, automation, API interaction, and web application testing. Core tool for inspecting HTTP behavior, crafting custom requests, and interacting with APIs from the command line.

Target / Context

Web application testing, REST API interaction, file transfers, authentication testing, and automation scripts. Available on Linux, macOS, and Windows.


Installation

ℹ︎Installation Commands:

Pre-installed on most Linux distros and macOS. Install on Ubuntu/Debian:

sudo apt install curl -y

Help: curl -h or curl —help all or man curl


Basic Usage

ℹ︎Basic Usage:

Send a GET request and print response to STDOUT

curl <URL>

Verbose; shows full request and response headers

curl -v <URL>

More verbose detail

curl -vvv <URL>

Flags & Options

ℹ︎Flags & Options:
FlagDescriptionExample
-vVerbose — show request and response headerscurl -v http://example.com
-ISend HEAD request — show response headers onlycurl -I http://example.com
-iInclude response headers in output (full response)curl -i http://example.com
-HSet a custom request headercurl -H ‘Content-Type: application/json’ <URL>
-ASet User-Agent stringcurl -A ‘Mozilla/5.0’ <URL>
-XSpecify HTTP methodcurl -X POST <URL>
-dSend POST body datacurl -d ‘username=admin&password=admin’ <URL>
-uPass username:password for basic authcurl -u admin:password <URL>
-bSend a cookie with the requestcurl -b ‘PHPSESSID=abc123’ <URL>
-LFollow redirectscurl -L <URL>
-OSave output to file using remote filenamecurl -O http://example.com/file.zip
-oSave output to a specified filecurl -o myfile.zip <URL>
-sSilent mode — suppress progress outputcurl -s <URL>
-kSkip SSL certificate verificationcurl -k https://local-dev.example.com

Common Use Cases

Basic GET Request

ℹ︎Commands:

Raw HTML to STDOUT

curl http://example.com

Full request/response with headers

curl -v http://example.com

Headers only (HEAD request)

curl -I http://example.com

POST Request with Form Data

ℹ︎Commands:
curl -X POST -d 'username=admin&password=admin' http://<IP>:<PORT>/login.php

Add -L to follow the redirect that most login forms issue after successful auth:

curl -X POST -d 'username=admin&password=admin' -L http://<IP>:<PORT>/login.php
ℹ︎Commands:

Use -b to include a session cookie obtained after login:

curl -b 'PHPSESSID=c1nsa6op7vtk7kdis7bcnbadf1' http://<IP>:<PORT>/dashboard

POST with cookie and JSON body:

curl -X POST -d '{"search":"london"}' -b 'PHPSESSID=c1nsa6op7vtk7kdis7bcnbadf1' -H 'Content-Type: application/json' http://<IP>:<PORT>/search.php

HTTP Basic Authentication

ℹ︎Commands:

Using -u flag:

curl -u admin:password http://<IP>:<PORT>/admin

Alternatively embed credentials in URL:

curl http://admin:password@<IP>:<PORT>/admin

Manually set Authorization header with base64 encoded credentials:

curl -H 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' http://<IP>:<PORT>/admin

Custom Headers and SSL Skip

ℹ︎Commands:

Set custom headers:

curl -H 'X-Forwarded-For: 127.0.0.1' http://example.com

Skip SSL verification (for self-signed or expired certs):

curl -k https://example.com

REST API — CRUD Operations

ℹ︎Commands:

Read (GET):

curl http://<IP>:<PORT>/api.php/city/london

Pipe to jq for formatted JSON output: curl http://<IP>:<PORT>/api.php/city/ | jq

Create (POST):

curl -X POST http://<IP>:<PORT>/api.php/city/ -d '{"city_name":"HTB_City","country_name":"HTB"}' -H 'Content-Type: application/json'

Update (PUT):

curl -X PUT http://<IP>:<PORT>/api.php/city/london -d '{"city_name":"New_City","country_name":"HTB"}' -H 'Content-Type: application/json'

Delete (DELETE):

curl -X DELETE http://<IP>:<PORT>/api.php/city/New_City

Use -X OPTIONS to check which methods the API accepts.

Copy Request from Browser DevTools

ℹ︎Steps:
  1. Open DevTools (F12 or Ctrl+Shift+I) → Network tab
  2. Perform the action in the browser
  3. Right-click the request → Copy → Copy as cURL
  4. Paste the full curl command into terminal — all headers and cookies included

IMAP/POP3 Mail Server Testing

ℹ︎Commands:

Connect to IMAP over TLS and enumerate banner/certificate:

curl -k 'imaps://<target>' --user <user>:<pass>
curl -k 'imaps://<target>' --user <user>:<pass> -v

— Verbose output reveals TLS version, full SSL certificate (CN, org, expiry), and server banner including mail server version

POP3 over TLS:

curl -k 'pop3s://<target>' --user <user>:<pass> -v

  • HTTP Interception

References / Images