Added example files and tutorial

This commit is contained in:
Matt Joyce
2024-12-05 22:09:47 +11:00
parent c49f47ecab
commit d8671ea03a
10 changed files with 265 additions and 0 deletions

View File

Binary file not shown.

View File

@@ -0,0 +1,24 @@
#!/bin/bash
# remote-security-report.sh
# Usage: remote-security-report.sh cert host [report_name]
cert_path="$1"
host="$2"
report_name="${3:-report}"
temp_file="/tmp/security-report-${report_name}.txt"
# Copy the security report script to remote host
scp -i "$cert_path" /usr/local/bin/security-report.sh "${host}:~/security-report.sh" >&2
# Make it executable and run it on remote host
ssh -i "$cert_path" "$host" "chmod +x ~/security-report.sh && sudo ~/security-report.sh ${temp_file}" >&2
# Copy the report back
scp -i "$cert_path" "${host}:${temp_file}" "${temp_file}" >&2
# Cleanup remote files
ssh -i "$cert_path" "$host" "rm ~/security-report.sh ${temp_file}" >&2
# Output the local file path for fabric to read
echo "${temp_file}"

View File

@@ -0,0 +1,17 @@
name: "remote-security"
executable: "/usr/local/bin/remote-security-report.sh"
type: "executable"
timeout: "60s"
description: "Generate security report from remote system"
operations:
report:
cmd_template: "{{executable}} {{1}} {{2}} {{3}}"
config:
output:
method: "file"
file_config:
cleanup: true
path_from_stdout: true
work_dir: "/tmp"

View File

@@ -0,0 +1,113 @@
#!/bin/bash
# security-report.sh - Enhanced system security information collection
# Usage: security-report.sh [output_file]
output_file=${1:-/tmp/security-report.txt}
{
echo "=== System Security Report ==="
echo "Generated: $(date)"
echo "Hostname: $(hostname)"
echo "Kernel: $(uname -r)"
echo
echo "=== System Updates ==="
echo "Last update: $(stat -c %y /var/cache/apt/pkgcache.bin | cut -d' ' -f1)"
echo "Pending updates:"
apt list --upgradable 2>/dev/null
echo -e "\n=== Security Updates ==="
echo "Pending security updates:"
apt list --upgradable 2>/dev/null | grep -i security
echo -e "\n=== User Accounts ==="
echo "Users with login shells:"
grep -v '/nologin\|/false' /etc/passwd
echo -e "\nUsers who can login:"
awk -F: '$2!="*" && $2!="!" {print $1}' /etc/shadow
echo -e "\nUsers with empty passwords:"
awk -F: '$2=="" {print $1}' /etc/shadow
echo -e "\nUsers with UID 0:"
awk -F: '$3==0 {print $1}' /etc/passwd
echo -e "\n=== Sudo Configuration ==="
echo "Users/groups with sudo privileges:"
grep -h '^[^#]' /etc/sudoers.d/* /etc/sudoers 2>/dev/null
echo -e "\nUsers with passwordless sudo:"
grep -h NOPASSWD /etc/sudoers.d/* /etc/sudoers 2>/dev/null
echo -e "\n=== SSH Configuration ==="
if [ -f /etc/ssh/sshd_config ]; then
echo "Key SSH settings:"
grep -E '^(PermitRootLogin|PasswordAuthentication|Port|Protocol|X11Forwarding|MaxAuthTries|PermitEmptyPasswords)' /etc/ssh/sshd_config
fi
echo -e "\n=== SSH Keys ==="
echo "Authorized keys found:"
find /home -name "authorized_keys" -ls 2>/dev/null
echo -e "\n=== Firewall Status ==="
echo "UFW Status:"
ufw status verbose
echo -e "\nIPTables Rules:"
iptables -L -n
echo -e "\n=== Network Services ==="
echo "Listening services (port - process):"
netstat -tlpn 2>/dev/null | grep LISTEN
echo -e "\n=== Recent Authentication Failures ==="
echo "Last 5 failed SSH attempts:"
grep "Failed password" /var/log/auth.log | tail -5
echo -e "\n=== File Permissions ==="
echo "World-writable files in /etc:"
find /etc -type f -perm -002 -ls 2>/dev/null
echo -e "\nWorld-writable directories in /etc:"
find /etc -type d -perm -002 -ls 2>/dev/null
echo -e "\n=== System Resource Usage ==="
echo "Disk Usage:"
df -h
echo -e "\nMemory Usage:"
free -h
echo -e "\nTop 5 CPU-using processes:"
ps aux --sort=-%cpu | head -6
echo -e "\n=== System Timers ==="
echo "Active timers (potential scheduled tasks):"
systemctl list-timers --all
echo -e "\n=== Important Service Status ==="
for service in ssh ufw apparmor fail2ban clamav-freshclam; do
echo "Status of $service:"
systemctl status $service --no-pager 2>/dev/null
done
echo -e "\n=== Fail2Ban Logs ==="
echo "Recent Fail2Ban activity (fail2ban.log):"
if [ -f /var/log/fail2ban.log ]; then
echo "=== Current log (fail2ban.log) ==="
cat /var/log/fail2ban.log
else
echo "fail2ban.log not found"
fi
if [ -f /var/log/fail2ban.log.1 ]; then
echo -e "\n=== Previous log (fail2ban.log.1) ==="
cat /var/log/fail2ban.log.1
else
echo -e "\nfail2ban.log.1 not found"
fi
echo -e "\n=== Fail2Ban Status ==="
echo "Currently banned IPs:"
sudo fail2ban-client status
} > "$output_file"
# Output the file path for fabric to read
echo "$output_file"

View File

@@ -0,0 +1,18 @@
name: "security-report"
executable: "/usr/local/bin/security-report.sh"
type: "executable"
timeout: "30s"
description: "Generate system security report"
version: "1.0.0"
operations:
generate:
cmd_template: "{{executable}} /tmp/security-report-{{1}}.txt"
config:
output:
method: "file"
file_config:
cleanup: true
path_from_stdout: true
work_dir: "/tmp"

View File

@@ -0,0 +1,23 @@
name: memory-query
executable: /usr/bin/sqlite3
type: executable
timeout: "5s"
description: "Query memories database"
version: "1.0.0"
env: []
operations:
goal:
cmd_template: "{{executable}} -json /home/matt/memories.db \"select * from memories where type= 'goal'\""
value:
cmd_template: "{{executable}} -json /home/matt/memories.db \"select * from memories where type= 'value'\""
project:
cmd_template: "{{executable}} -json /home/matt/memories.db \"select * from memories where type= 'project'\""
byid:
cmd_template: "{{executable}} -json /home/matt/memories.db \"select * from memories where uid= {{value}}\""
all:
cmd_template: "{{executable}} -json ~/memories.db \"select * from memories\""
config:
output:
method: stdout

View File

@@ -0,0 +1,18 @@
#!/bin/bash
LOG_DIR="/var/log/package_tracking"
DATE=$(date +%Y%m%d)
# Ensure directory exists
mkdir -p "$LOG_DIR"
# Current package list
dpkg -l > "$LOG_DIR/packages_current.list"
# Create diff if previous exists
if [ -f "$LOG_DIR/packages_previous.list" ]; then
diff "$LOG_DIR/packages_previous.list" "$LOG_DIR/packages_current.list" > "$LOG_DIR/changes_current.diff"
fi
# Keep copy for next comparison
cp "$LOG_DIR/packages_current.list" "$LOG_DIR/packages_previous.list"

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python3
import sys
import json
import random
# A small set of words for demonstration!
WORD_LIST = [
"apple", "banana", "cherry", "date", "elderberry",
"fig", "grape", "honeydew", "kiwi", "lemon",
"mango", "nectarine", "orange", "papaya", "quince",
"raspberry", "strawberry", "tangerine", "ugli", "watermelon"
]
def generate_words(count):
try:
count = int(count)
if count < 1:
return json.dumps({"error": "Count must be positive"})
# Generate random words
words = random.sample(WORD_LIST, min(count, len(WORD_LIST)))
# Return JSON formatted result
return json.dumps({
"words": words,
"count": len(words)
})
except ValueError:
return json.dumps({"error": "Invalid count parameter"})
if __name__ == "__main__":
if len(sys.argv) != 2:
print(json.dumps({"error": "Exactly one argument required"}))
sys.exit(1)
print(generate_words(sys.argv[1]))

View File

@@ -0,0 +1,16 @@
name: word-generator
executable: /usr/local/bin/word-generator.py
type: executable
timeout: "5s"
description: "Generates random words based on count parameter"
version: "1.0.0"
env: []
operations:
generate:
cmd_template: "{{executable}} {{value}}"
config:
output:
method: stdout