强访设计文档

nfs_security_exec_file_type 包含

1
2
3
4
5
6
7
8
9
10
11
apt_exec_t
auditctl_exec_t
dpkg_exec_t
nfs_chcon_exec_t
nfs_sec_exec_t
nfs_security_exec_t
quota_exec_t
semanage_exec_t
su_exec_t
sudo_exec_t
useradd_exec_t

nfs_security_domain_type 包含

1
2
3
4
5
6
 auditctl_t
local_login_t
nfs_security_t
quota_t
semanage_t
useradd_t

nfs_security_file_type 包含

1
2
3
etc_t
security_t
var_log_t

针对nfs_security_exec_file_type对execute_no_trans权限的限制

1
2
3
4
5
6
ifdef(`enable_mls',`
constrain file { execute_no_trans }
(
u1 == u2
or t2 != nfs_security_exec_file_type
);

对nfs_security_domain_type user_home_target 做了限制,放行nfs_security_domain_type对目录读写权限,限制用户的域访问其他用户的家目录

1
2
3
4
5
6
7
8
9
constrain dir { open search }
(
u1 == u2
or u1 == system_u
or u1 == unconfined_u
or t1 == nfs_security_domain_type
or t2 != user_home_target
or ( u1 == user_u and u2 == system_u )
);

限制对nfs_security_file_type的读权限

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
constrain dir_file_class_set { create relabelto relabelfrom }
(
u1 == u2
or t1 == can_change_object_identity
or (t1 == user_t and t2 == user_home_dir_t)
or (t1 == secadm_t and t2 == secadm_home_dir_t)
or (t1 == sysadm_t and t2 == sysadm_home_dir_t)
or (t1 == auditadm_t and t2 == auditadm_home_dir_t)
);

constrain file { execute_no_trans }
(
u1 == u2
or t1 == nfs_security_t
or t1 == useradd_t
or t2 != nfs_security_exec_file_type
);

constrain file { read }
(
u1 == u2
or u1 == system_u
or u1 == unconfined_u
or t2 != nfs_security_file_type
or (t1 != sysadm_t and t1 != auditadm_t and t1 != user_t and t2 == security_t)
or (t2 == var_log_t)
or (t2 == etc_t)
);

constrain file { write }
(
u1 == u2
or u1 == system_u
or u1 == unconfined_u
or t2 != nfs_security_file_type
or (t1 != sysadm_t and t1 != auditadm_t and t1 != user_t and t2 == security_t)
or (t1 != secadm_t and t1 != auditadm_t and t1 != user_t and t2 == var_log_t)
or ( t1 != user_t and t2 == etc_t)
);

constrain process { sigkill signal }
(
t2 != auditd_t
);

title: dbus方案
date: 2022-02-15 14:56:21
tags:

  • dbus

dbus替代系统内使用sudo nopasswd机制取得root权限方案

现在我们系统内一些在普通用户下需要无密码root权限的操作,是通过给对应的脚本或者程序sudo的NOPASSWD权限来实现的,这种实现方式存在很大的安全隐患,如果被配置了sudo的NOPASSWD的脚本被恶意篡改,那将会有很大的安全隐患。

python demo

以应用商城的安装脚本为例子

1
/usr/share/cdos-softcenter/apt-get-bash.py

脚本中很多步骤是不需要root权限的,需要的只有 install、remove、update、upgrade等操作,我们可以使用dbus的机制把这一部分操作摘取出来,放到一个服务中去,而其他的操作只给予普通用户权限。

针对这个我写了一个使用dbus替代的验证demo

在server端里添加一个回调函数 Test

1
2
3
4
5
6
7
8
9
10
11
class SomeObject(dbus.service.Object):

@dbus.service.method("com.example.SampleInterface",
in_signature='s', out_signature='as')
def Test(self, hello_message):
print("service:", str(hello_message))
cmd="apt " + hello_message + " -y"
ret=subprocess.getoutput(cmd)

return [ret, "with unique name",
session_bus.get_unique_name()]

在client端发送method call来调用server的中的函数

1
2
3
4
5
6
7
try:
remote_object = bus.get_object("com.example.SampleService",
"/SomeObject")

# you can either specify the dbus_interface in each call...
hello_reply_list = remote_object.Test(cmd,
dbus_interface = "com.example.SampleInterface")

使用root用户执行

1
python3 service.py

普通用户执行

1
python3 client.py remove d-feet -y

得到执行服务端返回的执行结果

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
client:
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

正在读取软件包列表...
正在分析软件包的依赖关系树...
正在读取状态信息...
下列软件包将被【卸载】:
d-feet
升级了 0 个软件包,新安装了 0 个软件包,要卸载 1 个软件包,有 154 个软件包未被升级。
解压缩后将会空出 597 kB 的空间。
(正在读取数据库 ...
(正在读取数据库 ... 5%
(正在读取数据库 ... 10%
(正在读取数据库 ... 15%
(正在读取数据库 ... 20%
(正在读取数据库 ... 25%
(正在读取数据库 ... 30%
(正在读取数据库 ... 35%
(正在读取数据库 ... 40%
(正在读取数据库 ... 45%
(正在读取数据库 ... 50%
(正在读取数据库 ... 55%
(正在读取数据库 ... 60%
(正在读取数据库 ... 65%
(正在读取数据库 ... 70%
(正在读取数据库 ... 75%
(正在读取数据库 ... 80%
(正在读取数据库 ... 85%
(正在读取数据库 ... 90%
(正在读取数据库 ... 95%
(正在读取数据库 ... 100%
(正在读取数据库 ... 系统当前共安装有 200005 个文件和目录。)
正在卸载 d-feet (0.3.14-1) ...
正在处理用于 mime-support (3.62) 的触发器 ...
正在处理用于 hicolor-icon-theme (0.17-2) 的触发器 ...
正在处理用于 libglib2.0-0:amd64 (2.58.3-2+deb10u3+nfs4) 的触发器 ...
正在处理用于 man-db (2.8.5-2) 的触发器 ...
正在处理用于 desktop-file-utils (0.23-4) 的触发器 ...

C Qt demo

针对不同的情况我还写了c的dbus的demo和qt的dbus的demo

c的dbus常用接口可以看dbus-c.md,使用方法可以看demo里的代码

服务端的代码可以看 dbus_receive()函数

发送端可以看dbus_send_signal()和dbus_send_method_call(),一个是发送signal,一个是发送method call请求,c的demo中,method call函数是将接收到的数据再原路返回。

c demo用法

root用户执行

1
./demo receive

普通用户执行

1
2
./demo send SIGNAL STRING hello
./demo send METHOD INT32 99

第一个发送signal ,发送数据类型为string,数据为hello,没有返回值

第二个是发送method call,数据类型为int,数据为99

在使用c的基础上又写了qt的demo

callback按钮为发送method call,在第一个输入框内输入字符,发送给服务端,接收返回结果在第二个框内显示,send为发送signal,这个可以使用c demo来作为服务端。

![q t](./dbus方案/q t.png)

dbus api 使用流程图

下面流程图为服务端处理method call的流程
建立服务流程

下面流程图为服务端处理信号的流程
服务处理信号

下面流程图为客户端发送函数调用的流程
发送函数调用

下面流程图为客户端发送信号的流程图
发送信号

添加内核模块

将模块代码放到指定位置
drivers/char/vtcm/

然后添加Makefile

obj-$(CONFIG_VTCM) += vtcm.o

添加Kconfig

config VTCM
tristate “VTCM Driver Support”
depends on TCG_TPM
default m
help
This enables support for VTCM driver.

​ If unsure, say N.

修改 drivers/char/Makefile,添加
obj-$(CONFIG_VTCM) += vtcm/

修改 drivers/char/Kconfig,添加
source “drivers/char/vtcm/Kconfig”

audispd-plugins

audispd-plugins功能调研

audisp-remote.conf

remote_server = //插件将向其发送日志信息的远程服务器主机名或者地址。

port = 60 //远程服务器接受信息端口。

##local_port = //本地计算机发送信息时的端口,如果不指定,则使用任何可用的端口。

transport = tcp //此参数告诉远程日志记录应用程序如何将事件发送到远程系统。现在唯一有效的值是tcp。如果设置为tcp,远程日志记录应用程序将只与远程系统建立正常的明文连接。

queue_file = /var/spool/audit/remote.log //队列文件

mode = immediate //此参数告诉远程日志记录应用程序使用什么策略将记录获取到远程系统。有效值为immediateforward。如果设置为immediate,远程日志记录应用程序将尝试在获取事件后立即发送它们。forward意味着它会将事件存储到磁盘,然后尝试发送记录。如果无法建立连接,它将对记录进行排队,直到它可以连接到远程系统。

queue_depth = 10240 //此选项是一个无符号整数,用于确定在将其视为发送失败之前可以将多少条记录缓冲到磁盘或内存中。此参数影响模式选项的**转发模式和临时网络中断的内部排队。

format = managed //此参数告诉远程日志记录应用程序将使用哪种数据格式用于通过网络发送的消息。默认时managed会增加开销,如果改成ascii会减少开销

network_retry_time = 1 //检测到网络错误时重试之间的时间(以秒为单位)。

max_tries_per_record = 3 //尝试传递每条消息的最大次数。最小值为 1,因为即使是完全成功的交付也需要至少尝试一次。

max_time_per_record = 5 //尝试传递每条消息所花费的最长时间(以秒为单位)。

heartbeat_timeout = 0 //此参数确定客户端应以秒为单位向远程服务器发送心跳事件的频率。这用于让客户端和服务器都知道每一端都处于活动状态并且没有以没有不干净地关闭连接的方式终止。该值必须与服务器的tcp_client_max_idle设置相协调。默认值为 0,即禁用发送心跳。

network_failure_action = stop //此参数告诉系统在将审计事件发送到远程系统时检测到错误时要采取的操作。有效值为 ignoresyslogexecsuspendsinglehaltstop

disk_low_action = ignore //同样,如果远程端发出磁盘低错误信号,此参数会告诉系统采取什么操作。默认是忽略它。

disk_full_action = warn_once //此参数告诉系统如果远程端发出磁盘已满错误信号要采取的操作。

disk_error_action = warn_once //这个参数告诉系统如果远程端发出磁盘错误信号要采取什么行动。

remote_ending_action = reconnect //这个参数告诉系统如果远程端发出磁盘错误信号要采取什么行动。此操作有一个附加选项, 重新连接,它告诉远程插件在收到下一条审计记录后尝试重新连接到服务器。如果不成功,审计记录可能会丢失。

generic_error_action = syslog //如果远程端发出我们无法识别的错误信号,此参数会告诉系统采取什么操作。

generic_warning_action = syslog //这个参数告诉系统如果远程端发出我们不认识的警告信号要采取什么行动。

queue_error_action = stop //此参数告诉系统在使用本地记录队列时出现问题时要采取的操作。

overflow_action = syslog //这个参数告诉系统如果内部事件队列溢出要采取什么行动。有效值为ignoresyslogsuspendsinglehalt

startup_failure_action = warn_once_continue //此参数告诉系统在启动期间连接到远程系统时出现错误时要采取的操作。有效值为 ignore、syslog、exec、warn_once 和 warn_once_continue。

##krb5_principal =
##krb5_client_name = auditd
##krb5_key_file = /etc/audisp/audisp-remote.key

dbus_qtdemo使用文档

dbus替代sudo NOPASSWD的qt方案示例说明

撰写人:系统安全组

此文档提供一种使用dbus的机制来替代系统某些脚本权限过高的问题,我们系统中对一 些管理脚本赋予了sudo的NOPASSWD权限,如果脚本被修改执行,那么脚本可以直接 获取root权限,这个存在很大的安全隐患。 现在使用dbus写了一个demo,demo分为服务端和客戶端,客戶端相当于之前系统中的 管理脚本,只有普通用戶权限,将需要root权限的操作放到server端里去执行。

服务端

实现简介

qt demo的模拟场景一个是需要root权限执行 autitcl命令时,有客户端发送method call 来请求,由服务端来执行具体的操作,以及一个发送signal的演示

代码编译

需要安装的开发包libdbus-1-dev及需要移动一下头文件:

$ sudo apt install libdbus-1-dev -y
$ sudo cp /usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus/dbus-arch-deps.h /usr/include/dbus-1.0/dbus/

服务端编译

服务端代码是由c写的,进入c_service/编译service代码

1
2
wky@wky-pc:~/qt$ cd c_service/
wky@wky-pc:~/qt/c_service$ make

移动编译好的demo程序到/usr/bin/:

wky@wky-pc: sudo cp demo /usr/bin/

服务端配置

1conf配置

因为使用的是system bus,我们还需要给配置一下接口的conf文件,创建一个/etc/dbus-1/system.d/test1.conf内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!-- Bus that listens on a debug pipe and doesn't create any restrictions -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<type>system</type>

<listen>unix:tmpdir=/tmp</listen>

<standard_system_servicedirs />

<policy context="default">
<!-- Allow everything to be sent -->
<allow send_destination="*" eavesdrop="true"/>
<!-- Allow everything to be received -->
<allow eavesdrop="true"/>
<!-- Allow anyone to own anything -->
<allow own="*"/>
<allow user="*"/>
</policy>

</busconfig>

此文件中几个关键的配置说明:

system dbus 服务的bus类型,分为system和session,我们要垮用戶通信,就需要用 system总线 unix:tmpdir=/tmp 设置监听地址

dbus service文件目录,在/usr/share/dbus-1/system-services下 配置dbus的一些策略

主要是注册com.dbus.receiver_app,send_interface和send_destination为了方便 调试我这里都是用*。

2 服务自启动配置

为了使服务端随着系统启动就进行自启动,需要配置/usr/share/dbus-1/system-services/com.example.SampleService.service文件,示例如下: 在/usr/share/ dbus-1/system-services/下创建一个com.dbus.receiver_app.service

1
2
3
4
5
wky@wky-pc:~$ cat /usr/share/dbus-1/system-services/com.dbus.receiver_app.service
[D-BUS Service]
Name=com.dbus.receiver_app
Exec=/usr/bin/demo receive
User=root

这个文件是用来给dbus服务程序做按需启动的,当客戶端发起请求时,会根据 test1.conf中的 在/usr/share/dbus-1/system-services/找到对应的service文件,来 启动dbus的服务程序。

Name=com.dbus.receiver_app 这个跟代码里服务程序的bus name对应起来。 Exec=/usr/bin/demo receive 这个为启动服务程序的方式。

User=root 启动服务程序的用戶,因为我们是为了替代sudo nopasswd权限滥用问 题,服务端就用root就可以。

客户端

编译客户端,进入到src目录中编译qt代码

wky@wky-pc:~/qt$ cd src/

wky@wky-pc:~/qt/src$ make

注:新的qt工程如果要用dbus接口,可能需要在Makefile中的INCPATH参数后面补充上 -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -ldbus-1

然后执行 ./dbus 启动qt客户端

客户端一共两个按钮,signal按钮是向服务端发送一个信号,信号的信息填写到 路径 的textedit框中就可以发送给服务端

如果是手动执行的服务端程序就可以看到服务端打印的信息。

主要功能是第一个按钮 method call,是模拟执行下面这条命令

auditctl -w /tmp/111 -p wax -k testaudit

这条命令普通用户权限是无法执行的,只有root用户有权限

路径 中填入 /tmp/111

权限 中填入 wax

key值 中填入 testaudit

点击method call ,效果如下,如果服务端运行成功,则返回一个sucess

success

此时用root用户执行下面命令可以看到规则已经添加

1
2
root@wky-pc:/home/wky/qt/src# auditctl -l
-w /tmp/111 -p wxa -k testaudit

这时候如果再点击method call ,因为规则已经存在,服务端执行命令失败,则返回一个false

false

可以使用root用户执行 auditctl -D 清空规则,再次执行就可以成功

dbus配置说明

以c的dbus demo代码为例子,做一个自启动的dbus服务配置

首先c demo的源码目录下有一个 test1.conf文

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!-- Bus that listens on a debug pipe and doesn't create any restrictions -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<type>system</type>

<listen>unix:tmpdir=/tmp</listen>

<standard_system_servicedirs />

<policy context="default">
<!-- Allow everything to be sent -->
<allow send_destination="*" eavesdrop="true"/>
<!-- Allow everything to be received -->
<allow eavesdrop="true"/>
<!-- Allow anyone to own anything -->
<allow own="*"/>
<allow user="*"/>
</policy>

</busconfig>

先将这个文件放到 /etc/dbus-1/system.d/ 下,几个关键的配置说明

system dbus 服务的bus类型,分为system和session,我们要垮用户通信,就需要用system总线

unix:tmpdir=/tmp 设置监听地址

dbus service文件目录,在/usr/share/dbus-1/system-services下

配置dbus的一些策略

然后需要在/usr/share/dbus-1/system-services/下创建一个 com.dbus.receiver_app.service

1
2
3
4
5
cat /usr/share/dbus-1/system-services/com.dbus.receiver_app.service
[D-BUS Service]
Name=com.dbus.receiver_app
Exec=/usr/bin/demo receive
User=root

这个文件是用来给dbus服务程序做按需启动的,当客户端发起请求时,会根据 test1.conf中的 在/usr/share/dbus-1/system-services/找到对应的service文件,来启动dbus的服务程序

Name=com.dbus.receiver_app 这个跟代码里服务程序的bus name对应起来

Exec=/usr/bin/demo receive 这个为启动服务程序的方式

User=root 启动服务程序的用户,因为我们是为了替代sudo nopasswd权限滥用问题,服务端就用root就可以

然后把c的源码编译一下,直接make一下,然后将编译好的demo复制一份到/usr/bin/下

再用普通用户执行

1
2
wky@wky-pc:~/C_dbus$ ./demo send METHOD INT32 99
[59355] Got Method Return INT32: 99

可以获取到服务端返回的返回值

1
2
3
wky@wky-pc:~/C_dbus$ ps aux |grep demo
root 9584 0.0 0.0 5008 1100 ? S 14:21 0:00 /usr/bin/demo receive
wky 59389 0.0 0.0 9152 888 pts/2 S+ 17:24 0:00 grep demo

使用ps查看一下,也可以看到服务端已经以root权限启动了

dbus_c

C dbus开发

发送消息

dbus错误结构体

1
2
DBusError error;
dbus_error_init(&error);

连接到dbus总线

1
DBusConnection* connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);

如果要用system bus,第一个参数就是DBUS_BUS_SYSTEM,如果要用session bus,那么第一个参数就是DBUS_BUS_SESSION

注册连接名称

1
int ret = dbus_bus_request_name(connection, sender.bus_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &error);

第二个参数为 DBUS_APPLICATION sender;

接着创建完善和发送dbus消息,这个流程是发送信号的

1
2
3
DBusMessage* message = dbus_message_new_signal(receiver.object_path, receiver.interface_name, receiver.member_name);
dbus_message_iter_init_append(message, &iter);
dbus_connection_send(connection, message, &serial)

如果是要发送函数调用,发送流程如下

1
2
3
DBusMessage* message = dbus_message_new_signal(receiver.object_path, receiver.interface_name, receiver.member_name);
dbus_message_iter_init_append(message, &iter);
dbus_connection_send_with_reply(connection, message, &pending, DBUS_TIMEOUT_USE_DEFAULT)

阻塞等待函数返回结果

1
2
3
dbus_pending_call_block(pending);              
message = dbus_pending_call_steal_reply(pending);
dbus_pending_call_unref(pending);

提取结果

1
2
dbus_message_iter_init(message, &iter)
ret = dbus_message_iter_get_arg_type(&iter);

接受消息

dbus错误结构体

1
2
DBusError error;
dbus_error_init(&error);

连接到dbus总线

1
DBusConnection* connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);

注册连接名称

1
int ret = dbus_bus_request_name(connection, sender.bus_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &error);

添加消息筛选

1
dbus_bus_add_match(connection, rule, &error);

rule为char*

循环接收和处理消息

1
2
dbus_connection_read_write(connection, 0);
message = dbus_connection_pop_message(connection);

分析接收到的消息

1
2
dbus_message_is_signal(message, self.interface_name, DBUS_MEMBER_SIGNAL)
dbus_message_is_method_call(message, self.interface_name, DBUS_MEMBER_METHOD)

根据这两个函数的返回值判断接收到的是一个信号还是一个函数调用请求

gvm离线初始化

此文档是在安装完gvm组件的kali系统上离线完成gvm初始化的操作文档

首先要先把gvm组件安装好(这一步如果需要,可以之后可以修改成将必要的包下载到本地来安装)

先修改 /etc/apt/sources.list ,将kali源更换一下,如果默认是这个源就不用换

1
2
deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
deb-src http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib

执行下面命令将gvm相关的组建安装好

1
2
3
┌──(root💀kali)-[/home/kali]
└─# apt update
└─# apt install gvm*

安装完可以查看下gvm的安装版本

1
2
3
4
5
6
7
8
┌──(root💀kali)-[/home/kali]
└─# gvmd --version 127 ⨯
Greenbone Vulnerability Manager 21.4.4
Manager DB revision 242
Copyright (C) 2009-2021 Greenbone Networks GmbH
License: AGPL-3.0-or-later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

断网初始化gvm

如果是联网的环境,可以直接执行下面命令开始进行gvm的初始化流程

1
2
┌──(root💀kali)-[/home/kali]
└─# gvm-setup

检查postgreSql的版本

在安装过程成,可能会遇到系统里有两个版本PostgreSQL的情况
最新版本的gvm需要14版本的postgresql数据库,如果系统里默认的主版本是13版本,就需要修改一下

先查看系统里的PostgreSQL版本

1
2
3
4
5
┌──(root💀kali)-[/home/kali]
└─# pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
13 main 5432 down postgres /var/lib/postgresql/13/main /var/log/postgresql/postgresql-13-main.log
14 main 5433 down postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log

删除13版本的PostgreSQL

1
2
┌──(root💀kali)-[/home/kali]
└─# pg_dropcluster --stop 13 main

将14设置为主要版本

1
2
┌──(root💀kali)-[/home/kali]
└─# pg_upgradecluster 14 main

然后把14版本的PostgreSQL监听端口修改成5432

修改/etc/postgresql/14/main/postgresql.conf ,将其中的port = 修改为5432

1
2
3
4
port = 5432                             # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories

解压初始化脚本包

我已经将修改过的初始化脚本和备份好的数据库文件打包成init_gvm.tar.gz包

解压压缩包

1
2
3
4
5
6
7
8
┌──(root💀kali)-[/home/kali]
└─# tar -xzvf init_gvm.tar.gz
init_gvm/
init_gvm/init.sh
init_gvm/greenbone-feed-sync
init_gvm/plugins.tar.gz
init_gvm/greenbone-nvt-sync
init_gvm/gvm.tar.gz

进入到init_gvm目录,执行init脚本

1
2
┌──(root💀kali)-[/home/kali/init_gvm]
└─# sudo sh init.sh

执行gvm-setup并等待初始化完成

1
2
┌──(root💀kali)-[/home/kali/init_gvm]
└─# gvm-setup

执行gvm-check-setup检查初始化是否成功

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
┌──(root💀kali)-[/home/kali/init_gvm]
└─# gvm-check-setup
gvm-check-setup 21.4.3
Test completeness and readiness of GVM-21.4.3
Step 1: Checking OpenVAS (Scanner)...
OK: OpenVAS Scanner is present in version 21.4.3.
OK: Server CA Certificate is present as /var/lib/gvm/CA/servercert.pem.
Checking permissions of /var/lib/openvas/gnupg/*
OK: _gvm owns all files in /var/lib/openvas/gnupg
OK: redis-server is present.
OK: scanner (db_address setting) is configured properly using the redis-server socket: /var/run/redis-openvas/redis-server.sock
OK: redis-server is running and listening on socket: /var/run/redis-openvas/redis-server.sock.
OK: redis-server configuration is OK and redis-server is running.
OK: _gvm owns all files in /var/lib/openvas/plugins
OK: NVT collection in /var/lib/openvas/plugins contains 77525 NVTs.
Checking that the obsolete redis database has been removed
OK: No old Redis DB
OK: ospd-OpenVAS is present in version 21.4.3.
Step 2: Checking GVMD Manager ...
OK: GVM Manager (gvmd) is present in version 21.4.4.
Step 3: Checking Certificates ...
OK: GVM client certificate is valid and present as /var/lib/gvm/CA/clientcert.pem.
OK: Your GVM certificate infrastructure passed validation.
Step 4: Checking data ...
OK: SCAP data found in /var/lib/gvm/scap-data.
OK: CERT data found in /var/lib/gvm/cert-data.
Step 5: Checking Postgresql DB and user ...
OK: Postgresql version and default port are OK.
gvmd | _gvm | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
OK: At least one user exists.
Step 6: Checking Greenbone Security Assistant (GSA) ...
Oops, secure memory pool already initialized
OK: Greenbone Security Assistant is present in version 21.4.3.
Step 7: Checking if GVM services are up and running ...
Starting ospd-openvas service
Waiting for ospd-openvas service
OK: ospd-openvas service is active.
Starting gvmd service
Waiting for gvmd service
OK: gvmd service is active.
Starting greenbone-security-assistant service
Waiting for greenbone-security-assistant service
OK: greenbone-security-assistant service is active.
Step 8: Checking few other requirements...
OK: nmap is present in version 21.4.3.
OK: ssh-keygen found, LSC credential generation for GNU/Linux targets is likely to work.
WARNING: Could not find makensis binary, LSC credential package generation for Microsoft Windows targets will not work.
SUGGEST: Install nsis.
OK: xsltproc found.
WARNING: Your password policy is empty.
SUGGEST: Edit the /etc/gvm/pwpolicy.conf file to set a password policy.

It seems like your GVM-21.4.3 installation is OK.

显示如上结果则表明初始化过程成功完成
然后重启下gvm的服务

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
┌──(root💀kali)-[/home/kali/init_gvm]
└─# gvm-stop
┌──(root💀kali)-[/home/kali/init_gvm]
└─# gvm-start 3 ⨯
[>] Please wait for the GVM services to start.
[>]
[>] You might need to refresh your browser once it opens.
[>]
[>] Web UI (Greenbone Security Assistant): https://127.0.0.1:9392

● greenbone-security-assistant.service - Greenbone Security Assistant (gsad)
Loaded: loaded (/lib/systemd/system/greenbone-security-assistant.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-11-30 18:30:45 CST; 9ms ago
Docs: man:gsad(8)
https://www.greenbone.net
Process: 6970 ExecStart=/usr/sbin/gsad --listen=127.0.0.1 --port=9392 (code=exited, status=0/SUCCESS)
Main PID: 6971 (gsad)
Tasks: 3 (limit: 4578)
Memory: 2.1M
CPU: 15ms
CGroup: /system.slice/greenbone-security-assistant.service
├─6971 /usr/sbin/gsad --listen=127.0.0.1 --port=9392
└─6972 /usr/sbin/gsad --listen=127.0.0.1 --port=9392

11月 30 18:30:45 kali systemd[1]: Starting Greenbone Security Assistant (gsad)...
11月 30 18:30:45 kali gsad[6970]: Oops, secure memory pool already initialized
11月 30 18:30:45 kali systemd[1]: Started Greenbone Security Assistant (gsad).

● gvmd.service - Greenbone Vulnerability Manager daemon (gvmd)
Loaded: loaded (/lib/systemd/system/gvmd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-11-30 18:30:40 CST; 5s ago
Docs: man:gvmd(8)
Process: 6939 ExecStart=/usr/sbin/gvmd --osp-vt-update=/run/ospd/ospd.sock --listen-group=_gvm (code=exited, status=0/SUCCESS)
Main PID: 6945 (gvmd)
Tasks: 1 (limit: 4578)
Memory: 5.2M
CPU: 63ms
CGroup: /system.slice/gvmd.service
└─6945 "gvmd: Waiting for incoming connections" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

11月 30 18:30:39 kali systemd[1]: Starting Greenbone Vulnerability Manager daemon (gvmd)...
11月 30 18:30:39 kali systemd[1]: gvmd.service: Can't open PID file /run/gvm/gvmd.pid (yet?) after start: Operation not permitted
11月 30 18:30:40 kali systemd[1]: Started Greenbone Vulnerability Manager daemon (gvmd).

● ospd-openvas.service - OSPd Wrapper for the OpenVAS Scanner (ospd-openvas)
Loaded: loaded (/lib/systemd/system/ospd-openvas.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-11-30 18:30:39 CST; 5s ago
Docs: man:ospd-openvas(8)
man:openvas(8)
Process: 6935 ExecStart=/usr/bin/ospd-openvas --config /etc/gvm/ospd-openvas.conf --log-config /etc/gvm/ospd-logging.conf --unix-socket /run/ospd/ospd.sock --pid-file /run/ospd/ospd-openvas.pid --log-file /var/log/gvm/ospd-openvas.log --lock-file-dir /var/lib/openvas (code=exited, status=0/SUCCESS)
Main PID: 6937 (ospd-openvas)
Tasks: 4 (limit: 4578)
Memory: 24.0M
CPU: 199ms
CGroup: /system.slice/ospd-openvas.service
├─6937 /usr/bin/python3 /usr/bin/ospd-openvas --config /etc/gvm/ospd-openvas.conf --log-config /etc/gvm/ospd-logging.conf --unix-socket /run/ospd/ospd.sock --pid-file /run/ospd/ospd-openvas.pid --log-file /var/log/gvm/ospd-openvas.log --lock-file-dir /var/lib/openvas
└─6940 /usr/bin/python3 /usr/bin/ospd-openvas --config /etc/gvm/ospd-openvas.conf --log-config /etc/gvm/ospd-logging.conf --unix-socket /run/ospd/ospd.sock --pid-file /run/ospd/ospd-openvas.pid --log-file /var/log/gvm/ospd-openvas.log --lock-file-dir /var/lib/openvas

11月 30 18:30:39 kali systemd[1]: Starting OSPd Wrapper for the OpenVAS Scanner (ospd-openvas)...
11月 30 18:30:39 kali systemd[1]: Started OSPd Wrapper for the OpenVAS Scanner (ospd-openvas).

[>] Opening Web UI (https://127.0.0.1:9392) in: 5... 4... 3... 2... 1...

设置用户名和密码

1
2
┌──(root💀kali)-[/home/kali/init_gvm]
└─# runuser -u _gvm -- gvmd --user=admin --new-password=abc123

gvm 使用

打开浏览器,输入127.0.0.1:9392 如图,点击advanced,然后再点击 Accept the Risk and Continue
1

输入刚才设置的用户名密码
2

在Administration栏中选择feed status
3
等SCAP CERT GVMD_DATA的Status项从updating…的状态变为 xx days之后,就可以正常使用gvm来进行漏洞扫描了。

更新数据库

联网机器

联网的机器更新更新漏洞数据库只需要执行下面命令即可

1
2
┌──(root💀kali)-[/home/wky]
└─# gvm-feed-update

断网机器更新

断网机器更新需要先将更新好的机器中数据库文件整体打包出来

1
2
3
4
┌──(root💀kali)-[/var/lib/openvas]
└─# tar -czvf ~/plugins.tar.gz /var/lib/openvas/plugins
┌──(root💀kali)-[/var/lib]
└─# tar -czvf ~/gvm.tar.gz /var/lib/gvm

将打包好的plugins.tar.gz 和gvm.tar.gz拿到断网机器上并复制到 /tmp目录下

然后再执行

1
2
┌──(root💀kali)-[/home/wky]
└─# gvm-feed-update

即可,因为断网的更新脚本已经被修改过了,会在/tmp下寻找数据库的压缩包来更新数据库