Week 3 Firewall Challenge
Source: Dev.to
The Scenario
Youāre the security engineer. The network is live. Configure the firewall or the company is vulnerable.
No solutions. No stepābyāstep. Just requirements and a ruleset validator.
Sound intimidating? Good. Thatās the point.
What Youāre Building
š Your deliverable: A complete iptables ruleset saved to a file (challenge4-ruleset.txt)
Youāll configure a 3āzone corporate firewall protecting:
- Internet ā Server Farm (web, mail, database, DNS servers)
- Corporate LAN ā Server Farm (employee access)
- Corporate LAN ā Internet (browsing, updates)
There are 18 specific requirements covering:
- ā Access control (who can reach what?)
- ā Security logging (with rate limiting)
- ā Antiāspoofing protection
- ā Stateful connection tracking
- ā Network segmentation
What You Must Create
- A bash script with iptables commands (
challenge4-solution.sh) - A saved ruleset file from
iptables-save(challenge4-ruleset.txt) - Upload the ruleset file to Claude/ChatGPT for AI grading
Why This Challenge Is Different
Most firewall tutorials:
- Give you the commands
- Explain each line
- Hold your hand through setup
- Test nothing
This challenge:
- Gives you requirements, not commands
- You figure out the implementation
- Clear success criteria (pass/fail)
- Tests realāworld scenarios
Itās designed like a takeāhome security interview.
What Youāll Learn
1. Stateful Firewalls
# Implement connection tracking
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
Understanding why this rule comes first separates beginners from professionals.
2. Network Segmentation
- Internet ā Can access Web/Mail servers only
- Employees ā Can access internal portal, NOT database directly
- IT Admin ā SSH access to all servers
- Web Server ā Database access, Employees CANāT reach DB directly
3. Security Logging (Without Breaking Your Disk)
# Rateālimited logging prevents logāflooding attacks
iptables -A FORWARD -m limit --limit 5/min --limit-burst 10 -j LOG
Youāll learn when to log, when to rateālimit, and why both matter.
4. AntiāSpoofing Protection
# Block packets claiming to be from your network but arriving on the wrong interface
iptables -A FORWARD -i eth1 ! -s 192.168.10.0/24 -j DROP
This defends against IP spoofing attacks.
The Challenge Structure
Part 1: Basic Setup
- Set default policies
- Configure stateful connection tracking
- Drop invalid packets
Part 2: Internet ā Server Farm
- Allow HTTP/HTTPS to the web server only
- Allow SMTP to the mail server only
- Block everything else (with logging)
Part 3: Corporate LAN ā Server Farm
- Employees access web portal and email
- IT Admin gets SSH to all servers
- Web server can query database
- Everyone else blocked
Part 4: Corporate LAN ā Internet
- Employees browse the web, use DNS
- Internet canāt reach Corporate LAN directly
Part 5: Security Hardening
- Antiāspoofing rules
- Connection rate limiting
- Comprehensive logging
Total: 18 specific requirements you must implement correctly.
How Hard Is It?
- Beginner? Youāll struggle (thatās the point).
- Intermediate? Finish in 45ā60āÆminutes if you know iptables basics.
- Expert? Prove it. Complete it perfectly on the first try.
Everyone ends up with a realistic corporate firewall ruleset for their portfolio.
The Challenge Workflow
1. Write iptables script ā 2. Save ruleset file ā 3. Upload to AI ā 4. Get graded
(30ā60āÆmin) (iptablesāsave) (Claude) (Score/100)
ā
Fix & retry
until 95+/100
You MUST create an actual file with your iptables rules ā this isnāt a reading exercise!
How to Complete This Challenge
ā ļø IMPORTANT
You must create an actual iptables ruleset file, not just read the requirements!
The challenge has 7 clear steps:
StepāÆ1: Get the Challenge
git clone https://github.com/fosres/AppSec-Exercises.git
cd AppSec-Exercises/Week-3-Firewalls
cat Challenge_4_Corporate_Network_Firewall.md
StepāÆ2: Read All 18 Requirements
The challenge document includes:
- ā Network topology diagram (3 zones: Internet, Corporate LAN, Server Farm)
- ā 18 numbered requirements (what to allow/block)
- ā Clear specifications for rate limiting
- ā Clear specifications for logging
- ā Successācriteria checklist
Read everything before writing a single command!
Note: A working solution exists here, but try it yourself first! Youāll learn much more from struggling than from copying.
StepāÆ3: Write Your iptables Script
# Create your solution file
vim challenge4-solution.sh
Add the necessary iptables commands, make the script executable, and test it on a suitable Linux host.
StepāÆ4: Save the Ruleset
sudo iptables-save > challenge4-ruleset.txt
StepāÆ5: Upload for AI Grading
Submit challenge4-ruleset.txt to Claude/ChatGPT (or the provided validator) and review the feedback.
StepāÆ6: Iterate
Fix any issues reported by the validator, reāsave the ruleset, and reāupload until you achieve a passing score (ā„āÆ95/100).
StepāÆ7: Document Your Work
Add comments to challenge4-solution.sh explaining each rule and why it satisfies the corresponding requirement. This will be valuable for future reference and for showcasing your solution in a portfolio.
Corporate Network Firewall ā Challenge 4
Template to start with
#!/bin/bash
# Challenge 4: Corporate Network Firewall
# Your Name - Date
# Flush existing rules
sudo iptables -F
sudo iptables -X
# Set default policies
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT
# ============================================
# PART 1: BASIC SETUP
# ============================================
# Rule 1: Allow established connections
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# Rule 2: Drop invalid packets
sudo iptables -A FORWARD -m conntrack --ctstate INVALID -j DROP
# ============================================
# PART 2: ANTIāSPOOFING
# ============================================
# Rule 3: Block spoofed packets on eth1
# TODO: Implement this
# ============================================
# CONTINUE WITH ALL 18 REQUIREMENTS...
# ============================================
echo "Firewall configured successfully!"
Your job: Implement all 18 requirements as iptables rules in the script above.
StepāÆ4 ā Test Your Script (Optional)
If you have a VM or lab environment:
# Make executable
chmod +x challenge4-solution.sh
# Run it
sudo ./challenge4-solution.sh
# Verify rules loaded
sudo iptables -L FORWARD -v -n
Tip: If you donāt have a lab, you can skip to StepāÆ5.
StepāÆ5 ā Save Your Ruleset to a File
This is REQUIRED for grading.
If you ran the script
# Save the active iptables rules
sudo iptables-save > challenge4-ruleset.txt
If you donāt have a lab
- Manually create the ruleset file by extracting only the
iptablescommands from your script. - Remove
sudoandecholines, keeping just theiptablescommands. - The format should match the output of
iptables-save.
Example challenge4-ruleset.txt
# Generated by iptables-save v1.8.9
*filter
:INPUT ACCEPT [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m conntrack --ctstate INVALID -j DROP
-A FORWARD ! -s 192.168.10.0/24 -i eth1 -j LOG --log-prefix "LAN-SPOOF: "
-A FORWARD ! -s 192.168.10.0/24 -i eth1 -j DROP
# ... rest of your rules ...
COMMIT
# Completed on [date]
This file is what youāll submit for grading!
StepāÆ6 ā Get AIāPowered Grading
Upload your ruleset to Claude or ChatGPT for instant feedback.
- Go to the appropriate AI interface.
- Copy/paste the following prompt:
I completed the Corporate Network Firewall Challenge (Challenge 4).
Please grade my iptables ruleset against all 18 requirements.
Challenge requirements:
[Paste the entire Challenge_4_Corporate_Network_Firewall.md file here]
My iptables ruleset:
[Paste your challenge4-ruleset.txt file here]
Please provide:
1. Score out of 100
2. Which requirements I passed/failed
3. Specific issues with my rules
4. Security problems or bestāpractice violations
5. Suggestions for improvement
The AI will:
- ā Check all 18 requirements systematically
- ā Verify rule ordering is correct
- ā Identify security issues
- ā Confirm rateālimiting and logging are applied correctly
- ā Give a detailed score breakdown and improvement suggestions
Example grading output
Score: 85/100
ā
Requirement 1: ESTABLISHED connections (PASS)
ā
Requirement 2: INVALID drop (PASS)
ā Requirement 4: Missing rate limiting on LOG rule (FAIL)
ā ļø Requirement 7: Using entire subnet instead of specific IP (SECURITY ISSUE)
...
Issues found:
1. LOG rule missing -m limit (will flood logs during attack)
2. -d 192.168.20.0/24 too broad (should be 192.168.20.10)
Your score: 85/100 ā Fix these issues for 100/100!
StepāÆ7 ā Iterate Until Perfect
If your score is below 95/100:
- Read the AIās feedback carefully.
- Fix the specific issues identified.
- Update your script.
- Save the new ruleset:
sudo iptables-save > challenge4-ruleset.txt - Reāsubmit for grading.
Repeat until you achieve 95ā100/100 ā thatās when you know youāve mastered it.
Why You Should Star the Repo ā
This isnāt just a blog post ā itās an entire handsāon curriculum.
The repo includes:
- ā ChallengeāÆ1: Basic Linux firewall (beginner)
- ā ChallengeāÆ2: Multiāinterface DMZ setup (intermediate)
- ā ChallengeāÆ3: PCIāDSS compliant firewall (advanced)
- ā ChallengeāÆ4: Corporate network (this one!)
- š More challenges coming: VPN integration, cloud firewalls, Kubernetes network policies
Benefits of starring:
- ā Bookmark for later
- ā Support openāsource security education
- ā Get notified of new challenges
- ā Show appreciation (itās free!)
Common Mistakes (Donāt Peek Until You Try!)
ā ļø Seriously, attempt the challenge BEFORE reading these!
MistakeāÆ1: Forgetting ESTABLISHED connections
# Wrong: Each direction needs explicit rules
# Right: One ESTABLISHED rule handles return traffic
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
MistakeāÆ2: Wrong rule order
# Wrong: DROP before ALLOW
-A FORWARD -i eth0 -o eth1 -j DROP # Blocks everything!
-A FORWARD -i eth0 -o eth1 -p tcp --dport 443 -j ACCEPT # Never reached
# Right: ALLOW before DROP
-A FORWARD -i eth0 -o eth1 -p tcp --dport 443 -j ACCEPT
-A FORWARD -i eth0 -o eth1 -j DROP
MistakeāÆ3: Forgetting rate limiting on LOG rules
# Wrong: Attackers can flood your logs
-A FORWARD -j LOG
# Right: Rateālimited logging
-A FORWARD -m limit --limit 5/min --limit-burst 10 -j LOG
MistakeāÆ4: Too broad destination IPs
# Wrong: Allows access to entire server network
-A FORWARD -d 192.168.20.0/24 -p tcp --dport 3306 -j ACCEPT
# Right: Only specific database server
-A FORWARD -d 192.168.20.30 -p tcp --dport 3306 -j ACCEPT
ā ļø WARNING: Try the challenge yourself FIRST before looking at solutions.
Youāll learn 10Ć more by struggling through it than by copying someone elseās work.
Working solution (reference only)
š View solution (100/100 score)
Remember: multiple valid approaches exist. The linked solution is one way to score 100/100; your own solution may differ and be equally valid.
After You Complete Thisā¦
Skills youāll gain
- Configure enterpriseāstyle firewalls from scratch.
- Explain stateful vs. stateless filtering.
- Design multiāzone network architectures.
- Implement security logging without breaking things.
- Ace firewall questions in security interviews.
Resume bullet
āConfigured enterpriseāstyle corporate firewall with 3āzone segmentation, stateful filtering, antiāspoofing protection, and comprehensive security logging.ā
Portfolio tip
- Link to your GitHub solution (if you share it).
- Mention it in interviews: āI completed a corporate firewall challenge that tested 18 realāworld requirements including network segmentation, rateālimited logging, and antiāspoofing.ā
The Community
After completing the challenge
- Compare with my solution (optional) ā see the 100/100 ruleset, learn alternative approaches.
- Share your solution (optional) ā create a GitHub Gist, write a blog post, help others in the discussion.
- Give feedback ā Was anything unclear? Should requirements be more/less detailed? What other challenges would you like?
- Star the repo ā ā support the project, get notified of new challenges, help others discover it.
Ready? Hereās Your Mission šÆ
- ā Star the repo (to get the requirements).
- š Read all 18 requirements carefully.
- š» Write your iptables script (all 18 requirements as rules).
- š¾ Save your ruleset to
challenge4-ruleset.txtusingiptables-save. - š¤ Upload to Claude/ChatGPT for instant AI grading.
- š Fix issues and reāsubmit until you achieve a score of 95āÆ+/100.