A firewall is a network security device (hardware or software) that monitors and controls incoming and outgoing network traffic based on predefined security rules. Firewalls operate at the network layer (packet filtering) or application layer (stateful inspection / deep packet inspection).
| Type | How It Works | Strengths | Weaknesses |
|---|---|---|---|
| Packet Filter | Checks IP/port headers only | Fast, simple | Cannot inspect payload — misses app-layer attacks |
| Stateful Inspection | Tracks TCP connection state — allows only valid packets for established connections | Better than packet filter | Still cannot inspect encrypted payloads |
| Application Proxy | Acts as intermediary — inspects full application data | Understands protocols deeply | Slower, complex, protocol-specific |
| WAF (Web Application Firewall) | Inspects HTTP/HTTPS specifically for web attacks | Blocks SQL injection, XSS, CSRF | Only for HTTP — needs SSL offloading to inspect HTTPS |
Building a secure Internet application requires protecting against common attack patterns. The OWASP Top 10 lists the most critical web application security risks. Every developer building Internet applications must understand these.
Try: ' OR 1=1 -- or ; DROP TABLE users
SELECT * FROM users WHERE name='" + username + "'. An attacker enters admin' -- as the username. What happens?SELECT * FROM users WHERE name='admin' --'. The -- comments out the rest (including the password check), so any user named 'admin' is returned without needing the password. This is SQL injection.admin' -- turns the query into where -- comments out the password condition. Fix: use parameterised queries (prepared statements) — never concatenate user input.Every Internet application built in this course — Finger, Whois, FTP, HTTP server, IRC, email — must be hardened against the security vulnerabilities we have studied. Here is a practical security checklist for Winsock-based applications.
recv(sock, buf, sizeof(buf)-1, 0).Authentication = verifying identity ("Who are you?"). Authorization = verifying permission ("What are you allowed to do?"). Both are required: authenticating a user does not automatically mean they can access every resource.
| Method | How It Works | Strength | Weakness |
|---|---|---|---|
| Password | User proves knowledge of a secret string | Simple to implement | Phishing, weak passwords, credential stuffing |
| Multi-Factor (MFA) | Password + second factor (OTP, hardware key) | Stops most password attacks | User friction; SMS OTP can be SIM-swapped |
| Public Key / Certificate | Client proves ownership of a private key | Phishing-resistant; no password to steal | Key management complexity |
| OAuth 2.0 / OpenID Connect | Delegate auth to trusted provider (Google, GitHub) | No password management; provider handles security | Depends on third-party availability |
| API Keys | Static secret in requests | Simple for server-to-server | Must be rotated; risky if exposed |
| Chapter / Feature | Security Practice |
|---|---|
| Ch3 Winsock | Always call WSACleanup() — prevent resource leaks. Validate recv() return values. |
| Ch5 Finger | Disable on modern systems. Never expose user data without authentication. |
| Ch6 Whois | Rate-limit queries. Do not expose internal network info. |
| Ch7 FTP | Use SFTP or FTPS. Never plain FTP — credentials sent in clear text. |
| Ch8 HTTP Server | Sanitise paths (../). Return 403 not 404 for traversal attempts. Use HTTPS. |
| Ch9 IRC | Validate all incoming messages. NickServ for identity. Use TLS port 6697. |
| Ch11 Email | Use STARTTLS/SSL for SMTP, IMAP, POP3. Hash + salt passwords. SPF/DKIM/DMARC. |
| Ch13 TLS | Verify certificates. Check hostname. Reject expired or self-signed certs. |
| Ch14 General | Input validation. Parameterised queries. Least privilege. Security logging. |
Network security system controlling traffic by IP, port, and protocol rules. Default deny = most secure posture.
Inserting SQL code into user input to manipulate database queries. Fix: parameterised queries.
Writing more data than a buffer can hold — overwrites adjacent memory. Fix: always limit recv() to sizeof(buf).
Verifying WHO someone is. Passwords, MFA, certificates, OAuth.
Verifying WHAT someone is allowed to do. Separate from authentication.
Grant only the minimum permissions needed. Servers should not run as Administrator.
- Firewalls control network traffic by rules. Default deny (block all, allow specific) is the most secure posture.
- Stateful inspection firewalls track TCP connection state — more secure than simple packet filtering.
- OWASP Top 10: SQL injection, XSS, broken authentication, directory traversal, insecure direct object reference, misconfiguration.
- Fix SQL injection with parameterised queries — never concatenate user input into SQL strings.
- Buffer overflow: always pass
sizeof(buf)-1to recv() — never a larger size than allocated. - Authentication = who are you? Authorization = what can you do? Both are required separately.
- Secure Winsock checklist: TLS, input validation, path sanitisation, timeouts, rate limiting, logging, least privilege.
- Apply security from design — retrofitting security into finished code is difficult and error-prone.
- Every protocol in this course (Finger, FTP, HTTP, IRC, Email) has a secure variant — always prefer the encrypted version.