Downloading Files


Web Basics.

Retrieving content from servers



Challenges

Download Text

🎯 What You'll Learn

  • Downloading text content from servers
  • Understanding Content-Type headers
  • Reading server responses

📖 The Concept

The simplest form of downloading is retrieving text. When you curl a URL, you're downloading content!

How Downloads Work

1. Client sends GET request
2. Server sends headers (metadata about the content)
3. Server sends body (the actual content)
4. Client receives and displays/saves it

Content-Type Header

The server tells you what kind of content it's sending:

Content-Type: text/plain          ← Plain text
Content-Type: text/html           ← HTML page
Content-Type: application/json    ← JSON data
Content-Type: text/csv            ← CSV data

Basic Download with curl

curl http://example.com/file.txt      # Display content
curl -s http://example.com/file.txt   # Silent mode (no progress)

Checking Headers Only

curl -I http://example.com/file.txt   # HEAD request - headers only
curl -i http://example.com/file.txt   # Include headers with content

🚀 Your Challenge

Download a text file from the server. The file contains encoded data - decode it to find the flag!

curl http://challenge/secret.txt

The content is base64 encoded. Decode it with:

curl http://challenge/secret.txt | base64 -d

Good luck! 🍀

Connect with SSH

Link your SSH key, then connect with: ssh hacker@dojo.idg.ctf

Download Binary

🎯 What You'll Learn

  • Downloading binary files (images, archives)
  • Binary vs text content
  • Using curl for binary downloads

📖 The Concept

Not all files are text! Binary files include:

  • Images (PNG, JPG, GIF)
  • Archives (ZIP, TAR, GZ)
  • Executables (EXE, binary programs)
  • Documents (PDF, DOCX)

Binary Content-Types

Content-Type: image/png
Content-Type: image/jpeg
Content-Type: application/zip
Content-Type: application/octet-stream  ← Generic binary

Downloading Binary with curl

# Save to file (important for binary!)
curl http://example.com/image.png -o image.png

# Using output redirection
curl http://example.com/archive.zip > archive.zip

Inspecting Binary Files

file image.png           # Identify file type
hexdump -C file.bin      # View hex content
strings file.bin         # Extract text from binary

🚀 Your Challenge

Download a PNG image from the server. The flag is hidden in the image metadata!

# Download the image
curl http://challenge/secret.png -o secret.png

# Check the file
file secret.png

# Extract strings (text) from the binary
strings secret.png | grep flag

Good luck! 🍀

Connect with SSH

Link your SSH key, then connect with: ssh hacker@dojo.idg.ctf

Save to File

🎯 What You'll Learn

  • Saving downloads to files
  • Using curl output options
  • wget as an alternative

📖 The Concept

By default, curl prints content to your terminal. For files, you want to save to disk!

curl Output Options

# -o: Save to specific filename
curl http://example.com/data.json -o mydata.json

# -O: Save with original filename from URL
curl -O http://example.com/report.pdf

# Redirect to file
curl http://example.com/page > page.html

wget Alternative

# wget saves to file by default
wget http://example.com/file.zip

# Specify output name
wget http://example.com/file.zip -O custom-name.zip

# Quiet mode
wget -q http://example.com/file.zip

curl vs wget

Feature curl wget
Default output stdout file
Multiple files harder easy
Protocols many HTTP/FTP
Resume downloads -C - -c

🚀 Your Challenge

The server generates a unique file each time. Download it, save it, and read its contents!

# Step 1: Save the file
curl http://challenge/generate -o flag.txt

# Step 2: Read the saved file
cat flag.txt

⚠️ The content only displays correctly when saved to a file (not printed to terminal)!

Good luck! 🍀

Connect with SSH

Link your SSH key, then connect with: ssh hacker@dojo.idg.ctf

Follow Redirects

🎯 What You'll Learn

  • HTTP redirects (301, 302, etc.)
  • Following redirect chains
  • Using curl -L option

📖 The Concept

Servers can tell clients "the thing you want is somewhere else" using redirects.

Redirect Status Codes

Code Name Meaning
301 Moved Permanently Resource moved forever
302 Found Temporary redirect
303 See Other Redirect to different resource
307 Temporary Redirect Same as 302, keep method
308 Permanent Redirect Same as 301, keep method

How Redirects Work

Client: GET /old-page
Server: 301 Moved Permanently
        Location: /new-page

Client: GET /new-page  (if following redirects)
Server: 200 OK + content

curl and Redirects

# Default: curl does NOT follow redirects
curl http://example.com/old    # Shows redirect response

# -L: Follow redirects automatically
curl -L http://example.com/old  # Gets final content

# -I: See redirect headers
curl -I http://example.com/old

Maximum Redirects

curl -L --max-redirs 5 http://example.com/  # Max 5 redirects

🚀 Your Challenge

The flag is hidden behind multiple redirects! Follow them all to find it.

# This shows only the redirect response
curl http://challenge/start

# This follows all redirects to the end
curl -L http://challenge/start

Good luck! 🍀

Connect with SSH

Link your SSH key, then connect with: ssh hacker@dojo.idg.ctf

30-Day Scoreboard:

This scoreboard reflects solves for challenges in this module after the module launched in this dojo.

Rank Hacker Badges Score