Guest User

Untitled

a guest
Jul 2nd, 2026
67
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.39 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Greenbone Community Edition (OpenVAS) – source build for CentOS 9 Stream
  4. # Based on: https://greenbone.github.io/docs/latest/22.4/source-build/index.html
  5. #
  6. # Run as a regular user that has sudo privileges (NOT as root).
  7. # The script is idempotent-friendly and uses `set -e` to stop on the first error.
  8. #
  9. # Usage:
  10. # chmod +x centos_openvas.sh
  11. # ./centos_openvas.sh
  12. #
  13. # added workarounds to compile openvas-smb also in centos/rocky 9/10, which is not officially supported by Greenbone (upstream only documents Debian/Ubuntu)
  14. #
  15.  
  16. set -euo pipefail
  17.  
  18. # ---------------------------------------------------------------------------
  19. # 0. Sanity checks
  20. # ---------------------------------------------------------------------------
  21. if [[ $EUID -eq 0 ]]; then
  22. echo "ERROR: Do not run this script as root. Run as a regular sudo user." >&2
  23. exit 1
  24. fi
  25.  
  26. if ! command -v sudo >/dev/null 2>&1; then
  27. echo "ERROR: sudo is required." >&2
  28. exit 1
  29. fi
  30.  
  31. if ! grep -qiE "centos|rocky" /etc/os-release; then
  32. echo "WARNING: This script targets CentOS 9 Stream / Rocky Linux. Continuing anyway in 5s..." >&2
  33. sleep 5
  34. fi
  35.  
  36. # ---------------------------------------------------------------------------
  37. # 1. Component versions (pin to versions documented in the 22.4 guide)
  38. # ---------------------------------------------------------------------------
  39. export GVM_LIBS_VERSION=22.31.1
  40. export GVMD_VERSION=26.10.0
  41. export PG_GVM_VERSION=22.6.9
  42. export GSA_VERSION=25.0.0
  43. export GSAD_VERSION=24.3.0
  44. export OPENVAS_SCANNER_VERSION=23.20.1
  45. export OSPD_OPENVAS_VERSION=22.9.0
  46. export OPENVAS_DAEMON=23.20.0
  47. export OPENVAS_SMB_VERSION=22.5.7
  48.  
  49. # openvas-smb is not officially supported on CentOS/Rocky (upstream only
  50. # documents Debian/Ubuntu). The workaround in section 10c builds its Heimdal
  51. # Kerberos dependency from source — EL9/EL10 and EPEL do not ship heimdal-devel
  52. # and MIT krb5 is not a drop-in replacement — then compiles openvas-smb against
  53. # it to enable Windows / SMB / WMI target scans.
  54. export HEIMDAL_VERSION=7.8.0
  55.  
  56. # ---------------------------------------------------------------------------
  57. # 2. Environment variables
  58. # ---------------------------------------------------------------------------
  59. export INSTALL_PREFIX=/usr/local
  60. export PATH=$PATH:$INSTALL_PREFIX/sbin
  61. export SOURCE_DIR=$HOME/source
  62. export BUILD_DIR=$HOME/build
  63. export INSTALL_DIR=$HOME/install
  64.  
  65. mkdir -p "$SOURCE_DIR" "$BUILD_DIR" "$INSTALL_DIR"
  66.  
  67. # ---------------------------------------------------------------------------
  68. # 3. Create gvm user / group and add current user to it
  69. # ---------------------------------------------------------------------------
  70. if ! id -u gvm >/dev/null 2>&1; then
  71. sudo useradd -r -M -U -G wheel -s /usr/sbin/nologin gvm
  72. fi
  73. sudo usermod -aG gvm "$USER"
  74.  
  75. # ---------------------------------------------------------------------------
  76. # 4. Enable required repositories and install common build dependencies
  77. # ---------------------------------------------------------------------------
  78. sudo dnf config-manager --set-enabled crb
  79. # epel-next-release only exists on CentOS Stream; Rocky Linux uses epel-release only
  80. sudo dnf install -y epel-release
  81. if dnf info epel-next-release &>/dev/null; then
  82. sudo dnf install -y epel-next-release
  83. fi
  84. sudo dnf upgrade -y
  85. sudo dnf groupinstall -y 'Development Tools'
  86.  
  87. sudo dnf install -y \
  88. cmake \
  89. python3-pip \
  90. tar \
  91. gcc-c++ \
  92. doxygen \
  93. xmltoman \
  94. curl \
  95. gnupg2 \
  96. pkg-config
  97.  
  98. # LaTeX / pdflatex and related packages
  99. sudo dnf install -y \
  100. texlive \
  101. texlive-latex \
  102. texlive-xetex \
  103. texlive-luatex \
  104. texlive-collection-latexrecommended \
  105. texlive-collection-fontsrecommended \
  106. texlive-dvipng \
  107. texlive-dvips \
  108. texlive-makeindex \
  109. texlive-lm \
  110. texlive-lm-math \
  111. latexmk
  112.  
  113. sudo tee /etc/ld.so.conf.d/local.conf >/dev/null <<EOF
  114. /usr/local/lib
  115. /usr/local/lib64
  116. EOF
  117. sudo ldconfig
  118.  
  119. # Distro net-snmp conflicts with the source build needed by openvas-scanner
  120. sudo dnf remove -y net-snmp net-snmp-devel || true
  121. sudo dnf install -y \
  122. systemd \
  123. gcc \
  124. openssl-devel \
  125. bzip2-devel \
  126. elfutils-devel \
  127. libselinux-devel \
  128. elfutils-libelf-devel \
  129. rpm-devel \
  130. perl-devel \
  131. procps \
  132. python3-devel \
  133. python3-setuptools \
  134. chrpath \
  135. mariadb-connector-c-devel
  136.  
  137. # Build net-snmp from source (5.9.4 – fixes swrun linker bug present in 5.9.1)
  138. if [[ ! -x /usr/local/sbin/snmpd ]]; then
  139. cd "$SOURCE_DIR"
  140. curl -fL -o net-snmp-5.9.4.tar.gz \
  141. https://sourceforge.net/projects/net-snmp/files/net-snmp/5.9.4/net-snmp-5.9.4.tar.gz/download
  142. tar xzf net-snmp-5.9.4.tar.gz
  143. cd net-snmp-5.9.4
  144. ./configure --prefix=/usr/local \
  145. --with-default-snmp-version=3 \
  146. --with-sys-contact="root@localhost" \
  147. --with-sys-location="Unknown" \
  148. --with-logfile="/var/log/snmpd.log" \
  149. --with-persistent-directory="/var/net-snmp"
  150. make -j"$(nproc)"
  151. sudo make install
  152. sudo ldconfig
  153. fi
  154.  
  155. # Build paho.mqtt.c from source (required by gvm-libs on CentOS)
  156. if [[ ! -f /usr/local/lib/libpaho-mqtt3c.so ]] && [[ ! -f /usr/local/lib64/libpaho-mqtt3c.so ]]; then
  157. cd "$SOURCE_DIR"
  158. curl -fL -o paho.mqtt.c.tar.gz \
  159. https://codeload.github.com/eclipse/paho.mqtt.c/tar.gz/refs/tags/v1.3.10
  160. tar xzf paho.mqtt.c.tar.gz
  161. cd paho.mqtt.c-1.3.10
  162. mkdir -p build && cd build
  163. cmake -DPAHO_WITH_SSL=TRUE -DPAHO_ENABLE_TESTING=FALSE ..
  164. make -j"$(nproc)"
  165. sudo make install
  166. sudo ldconfig
  167. fi
  168.  
  169. # Install curl-devel so that libcurl.pc is present for pkg-config/CMake.
  170. # This is needed even when the system libcurl is new enough to skip the
  171. # source build below, otherwise downstream cmake steps fail with
  172. # "Package 'libcurl', required by 'virtual:world', not found".
  173. sudo dnf install -y curl-devel
  174.  
  175. # Build libcurl from source only when the system version is < 7.83.0.
  176. # Check pkg-config first; fall back to parsing `curl --version` when the
  177. # libcurl .pc file is not yet installed (e.g. on Rocky Linux 10 before
  178. # curl-devel is present). This prevents overwriting a newer system libcurl
  179. # (Rocky Linux 10 ships 8.9+) with an older source build, which would break
  180. # the system curl binary with an undefined-symbol error.
  181. _libcurl_ok=false
  182. if pkg-config --atleast-version=7.83.0 libcurl 2>/dev/null; then
  183. _libcurl_ok=true
  184. elif _cv=$(curl --version 2>/dev/null | awk 'NR==1{print $2}') && \
  185. [[ -n "$_cv" ]] && \
  186. printf '%s\n%s\n' "7.83.0" "$_cv" | sort -V -C 2>/dev/null; then
  187. _libcurl_ok=true
  188. fi
  189. if ! $_libcurl_ok; then
  190. cd "$SOURCE_DIR"
  191. CURL_VERSION=8.7.1
  192. curl -fL -o "curl-${CURL_VERSION}.tar.gz" \
  193. "https://curl.se/download/curl-${CURL_VERSION}.tar.gz"
  194. tar xzf "curl-${CURL_VERSION}.tar.gz"
  195. cd "curl-${CURL_VERSION}"
  196. ./configure --prefix=/usr/local --with-openssl --without-libpsl
  197. make -j"$(nproc)"
  198. sudo make install
  199. sudo ldconfig
  200. fi
  201.  
  202. # Ensure pkg-config finds source-built libraries before system ones
  203. export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
  204.  
  205. # ---------------------------------------------------------------------------
  206. # 5. Import the Greenbone Community signing key
  207. # ---------------------------------------------------------------------------
  208. curl -fL https://www.greenbone.net/GBCommunitySigningKey.asc -o /tmp/GBCommunitySigningKey.asc
  209. gpg --import /tmp/GBCommunitySigningKey.asc || true
  210. echo "8AE4BE429B60A59B311C2E739823FAA60ED1E580:6:" | gpg --import-ownertrust
  211.  
  212. # Helper: download + verify + extract a tarball
  213. fetch_and_verify() {
  214. local name="$1" # repo name, e.g. gvm-libs
  215. local version="$2"
  216. local asc_basename="${3:-${name}-${version}.tar.gz.asc}" # some assets prefix with v
  217.  
  218. local tgz="$SOURCE_DIR/${name}-${version}.tar.gz"
  219. local asc="$SOURCE_DIR/${name}-${version}.tar.gz.asc"
  220.  
  221. curl -fL "https://github.com/greenbone/${name}/archive/refs/tags/v${version}.tar.gz" -o "$tgz"
  222. curl -fL "https://github.com/greenbone/${name}/releases/download/v${version}/${asc_basename}" -o "$asc"
  223. gpg --verify "$asc" "$tgz"
  224. tar -C "$SOURCE_DIR" -xzf "$tgz"
  225. }
  226.  
  227. # ---------------------------------------------------------------------------
  228. # 6. gvm-libs
  229. # ---------------------------------------------------------------------------
  230. sudo dnf install -y \
  231. cjson-devel \
  232. glib2-devel \
  233. gnutls-devel \
  234. gpgme-devel \
  235. hiredis-devel \
  236. libgcrypt-devel \
  237. libnet-devel \
  238. libpcap-devel \
  239. libssh-devel \
  240. libuuid-devel \
  241. libxml2-devel \
  242. uuid-devel \
  243. openldap-devel \
  244. radcli-devel
  245.  
  246. fetch_and_verify gvm-libs "$GVM_LIBS_VERSION" "gvm-libs-${GVM_LIBS_VERSION}.tar.gz.asc"
  247.  
  248. mkdir -p "$BUILD_DIR/gvm-libs"
  249. cmake \
  250. -S "$SOURCE_DIR/gvm-libs-$GVM_LIBS_VERSION" \
  251. -B "$BUILD_DIR/gvm-libs" \
  252. -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
  253. -DCMAKE_BUILD_TYPE=Release \
  254. -DSYSCONFDIR=/etc \
  255. -DLOCALSTATEDIR=/var
  256. cmake --build "$BUILD_DIR/gvm-libs" -j"$(nproc)"
  257.  
  258. mkdir -p "$INSTALL_DIR/gvm-libs"
  259. make -C "$BUILD_DIR/gvm-libs" DESTDIR="$INSTALL_DIR/gvm-libs" install
  260. sudo cp -rv "$INSTALL_DIR/gvm-libs/"* /
  261. sudo ldconfig
  262.  
  263. # ---------------------------------------------------------------------------
  264. # 7. gvmd
  265. # ---------------------------------------------------------------------------
  266. sudo dnf install -y \
  267. glib2-devel \
  268. gnutls-devel \
  269. postgresql-server-devel \
  270. libical-devel \
  271. libxslt \
  272. rsync \
  273. libbsd-devel \
  274. gpgme-devel
  275.  
  276. # gvmd expects Debian-style <postgresql/libpq-fe.h> but CentOS puts headers
  277. # directly under /usr/include. Create a compat symlink directory.
  278. if [[ ! -d /usr/include/postgresql ]]; then
  279. sudo mkdir -p /usr/include/postgresql
  280. for f in /usr/include/libpq-fe.h /usr/include/libpq-events.h \
  281. /usr/include/postgres_ext.h /usr/include/pg_config.h \
  282. /usr/include/pg_config_ext.h /usr/include/pg_config_manual.h; do
  283. [ -f "$f" ] && sudo ln -sf "$f" /usr/include/postgresql/
  284. done
  285. [ -d /usr/include/libpq ] && sudo ln -sfn /usr/include/libpq /usr/include/postgresql/libpq
  286. fi
  287.  
  288. # Optional helpers (report formats, alerts, etc.)
  289. sudo dnf install -y --setopt=install_weak_deps=False \
  290. gnupg2-smime \
  291. openssh-clients \
  292. xmlstarlet \
  293. zip \
  294. rpm \
  295. fakeroot \
  296. dpkg \
  297. gnupg \
  298. wget \
  299. sshpass \
  300. socat \
  301. samba-client \
  302. python3-lxml \
  303. gnutls-utils || true
  304.  
  305. fetch_and_verify gvmd "$GVMD_VERSION" "gvmd-${GVMD_VERSION}.tar.gz.asc"
  306.  
  307. # CentOS puts the server-side pg_config.h (which contains PG_VERSION) under
  308. # /usr/include/pgsql/server. Point FindPostgreSQL there so the version regex
  309. # in gvmd's CMakeLists.txt succeeds.
  310. GVMD_PG_INCLUDEDIR=$(pg_config --includedir 2>/dev/null || echo /usr/include)
  311. GVMD_PG_SERVER_INCLUDEDIR=$(pg_config --includedir-server 2>/dev/null || echo /usr/include/pgsql/server)
  312. GVMD_PG_LIBDIR=$(pg_config --libdir 2>/dev/null || echo /usr/lib64)
  313.  
  314. mkdir -p "$BUILD_DIR/gvmd"
  315. cmake \
  316. -S "$SOURCE_DIR/gvmd-$GVMD_VERSION" \
  317. -B "$BUILD_DIR/gvmd" \
  318. -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
  319. -DCMAKE_BUILD_TYPE=Release \
  320. -DLOCALSTATEDIR=/var \
  321. -DSYSCONFDIR=/etc \
  322. -DGVM_DATA_DIR=/var \
  323. -DGVM_LOG_DIR=/var/log/gvm \
  324. -DGVMD_RUN_DIR=/run/gvmd \
  325. -DOPENVAS_DEFAULT_SOCKET=/run/ospd/ospd-openvas.sock \
  326. -DGVM_FEED_LOCK_PATH=/var/lib/gvm/feed-update.lock \
  327. -DLOGROTATE_DIR=/etc/logrotate.d \
  328. -DPostgreSQL_INCLUDE_DIR="$GVMD_PG_INCLUDEDIR" \
  329. -DPostgreSQL_TYPE_INCLUDE_DIR="$GVMD_PG_SERVER_INCLUDEDIR" \
  330. -DPostgreSQL_LIBRARY_DIR="$GVMD_PG_LIBDIR"
  331. cmake --build "$BUILD_DIR/gvmd" -j"$(nproc)"
  332.  
  333. mkdir -p "$INSTALL_DIR/gvmd"
  334. make -C "$BUILD_DIR/gvmd" DESTDIR="$INSTALL_DIR/gvmd" install
  335. sudo cp -rv "$INSTALL_DIR/gvmd/"* /
  336.  
  337. # ---------------------------------------------------------------------------
  338. # 8. pg-gvm
  339. # ---------------------------------------------------------------------------
  340. sudo dnf install -y \
  341. glib2-devel \
  342. gnutls-devel \
  343. libical-devel \
  344. postgresql-server-devel
  345.  
  346. fetch_and_verify pg-gvm "$PG_GVM_VERSION" "pg-gvm-${PG_GVM_VERSION}.tar.gz.asc"
  347.  
  348. # Help CMake's FindPostgreSQL locate the server headers (pg_config.h holds the
  349. # version string) which live under /usr/include/pgsql/server on CentOS.
  350. PG_INCLUDEDIR=$(pg_config --includedir 2>/dev/null || echo /usr/include)
  351. PG_SERVER_INCLUDEDIR=$(pg_config --includedir-server 2>/dev/null || echo /usr/include/pgsql/server)
  352. PG_LIBDIR=$(pg_config --libdir 2>/dev/null || echo /usr/lib64)
  353.  
  354. mkdir -p "$BUILD_DIR/pg-gvm"
  355. cmake \
  356. -S "$SOURCE_DIR/pg-gvm-$PG_GVM_VERSION" \
  357. -B "$BUILD_DIR/pg-gvm" \
  358. -DCMAKE_BUILD_TYPE=Release \
  359. -DPostgreSQL_INCLUDE_DIR="$PG_INCLUDEDIR" \
  360. -DPostgreSQL_TYPE_INCLUDE_DIR="$PG_SERVER_INCLUDEDIR" \
  361. -DPostgreSQL_LIBRARY_DIR="$PG_LIBDIR"
  362. cmake --build "$BUILD_DIR/pg-gvm" -j"$(nproc)"
  363.  
  364. mkdir -p "$INSTALL_DIR/pg-gvm"
  365. make -C "$BUILD_DIR/pg-gvm" DESTDIR="$INSTALL_DIR/pg-gvm" install
  366. sudo cp -rv "$INSTALL_DIR/pg-gvm/"* /
  367.  
  368. # ---------------------------------------------------------------------------
  369. # 9. GSA (web app, pre-built distributable)
  370. # ---------------------------------------------------------------------------
  371. curl -fL \
  372. "https://github.com/greenbone/gsa/releases/download/v${GSA_VERSION}/gsa-dist-${GSA_VERSION}.tar.gz" \
  373. -o "$SOURCE_DIR/gsa-${GSA_VERSION}.tar.gz"
  374. curl -fL \
  375. "https://github.com/greenbone/gsa/releases/download/v${GSA_VERSION}/gsa-dist-${GSA_VERSION}.tar.gz.asc" \
  376. -o "$SOURCE_DIR/gsa-${GSA_VERSION}.tar.gz.asc"
  377. gpg --verify "$SOURCE_DIR/gsa-${GSA_VERSION}.tar.gz.asc" "$SOURCE_DIR/gsa-${GSA_VERSION}.tar.gz"
  378.  
  379. mkdir -p "$SOURCE_DIR/gsa-${GSA_VERSION}"
  380. tar -C "$SOURCE_DIR/gsa-${GSA_VERSION}" -xzf "$SOURCE_DIR/gsa-${GSA_VERSION}.tar.gz"
  381.  
  382. sudo mkdir -p "$INSTALL_PREFIX/share/gvm/gsad/web/"
  383. sudo cp -rv "$SOURCE_DIR/gsa-${GSA_VERSION}/"* "$INSTALL_PREFIX/share/gvm/gsad/web/"
  384.  
  385. # ---------------------------------------------------------------------------
  386. # 10. gsad (web server)
  387. # ---------------------------------------------------------------------------
  388. sudo dnf install -y \
  389. glib2-devel \
  390. gnutls-devel \
  391. libmicrohttpd-devel \
  392. libxml2-devel
  393.  
  394. # Open the GSA port in firewalld if it is running
  395. if systemctl is-active --quiet firewalld; then
  396. sudo firewall-cmd --add-port=9392/tcp
  397. sudo firewall-cmd --runtime-to-permanent
  398. fi
  399.  
  400. fetch_and_verify gsad "$GSAD_VERSION" "gsad-${GSAD_VERSION}.tar.gz.asc"
  401.  
  402. mkdir -p "$BUILD_DIR/gsad"
  403. cmake \
  404. -S "$SOURCE_DIR/gsad-$GSAD_VERSION" \
  405. -B "$BUILD_DIR/gsad" \
  406. -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
  407. -DCMAKE_BUILD_TYPE=Release \
  408. -DSYSCONFDIR=/etc \
  409. -DLOCALSTATEDIR=/var \
  410. -DGVMD_RUN_DIR=/run/gvmd \
  411. -DGSAD_RUN_DIR=/run/gsad \
  412. -DGVM_LOG_DIR=/var/log/gvm \
  413. -DLOGROTATE_DIR=/etc/logrotate.d
  414. cmake --build "$BUILD_DIR/gsad" -j"$(nproc)"
  415.  
  416. mkdir -p "$INSTALL_DIR/gsad"
  417. make -C "$BUILD_DIR/gsad" DESTDIR="$INSTALL_DIR/gsad" install
  418. sudo cp -rv "$INSTALL_DIR/gsad/"* /
  419.  
  420. # ---------------------------------------------------------------------------
  421. # 10c. openvas-smb (Windows / SMB / WMI support) — CentOS/Rocky workaround
  422. # ---------------------------------------------------------------------------
  423. # openvas-smb is only officially supported on Debian/Ubuntu because it needs
  424. # Heimdal Kerberos (heimdal-devel), which EL9/EL10 and EPEL do not package.
  425. # MIT krb5 is NOT a drop-in replacement — openvas-smb links Heimdal's GSSAPI
  426. # stack specifically. The workaround: build Heimdal from source into an
  427. # isolated prefix (/opt/heimdal) and point openvas-smb's build at it.
  428. #
  429. # This must run BEFORE openvas-scanner so the scanner detects and links the
  430. # WMI/SMB client libraries (libopenvas_wmiclient) it needs for Windows scans.
  431. sudo dnf install -y \
  432. gnutls-devel \
  433. glib2-devel \
  434. popt-devel \
  435. libunistring-devel \
  436. perl \
  437. perl-JSON \
  438. flex \
  439. bison \
  440. texinfo \
  441. ncurses-devel \
  442. readline-devel \
  443. libxcrypt-devel \
  444. gmp-devel \
  445. gcc \
  446. gcc-c++ \
  447. make
  448.  
  449. # --- Build Heimdal from source (only if not already installed) -------------
  450. export HEIMDAL_PREFIX=/opt/heimdal
  451. if [[ ! -f "$HEIMDAL_PREFIX/include/gssapi.h" ]]; then
  452. cd "$SOURCE_DIR"
  453. curl -fL -o "heimdal-${HEIMDAL_VERSION}.tar.gz" \
  454. "https://github.com/heimdal/heimdal/releases/download/heimdal-${HEIMDAL_VERSION}/heimdal-${HEIMDAL_VERSION}.tar.gz"
  455. # Always start from a pristine tree — a previous failed build leaves stale
  456. # objects and a config.status that would otherwise be reused, so new
  457. # configure flags below would not take effect on a re-run.
  458. rm -rf "heimdal-${HEIMDAL_VERSION}"
  459. tar xzf "heimdal-${HEIMDAL_VERSION}.tar.gz"
  460. cd "heimdal-${HEIMDAL_VERSION}"
  461. # --disable-otp / --disable-afs-support drop optional deps; the GSSAPI and
  462. # krb5 client libraries that openvas-smb links against are still built.
  463. #
  464. # LIBS=-lcrypt: on EL10 (glibc >= 2.38) crypt() was removed from glibc and
  465. # now lives in libxcrypt. Heimdal's libroken uses crypt() but does not add
  466. # -lcrypt, causing "undefined reference to `crypt'" at link time. Forcing
  467. # -lcrypt into LIBS makes libroken and its test programs link.
  468. #
  469. # POSIX_GETPWNAM_R: Heimdal's runtime configure check for a POSIX
  470. # getpwnam_r returns "no" in minimal build environments, leaving
  471. # POSIX_GETPWNAM_R undefined. libkrb5 then references the roken wrapper
  472. # rk_getpwnam_r, which getpwnam_r.c never compiles -> "undefined reference
  473. # to `rk_getpwnam_r'". glibc's getpwnam_r IS POSIX, so we both force the
  474. # configure cache result AND define the macro via CPPFLAGS. The CPPFLAGS
  475. # define is the reliable part: it makes roken.h alias rk_getpwnam_r
  476. # directly to glibc's getpwnam_r, so the wrapper symbol is never emitted.
  477. ./configure \
  478. --prefix="$HEIMDAL_PREFIX" \
  479. --disable-otp \
  480. --without-x \
  481. --disable-afs-support \
  482. --disable-heimdal-documentation \
  483. ac_cv_func_getpwnam_r_posix=yes \
  484. CPPFLAGS="-DPOSIX_GETPWNAM_R=1" \
  485. LIBS=-lcrypt
  486. make -j"$(nproc)"
  487. sudo make install
  488. fi
  489.  
  490. # Make the Heimdal libraries discoverable at build and run time.
  491. sudo tee /etc/ld.so.conf.d/heimdal.conf >/dev/null <<EOF
  492. $HEIMDAL_PREFIX/lib
  493. EOF
  494. sudo ldconfig
  495.  
  496. # openvas-smb's bundled samba includes Heimdal headers as <heimdal/gssapi/gssapi.h>
  497. # but Heimdal installs them without that prefix (e.g. <gssapi/gssapi.h>).
  498. # Create a compat shim: /opt/heimdal-compat/heimdal -> $HEIMDAL_PREFIX/include
  499. # so that both <heimdal/xxx.h> and <xxx.h> forms resolve correctly.
  500. HEIMDAL_COMPAT=/opt/heimdal-compat
  501. sudo mkdir -p "$HEIMDAL_COMPAT"
  502. sudo ln -sfn "$HEIMDAL_PREFIX/include" "$HEIMDAL_COMPAT/heimdal"
  503.  
  504. # Expose Heimdal's pkg-config metadata NOW so that the openvas-smb cmake step
  505. # below can find heimdal-gssapi.pc. Must come before cmake, not after.
  506. export PKG_CONFIG_PATH=$HEIMDAL_PREFIX/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
  507.  
  508. # Rocky/RHEL 9 ships a gnutls.pc whose linker flags reference a build-time-only
  509. # static archive path (/builddir/build/BUILD/gnutls-*/bundled_gmp/.libs/libgmp.a).
  510. # openvas-smb's top-level CMakeLists does `pkg_check_modules(GNUTLS ...)`, so
  511. # pkg-config passes that absolute path straight into GNUTLS_LIBRARIES and the
  512. # link line for libopenvas_wmiclient. Since that .a does not exist on the build
  513. # host, make fails with "No rule to make target .../libgmp.a". Rocky 10's
  514. # gnutls.pc does not carry this path, which is why the build only breaks on 9.
  515. # Fix: write a sanitized copy of gnutls.pc (bad path -> -lgmp) into a private
  516. # dir and prepend it to PKG_CONFIG_PATH so the openvas-smb build picks it up.
  517. GNUTLS_PC_OVERRIDE_DIR=
  518. _gnutls_pc_dir="$(pkg-config --variable=pcfiledir gnutls 2>/dev/null || true)"
  519. _gnutls_pc="${_gnutls_pc_dir:-}/gnutls.pc"
  520. if [[ -f "$_gnutls_pc" ]] && grep -q '/builddir/build/BUILD/' "$_gnutls_pc"; then
  521. GNUTLS_PC_OVERRIDE_DIR="$BUILD_DIR/openvas-smb-pcfix"
  522. mkdir -p "$GNUTLS_PC_OVERRIDE_DIR"
  523. # Drop the transient -L search path and rewrite the absolute libgmp.a
  524. # reference to a normal -lgmp so the system libgmp (gmp-devel) is used.
  525. sed -E \
  526. -e 's#-L/builddir/build/BUILD/[^[:space:]]*##g' \
  527. -e 's#/builddir/build/BUILD/[^[:space:]]*/libgmp\.a#-lgmp#g' \
  528. "$_gnutls_pc" > "$GNUTLS_PC_OVERRIDE_DIR/gnutls.pc"
  529. export PKG_CONFIG_PATH="$GNUTLS_PC_OVERRIDE_DIR${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
  530. fi
  531.  
  532. fetch_and_verify openvas-smb "$OPENVAS_SMB_VERSION" "openvas-smb-v${OPENVAS_SMB_VERSION}.tar.gz.asc"
  533.  
  534. # openvas-smb 22.5.7 vendors an old Samba snapshot whose send-to-KDC callback
  535. # smb_krb5_send_and_recv_func() uses the 5-argument krb5_send_to_kdc_func
  536. # signature. Heimdal 7.8.0's typedef adds a `time_t timeout` parameter between
  537. # the krb5_krbhst_info* and the send buffer, so krb5_set_send_to_kdc_func()
  538. # fails with "incompatible pointer type" — which GCC 14 on EL10 treats as a
  539. # hard error, not a warning. Patch the callback to take the (unused) timeout
  540. # argument so its type matches Heimdal 7.8.0. The signature appears in three
  541. # places — the definition (krb5_init_context.c) and two prototypes
  542. # (krb5_init_context.h and proto.h) — all of which must match or the compiler
  543. # reports "conflicting types". Idempotent: only patches once.
  544. SMB_KRB5_SRC="$SOURCE_DIR/openvas-smb-$OPENVAS_SMB_VERSION/samba/auth/kerberos"
  545. for _smb_krb5_f in \
  546. "$SMB_KRB5_SRC/krb5_init_context.c" \
  547. "$SMB_KRB5_SRC/krb5_init_context.h" \
  548. "$SMB_KRB5_SRC/proto.h"; do
  549. if ! grep -q 'time_t timeout, const krb5_data \*send_buf' "$_smb_krb5_f"; then
  550. sed -i 's/const krb5_data \*send_buf,/time_t timeout, const krb5_data *send_buf,/' "$_smb_krb5_f"
  551. fi
  552. done
  553.  
  554. # Point CMake / pkg-config / linker at the isolated Heimdal prefix so the
  555. # openvas-smb build finds Heimdal's headers and libraries instead of MIT krb5.
  556. #
  557. # -include gssapi/gssapi_krb5.h: The bundled samba code in openvas-smb calls
  558. # Heimdal GSSAPI krb5 extension functions (gss_krb5_import_cred,
  559. # gss_krb5_copy_ccache) but some source files (credentials_krb5.c) never
  560. # include <gssapi/gssapi_krb5.h> where they are declared — causing "implicit
  561. # declaration of function" errors. Using -include force-includes that header
  562. # at the top of every translation unit so all GSSAPI krb5 symbols are visible.
  563. #
  564. # -Wno-error=incompatible-pointer-types (and friends): GCC 14 (EL10's default
  565. # compiler) promoted several formerly-warning diagnostics to hard errors by
  566. # default — incompatible-pointer-types, implicit-function-declaration,
  567. # int-conversion and implicit-int. The old Samba snapshot vendored by
  568. # openvas-smb 22.5.7 trips these in many places (e.g. the DCOM vtable
  569. # initializers in lib/com/classes/simple.c whose _send members intentionally
  570. # use loosely-typed function pointers). These are long-standing constructs that
  571. # older compilers accepted as warnings, so demote them back to warnings for
  572. # this package instead of patching hundreds of call sites.
  573. # A previous configure may have cached the bad libgmp.a path; start clean so
  574. # the sanitized gnutls.pc above is actually picked up.
  575. if [[ -f "$BUILD_DIR/openvas-smb/CMakeCache.txt" ]]; then
  576. rm -rf "$BUILD_DIR/openvas-smb"
  577. fi
  578. mkdir -p "$BUILD_DIR/openvas-smb"
  579. cmake \
  580. -S "$SOURCE_DIR/openvas-smb-$OPENVAS_SMB_VERSION" \
  581. -B "$BUILD_DIR/openvas-smb" \
  582. -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
  583. -DCMAKE_BUILD_TYPE=Release \
  584. -DCMAKE_PREFIX_PATH="$HEIMDAL_PREFIX" \
  585. -DCMAKE_LIBRARY_PATH="$HEIMDAL_PREFIX/lib" \
  586. -DCMAKE_C_FLAGS="-I$HEIMDAL_COMPAT -I$HEIMDAL_PREFIX/include -include gssapi/gssapi_krb5.h -D_GNU_SOURCE -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration -Wno-error=int-conversion -Wno-error=implicit-int" \
  587. -DKRB5_CONFIG="$HEIMDAL_PREFIX/bin/krb5-config"
  588. cmake --build "$BUILD_DIR/openvas-smb" -j"$(nproc)"
  589.  
  590. mkdir -p "$INSTALL_DIR/openvas-smb"
  591. make -C "$BUILD_DIR/openvas-smb" DESTDIR="$INSTALL_DIR/openvas-smb" install
  592. sudo cp -rv "$INSTALL_DIR/openvas-smb/"* /
  593. sudo ldconfig
  594.  
  595. # Expose openvas-smb's installed pkg-config data (libopenvas_wmiclient) so the
  596. # openvas-scanner cmake build below can detect and link WMI/SMB support.
  597. # $INSTALL_PREFIX/lib/pkgconfig was already added earlier; re-export to ensure
  598. # it is first in the path in case it was prepended differently above.
  599. export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig:$INSTALL_PREFIX/lib64/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
  600.  
  601. # ---------------------------------------------------------------------------
  602. # 11. openvas-scanner
  603. # ---------------------------------------------------------------------------
  604. sudo dnf install -y \
  605. bison \
  606. glib2-devel \
  607. gnutls-devel \
  608. libgcrypt-devel \
  609. libpcap-devel \
  610. gpgme-devel \
  611. libksba-devel \
  612. rsync \
  613. nmap \
  614. json-glib-devel \
  615. libcurl-devel \
  616. libbsd-devel \
  617. krb5-devel
  618.  
  619. fetch_and_verify openvas-scanner "$OPENVAS_SCANNER_VERSION" "openvas-scanner-v${OPENVAS_SCANNER_VERSION}.tar.gz.asc"
  620.  
  621. mkdir -p "$BUILD_DIR/openvas-scanner"
  622. cmake \
  623. -S "$SOURCE_DIR/openvas-scanner-$OPENVAS_SCANNER_VERSION" \
  624. -B "$BUILD_DIR/openvas-scanner" \
  625. -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
  626. -DCMAKE_BUILD_TYPE=Release \
  627. -DSYSCONFDIR=/etc \
  628. -DLOCALSTATEDIR=/var \
  629. -DOPENVAS_FEED_LOCK_PATH=/var/lib/openvas/feed-update.lock \
  630. -DOPENVAS_RUN_DIR=/run/ospd
  631. cmake --build "$BUILD_DIR/openvas-scanner" -j"$(nproc)"
  632.  
  633. mkdir -p "$INSTALL_DIR/openvas-scanner"
  634. make -C "$BUILD_DIR/openvas-scanner" DESTDIR="$INSTALL_DIR/openvas-scanner" install
  635. sudo cp -rv "$INSTALL_DIR/openvas-scanner/"* /
  636.  
  637. sudo mkdir -p /etc/openvas
  638. printf "table_driven_lsc = yes\n" | sudo tee /etc/openvas/openvas.conf
  639. printf "openvasd_server = http://127.0.0.1:3000\n" | sudo tee -a /etc/openvas/openvas.conf
  640. # Tell openvas/ospd-openvas where the Redis knowledge-base socket lives, matching
  641. # the unixsocket path in redis-openvas.conf. Without this the scanner cannot
  642. # connect to the KB ("Not possible to connect to the kb").
  643. printf "db_address = /run/redis-openvas/redis.sock\n" | sudo tee -a /etc/openvas/openvas.conf
  644.  
  645. # ---------------------------------------------------------------------------
  646. # 12. ospd-openvas
  647. # ---------------------------------------------------------------------------
  648. sudo dnf install -y \
  649. python3 \
  650. python3-pip \
  651. python3-setuptools \
  652. python3-packaging \
  653. python3-wrapt \
  654. python3-cffi \
  655. python3-psutil \
  656. python3-lxml \
  657. python3-defusedxml \
  658. python3-paramiko \
  659. python3-redis \
  660. python3-gnupg \
  661. python3-wheel
  662.  
  663. fetch_and_verify ospd-openvas "$OSPD_OPENVAS_VERSION" "ospd-openvas-v${OSPD_OPENVAS_VERSION}.tar.gz.asc"
  664.  
  665. mkdir -p "$INSTALL_DIR/ospd-openvas"
  666. cd "$SOURCE_DIR/ospd-openvas-$OSPD_OPENVAS_VERSION"
  667. python3 -m pip install --root="$INSTALL_DIR/ospd-openvas" --ignore-installed --no-warn-script-location .
  668. sudo cp -rv "$INSTALL_DIR/ospd-openvas/"* /
  669.  
  670. # ---------------------------------------------------------------------------
  671. # 13. openvasd (Rust)
  672. # ---------------------------------------------------------------------------
  673. # perl-FindBin / perl-core are required so the build does not fail parsing
  674. # perl scripts; pkg-config + openssl-devel let openssl-sys link the system
  675. # OpenSSL instead of compiling a vendored copy from source.
  676. sudo dnf install -y pkg-config openssl-devel perl-FindBin perl-core perl-IPC-Cmd
  677.  
  678. # Default CentOS Rust is too old — install rustup for the current user
  679. if ! command -v rustup >/dev/null 2>&1; then
  680. curl -fsSL --proto '=https' --tlsv1.2 https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
  681. fi
  682. # shellcheck source=/dev/null
  683. source "$HOME/.cargo/env"
  684. rustup update stable
  685.  
  686. # Reuse already extracted openvas-scanner sources if version matches; otherwise download
  687. if [[ "$OPENVAS_SCANNER_VERSION" != "$OPENVAS_DAEMON" ]]; then
  688. fetch_and_verify openvas-scanner "$OPENVAS_DAEMON" "openvas-scanner-v${OPENVAS_DAEMON}.tar.gz.asc"
  689. fi
  690.  
  691. # Force openssl-sys to use the system OpenSSL (openssl-devel) rather than
  692. # building a vendored copy from source, which avoids the perl/FindBin build path.
  693. export OPENSSL_NO_VENDOR=1
  694. export PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
  695.  
  696. mkdir -p "$INSTALL_DIR/openvasd/usr/local/bin"
  697. cd "$SOURCE_DIR/openvas-scanner-$OPENVAS_DAEMON/rust"
  698. make || true
  699. cargo build --release
  700.  
  701. sudo cp -v target/release/openvasd "$INSTALL_DIR/openvasd/usr/local/bin/"
  702. sudo cp -v target/release/scannerctl "$INSTALL_DIR/openvasd/usr/local/bin/"
  703. sudo cp -rv "$INSTALL_DIR/openvasd/"* /
  704.  
  705. # ---------------------------------------------------------------------------
  706. # 14. greenbone-feed-sync
  707. # ---------------------------------------------------------------------------
  708. mkdir -p "$INSTALL_DIR/greenbone-feed-sync"
  709. python3 -m pip install --root="$INSTALL_DIR/greenbone-feed-sync" \
  710. --ignore-installed --no-warn-script-location greenbone-feed-sync
  711. sudo cp -rv "$INSTALL_DIR/greenbone-feed-sync/"* /
  712.  
  713. # ---------------------------------------------------------------------------
  714. # 15. gvm-tools
  715. # ---------------------------------------------------------------------------
  716. mkdir -p "$INSTALL_DIR/gvm-tools"
  717. python3 -m pip install --root="$INSTALL_DIR/gvm-tools" \
  718. --ignore-installed --no-warn-script-location gvm-tools
  719. sudo cp -rv "$INSTALL_DIR/gvm-tools/"* /
  720.  
  721. # ===========================================================================
  722. # SYSTEM SETUP
  723. # ===========================================================================
  724.  
  725. # ---------------------------------------------------------------------------
  726. # 16. Redis with openvas configuration
  727. # ---------------------------------------------------------------------------
  728. sudo dnf install -y policycoreutils-python-utils
  729.  
  730. # Build Redis from source — avoids modular filtering issues on EL10
  731. if ! command -v redis-server >/dev/null 2>&1; then
  732. REDIS_VERSION=7.2.5
  733. cd "$SOURCE_DIR"
  734. curl -fL -o "redis-${REDIS_VERSION}.tar.gz" \
  735. "https://download.redis.io/releases/redis-${REDIS_VERSION}.tar.gz"
  736. tar xzf "redis-${REDIS_VERSION}.tar.gz"
  737. cd "redis-${REDIS_VERSION}"
  738. make -j"$(nproc)" BUILD_TLS=yes
  739. sudo make PREFIX=/usr/local install
  740. # Create redis user/group if missing
  741. if ! id -u redis >/dev/null 2>&1; then
  742. sudo useradd -r -M -s /sbin/nologin redis
  743. fi
  744. sudo mkdir -p /etc/redis /var/lib/redis /var/log/redis
  745. sudo chown redis:redis /var/lib/redis /var/log/redis
  746. fi
  747.  
  748. # /var/run is a symlink to /run on modern systemd — use /run to avoid the
  749. # equivalency-rule conflict that semanage raises.
  750. sudo semanage fcontext -a -f a -t redis_var_run_t -r s0 \
  751. '/run/redis-openvas(/.*)?' || true
  752.  
  753. sudo tee /etc/tmpfiles.d/redis-openvas.conf >/dev/null <<'EOF'
  754. d /var/lib/redis/openvas 0750 redis redis - -
  755. z /var/lib/redis/openvas 0750 redis redis - -
  756. d /run/redis-openvas 0750 redis redis - -
  757. z /run/redis-openvas 0750 redis redis - -
  758. EOF
  759. sudo systemd-tmpfiles --create
  760.  
  761. sudo tee /etc/systemd/system/[email protected] >/dev/null <<'EOF'
  762. [Unit]
  763. Description=Redis persistent key-value database
  764. After=network.target
  765. After=network-online.target
  766. Wants=network-online.target
  767.  
  768. [Service]
  769. WorkingDirectory=/var/lib/redis/%i
  770. # Type=simple: source-built Redis has no libsystemd linkage so it cannot
  771. # send sd_notify; Type=notify would time out waiting for READY=1.
  772. Type=simple
  773. ExecStart=/usr/local/bin/redis-server /etc/redis/redis-%i.conf --daemonize no
  774. ExecStop=/usr/local/bin/redis-cli -s /run/redis-%i/redis.sock shutdown nosave
  775. User=redis
  776. Group=redis
  777. RuntimeDirectory=%i
  778. RuntimeDirectoryMode=0755
  779.  
  780. [Install]
  781. WantedBy=multi-user.target
  782. EOF
  783.  
  784. sudo cp "$SOURCE_DIR/openvas-scanner-$OPENVAS_SCANNER_VERSION/config/redis-openvas.conf" /etc/redis/
  785. sudo chown redis:redis /etc/redis/redis-openvas.conf
  786.  
  787. sudo systemctl daemon-reload
  788. sudo systemctl enable --now [email protected]
  789.  
  790. sudo usermod -aG redis gvm
  791.  
  792. # ---------------------------------------------------------------------------
  793. # 17. Directory permissions
  794. # ---------------------------------------------------------------------------
  795. sudo mkdir -p /var/lib/notus /run/gvmd /var/lib/gvm /var/lib/openvas /var/log/gvm
  796.  
  797. sudo chown -R gvm:gvm /var/lib/gvm
  798. sudo chown -R gvm:gvm /var/lib/openvas
  799. sudo chown -R gvm:gvm /var/lib/notus
  800. sudo chown -R gvm:gvm /var/log/gvm
  801. sudo chown -R gvm:gvm /run/gvmd
  802.  
  803. sudo chmod -R g+srw /var/lib/gvm
  804. sudo chmod -R g+srw /var/lib/openvas
  805. sudo chmod -R g+srw /var/log/gvm
  806.  
  807. sudo chown gvm:gvm /usr/local/sbin/gvmd
  808. sudo chmod 6750 /usr/local/sbin/gvmd
  809.  
  810. # ---------------------------------------------------------------------------
  811. # 17b. TLS certificate for gsad
  812. # ---------------------------------------------------------------------------
  813. # gvm-manage-certs -a creates:
  814. # /var/lib/gvm/CA/cacert.pem
  815. # /var/lib/gvm/CA/servercert.pem
  816. # /var/lib/gvm/private/CA/serverkey.pem
  817. # Its install path varies by gvmd version; fall back to openssl if absent.
  818. if [[ ! -f /var/lib/gvm/CA/servercert.pem ]]; then
  819. sudo mkdir -p /var/lib/gvm/CA /var/lib/gvm/private/CA
  820. GVM_MANAGE_CERTS=$(find /usr/local -name gvm-manage-certs -type f 2>/dev/null | head -1)
  821. if [[ -n "$GVM_MANAGE_CERTS" ]]; then
  822. sudo chown -R gvm:gvm /var/lib/gvm/CA /var/lib/gvm/private
  823. sudo -u gvm "$GVM_MANAGE_CERTS" -a
  824. else
  825. sudo openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
  826. -keyout /var/lib/gvm/private/CA/serverkey.pem \
  827. -out /var/lib/gvm/CA/servercert.pem \
  828. -subj "/CN=Greenbone Security Assistant"
  829. sudo chown -R gvm:gvm /var/lib/gvm/CA /var/lib/gvm/private
  830. fi
  831. fi
  832. sudo chmod 640 /var/lib/gvm/private/CA/serverkey.pem
  833. sudo chown gvm:gvm /var/lib/gvm/private/CA/serverkey.pem
  834.  
  835. # ---------------------------------------------------------------------------
  836. # 18. Feed validation GnuPG keyring
  837. # ---------------------------------------------------------------------------
  838. export GNUPGHOME=/tmp/openvas-gnupg
  839. mkdir -p "$GNUPGHOME"
  840. gpg --import /tmp/GBCommunitySigningKey.asc || true
  841. echo "8AE4BE429B60A59B311C2E739823FAA60ED1E580:6:" | gpg --import-ownertrust
  842.  
  843. export OPENVAS_GNUPG_HOME=/etc/openvas/gnupg
  844. sudo mkdir -p "$OPENVAS_GNUPG_HOME"
  845. sudo cp -r /tmp/openvas-gnupg/* "$OPENVAS_GNUPG_HOME/"
  846. sudo chown -R gvm:gvm "$OPENVAS_GNUPG_HOME"
  847. unset GNUPGHOME
  848.  
  849. # ---------------------------------------------------------------------------
  850. # 19. sudo configuration for scanning
  851. # ---------------------------------------------------------------------------
  852. sudo tee /etc/sudoers.d/gvm >/dev/null <<'EOF'
  853. # Allow /usr/local path
  854. Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  855.  
  856. # Allow users of the gvm group to run openvas
  857. %gvm ALL = NOPASSWD: /usr/local/sbin/openvas
  858. EOF
  859. sudo chmod 0440 /etc/sudoers.d/gvm
  860. sudo visudo -cf /etc/sudoers.d/gvm
  861.  
  862. # ---------------------------------------------------------------------------
  863. # 20. PostgreSQL
  864. # ---------------------------------------------------------------------------
  865. sudo dnf install -y postgresql-server postgresql-contrib
  866.  
  867. if [[ ! -f /var/lib/pgsql/data/PG_VERSION ]]; then
  868. sudo postgresql-setup --initdb --unit postgresql
  869. fi
  870. sudo systemctl enable --now postgresql
  871.  
  872. sudo -u postgres bash -c '
  873. set -e
  874. if ! psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='\''gvm'\''" | grep -q 1; then
  875. createuser -DRS gvm
  876. fi
  877. if ! psql -tAc "SELECT 1 FROM pg_database WHERE datname='\''gvmd'\''" | grep -q 1; then
  878. createdb -O gvm gvmd
  879. fi
  880. psql gvmd -c "create role dba with superuser noinherit;" || true
  881. psql gvmd -c "grant dba to gvm;"
  882. '
  883.  
  884. # ---------------------------------------------------------------------------
  885. # 21. systemd service units
  886. # ---------------------------------------------------------------------------
  887. sudo tee /etc/systemd/system/ospd-openvas.service >/dev/null <<'EOF'
  888. [Unit]
  889. Description=OSPd Wrapper for the OpenVAS Scanner (ospd-openvas)
  890. Documentation=man:ospd-openvas(8) man:openvas(8)
  891. After=network.target networking.service [email protected] openvasd.service
  892. [email protected] openvasd.service
  893. ConditionKernelCommandLine=!recovery
  894.  
  895. [Service]
  896. Type=exec
  897. User=gvm
  898. Group=gvm
  899. RuntimeDirectory=ospd
  900. RuntimeDirectoryMode=2775
  901. PIDFile=/run/ospd/ospd-openvas.pid
  902. ExecStart=/usr/local/bin/ospd-openvas --foreground --unix-socket /run/ospd/ospd-openvas.sock --pid-file /run/ospd/ospd-openvas.pid --log-file /var/log/gvm/ospd-openvas.log --lock-file-dir /var/lib/openvas --socket-mode 0o770 --notus-feed-dir /var/lib/notus/advisories
  903. SuccessExitStatus=SIGKILL
  904. Restart=always
  905. RestartSec=60
  906.  
  907. [Install]
  908. WantedBy=multi-user.target
  909. EOF
  910.  
  911. sudo tee /etc/systemd/system/gvmd.service >/dev/null <<'EOF'
  912. [Unit]
  913. Description=Greenbone Vulnerability Manager daemon (gvmd)
  914. After=network.target networking.service postgresql.service ospd-openvas.service
  915. Wants=postgresql.service ospd-openvas.service
  916. Documentation=man:gvmd(8)
  917. ConditionKernelCommandLine=!recovery
  918.  
  919. [Service]
  920. Type=exec
  921. User=gvm
  922. Group=gvm
  923. PIDFile=/run/gvmd/gvmd.pid
  924. RuntimeDirectory=gvmd
  925. RuntimeDirectoryMode=2775
  926. ExecStart=/usr/local/sbin/gvmd --foreground --osp-vt-update=/run/ospd/ospd-openvas.sock --listen-group=gvm
  927. Restart=always
  928. TimeoutStopSec=10
  929.  
  930. [Install]
  931. WantedBy=multi-user.target
  932. EOF
  933.  
  934. sudo tee /etc/systemd/system/gsad.service >/dev/null <<'EOF'
  935. [Unit]
  936. Description=Greenbone Security Assistant daemon (gsad)
  937. Documentation=man:gsad(8) https://www.greenbone.net
  938. After=network.target gvmd.service
  939. Wants=gvmd.service
  940.  
  941. [Service]
  942. Type=exec
  943. User=gvm
  944. Group=gvm
  945. RuntimeDirectory=gsad
  946. RuntimeDirectoryMode=2775
  947. PIDFile=/run/gsad/gsad.pid
  948. ExecStart=/usr/local/sbin/gsad --foreground --listen=0.0.0.0 --port=9392 --ssl-certificate=/var/lib/gvm/CA/servercert.pem --ssl-private-key=/var/lib/gvm/private/CA/serverkey.pem
  949. Restart=always
  950. TimeoutStopSec=10
  951.  
  952. [Install]
  953. WantedBy=multi-user.target
  954. Alias=greenbone-security-assistant.service
  955. EOF
  956.  
  957. sudo tee /etc/systemd/system/openvasd.service >/dev/null <<'EOF'
  958. [Unit]
  959. Description=OpenVASD
  960. Documentation=https://github.com/greenbone/openvas-scanner/tree/main/rust/openvasd
  961. ConditionKernelCommandLine=!recovery
  962.  
  963. [Service]
  964. Type=exec
  965. User=gvm
  966. RuntimeDirectory=openvasd
  967. RuntimeDirectoryMode=2775
  968. ExecStart=/usr/local/bin/openvasd --mode service_notus --products /var/lib/notus/products --advisories /var/lib/notus/advisories --listening 127.0.0.1:3000
  969. SuccessExitStatus=SIGKILL
  970. Restart=always
  971. RestartSec=60
  972.  
  973. [Install]
  974. WantedBy=multi-user.target
  975. EOF
  976.  
  977. sudo systemctl daemon-reload
  978.  
  979. # ---------------------------------------------------------------------------
  980. # 22. Initial feed synchronization (this can take a long time)
  981. # ---------------------------------------------------------------------------
  982. echo
  983. echo "==> Starting initial Greenbone feed sync. This may take a long time..."
  984. sudo /usr/local/bin/greenbone-feed-sync
  985.  
  986. # ---------------------------------------------------------------------------
  987. # 23. Enable + start services
  988. # ---------------------------------------------------------------------------
  989. sudo systemctl enable --now ospd-openvas
  990. sudo systemctl enable --now gvmd
  991. sudo systemctl enable --now gsad
  992. sudo systemctl enable --now openvasd
  993.  
  994. # ---------------------------------------------------------------------------
  995. # 24. Create admin user and set feed-import-owner
  996. # ---------------------------------------------------------------------------
  997. if ! sudo -u gvm /usr/local/sbin/gvmd --get-users | grep -q '^admin$'; then
  998. echo "==> Creating admin user (password will be printed once below):"
  999. sudo -u gvm /usr/local/sbin/gvmd --create-user=admin
  1000. fi
  1001.  
  1002. ADMIN_UUID=$(sudo -u gvm /usr/local/sbin/gvmd --get-users --verbose | awk '$1=="admin"{print $2; exit}')
  1003. if [[ -n "$ADMIN_UUID" ]]; then
  1004. sudo -u gvm /usr/local/sbin/gvmd \
  1005. --modify-setting 78eceaec-3385-11ea-b237-28d24461215b \
  1006. --value "$ADMIN_UUID"
  1007. fi
  1008.  
  1009. # ---------------------------------------------------------------------------
  1010. # Install comment.sty LaTeX package
  1011. # ---------------------------------------------------------------------------
  1012. sudo mkdir -p /usr/share/texlive/texmf-local/tex/latex/comment
  1013. sudo curl -L \
  1014. https://mirrors.ctan.org/macros/latex/contrib/comment/comment.sty \
  1015. -o /usr/share/texlive/texmf-local/tex/latex/comment/comment.sty
  1016. sudo mktexlsr
  1017.  
  1018. # ---------------------------------------------------------------------------
  1019. # Done
  1020. # ---------------------------------------------------------------------------
  1021. cat <<EOF
  1022.  
  1023. ============================================================================
  1024. Greenbone Community Edition installation complete.
  1025.  
  1026. - Web UI: https://127.0.0.1:9392
  1027. - Admin user: admin (password shown above, if newly created)
  1028. - Service status: sudo systemctl status ospd-openvas gvmd gsad openvasd
  1029. - Logs: /var/log/gvm/
  1030.  
  1031. NOTE: The first start of the services may take minutes to hours while the
  1032. feed data is loaded into memory and the database. Scans started before
  1033. loading completes will produce incomplete results.
  1034.  
  1035. Tail the loading progress with:
  1036. sudo tail -f /var/log/gvm/gvmd.log /var/log/gvm/ospd-openvas.log
  1037.  
  1038. Re-login (or run \`newgrp gvm\`) so your shell picks up the new gvm group
  1039. membership.
  1040. ============================================================================
  1041. EOF
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment