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
| Option | Description |
|---|---|
| -X | Specify HTTP method (GET, POST, PUT, DELETE, etc.) |
| -d | Send data (form submission, JSON, etc.) |
| -H | Add custom headers |
| -i | Include response headers in the output |
| -I | Show only response headers (HEAD request) |
| -o | Save output to a file |
| -u | Send HTTP basic auth (username:password) |
| -b | Send cookies |
| -c | Save cookies to a file |
| -L | Follow redirects |
| --proxy | Use proxy |
| --upload-file | Upload a file to a server |
| -k | Ignore 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
| Purpose | Command Example |
|---|---|
| Simple GET | curl https://example.com |
| POST form data | curl -d "user=admin" -X POST https://example.com |
| JSON POST | curl -H "Content-Type: application/json" -d '{}' ... |
| Auth with token | curl -H "Authorization: Bearer token" ... |
| Save output | curl https://site.com -o result.txt |
| Use proxy | curl --proxy http://127.0.0.1:8080 ... |
| Set cookies | curl -b "key=value" ... |
| Upload file | curl -F "file=@path" https://example.com/upload |
| Show headers only | curl -I https://example.com |
| Follow redirects | curl -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