···11-# DNS, Rsync, and Cron Services
22-33-## DNS Service (BIND)
44-55-### Service Name
66-- `named` (most distributions)
77-88-### Configuration Location
99-- Ubuntu: `/etc/bind/`
1010-- CentOS: May be in different location
1111-1212-### Check Service
1313-```bash
1414-systemctl status named
1515-```
1616-1717-### Basic Concept
1818-DNS translates domain names to IP addresses (forward lookup) and IP addresses to domain names (reverse lookup).
1919-2020-**Forward lookup**: `example.com` → `192.168.1.100`
2121-**Reverse lookup**: `192.168.1.100` → `example.com`
2222-2323-### Key Files (Bind)
2424-- `named.conf` - Main configuration
2525-- Zone files - Define DNS records for domains
2626-2727-**This is a complex service** - requires understanding of:
2828-- Zone files
2929-- DNS record types (A, PTR, CNAME, MX, etc.)
3030-- Forward vs reverse zones
3131-- DNS hierarchy
3232-3333----
11+# Rsync and Cron Services
342353## Rsync - File Synchronization/Backup
364
+281
05-dns-service.md
···11+# DNS Service (BIND)
22+33+## Overview
44+55+DNS translates domain names to IP addresses (forward lookup) and IP addresses to domain names (reverse lookup).
66+77+- **Forward lookup**: `ncaecybergames.org` → `192.168.8.2`
88+- **Reverse lookup**: `192.168.8.2` → `ncaecybergames.org`
99+1010+---
1111+1212+## Service Name
1313+1414+- `named` (not `bind`)
1515+1616+```bash
1717+systemctl status named
1818+sudo systemctl start named
1919+sudo systemctl enable named
2020+```
2121+2222+---
2323+2424+## Configuration Locations
2525+2626+### Ubuntu
2727+```
2828+/etc/bind/
2929+├── named.conf # Main config (includes other files)
3030+├── named.conf.options # Server options
3131+├── named.conf.local # Local zone definitions
3232+├── named.conf.default-zones # Default zones (localhost, etc.)
3333+├── db.empty # Template file to copy for new zones
3434+├── db.local # Localhost zone file
3535+├── db.127 # Localhost reverse zone
3636+└── zones/ # Your custom zone files (create this)
3737+```
3838+3939+### CentOS/RHEL
4040+Configuration may be in a different location - check `/etc/named/` or `/var/named/`
4141+4242+---
4343+4444+## Key Concepts
4545+4646+### Zone Files
4747+- **Forward zone**: Maps domain names → IP addresses (A records)
4848+- **Reverse zone**: Maps IP addresses → domain names (PTR records)
4949+5050+### Include Structure
5151+The main `named.conf` typically includes other config files:
5252+```
5353+include "/etc/bind/named.conf.options";
5454+include "/etc/bind/named.conf.local";
5555+include "/etc/bind/named.conf.default-zones";
5656+```
5757+5858+### allow-update Directive
5959+6060+Controls whether dynamic DNS updates are permitted for a zone:
6161+6262+```
6363+zone "example.org" IN {
6464+ type master;
6565+ file "/etc/bind/zones/forward.example.org";
6666+ allow-update { none; }; # No dynamic updates allowed
6767+};
6868+```
6969+7070+| Value | Meaning |
7171+|-------|---------|
7272+| `{ none; }` | No updates allowed (static zone, manual edits only) |
7373+| `{ key mykey; }` | Allow updates signed with a specific TSIG key |
7474+| `{ 192.168.8.5; }` | Allow updates from a specific IP address |
7575+7676+**For competition: Always use `{ none; };`** - prevents attackers from remotely modifying your DNS records.
7777+7878+---
7979+8080+## Setting Up DNS Zones
8181+8282+### Step 1: Add Zone Definitions
8383+8484+Edit the zones config file (Ubuntu: `named.conf.default-zones`):
8585+```bash
8686+sudo nano /etc/bind/named.conf.default-zones
8787+```
8888+8989+Add a **forward lookup zone**:
9090+```
9191+zone "ncaecybergames.org" IN {
9292+ type master;
9393+ file "/etc/bind/zones/forward.ncaecybergames.org";
9494+ allow-update { none; };
9595+};
9696+```
9797+9898+Add a **reverse lookup zone**:
9999+```
100100+zone "8.168.192.in-addr.arpa" IN {
101101+ type master;
102102+ file "/etc/bind/zones/reverse.ncaecybergames.org";
103103+ allow-update { none; };
104104+};
105105+```
106106+107107+**Important**: For reverse zones, write the network portion of the IP **backwards**:
108108+- IP: `192.168.8.x` → Zone: `8.168.192.in-addr.arpa`
109109+110110+---
111111+112112+### Step 2: Create Zone Files Directory
113113+114114+```bash
115115+sudo mkdir /etc/bind/zones
116116+```
117117+118118+---
119119+120120+### Step 3: Copy Template Files
121121+122122+Copy the empty template (preserves correct ownership and permissions):
123123+```bash
124124+sudo cp /etc/bind/db.empty /etc/bind/zones/forward.ncaecybergames.org
125125+sudo cp /etc/bind/db.empty /etc/bind/zones/reverse.ncaecybergames.org
126126+```
127127+128128+**Why copy instead of create from scratch?**
129129+- Preserves correct ownership (`root:bind`)
130130+- Preserves correct permissions (`644`)
131131+- If permissions/ownership are wrong, bind can't read the files
132132+133133+Check permissions:
134134+```bash
135135+ls -l /etc/bind/zones/
136136+```
137137+138138+---
139139+140140+### Step 4: Configure Forward Zone File
141141+142142+```bash
143143+sudo nano /etc/bind/zones/forward.ncaecybergames.org
144144+```
145145+146146+Example forward zone file:
147147+```
148148+$TTL 604800
149149+@ IN SOA ncaecybergames.org. root. (
150150+ 2 ; Serial (INCREMENT THIS ON EVERY CHANGE!)
151151+ 604800 ; Refresh
152152+ 86400 ; Retry
153153+ 2419200 ; Expire
154154+ 604800 ) ; Negative Cache TTL
155155+156156+@ IN NS sandbox-ubuntu.
157157+sandbox-ubuntu IN A 192.168.8.2
158158+www IN A 192.168.8.2
159159+```
160160+161161+**Key points:**
162162+- Replace `localhost` with your domain (`ncaecybergames.org.`)
163163+- Replace `localhost` after `NS` with your server hostname (`sandbox-ubuntu.`)
164164+- **Always increment the serial number** when making changes (1→2→3...)
165165+- Add A records for each subdomain
166166+167167+---
168168+169169+### Step 5: Configure Reverse Zone File
170170+171171+```bash
172172+sudo nano /etc/bind/zones/reverse.ncaecybergames.org
173173+```
174174+175175+Example reverse zone file:
176176+```
177177+$TTL 604800
178178+@ IN SOA ncaecybergames.org. root.ncaecybergames.org. (
179179+ 2 ; Serial (INCREMENT THIS ON EVERY CHANGE!)
180180+ 604800 ; Refresh
181181+ 86400 ; Retry
182182+ 2419200 ; Expire
183183+ 604800 ) ; Negative Cache TTL
184184+185185+@ IN NS sandbox-ubuntu.
186186+2 IN PTR www.ncaecybergames.org.
187187+2 IN PTR sandbox-ubuntu.ncaecybergames.org.
188188+```
189189+190190+**Key points:**
191191+- For reverse zones, domain names end with a **period** (`.`)
192192+- PTR record uses only the **host portion** of IP (for `192.168.8.2`, just use `2`)
193193+- Multiple PTR records can point to the same IP
194194+195195+---
196196+197197+## Start and Test DNS
198198+199199+### Start the Service
200200+```bash
201201+sudo systemctl start named
202202+systemctl status named
203203+```
204204+205205+If it fails to start, check for typos in your config files (missing semicolons, periods, spaces).
206206+207207+---
208208+209209+### Configure Client to Use Your DNS Server
210210+211211+Edit `/etc/resolv.conf`:
212212+```bash
213213+sudo nano /etc/resolv.conf
214214+```
215215+216216+Add your DNS server:
217217+```
218218+nameserver 192.168.8.2
219219+```
220220+221221+Or add to netplan (`/etc/netplan/*.yaml`):
222222+```yaml
223223+nameservers:
224224+ addresses:
225225+ - 192.168.8.2
226226+```
227227+228228+---
229229+230230+## Testing DNS
231231+232232+### Using nslookup
233233+234234+Forward lookup:
235235+```bash
236236+nslookup www.ncaecybergames.org
237237+```
238238+239239+Reverse lookup:
240240+```bash
241241+nslookup 192.168.8.2
242242+```
243243+244244+### Using Browser
245245+Navigate to `http://www.ncaecybergames.org` - should load your web server.
246246+247247+---
248248+249249+## Troubleshooting
250250+251251+### Service Won't Start
252252+- Check for typos in zone files (missing semicolons, periods)
253253+- Check file permissions (`644`) and ownership (`root:bind`)
254254+- Check config syntax: `named-checkconf`
255255+- Check zone file syntax: `named-checkzone ncaecybergames.org /etc/bind/zones/forward.ncaecybergames.org`
256256+257257+### DNS Not Resolving
258258+- Verify service is running: `systemctl status named`
259259+- Check `/etc/resolv.conf` has your DNS server listed
260260+- Test with `nslookup` to isolate DNS vs other issues
261261+262262+### Common Mistakes
263263+- Forgetting to increment serial number after changes
264264+- Missing periods at end of domain names in reverse zone files
265265+- Wrong file permissions/ownership
266266+- Typos in IP addresses or domain names
267267+- Missing semicolons in config files
268268+269269+---
270270+271271+## Quick Reference
272272+273273+| Task | Command |
274274+|------|---------|
275275+| Check service status | `systemctl status named` |
276276+| Start service | `sudo systemctl start named` |
277277+| Restart after config change | `sudo systemctl restart named` |
278278+| Check config syntax | `named-checkconf` |
279279+| Check zone syntax | `named-checkzone DOMAIN ZONEFILE` |
280280+| Forward lookup | `nslookup DOMAIN` |
281281+| Reverse lookup | `nslookup IP` |
06-ufw-firewall.md
07-ufw-firewall.md
-293
07-active-connection-defense.md
···11-# Active Connection Defense
22-33-## Overview
44-Monitoring and managing active network connections is critical during competitions. This guide covers tools for identifying who's connected to your system and how to terminate malicious connections.
55-66-## Core Monitoring Tools
77-88-### netstat - Network Statistics
99-1010-**Most useful form**:
1111-```bash
1212-sudo netstat -tunap
1313-```
1414-1515-**Breakdown**:
1616-- `-t` = TCP connections
1717-- `-u` = UDP connections
1818-- `-n` = Show numeric ports (22 instead of "ssh")
1919-- `-a` = Show listening and established connections
2020-- `-p` = Show process IDs (requires sudo)
2121-2222-**Output columns**:
2323-```
2424-Proto Local Address Foreign Address State PID/Program
2525-tcp 192.168.195.100:22 192.168.195.2:51736 ESTABLISHED 265408/sshd
2626-```
2727-2828-**Common filters**:
2929-```bash
3030-netstat -tunap | grep ESTABLISHED # Only active connections
3131-netstat -tunap | grep :22 # Only SSH connections
3232-netstat -tunap | less # Scroll through output
3333-```
3434-3535-### ss - Socket Statistics
3636-3737-Modern replacement for netstat. Similar syntax:
3838-3939-```bash
4040-ss # Basic output (lots of info)
4141-ss | grep ESTAB # Only established connections
4242-ss -tunap # Same flags as netstat
4343-```
4444-4545-**Advantage**: ss is installed on more modern systems by default.
4646-4747-### w - Who is logged in
4848-4949-```bash
5050-w
5151-```
5252-5353-**Shows**:
5454-- Username
5555-- From where (IP address or `:0` for local console)
5656-- Login time
5757-- What they're doing
5858-5959-**Example output**:
6060-```
6161-USER FROM WHAT
6262-sandbox :0 -bash
6363-bob 192.168.195.2 -bash
6464-jenny 192.168.195.2 -bash
6565-```
6666-6767-**Key indicator**:
6868-- `:0` = Local console (physically at the machine)
6969-- IP address = Remote connection (SSH, etc.)
7070-7171-## Finding Process Information
7272-7373-### top - Interactive Process Viewer
7474-7575-```bash
7676-top
7777-```
7878-7979-- Shows CPU/memory usage
8080-- Lists running processes
8181-- Press `q` to quit
8282-8383-### htop - Enhanced Process Viewer
8484-8585-```bash
8686-htop # If installed (not always available)
8787-```
8888-8989-More colorful and interactive than `top`.
9090-9191-### ps - Process Status
9292-9393-```bash
9494-ps aux # All processes, all users
9595-ps aux | grep ssh # Find SSH processes
9696-```
9797-9898-## Killing Connections
9999-100100-### Kill by Process ID (PID)
101101-102102-1. **Find the PID**:
103103-```bash
104104-sudo netstat -tunap
105105-# Example output shows PID 265465 for jenny's SSH connection
106106-```
107107-108108-2. **Kill the process**:
109109-```bash
110110-sudo kill 265465
111111-```
112112-113113-**From the user's perspective**: Connection closes immediately
114114-```
115115-Connection to 192.168.195.100 closed by remote host.
116116-```
117117-118118-### Kill by Username (pkill)
119119-120120-```bash
121121-sudo pkill -kill -u jenny # Kill all processes for user jenny
122122-sudo pkill -kill -u bob # Kill all processes for user bob
123123-```
124124-125125-**Warning**: This kills ALL processes for that user, including:
126126-- Active SSH sessions
127127-- Running programs
128128-- Background jobs
129129-130130-### Kill Signal Types
131131-132132-```bash
133133-sudo kill PID # SIGTERM (graceful shutdown, default)
134134-sudo kill -9 PID # SIGKILL (force kill immediately)
135135-sudo pkill -kill -u user # -kill = SIGKILL
136136-```
137137-138138-## Competition Workflow
139139-140140-### Active Defense Pattern
141141-142142-1. **Someone monitors connections**:
143143-```bash
144144-# Run periodically or in a loop
145145-sudo netstat -tunap
146146-```
147147-148148-2. **Identify suspicious connections**:
149149-- Unknown IP addresses
150150-- Unexpected users logged in
151151-- Unusual ports
152152-153153-3. **Kill immediately**:
154154-```bash
155155-sudo pkill -kill -u <suspicious_user>
156156-# or
157157-sudo kill <PID>
158158-```
159159-160160-4. **Someone else hardens the system**:
161161-- Change passwords
162162-- Disable accounts
163163-- Configure firewall
164164-- Close unnecessary services
165165-166166-### Example Monitoring Script
167167-168168-```bash
169169-#!/bin/bash
170170-# Quick connection checker
171171-while true; do
172172- clear
173173- echo "=== Active SSH Connections ==="
174174- sudo netstat -tunap | grep :22 | grep ESTABLISHED
175175- sleep 5
176176-done
177177-```
178178-179179-## Common Scenarios
180180-181181-### Scenario 1: Unknown SSH Connection
182182-183183-```bash
184184-# See who's connected
185185-w
186186-187187-# Find their process ID
188188-sudo netstat -tunap | grep ESTABLISHED
189189-190190-# Kill by PID
191191-sudo kill 265465
192192-```
193193-194194-### Scenario 2: Brute Force Attempts
195195-196196-```bash
197197-# See all connection attempts
198198-sudo netstat -tunap | grep :22
199199-200200-# Check auth logs
201201-sudo tail -f /var/log/auth.log
202202-203203-# Block the source IP with firewall
204204-sudo ufw deny from <attacker_ip>
205205-```
206206-207207-### Scenario 3: Multiple Sessions from Same User
208208-209209-```bash
210210-# Kill all sessions for a user
211211-sudo pkill -kill -u jenny
212212-213213-# Disable the account
214214-sudo passwd -l jenny # Lock password
215215-sudo usermod -s /bin/false jenny # Disable shell
216216-```
217217-218218-## Warnings and Gotchas
219219-220220-### Don't Kill Yourself
221221-222222-```bash
223223-# BAD - if you're logged in as sandbox:
224224-sudo pkill -kill -u sandbox
225225-# This kills YOUR session too!
226226-```
227227-228228-**Better approach**: Kill by specific PID if you're using the same username.
229229-230230-### Don't Kill Teammates
231231-232232-- Check with team before killing connections
233233-- Look at FROM addresses to identify internal vs external
234234-- Local (`:0`) connections are usually teammates at the console
235235-236236-### Shared Accounts
237237-238238-If red team is using the same account as you:
239239-- Kill by PID (specific to their connection)
240240-- Don't kill by username (you'll disconnect yourself)
241241-242242-## Process Information Fields
243243-244244-**Understanding PID in netstat**:
245245-```bash
246246-sudo netstat -tunap
247247-```
248248-249249-Output:
250250-```
251251-PID/Program name
252252-265408/sshd: sandbox
253253-265465/sshd: jenny
254254-```
255255-256256-- PID: Process ID (unique number)
257257-- Program: Which service (sshd, apache2, etc.)
258258-- User context: Which user owns the process
259259-260260-## Monitoring vs. Hardening
261261-262262-**Active monitoring** (short-term):
263263-- Running netstat/ss repeatedly
264264-- Killing suspicious connections as they appear
265265-- Playing "whack-a-mole"
266266-267267-**Hardening** (long-term):
268268-- Change passwords
269269-- Disable unused accounts
270270-- Configure firewall rules
271271-- Close unnecessary services
272272-- Update vulnerable software
273273-274274-**Best practice**: Use monitoring to buy time while someone else hardens the system. You can't watch connections for 6 hours straight.
275275-276276-## Tool Availability
277277-278278-| Tool | Typical Availability |
279279-|------|---------------------|
280280-| netstat | Most systems (may need `net-tools` package) |
281281-| ss | Modern systems (usually pre-installed) |
282282-| w | All Unix/Linux systems |
283283-| top | All Unix/Linux systems |
284284-| htop | Optional (install with apt/yum) |
285285-| ps | All Unix/Linux systems |
286286-287287-**If netstat is missing**:
288288-```bash
289289-sudo apt install net-tools # Debian/Ubuntu
290290-sudo yum install net-tools # CentOS/RHEL
291291-```
292292-293293-Or just use `ss` instead.
+206
08-active-connection-defense.md
···11+# Active Connection Defense
22+33+Techniques for monitoring and terminating suspicious connections during competition.
44+55+---
66+77+## View Active Connections
88+99+### netstat Command
1010+1111+Basic usage (too much output):
1212+```bash
1313+netstat
1414+```
1515+1616+**Useful filtered version:**
1717+```bash
1818+netstat -tu # TCP and UDP connections only
1919+netstat -tun # + resolve port numbers (shows 22 instead of "ssh")
2020+netstat -tuna # + show listening ports too
2121+sudo netstat -tunap # + show process IDs (requires sudo)
2222+```
2323+2424+**Remember: `netstat -tunap`** (tuna + p)
2525+2626+| Flag | Meaning |
2727+|------|---------|
2828+| `-t` | TCP connections |
2929+| `-u` | UDP connections |
3030+| `-n` | Show port numbers (not names) |
3131+| `-a` | Show all (including listening) |
3232+| `-p` | Show process IDs (requires sudo) |
3333+3434+Example output:
3535+```
3636+Proto Local Address Foreign Address State PID/Program
3737+tcp 192.168.8.2:22 192.168.8.100:51736 ESTABLISHED 26546/sshd: jenny
3838+tcp 192.168.8.2:22 192.168.8.100:51732 ESTABLISHED 26540/sshd: bob
3939+```
4040+4141+### Filter with grep
4242+```bash
4343+sudo netstat -tunap | grep ESTABLISHED
4444+sudo netstat -tunap | grep ssh
4545+```
4646+4747+### ss Command (alternative to netstat)
4848+4949+Some systems don't have netstat - use `ss` instead:
5050+```bash
5151+ss
5252+ss -t # TCP only
5353+ss | grep ESTABLISHED
5454+```
5555+5656+---
5757+5858+## View Logged-In Users
5959+6060+### w Command
6161+```bash
6262+w
6363+```
6464+6565+Shows:
6666+- Username
6767+- TTY (terminal)
6868+- From (IP address for remote, `:0` for local GUI)
6969+- Login time
7070+- What they're running
7171+7272+Example output:
7373+```
7474+USER TTY FROM LOGIN@ WHAT
7575+sandbox :0 :0 09:00 /usr/bin/gnome-shell <- Local GUI
7676+bob pts/1 192.168.8.100 10:15 -bash <- Remote SSH
7777+jenny pts/2 192.168.8.100 10:16 -bash <- Remote SSH
7878+```
7979+8080+**Note:** `:0` means local GUI session (probably your teammate), IP address means remote connection (possibly attacker).
8181+8282+---
8383+8484+## Kill Connections
8585+8686+### Kill by Process ID
8787+8888+1. Find the PID with `netstat -tunap`
8989+2. Kill it:
9090+```bash
9191+sudo kill <PID>
9292+```
9393+9494+Example:
9595+```bash
9696+sudo netstat -tunap | grep ESTABLISHED
9797+# See jenny's connection has PID 26546
9898+sudo kill 26546
9999+```
100100+101101+### Kill by Username
102102+103103+Log out all sessions for a specific user:
104104+```bash
105105+sudo pkill -kill -u jenny
106106+sudo pkill -kill -u bob
107107+```
108108+109109+**⚠️ WARNING: Don't kill yourself!**
110110+```bash
111111+sudo pkill -kill -u sandbox # This kills YOUR session too!
112112+```
113113+114114+If attacker is using the same account as you, kill by PID instead.
115115+116116+---
117117+118118+## Monitor Processes
119119+120120+### top Command
121121+```bash
122122+top # Live view of running processes
123123+htop # Fancier version (may need to install)
124124+```
125125+126126+Press `q` to quit.
127127+128128+### ps Command
129129+```bash
130130+ps -aux # Show all processes with details
131131+ps -aux | grep python # Find Python scripts
132132+ps -aux | grep bash # Find bash scripts
133133+```
134134+135135+Look for suspicious scripts running in background (attackers may leave these).
136136+137137+---
138138+139139+## Send Messages to Users
140140+141141+### Broadcast to All Users
142142+```bash
143143+wall "Server shutting down in 5 minutes. Please save your work."
144144+```
145145+146146+All logged-in users see the message in their terminal.
147147+148148+### Message Specific User
149149+```bash
150150+w # Find their TTY (e.g., pts/2)
151151+sudo write bob pts/2 # Opens interactive message
152152+# Type your message, Ctrl+C to end
153153+```
154154+155155+---
156156+157157+## Competition Strategy
158158+159159+### Active Defense Workflow
160160+161161+1. **Monitor continuously:**
162162+ ```bash
163163+ sudo netstat -tunap | grep ESTABLISHED
164164+ w
165165+ ```
166166+167167+2. **Identify suspicious connections:**
168168+ - Unknown usernames
169169+ - Connections from unexpected IPs
170170+ - Multiple sessions from same IP
171171+172172+3. **Kill suspicious connections:**
173173+ ```bash
174174+ sudo kill <PID> # By process ID
175175+ sudo pkill -kill -u <user> # By username
176176+ ```
177177+178178+4. **Meanwhile, teammate secures server:**
179179+ - Change passwords
180180+ - Lock down user accounts
181181+ - Enable firewall
182182+ - Remove unnecessary services
183183+184184+### Watch Out For
185185+186186+- **Background scripts**: Attackers may leave Python/bash scripts running
187187+ ```bash
188188+ ps -aux | grep python
189189+ ps -aux | grep bash
190190+ ```
191191+- **Cron jobs**: Check `crontab -l` and `/etc/cron.*`
192192+- **Friendly fire**: Don't kill your own sessions or teammates!
193193+194194+---
195195+196196+## Quick Reference
197197+198198+| Task | Command |
199199+|------|---------|
200200+| View connections | `sudo netstat -tunap` |
201201+| View logged-in users | `w` |
202202+| Kill by PID | `sudo kill <PID>` |
203203+| Kill by username | `sudo pkill -kill -u <user>` |
204204+| View processes | `ps -aux` or `top` |
205205+| Broadcast message | `wall "message"` |
206206+| Message specific user | `sudo write <user> <tty>` |