-
Notifications
You must be signed in to change notification settings - Fork 19
/
openvas_commander.sh
290 lines (250 loc) · 8.23 KB
/
openvas_commander.sh
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
#!/bin/bash
function install_dependencies()
{
apt-get install -y build-essential devscripts dpatch curl libassuan-dev libglib2.0-dev libgpgme11-dev libpcre3-dev libpth-dev libwrap0-dev libgmp-dev libgmp3-dev libgpgme11-dev libpcre3-dev libpth-dev quilt cmake pkg-config libssh-dev libglib2.0-dev libpcap-dev libgpgme11-dev uuid-dev bison libksba-dev doxygen sqlfairy xmltoman sqlite3 libsqlite3-dev wamerican redis-server libhiredis-dev libsnmp-dev libmicrohttpd-dev libxml2-dev libxslt1-dev xsltproc libssh2-1-dev libldap2-dev autoconf nmap libgnutls28-dev gnutls-bin libpopt-dev heimdal-dev heimdal-multidev libpopt-dev mingw32 texlive-full rpm alien nsis rsync python2.7 python-setuptools checkinstall
}
function configure_redis()
{
if [ ! -f /etc/redis/redis.orig ]; then
cp /etc/redis/redis.conf /etc/redis/redis.orig
echo "unixsocket /tmp/redis.sock" >> /etc/redis/redis.conf
service redis-server restart
fi
}
function get_openvas_source_table()
{
curl -s http://openvas.org/install-source.html | sed -e ':a;N;$!ba;s/\n/ /g' -e 's/.*<table class="dl_table"//' -e 's/<\/table>.*//' -e 's/<tr>/\n<tr>/g' | grep "<tr>" | grep -v "bgcolor" | sed -e 's/[ \t]*<\/t[dh]>[ \t]*/|/g' -e 's/"[ \t]*>[^<]*<\/a>//g' -e 's/<a href="//g' -e 's/[ \t]*<[/]*t[rdh]>[ \t]*//g' -e 's/|$//' | grep -v "Supports OMP "
}
function get_available_source_sets()
{
get_openvas_source_table | head -n 1 | sed 's/|/\n/g'
}
function check_releas_name()
{
local release_name="$1"
is_available=`get_available_source_sets | grep "^$release_name$"`
if [ "$is_available" == "" ]
then
echo "wrong release name"
else
echo "ok"
fi
}
function get_source_set()
{
local release_name="$1"
col=`get_available_source_sets | awk -v name="$release_name" '{ if ( $0 == name ){print NR}}'`
echo "$openvas_source_table" | awk -F"|" -v col="$col" '{ if ( NR != 1 && $1 != "" && $col != "" ){print $col}}'
}
function download_source_set()
{
mkdir openvas 2>/dev/null
cd openvas/
get_source_set "$release_name" | xargs -i wget '{}'
cd ../
}
function create_folders()
{
cd openvas/
find | grep ".tar.gz$" | xargs -i tar zxvfp '{}'
cd ../
}
function install_component()
{
local component="$1"
cd openvas
cd $component-*
mkdir build
cd build
cmake ..
make
make doc-full
version=`pwd | sed 's/\//\n/g' | grep "$component" | sed "s/$component-//"`
checkinstall --pkgname "$component" --pkgversion "$version" --maintainer "openvas_commander" -y
cd ../../../
}
function mkcerts()
{
openvas-mkcert 2>/dev/null
openvas-mkcert-client -n -i 2>/dev/null
openvas-manage-certs -a 2>/dev/null
}
function print_help()
{
echo "Usage: ./openvas_commander.sh OPTION [PARAM]
Installing dependencies:
--install-dependencies install Debian packages
Getting data from openvas.org:
--show-releases show release version, e.g. OpenVAS-9
--show-sources RELEASE show RELEASE source archives
--download-sources RELEASE download RELEASE sources archives
Process software components:
--create-folders create folders for sources archives
--install-all install all components
--install-component COMPONENT install COMPONENT
--uninstall-all uninstall all components
--uninstall-component COMPONENT uninstall COMPONENT
Configuration:
--configure-all configure all components
--delete-admin delete OpenVAS admin account
Process software components:
--update-content update OpenVAS NVT, OVAL and CERT content
--update-content-nvt update only OpenVAS NVT content
--rebuild-content rebuild database
Manage processes:
--start-all start openvasmd, openvassd and gsad processes
use --check-proc to make sure that processes ready
--kill-all kill openvasmd, openvassd and gsad processes
--check-proc check state of openvasmd, openvassd and gsad processes
Check installation status:
--check-status [VERSION] download and run openvas-check-setup tool
\"v9\" by default
Other:
--help, -h, ? help page"
}
#################################
release_name="$1"
openvas_source_table=`get_openvas_source_table`
if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ "$1" == "?" ]
then
print_help
elif [ "$1" == "--install-dependencies" ]
then
install_dependencies
elif [ "$1" == "--show-releases" ]
then
get_available_source_sets
elif [ "$1" == "--show-sources" ]
then
release_name="$2"
check=`check_releas_name "$release_name"`
if [ "$check" == "ok" ]
then
get_source_set "$release_name"
else
echo "$check"
fi
elif [ "$1" == "--download-sources" ]
then
release_name="$2"
check=`check_releas_name "$release_name"`
if [ "$check" == "ok" ]
then
download_source_set "$release_name"
else
echo "$check"
fi
elif [ "$1" == "--create-folders" ]
then
create_folders
elif [ "$1" == "--uninstall-all" ]
then
dpkg -r "openvas-smb"
dpkg -r "openvas-libraries"
dpkg -r "openvas-scanner"
dpkg -r "openvas-manager"
dpkg -r "openvas-cli"
dpkg -r "greenbone-security-assistant"
elif [ "$1" == "--install-all" ]
then
install_component "openvas-smb"
install_component "openvas-libraries"
install_component "openvas-scanner"
install_component "openvas-manager"
install_component "openvas-cli"
install_component "greenbone-security-assistant"
elif [ "$1" == "--install-component" ]
then
install_component "$2"
elif [ "$1" == "--uninstall-component" ]
then
dpkg -r "$2"
elif [ "$1" == "--configure-all" ]
then
mkdir /usr/local/var/lib/openvas/openvasmd/
mkdir /usr/local/var/lib/openvas/openvasmd/gnupg
configure_redis
mkcerts
ldconfig
openvasmd --create-user=admin --role=Admin && openvasmd --user=admin --new-password=1
elif [ "$1" == "--delete-admin" ]
then
openvasmd --delete-user=admin
elif [ "$1" == "--update-content" ]
then
if [ -f /usr/local/sbin/openvas-nvt-sync ]
then
/usr/local/sbin/openvas-nvt-sync
/usr/local/sbin/openvas-scapdata-sync
/usr/local/sbin/openvas-certdata-sync
fi
if [ -f /usr/local/sbin/greenbone-certdata-sync ]
then
/usr/local/sbin/greenbone-nvt-sync
/usr/local/sbin/greenbone-scapdata-sync
/usr/local/sbin/greenbone-certdata-sync
fi
elif [ "$1" == "--update-content-nvt" ]
then
if [ -f /usr/local/sbin/openvas-nvt-sync ]
then
/usr/local/sbin/openvas-nvt-sync --curl
fi
if [ -f /usr/local/sbin/greenbone-certdata-sync ]
then
/usr/local/sbin/greenbone-nvt-sync --curl
fi
elif [ "$1" == "--rebuild-content" ]
then
/usr/local/sbin/openvasmd --rebuild --progress
elif [ "$1" == "--start-all" ]
then
mkdir /usr/local/var/run 2>/dev/null;
mkdir /usr/local/var/run/openvasmd 2>/dev/null;
touch /usr/local/var/run/openvasmd/openvasmd.pid;
/usr/local/sbin/openvasmd
/usr/local/sbin/openvassd
/usr/local/sbin/gsad
elif [ "$1" == "--kill-all" ]
then
ps aux | egrep "(openvas|gsad)" | awk '{print $2}' | xargs -i kill -9 '{}'
elif [ "$1" == "--check-status" ]
then
if [ ! -f openvas-check-setup ];
then
wget https://svn.wald.intevation.org/svn/openvas/trunk/tools/openvas-check-setup --no-check-certificate
chmod 0755 openvas-check-setup
fi
if [ "$2" == "" ]
then
version="v9"
else
version="$2"
fi
./openvas-check-setup --$version --server
elif [ "$1" == "--check-proc" ]
then
ps aux | egrep "(openvas.d|gsad)"
else
echo "Unknown command"
print_help
fi
#### TODO OSPD
#cd ospd-1*
#python setup.py install --prefix=/usr/local
#cd ../
#cd ospd-ancor-*
#python setup.py install --prefix=/usr/local
#cd ../
#cd ospd-debsecan-*
#python setup.py install --prefix=/usr/local
#cd ../
#cd ospd-ovaldi-*
#python setup.py install --prefix=/usr/local
#cd ../
#cd ospd-paloalto-*
#python setup.py install --prefix=/usr/local
#cd ../
#cd ospd-w3af-*
#python setup.py install --prefix=/usr/local
#cd ../