Aufgabe Security Audit für Kuno
Part 1: Security Audit Preparation
⏱️ Duration: 25 minutes
Create an audit directory structure
sudo mkdir -p /audit/{logs,reports,backups,scripts}
sudo mkdir -p /audit/logs/{user_activity,permission_changes,system_access}User Account Audit
Find all users with sudo privileges
grep -Po '^sudo.+:\K.*$' /etc/groupList all users with their UID and home directory
cat /etc/passwd | cut -d: -f1,3,6Find users who haven't changed their password recently
sudo cat /etc/shadow | cut -d: -f1,3Create a custom report file
Create: /audit/reports/user_audit_$(date +%Y%m%d).txt
Requirements:
Include: username, UID, group memberships, home directory, login shell
Use redirection:
command > file.txt
Part 2: Permission Security Scan
⏱️ Duration: 30 minutes
Dangerous Permission Detection
Find all world-writable files (security risk)
sudo find /home -type f -perm -002 -lsFind files with no owner
sudo find /home -nouser -o -nogroupFind SUID/SGID executables (potential security risk)
sudo find / -type f \( -perm -4000 -o -perm -2000 \) 2>/dev/nullFind files modified in the last 24 hours
sudo find /etc -type f -mtime -1Advanced Permission Analysis Tasks
Task 1: Create a file /audit/reports/permission_security_scan.txt containing:
Count of world-writable files
List of all SUID binaries
Files in
/tmpolder than 7 days
Task 2: Use pipes to filter and count
find /home -type f -perm -002 | wc -lTask 3: Combine multiple commands
ls -la /etc/ | grep "^d" | wc -l # Count directoriesPart 3: Automated User Management Script
⏱️ Duration: 25 minutes
Create a bash script: /audit/scripts/user_report.sh
/audit/scripts/user_report.sh#!/bin/bash
# User Report Generator
# Date: $(date)
echo "=== SYSTEM USER AUDIT REPORT ==="
echo "Generated on: $(date '+%Y-%m-%d %H:%M:%S')"
echo "================================"
echo ""
echo "Total number of users:"
cat /etc/passwd | wc -l
echo ""
echo "Users with login shells (excluding system users):"
grep -E "/bin/bash$|/bin/sh$" /etc/passwd | cut -d: -f1
echo ""
echo "Groups and their members:"
cat /etc/group | grep -E "developers|testers|management"
echo ""
echo "Recently modified files in /etc (last 7 days):"
sudo find /etc -type f -mtime -7 -printf "%T+ %p\n" | sort | head -10
echo ""
echo "Disk usage by home directories:"
sudo du -sh /home/* 2>/dev/null
echo ""Script Requirements
Make the script executable:
chmod +x /audit/scripts/user_report.shRun it and redirect output:
./user_report.sh > /audit/reports/daily_report.txtAdd error handling using
2>/dev/nullto suppress errorsUse variables to make it more flexible:
REPORT_DIR="/audit/reports"
REPORT_FILE="$REPORT_DIR/report_$(date +%Y%m%d).txt"Part 4: Advanced Command Combinations
⏱️ Duration: 10 minutes
Practice complex pipe operations
Find top 5 largest files in /home
sudo find /home -type f -exec du -h {} + | sort -rh | head -5Count files by extension
find /home -type f | sed 's/.*\.//' | sort | uniq -c | sort -rnList users sorted by UID
cat /etc/passwd | sort -t: -k3 -n | cut -d: -f1,3Find and display permissions for all .conf files
sudo find /etc -name "*.conf" -exec ls -lh {} \; | head -20Challenges with grep and awk
Extract only IP addresses from system logs (if available)
Find all lines in
/etc/groupcontaining "alice" OR "bob"Count how many users have
/bin/bashas their shell
Part 5: System Monitoring and Logs (Bonus)
⏱️ Duration: 15 minutes
System Investigation Tasks
Check system resource usage
Install and run
htop(from Day 3 content)
sudo apt install htop
htopUse
df -hto check disk spaceUse
free -hto check memory usage
Process investigation
ps aux | grep firefox
ps -ef --forest # Show process treeCheck for failed login attempts
sudo grep "Failed password" /var/log/auth.log | tail -20Monitor system logs in real-time
sudo tail -f /var/log/syslogDeliverables
Submit the following for assessment:
✅ A working
/audit/scripts/user_report.shscript with comments✅ Complete
/audit/reports/permission_security_scan.txtwith findings✅ A markdown document explaining:
3 security risks you discovered
How to fix each risk
Which commands you used to find them
✅ Screenshot showing the output of your script
✅ Answers to:
"Why is it dangerous to have world-writable files?"
"What is the SUID bit and why is it a security concern?"
Expandable: Suggested answers (for reference)
Assessment Criteria
Correctness
40%
Do the permissions and configurations work as specified?
Understanding
30%
Can you explain why certain permissions are used?
Documentation
20%
Are your commands and solutions well-documented?
Problem-solving
10%
Did you identify and fix issues independently?
Common Pitfalls:
Forgetting to use
sudofor system-level operationsNot handling errors properly in scripts (use
2>/dev/null)Missing the
-aflag when appending to files with>>Not making scripts executable with
chmod +x