Curl

4 min read711 words

curl

curl (Client URL) is a command-line tool used to transfer data to or from a server using various protocols like HTTP, HTTPS, FTP, SCP, and more.

It is a powerful tool for:

  • Sending HTTP requests
  • Interacting with APIs
  • Testing authentication
  • Uploading and downloading files
  • Debugging web services
  • Automating recon and exploitation

Why Use curl?

  • Supports many protocols: HTTP, HTTPS, FTP, SFTP, SCP, SMB, etc.
  • Allows sending custom headers, cookies, data, etc.
  • Great for web automation, pentesting, scripting, and APIs
  • Can simulate GET, POST, PUT, DELETE requests
  • Available by default on most Linux/macOS systems

Basic Syntax

curl [options] [URL]

Example:

curl https://example.com

Common curl Options

OptionDescription
-XSpecify HTTP method (GET, POST, PUT, DELETE, etc.)
-dSend data (form submission, JSON, etc.)
-HAdd custom headers
-iInclude response headers in the output
-IShow only response headers (HEAD request)
-oSave output to a file
-uSend HTTP basic auth (username:password)
-bSend cookies
-cSave cookies to a file
-LFollow redirects
--proxyUse proxy
--upload-fileUpload a file to a server
-kIgnore SSL certificate warnings

HTTP Methods Examples

GET Request (Default)

curl https://example.com

POST Request with Data

curl -X POST -d "username=admin&password=1234" https://example.com/login

PUT Request with JSON

curl -X PUT -H "Content-Type: application/json" -d '{"name":"Uday"}' https://example.com/api/user/1

DELETE Request

curl -X DELETE https://example.com/api/user/1

Send Custom Headers

curl -H "X-API-KEY: 123456" -H "Accept: application/json" https://api.example.com/data

Send JSON Data

curl -X POST -H "Content-Type: application/json" -d '{"username":"admin", "password":"pass"}' https://example.com/api/login

Basic Authentication

curl -u username:password https://example.com/protected

Bearer Token Authentication

curl -H "Authorization: Bearer <token>" https://example.com/protected

Save Response to File

curl https://example.com -o index.html

Show Only Response Headers

curl -I https://example.com

Show Headers and Body

curl -i https://example.com

Follow Redirects

curl -L http://example.com

Use Cookies

Send Cookie

curl -b "sessionid=abcd1234" https://example.com/profile

Save Cookies to File

curl -c cookies.txt https://example.com

Use Saved Cookies

curl -b cookies.txt https://example.com/dashboard

File Uploads

Upload file as form data

curl -F "file=@/path/to/file.txt" https://example.com/upload

Upload file to FTP

curl -T file.txt ftp://ftp.example.com --user user:pass

Use Proxy

curl --proxy http://127.0.0.1:8080 https://example.com

Useful with Burp Suite

curl -x http://127.0.0.1:8080 -k -L -H "Host: target.com" https://target.com/login

API Testing with curl

Example: Create User

curl -X POST -H "Content-Type: application/json" -d '{"name":"admin"}' https://api.example.com/users

Example: Get Authenticated Resource

curl -H "Authorization: Bearer <your_token>" https://api.example.com/secure-data

Penetration Testing Examples

Brute-force login (with wordlist)

for pass in $(cat passwords.txt); do curl -s -X POST -d "username=admin&password=$pass" https://example.com/login | grep "Welcome"; done

Testing for open redirect

curl "https://target.com/redirect?url=https://evil.com"

SSRF test via URL parameter

curl "https://target.com/fetch?url=http://127.0.0.1:80"

Get request with encoded payload

curl "https://example.com/search?q=../../../../etc/passwd"

Summary Table

PurposeCommand Example
Simple GETcurl https://example.com
POST form datacurl -d "user=admin" -X POST https://example.com
JSON POSTcurl -H "Content-Type: application/json" -d '{}' ...
Auth with tokencurl -H "Authorization: Bearer token" ...
Save outputcurl https://site.com -o result.txt
Use proxycurl --proxy http://127.0.0.1:8080 ...
Set cookiescurl -b "key=value" ...
Upload filecurl -F "file=@path" https://example.com/upload
Show headers onlycurl -I https://example.com
Follow redirectscurl -L http://example.com

Best Practices

  • Use verbose mode -v to debug requests
  • Always quote URLs and headers
  • Test manually before scripting
  • Combine with tools like Burp Suite for deeper analysis
  • Automate common recon tasks with scripts

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy