1.8 Networking Basics for Security★★
PYQs4
- Which port number is usually the default port of web servers like Apache? → 80 (HTTP) 2024-25 1M recent
- What port does Telnet use? a) 22 b) 80 c) 20 d) 23 → d) 23 2018-19 1M
- What is a response code? List them. 2022-23 5M recent
- LDAP stands for: a) Lightweight Directory Access Protocol b) Lightweight Data Access Protocol c) Lightweight Domain Access Protocol d) Lightweight DNS Access Protocol → a) Lightweight Directory Access Protocol 2014-15 2013-14 1M
What Happens When You Open a Website
- You type a website name, and the page appears in under a second.
- Feels like one step. It's actually a dozen, across several machines.
- Your phone finds an address, knocks on a numbered door, and asks for the page.
- Almost every attack in this subject hijacks one of those steps.
OSI and TCP/IP Models
Protocols and layers
- Protocol: a set of rules for how devices communicate (HTTP, TCP, IP).
- Layer: a group of related networking jobs; each layer serves the one above it.
The OSI model (7 layers)
| Layer | Job | Attacks at this layer |
|---|---|---|
| 7 Application | services for users: HTTP, DNS, email | XSS, SQL injection, phishing |
| 6 Presentation | format, encryption, compression | SSL stripping |
| 5 Session | starts and ends sessions | session hijacking |
| 4 Transport | TCP/UDP, ports, reliable delivery | SYN flood, port scanning |
| 3 Network | IP addresses, routing | IP spoofing, ICMP flood |
| 2 Data link | MAC addresses, switches | ARP spoofing, MAC flooding |
| 1 Physical | cables, signals, radio | wiretapping, jamming |
- Memory trick (7 → 1): All People Seem To Need Data Processing.
The TCP/IP model (4 layers)
- Application = OSI layers 5–7 (HTTP, DNS, SMTP).
- Transport = OSI layer 4 (TCP, UDP).
- Internet = OSI layer 3 (IP, ICMP).
- Network access (link) = OSI layers 1–2 (Ethernet, Wi-Fi).
TCP vs UDP
| Basis | TCP | UDP |
|---|---|---|
| Connection | connection set up first (handshake) | no connection, just sends |
| Reliability | lost data is resent | no resending |
| Order | data arrives in order | may arrive out of order |
| Speed | slower | faster |
| Used for | web, email, file transfer | video calls, DNS, online games |
The TCP three-way handshake
flowchart TD
A["<b>Client → server: SYN</b><br>(let's connect)"]:::blue --> B["<b>Server → client: SYN-ACK</b><br>(ready, confirm?)"]:::blue
B --> C["<b>Client → server: ACK</b><br>(confirmed)"]:::blue
C --> D["<b>Connection open</b><br>(data can flow)"]:::green
classDef blue fill:#5b84d424,stroke:#5b84d480
classDef green fill:#52a86e24,stroke:#52a86e80- A SYN flood sends thousands of SYNs and never completes step 3, filling the server's memory (→ 2.17).
- Port scans use these same packets to see which ports answer (→ 2.6).
Ports and Services PYQ 1M
A port is a number (0–65535) that identifies a specific service on a computer, so one IP address can run many services at once.
- Well-known ports: 0–1023 · registered: 1024–49151 · dynamic (temporary): 49152–65535.
| Port | Protocol | Use |
|---|---|---|
| 20, 21 | FTP | file transfer (20 data, 21 control) |
| 22 | SSH | secure remote login |
| 23 | Telnet | remote login, unencrypted |
| 25 | SMTP | sending email |
| 53 | DNS | name to IP lookup |
| 80 | HTTP | web pages; default for web servers like Apache |
| 110 | POP3 | downloading email |
| 143 | IMAP | reading email on the server |
| 389 | LDAP | directory lookups |
| 443 | HTTPS | secure web pages |
| 3389 | RDP | Windows remote desktop |
Security points
- Close every port that isn't needed; each open port is a possible way in.
- Firewalls allow or block traffic by port (→ 6.6).
- Use the encrypted version of a service: SSH instead of Telnet, HTTPS instead of HTTP (→ 6.8).
HTTP Response Codes PYQ 5M
HTTP requests and responses
- HTTP (HyperText Transfer Protocol): the rules a browser and a web server use to talk.
- Request: the browser sends a method and a path, e.g.
GET /results.html.- GET fetches data · POST sends form data · PUT updates · DELETE removes · HEAD fetches headers only.
- Response: the server sends back a status line (with the response code), headers and the body (the page).
An HTTP response code (status code) is a three-digit number sent by a web server in reply to a request, telling whether the request succeeded and, if not, why.
The five classes
- 1xx Informational: request received, continuing.
- 2xx Success: request received, understood and accepted.
- 3xx Redirection: the browser must go somewhere else.
- 4xx Client error: the request has a problem (wrong address, no permission).
- 5xx Server error: the server failed to handle a valid request.
Common codes
| Code | Name | Meaning |
|---|---|---|
| 100 | Continue | send the rest of the request |
| 200 | OK | success, page sent |
| 201 | Created | new resource created (after POST) |
| 204 | No Content | success, nothing to send back |
| 301 | Moved Permanently | page has a new permanent address |
| 302 | Found | temporary redirect |
| 304 | Not Modified | use the copy in your cache |
| 400 | Bad Request | request is malformed |
| 401 | Unauthorized | login required |
| 403 | Forbidden | logged in or not, access denied |
| 404 | Not Found | page doesn't exist |
| 429 | Too Many Requests | rate limit reached |
| 500 | Internal Server Error | server-side failure |
| 502 | Bad Gateway | bad reply from an upstream server |
| 503 | Service Unavailable | server overloaded or down |
| 504 | Gateway Timeout | upstream server too slow |
Why they matter for security
- Many 401/403 codes in a short time suggest password guessing.
- Bursts of 404 codes suggest someone scanning for hidden pages.
- Detailed 500 error pages can leak database details to attackers (→ 2.9).
- 503 errors under heavy traffic can signal a DDoS attack; 429 shows rate limiting at work.
IP, MAC, DNS and LDAP PYQ 1M · other
- IP address: the logical address of a device on a network. IPv4 is 32-bit (e.g. 192.168.1.10); IPv6 is 128-bit.
- MAC address: a 48-bit hardware address fixed in the network card (e.g. 00:1A:2B:3C:4D:5E); used inside the local network.
- DNS (Domain Name System): turns names like
sbi.co.ininto IP addresses; port 53 (attacks on it → 2.3). - LDAP (Lightweight Directory Access Protocol): a protocol for looking up and managing directory information (users, groups, devices) on a network, as in Microsoft Active Directory; port 389.
- RAS (Remote Access Service): lets users connect to an organisation's network from outside; needs strong passwords and a VPN.
⚡ Quick recall
- OSI 7 → 1? → application · presentation · session · transport · network · data link · physical (All People Seem To Need Data Processing)
- TCP/IP? → application · transport · internet · network access
- TCP vs UDP? → connection, reliable, ordered, slower vs connectionless, no resend, faster
- Handshake? → SYN → SYN-ACK → ACK · SYN flood abuses it
- Ports? → FTP 20/21 · SSH 22 · Telnet 23 · SMTP 25 · DNS 53 · HTTP 80 · POP3 110 · IMAP 143 · LDAP 389 · HTTPS 443 · RDP 3389
- Response code? → three-digit server reply · 1xx info · 2xx success · 3xx redirect · 4xx client error · 5xx server error
- Key codes? → 200 OK · 301/302 redirect · 304 not modified · 401 login · 403 forbidden · 404 not found · 500 server error · 503 unavailable
- 1M: Apache default → 80 · Telnet → 23 · LDAP → Lightweight Directory Access Protocol