Skip to content

Commit f4d55ad

Browse files
committed
feat: create starter audit script
0 parents  commit f4d55ad

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.log

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Basic Linux audit script
2+
3+
## How to run
4+
5+
```sh
6+
chmod +x sys-audit.sh
7+
./sys-audit.sh
8+
```

sys-audit.sh

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# Define output file
4+
OUTPUT_FILE="system_audit_$(date +%Y%m%d_%H%M%S).log"
5+
6+
echo "Starting System Audit..." | tee -a $OUTPUT_FILE
7+
8+
# System Information
9+
echo "Gathering System Information..." | tee -a $OUTPUT_FILE
10+
hostname | tee -a $OUTPUT_FILE
11+
uname -a | tee -a $OUTPUT_FILE
12+
cat /etc/os-release | tee -a $OUTPUT_FILE
13+
14+
# Disk Usage
15+
echo "Checking Disk Usage..." | tee -a $OUTPUT_FILE
16+
df -h | tee -a $OUTPUT_FILE
17+
18+
# Packages
19+
echo "Listing Installed Packages..." | tee -a $OUTPUT_FILE
20+
21+
detect_package_manager() {
22+
if command -v dpkg &> /dev/null; then
23+
echo "dpkg"
24+
elif command -v pacman &> /dev/null; then
25+
echo "pacman"
26+
elif command -v rpm &> /dev/null; then
27+
echo "rpm"
28+
else
29+
echo "unknown"
30+
fi
31+
}
32+
33+
PACKAGE_MANAGER=$(detect_package_manager)
34+
35+
case $PACKAGE_MANAGER in
36+
dpkg)
37+
dpkg -l | tee -a $OUTPUT_FILE
38+
;;
39+
pacman)
40+
pacman -Q | tee -a $OUTPUT_FILE
41+
;;
42+
rpm)
43+
rpm -qa | tee -a $OUTPUT_FILE
44+
;;
45+
*)
46+
echo "Unsupported package manager" | tee -a $OUTPUT_FILE
47+
;;
48+
esac
49+
50+
# Network Information
51+
echo "Gathering Network Information..." | tee -a $OUTPUT_FILE
52+
ip address | tee -a $OUTPUT_FILE
53+
ss -plants | tee -a $OUTPUT_FILE
54+
55+
# Open Ports
56+
echo "Checking Open Ports..." | tee -a $OUTPUT_FILE
57+
lsof -i -P -n | grep LISTEN | tee -a $OUTPUT_FILE
58+
59+
# Active Connections
60+
echo "Listing Active Connections..." | tee -a $OUTPUT_FILE
61+
ss -tunap | tee -a $OUTPUT_FILE
62+
63+
# Users and Groups
64+
echo "Listing Users and Groups..." | tee -a $OUTPUT_FILE
65+
cat /etc/passwd | tee -a $OUTPUT_FILE
66+
cat /etc/group | tee -a $OUTPUT_FILE
67+
68+
# Scheduled Tasks
69+
echo "Listing Scheduled Tasks..." | tee -a $OUTPUT_FILE
70+
crontab -l | tee -a $OUTPUT_FILE
71+
ls /etc/cron.* | tee -a $OUTPUT_FILE
72+
73+
# File System Tree
74+
echo "Generating File System Tree..." | tee -a $OUTPUT_FILE
75+
tree / -L 2 | tee -a $OUTPUT_FILE
76+
77+
echo "System Audit Completed. Results saved in $OUTPUT_FILE"

0 commit comments

Comments
 (0)