ctfwriteup
  • ✅/home/ret2basic.eth
  • Game Hacking
    • 👑Pwn Adventure 3: Pwnie Island
      • ✅Prep: Speed Hack
      • ✅Prep: Infinite Health and Mana (Offline)
      • ✅Prep: Analyze Network Packets with Wireshark
      • Prep: Build a Proxy in Python
      • ✅Until the Cows Come Home
      • Unbearable Revenge
      • Pirate's Treasure
    • Cheat Engine Tutorial
      • ✅Step 1: Setup
      • ✅Step 2: Scan for "Exact Value"
      • ✅Step 3: Scan for "Unknown initial value"
      • ✅Step 4: Scan for float and double
      • ✅Step 5: Replace instruction
      • Step 6: Pointer scanning
      • Step 7: Code injection
      • Step 8: Multilevel pointers
      • Step 9: Shared code
  • Web3 CTF
    • 👑Remedy CTF 2025 (Todo)
      • Diamond Heist
      • R vs Q
      • Rich Man's Bet
      • Casino Avengers
      • Frozen Voting
      • Lockdown
      • Proof of Thought
      • Maybe it's unnecessary?
      • Et tu, Permit2?
      • Not a very LUCKY TOKEN
      • risc4
      • HealthCheck as a Service
      • Restricted Proxy
      • Unstable Pool
      • Opaze Whisperer
      • "memorable" onlyOwner
      • World of Memecraft
      • Copy/Paste/Deploy
      • Peer-to-peer-to-me
      • Joe's Lending Mirage
      • Tokemak
      • OFAC Executive Order 13337
    • 👑Paradigm CTF 2023 (Todo)
      • Oven
      • Dragon Tyrant
    • Damn Vulnerable DeFi
      • ✅Unstoppable
      • ✅Naive Receiver
      • ✅Truster
      • ✅Side Entrance
      • ✅The Rewarder
      • ✅Selfie
      • ✅Compromised
      • ✅Puppet
      • ✅Puppet V2
      • ✅Free Rider
      • Backdoor
      • Climber
      • Wallet Mining (Todo)
      • Puppet V3 (Todo)
      • ABI Smuggling (Todo)
    • Milotruck Challs
      • ✅Greyhats Dollar
      • Escrow
      • Simple AMM Vault
      • Voting Vault
      • ✅Meta Staking
      • ✅Gnosis Unsafe
    • Secureum AMAZEX DSS Paris
      • ✅Operation magic redemption
      • Mission Modern WETH: Rescue the Ether
      • LendEx pool hack
      • Operation Rescue POSI Token!
      • Balloon Vault
      • Safe Yield?
      • ✅Crystal DAO
      • ✅Liquidatoooor
    • ✅Ethernaut
      • ✅Hello Ethernaut
      • ✅Fallback
      • ✅Fallout
      • ✅Coin Flip
      • ✅Telephone
      • ✅Token
      • ✅Delegation
      • ✅Force
      • ✅Vault
      • ✅King
      • ✅Re-entrancy
      • ✅Elevator
      • ✅Privacy
      • ✅Gatekeeper One
      • ✅Gatekeeper Two
      • ✅Naught Coin
      • ✅Preservation
      • ✅Recovery
      • ✅MagicNumber
      • ✅Alien Codex
      • ✅Denial
      • ✅Shop
      • ✅DEX
      • ✅DEX Two
      • ✅Puzzle Wallet
      • Motorbike
      • DoubleEntryPoint
      • ✅Good Samaritan
      • Gatekeeper Three
      • Switch
    • ✅Flashbots MEV-Share CTF
    • ✅Capture the Ether
      • ✅Lotteries
      • ✅Math
      • ✅Miscellaneous
    • ✅EVM Puzzles
      • ✅Puzzle 1
      • ✅Puzzle 2
      • ✅Puzzle 3
      • ✅Puzzle 4
      • ✅Puzzle 5
      • ✅Puzzle 6
      • ✅Puzzle 7
      • ✅Puzzle 8
      • ✅Puzzle 9
      • ✅Puzzle 10
    • ✅More EVM Puzzles
      • ✅Puzzle 1
      • ✅Puzzle 2
      • ✅Puzzle 3
      • ✅Puzzle 4
      • ✅Puzzle 5
      • ✅Puzzle 6
      • ✅Puzzle 7
      • ✅Puzzle 8
      • ✅Puzzle 9
      • ✅Puzzle 10
    • ✅QuillCTF
      • ✅MetaToken
      • ✅Temporary Variable
      • KeyCraft
      • ✅Lottery
      • ✅Private Club
      • Voting Machine
      • ✅Predictable NFT
      • ✅Invest Pool
      • PseudoRandom
      • ✅Gold NFT
      • Slot Puzzle
      • Moloch's Vault
      • ✅Donate
      • ✅WETH-11
      • Panda Token
      • Gate
      • ✅WETH10
      • ✅Pelusa
      • ✅True XOR
      • ✅Collatz Puzzle
      • ✅D31eg4t3
      • ✅Safe NFT
      • ✅VIP Bank
      • ✅Confidential Hash
      • ✅Road Closed
    • ✅unhacked
      • ✅reaper
  • RareSkills Puzzles
    • Solidity Exercises
    • Solidity Riddles
    • Yul Puzzles
      • ✅01 - ReturnBool
      • ✅02 - SimpleRevert
      • ✅03 - Return42
      • ✅04 - RevertWithError
      • ✅05 - RevertWithSelectorPlusArgs
      • 06 - RevertWithPanic
    • Huff Puzzles
    • Uniswap V2 Puzzles
    • Zero Knowledge Puzzles
  • Web2 CTF
    • Grey Cat CTF 2024
      • ✅Web Challs
    • pwn.college
      • Introduction
        • What is Computer Systems Security?
      • Program Interaction
        • Linux Command Line
        • 🚩embryoio
      • Program Misuse
        • Privilege Escalation
        • Mitigations
        • 🚩babysuid
      • Assembly Refresher
        • x86 Assembly
        • 🚩embryoasm
      • Shellcoding
        • Introduction
        • Common Challenges
        • Data Execution Prevention
        • 🚩babyshell
      • Sandboxing
        • chroot
        • seccomp
        • Escaping seccomp
        • 🚩babyjail
      • Debugging Refresher
        • x86 Assembly
        • 🚩embryogdb
      • Binary Reverse Engineering
        • Functions and Frames
        • Data Access
        • Static Tools
        • Dynamic Tools
        • Real-world Applications
        • 🚩babyrev
      • Memory Errors
        • High-Level Problems
        • Smashing the Stack
        • Causes of Corruption
        • Canary
        • ASLR
        • Causes of Disclosure
        • 🚩babymem
      • Exploitation
        • Introduction
        • Hijacking to Shellcode
        • Side Effects
        • JIT Spray
        • 🚩toddler1
      • Return Oriented Programming
        • Binary Lego
        • Techniques
        • Complications
        • 🚩babyrop
      • Dynamic Allocator Misuse
        • What is the Heap?
        • Dangers of the Heap
        • tcache
        • Chunks and Metadata
        • Metadata Corruption
        • 🚩babyheap
      • Race Conditions
        • Introduction
        • Races in the Filesystem
        • 🚩babyrace
      • Kernel Security
        • Environment Setup
        • Kernel Modules
        • Privilege Escalation
        • 🚩babykernel
      • Advanced Exploitation
        • toddler2
    • pwnable.kr
      • fd
      • collision
      • bof
      • flag
      • passcode
      • random
      • input
      • leg
      • mistake
      • shellshock
      • coin1
      • blackjack
      • lotto
      • cmd1
      • cmd2
      • uaf
      • memcpy
      • asm
      • unlink
      • blukat
      • horcruxes
    • ROP Emporium
      • ret2win
      • split
      • callme
      • write4
      • pivot
    • ✅Jarvis OJ Pwn Xman Series
    • ✅Jarvis OJ Crypto RSA Series
    • ✅picoMini by redpwn
      • Binary Exploitation
      • Reverse Engineering
      • Cryptography
      • Web Exploitation
      • Forensics
    • ✅picoCTF 2021
      • Reverse Engineering
      • Web Exploitation
      • Forensics
    • ✅picoCTF 2020 Mini-Competition
  • Red Teaming
    • vulnlab
      • Active Directory Chains
        • ✅Trusted (Easy)
        • Hybrid (Easy)
        • Lustrous (Medium)
        • Reflection (Medium)
        • Intercept (Hard)
      • Red Team Labs
        • Wutai (Medium)
        • Shinra (Hard)
    • Hack The Box
      • AD
        • Intelligence
        • Pivotapi
        • Sharp
        • Monteverde
        • Resolute
        • Endgame: P.O.O.
        • Forest
        • Sauna
        • Active
        • Blackfield
      • ✅Linux
        • ✅Safe (Easy)
        • ✅Delivery (Easy)
        • ✅TheNotebook (Medium)
        • ✅Brainfuck (Insane)
    • TCM Windows Privilege Escalation Course
      • ✅Hack The Box - Chatterbox (Medium)
      • Hack The Box - SecNotes (Medium)
    • ✅TCM Linux Privilege Escalation Course
      • ✅TryHackMe - Simple CTF (Easy)
      • ✅TryHackMe - Vulnversity (Easy)
      • ✅TryHackMe - CMesS (Medium)
      • ✅TryHackMe - UltraTech (Medium)
      • ✅TryHackMe - LazyAdmin (Easy)
      • ✅TryHackMe - Anonymous (Medium)
      • ✅TryHackMe - tomghost (Easy)
      • ✅TryHackMe - ConvertMyVideo (Medium)
      • ✅TryHackMe - Brainpan 1 (Hard)
Powered by GitBook
On this page
  • Lecture
  • Command Line
  • Process
  • File System
  • Absolute Paths vs. Relative Paths
  • Environment Variables
  • File Types
  • Symbolic Links vs. Hard Links
  • Symbolic Links (Symlinks, Soft Links)
  • Hard Links
  • Pipes
  • Input and Output Redirection
  1. Web2 CTF
  2. pwn.college
  3. Program Interaction

Linux Command Line

PreviousProgram InteractionNextembryoio

Last updated 3 years ago

Lecture

Command Line

The command line (aka "shell") is a powerful interface to a computer. Suppose we type a command cat flag:

Under the hood, Linux does the following things:

  1. I told the shell to run the program cat with the argument flag.

  2. The shell found the cat program file and launched it into a cat process with a flag argument.

  3. cat is a program that outputs files. It reads the flag argument and knows to output the flag file, which contains "pwn_college{1337}".

Process

  • A process is a running program.

  • A program is a file on your computer.

  • Files live in a file system.

  • Your web browser, your command line interpreter ("shell"), your text editor, all start out as files on the file system and become processes when they are executed.

File System

Unlike Windows (which traditionally has different file systems at different anchor points C:\, D:\, E:\, etc.), Linux presents a unified file system view:

/

The "anchor" of the filesystem. Pronounced "root".

/usr

The Unix System Resource. Contains all the system files.

/usr/bin

Executable files for programs installed on the computer.

/usr/lib

Shared libraries for use by programs on the computer.

/usr/share

Program resources (icons, art assets, etc).

/etc

System configuration.

/var

Logs, caches, etc.

/home

User-owned data.

/home/ctf

Data owned by you in the pwn.college infrastructure.

/proc

Runtime process data.

/tmp

Temporary data storage.

Absolute Paths vs. Relative Paths

  • Absolute paths start with /, such as /usr, /home/yans/flags/TOPSECRET, etc.

  • Relative paths don't start with /, and are relative to the current working directory.

Environment Variables

In the command cat flag, how does Linux know where cat is? The answer is the $PATH environmental variable.

"Environment variables" are a set of Key/Value pairs passed into every process when it is launched. Critical variables:

  • $PATH: a list of directories to search for programs in.

  • $PWD: the current working directory (same as the pwd command)

  • $HOME: the path to your home directory

  • $HOSTNAME: the name of your system

You can print environment variables with the env command, and set them with export:

If you're curious about what program file ends up becoming your cat process after it's found using the $PATH variable, use which.

File Types

Examine /home/yans/flags:

  • - is a regular file

  • d is a directory (yes, directories are actually just special files!)

  • l is a symbolic link (a file that transparently points to another file or directory)

  • p is a named pipe (also known as a FIFO. You will get very familiar with these this module!)

  • c is a character device file (i.e., backed by a hardware device that produces or receives data streams, such as a microphone)

  • b is a block device file (i.e., backed by a hardware device that stores and loads blocks of data, such as a hard drive)

  • s is a unix socket (essentially a local network connection encapsulated in a file)

Symbolic Links vs. Hard Links

Symbolic Links (Symlinks, Soft Links)

A symbolic/soft link is a special type of file that references another file. They are created ln -s (-s stands for symbolic):

You can also link directories:

Beware: Symbolic links to relative paths are relative to the directory containing the link!

Hard Links

A hard link (created with ln without the -s argument) is a direct reference to a file via its inode. You can also only hardlink files and not directories.

The inode is a database that describes the file/directory attributes such as metadata and the physical location on the hard drive. They are essentially the numerical equivalent of a full address. With an inode, the OS can retrieve information about the file such as permission privileges and the physical location of the data on the hard drive to access the file. Should a file be moved from one folder to another, the file will be moved to a different location on the hard drive and its inode value will change with it automatically.

A hard link is an equally "valid" reference to the original file as the original file itself. It is a file that happens to be backed by the same data as the original.

Pipes

Pipes facilitate a unidirectional flow of information. There are two types of pipes:

  1. Unnamed pipes, ethereal channels of information between processes. Most commonly used to direct data from one command to another.

  2. Named pipes, also known as FIFOs, created using the mkfifo command. Also used to help facilitate data flow in certain situations.

Input and Output Redirection

Command output can be redirected to files, and command input can be provided from files.

  • <in_file

    • Redirect in_file into the command's input

  • >out_file

    • Redirect the command's output into out_file, overwriting it

  • >>out_file

    • Redirect the command's output into out_file, appending to it

  • 2>error_file

    • Redirect the command's errors into error_file, overwriting it

  • 2>>error_file

    • Redirect the command's errors into error_file, appending to it

Input and Output Redirection

cat flag
Input and Output Redirection
Linux Command Line
Absolute Paths vs. Relative Paths
env and export
/home/yans/flags
ln -s
Link a directory
Symbolic link to a relative path
Symbolic link to an absolute path
Hard link