curl

curl linux command cheatsheet by Thamizhiniyan C S

Introduction

curl is a tool for transferring data from or to a server using URLs. It supports these protocols: DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and WSS.


Syntax

curl [options...]


Important Flags

FlagsDescription

-#

Will display a progress meter for you to know how much the download has progressed.(or use --silent flag for a silent crawl)

-o

Saves the file downloaded with the name given following the flag.

-O

Saves the file with the name it was saved on the server.

-C -

This flag can resume your broken download without specifying an offset.

--limit-rate

Limits the download/upload rate to somewhere near the specified range (Units in 100K,100M,100G)

-u

Provides user authentication (Format: -u user:password)

-T

Helps in uploading the file to some server(In our case php-reverse-shell)

-x

If you have to view the page through a PROXY. You can specify the proxy server with this flag. (-x proxy.server.com -u user:password(Authentication for proxy server))

-I

(Caps i) Queries the header and not the webpage.

-A

You can specify user agent to make request to the server

-L

Tells curl to follow redirects

-b

This flag allows you to specify cookies while making a curl request(Cookie should be in the format "NAME1=VALUE1;NAME2=VALUE2")

-d

This flag can be used to POST data to the server(generally used for posting form data).

-X

To specify the HTTP method on the URL. (GET,POST,TRACE,OPTIONS)


Examples

CommandDescription
curl -h

cURL help menu

curl inlanefreight.com

Basic GET request

curl -s -O inlanefreight.com/index.html

Download file

curl -k https://inlanefreight.com

Skip HTTPS (SSL) certificate validation

curl inlanefreight.com -v

Print full HTTP request/response details

curl -I https://www.inlanefreight.com

Send HEAD request (only prints response headers)

curl -i https://www.inlanefreight.com

Print response headers and response body

curl https://www.inlanefreight.com -A 'Mozilla/5.0'

Set User-Agent header

curl -u admin:admin http://<SERVER_IP>:<PORT>/

Set HTTP basic authorization credentials

curl http://admin:admin@<SERVER_IP>:<PORT>/

Pass HTTP basic authorization credentials in the URL

curl -H 'Authorization: Basic YWRtaW46YWRtaW4=' http://<SERVER_IP>:<PORT>/

Set request header

curl 'http://<SERVER_IP>:<PORT>/search.php?search=le'

Pass GET parameters

curl -X POST -d 'username=admin&password=admin' http://<SERVER_IP>:<PORT>/

Send POST request with POST data

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

Set request cookies

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

Send POST request with JSON data

APIs

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

Read entry

curl -s http://<SERVER_IP>:<PORT>/api.php/city/ | jq

jq

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

Create (add) entry

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

Update (modify) entry

curl -X DELETE http://<SERVER_IP>:<PORT>/api.php/city/New_HTB_City

Delete entry

Last updated