mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-10 06:48:04 -05:00
Added example files and tutorial
This commit is contained in:
0
plugins/template/Examples/README.md
Normal file
0
plugins/template/Examples/README.md
Normal file
BIN
plugins/template/Examples/memories.db
Normal file
BIN
plugins/template/Examples/memories.db
Normal file
Binary file not shown.
24
plugins/template/Examples/remote-security-report.sh
Executable file
24
plugins/template/Examples/remote-security-report.sh
Executable 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}"
|
||||
|
||||
17
plugins/template/Examples/remote-security-report.yaml
Normal file
17
plugins/template/Examples/remote-security-report.yaml
Normal 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"
|
||||
113
plugins/template/Examples/security-report.sh
Executable file
113
plugins/template/Examples/security-report.sh
Executable 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"
|
||||
|
||||
18
plugins/template/Examples/security-report.yaml
Normal file
18
plugins/template/Examples/security-report.yaml
Normal 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"
|
||||
23
plugins/template/Examples/sqlite3_demo.yaml
Normal file
23
plugins/template/Examples/sqlite3_demo.yaml
Normal 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
|
||||
18
plugins/template/Examples/track_packages.sh
Executable file
18
plugins/template/Examples/track_packages.sh
Executable 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"
|
||||
36
plugins/template/Examples/word-generator.py
Executable file
36
plugins/template/Examples/word-generator.py
Executable 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]))
|
||||
16
plugins/template/Examples/word-generator.yaml
Normal file
16
plugins/template/Examples/word-generator.yaml
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user