-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathgvm-check-setup
More file actions
executable file
·299 lines (257 loc) · 8.43 KB
/
Copy pathgvm-check-setup
File metadata and controls
executable file
·299 lines (257 loc) · 8.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/bin/bash
# Greenbone Community Edition Setup Check Script
# Compatible with Greenbone Community Edition 22.4+
#
# This script checks the completeness and readiness of the modern
# Greenbone Community Edition (GCE) installation.
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
LOG=/tmp/gvm-check-setup.log
CHECKVERSION=1.0.0
# Initialize log file
echo "gvm-check-setup $CHECKVERSION" > $LOG
echo " Date: $(date -R)" >> $LOG
echo "" >> $LOG
log_and_print() {
echo -e " $1"
echo " $1" >> $LOG
}
log_section() {
echo ""
echo -e "${BLUE}$1${NC}"
echo "$1" >> $LOG
}
log_ok() {
echo -e " ${GREEN}[OK]${NC} $1"
echo " [OK] $1" >> $LOG
}
log_warn() {
echo -e " ${YELLOW}[WARN]${NC} $1"
echo " [WARN] $1" >> $LOG
}
log_error() {
echo -e " ${RED}[ERROR]${NC} $1"
echo " [ERROR] $1" >> $LOG
}
check_failed() {
echo ""
echo -e "${RED}ERROR: Your Greenbone Community Edition installation is not yet complete!${NC}"
echo ""
echo "Please follow the instructions marked with FIX above and run this"
echo "script again."
echo ""
echo "Send us the log-file ($LOG) to help analyze the problem."
echo ""
exit 1
}
echo "======================================"
echo "gvm-check-setup $CHECKVERSION"
echo "Greenbone Community Edition Setup Check"
echo "======================================"
echo ""
# ============================================================================
# Step 1: Check for required binaries
# ============================================================================
log_section "Step 1: Checking required binaries..."
check_binary() {
local binary=$1
local package=$2
if command -v "$binary" &> /dev/null; then
log_ok "$binary found"
return 0
else
log_error "$binary not found"
log_and_print "FIX: Install $package"
return 1
fi
}
REQUIRED_BINS=(
"openvas:openvas-scanner"
"ospd-openvas:ospd-openvas"
"gvmd:gvmd"
"gsad:gsad"
"greenbone-feed-sync:greenbone-feed-sync"
"redis-server:redis-server"
"pg_isready:postgresql"
)
MISSING_BINS=0
for item in "${REQUIRED_BINS[@]}"; do
IFS=':' read -r binary package <<< "$item"
if ! check_binary "$binary" "$package"; then
MISSING_BINS=$((MISSING_BINS + 1))
fi
done
if [ $MISSING_BINS -gt 0 ]; then
check_failed
fi
# ============================================================================
# Step 2: Check Redis configuration
# ============================================================================
log_section "Step 2: Checking Redis configuration..."
REDIS_SOCKET="/run/redis-openvas/redis.sock"
if [ -S "$REDIS_SOCKET" ]; then
log_ok "Redis socket exists at $REDIS_SOCKET"
else
log_error "Redis socket not found at $REDIS_SOCKET"
log_and_print "FIX: Start Redis with: systemctl start redis-server@openvas.service"
check_failed
fi
# Check if Redis is responding
if redis-cli -s "$REDIS_SOCKET" ping &>/dev/null; then
log_ok "Redis is responding on socket"
else
log_error "Redis is not responding on socket"
log_and_print "FIX: Check Redis status with: systemctl status redis-server@openvas.service"
check_failed
fi
# ============================================================================
# Step 3: Check PostgreSQL
# ============================================================================
log_section "Step 3: Checking PostgreSQL..."
if pg_isready &>/dev/null; then
log_ok "PostgreSQL is running"
else
log_error "PostgreSQL is not running"
log_and_print "FIX: Start PostgreSQL with: systemctl start postgresql"
check_failed
fi
# Check if gvmd database exists
if sudo -u postgres psql -lqt | cut -d \| -f 1 | grep -qw gvmd; then
log_ok "gvmd database exists"
else
log_error "gvmd database not found"
log_and_print "FIX: Create database with: sudo -u postgres createdb -O gvm gvmd"
check_failed
fi
# ============================================================================
# Step 4: Check directory permissions
# ============================================================================
log_section "Step 4: Checking directory permissions..."
REQUIRED_DIRS=(
"/var/lib/gvm"
"/var/lib/openvas"
"/var/lib/notus"
"/var/log/gvm"
"/run/gvmd"
"/run/ospd"
"/etc/openvas"
)
for dir in "${REQUIRED_DIRS[@]}"; do
if [ -d "$dir" ]; then
log_ok "Directory $dir exists"
else
log_error "Directory $dir does not exist"
log_and_print "FIX: Create directory with: mkdir -p $dir"
check_failed
fi
done
# Check gvm user
if id "gvm" &>/dev/null; then
log_ok "gvm user exists"
else
log_error "gvm user does not exist"
log_and_print "FIX: Create user with: useradd -r -M -U -s /usr/sbin/nologin gvm"
check_failed
fi
# ============================================================================
# Step 5: Check GPG setup for feed validation
# ============================================================================
log_section "Step 5: Checking GPG setup for feed validation..."
GPG_DIR="/etc/openvas/gnupg"
if [ -d "$GPG_DIR" ] && [ "$(ls -A $GPG_DIR)" ]; then
log_ok "GPG directory exists and is not empty"
else
log_warn "GPG directory not properly configured"
log_and_print "SUGGEST: Run the setup script to configure GPG"
fi
# ============================================================================
# Step 6: Check services
# ============================================================================
log_section "Step 6: Checking services..."
check_service() {
local service=$1
if systemctl list-unit-files | grep -q "^${service}.service"; then
if systemctl is-active --quiet "$service" 2>/dev/null; then
log_ok "$service is running"
return 0
else
log_warn "$service is not running"
log_and_print "SUGGEST: Start with: systemctl start $service"
return 1
fi
else
log_warn "$service service file not found"
return 1
fi
}
# Check services (some may be optional)
check_service "openvasd" || true
check_service "ospd-openvas" || true
check_service "gvmd" || true
check_service "gsad" || true
# ============================================================================
# Step 7: Check feed data
# ============================================================================
log_section "Step 7: Checking feed data..."
# Check NVT directory
NVT_DIR="/var/lib/openvas/plugins"
if [ -d "$NVT_DIR" ]; then
NVT_COUNT=$(find "$NVT_DIR" -name "*.nasl" 2>/dev/null | wc -l)
if [ "$NVT_COUNT" -gt 1000 ]; then
log_ok "NVT collection contains $NVT_COUNT scripts"
else
log_warn "NVT collection seems small ($NVT_COUNT scripts)"
log_and_print "SUGGEST: Run greenbone-feed-sync to update feeds"
fi
else
log_error "NVT directory not found at $NVT_DIR"
log_and_print "FIX: Run greenbone-feed-sync to download feeds"
fi
# Check Notus advisories
NOTUS_DIR="/var/lib/notus/advisories"
if [ -d "$NOTUS_DIR" ]; then
log_ok "Notus advisories directory exists"
else
log_warn "Notus advisories directory not found"
log_and_print "SUGGEST: Run greenbone-feed-sync to update Notus data"
fi
# ============================================================================
# Step 8: Check users
# ============================================================================
log_section "Step 8: Checking users..."
if command -v gvmd &> /dev/null; then
USER_COUNT=$(gvmd --get-users 2>/dev/null | wc -l)
if [ "$USER_COUNT" -gt 0 ]; then
log_ok "Found $USER_COUNT user(s) in gvmd"
else
log_error "No users found in gvmd"
log_and_print "FIX: Create a user with: gvmd --create-user=admin"
check_failed
fi
fi
# ============================================================================
# Summary
# ============================================================================
echo ""
echo "======================================"
echo "Check Complete!"
echo "======================================"
echo ""
if [ -s $LOG ]; then
echo "Log file saved to: $LOG"
fi
echo ""
echo "Your Greenbone Community Edition installation appears to be correctly set up."
echo ""
echo "You can access the web interface at:"
echo " http://127.0.0.1:9392"
echo ""
echo "To manage services:"
echo " ./openvas-start - Start all services"
echo " ./openvas-stop - Stop all services"
echo ""