bpflock: A Linux device security audit tool based on eBPF implementation

0 26
bpflock only allows security audit tools similar to container managers, systemd,...

bpflock: A Linux device security audit tool based on eBPF implementation

bpflock only allows security audit tools similar to container managers, systemd, and others that areHost PID or network namespaceRunning containers/programs access complete Linux features and restrict those containers or programs running in their own namespaces. If bpflock runs under a restricted configuration file, all programs/containers (including privileged programs/containers) will be denied access.

In addition to this, bpflock can also protect the security of Linux devices through various security features, such asLinux security module + BPFetc.

Function introduction

1. Memory protection: Kernel image locking, kernel module protection, BPF protection;

2. Process protection: Fileless memory execution, namespace protection;

3. Hardware attack testing: USB protection;

4. System and application tracing: Trace application execution, trace privileged system operations;

5. File system protection: Read-only Root file system protection, sysfs protection;

6. Network protection;

Tool development

Dependent components

bpflock requires the following components:

1. Linux kernel version >= 5.13, the relevant configuration is as follows:

CONFIG_BPF_SYSCALL=y

CONFIG_DEBUG_INFO=y

CONFIG_DEBUG_INFO_BTF=y

CONFIG_KPROBES=y

CONFIG_LSM="...,bpf"

CONFIG_BPF_LSM=y

2. A kernel with BTF enabled

Enable BPF LSM support

1. Open the /etc/default/grub file with advanced privileges;

2. Add the following content to the GRUB_CMDLINE_LINUX variable and save:

"lsm=lockdown,capability,yama,apparmor,bpf"

Or

GRUB_CMDLINE_LINUX="lsm=lockdown,capability,yama,apparmor,bpf"

3. Update grub configuration:

sudo update-grub2

4. Restart the device

Docker usage

The following command can be used to run the tool with the default configuration file:

docker run --name bpflock -it --rm --cgroupns=host \

--pid=host --privileged \

-v /sys/kernel/:/sys/kernel/ \

-v /sys/fs/bpf:/sys/fs/bpf linuxlock/bpflock

Execution of code without file

docker run --name bpflock -it --rm --cgroupns=host --pid=host --privileged \


-e "BPFLOCK_FILELESSLOCK_PROFILE=restricted" \

-v /sys/kernel/:/sys/kernel/ \

-v /sys/fs/bpf:/sys/fs/bpf linuxlock/bpflock

Kernel module execution

docker run --name bpflock -it --rm --cgroupns=host --pid=host --privileged \


-e "BPFLOCK_KMODLOCK_PROFILE=restricted" \

-v /sys/kernel/:/sys/kernel/ \

-v /sys/fs/bpf:/sys/fs/bpf linuxlock/bpflock

Usage example:

$ sudo unshare -p -n -f

# modprobe xfs

modprobe: ERROR: could not insert 'xfs': Operation not permitted

Output result:

time="2022-02-07T06:50:25+01:00" level=info msg="event=syscall_execve tgid=52323 pid=52323 ppid=52288 uid=0 cgroupid=7014 comm=modprobe pcomm=bash filename=/usr/sbin/modprobe retval=0" bpfprog=execsnoop subsys=bpf

 

time="2022-02-07T06:50:25+01:00" level=info msg="event=lsm_kernel_read_file operation=loading module tgid=52323 pid=52323 ppid=52288 uid=0 cgroupid=7014 comm=modprobe pcomm=bash filename=xfs.ko retval=-1 reason=denied (restricted)" bpfprog=kmodlock subsys=bpf

Kernel image locking

docker run --name bpflock -it --rm --cgroupns=host --pid=host --privileged \


-e "BPFLOCK_KIMGLOCK_PROFILE=baseline" \

-v /sys/kernel/:/sys/kernel/ \

-v /sys/fs/bpf:/sys/fs/bpf linuxlock/bpflock

Usage example:

$ sudo unshare -f -p -n bash

# head -c 1 /dev/mem

head: cannot open '/dev/mem' for reading: Operation not permitted

Output result:

time="2022-02-07T06:57:22+01:00" level=info msg="event=syscall_execve tgid=52428 pid=52428 ppid=52288 uid=0 cgroupid=7014 comm=head pcomm=bash filename=/usr/bin/head retval=0" bpfprog=execsnoop subsys=bpf

 

time="2022-02-07T06:57:22+01:00" level=info msg="event=lsm_locked_down operation=/dev/mem,kmem,port tgid=52428 pid=52428 ppid=52288 uid=0 cgroupid=7014 comm=head pcomm=bash retval=-1 reason=denied (baseline)" bpfprog=kimglock subsys=bpf

BPF Protection

docker run --name bpflock -it --rm --cgroupns=host --pid=host --privileged \


-e "BPFLOCK_BPFRESTRICT_PROFILE=baseline" \

-v /sys/kernel/:/sys/kernel/ \

-v /sys/fs/bpf:/sys/fs/bpf linuxlock/bpflock

Usage example:

$ sudo unshare -f -p -n bash

# bpftool prog

Error: can't get next program: Operation not permitted

Output result:

time="2022-02-04T15:40:56Z" level=info msg="event=lsm_bpf tgid=2378 pid=2378 ppid=2364 uid=0 cgroupid=9458 comm=bpftool pcomm=bash filename= retval=-1 reason=baseline" bpfprog=bpfrestrict subsys=bpf

 

time="2022-02-04T15:40:56Z" level=info msg="event=lsm_bpf tgid=2378 pid=2378 ppid=2364 uid=0 cgroupid=9458 comm=bpftool pcomm=bash filename= retval=-1 reason=baseline" bpfprog=bpfrestrict subsys=bpf

Tool configuration & environment configuration

Assuming that the bpflock directory of your project already contains the bpflock.yaml and bpf.d configuration files, run the following command next:

ls bpflock/

bpf.d  bpflock.d  bpflock.yaml

docker run --name bpflock -it --rm --cgroupns=host --pid=host --privileged \


-v $(pwd)/bpflock/:/etc/bpflock \


-v /sys/kernel/:/sys/kernel/ \

-v /sys/fs/bpf:/sys/fs/bpf linuxlock/bpflock

We can also use the "--env-file" command to pass environment variables:

docker run --name bpflock -it --rm --cgroupns=host --pid=host --privileged \


--env-file bpflock.env.list \

-v /sys/kernel/:/sys/kernel/ \

-v /sys/fs/bpf:/sys/fs/bpf linuxlock/bpflock

License Agreement

The development and release of this project followApache-2.0Open Source License Agreement.

Project address

bpflock:【GitHub link

Reference materials

https://ebpf.io/

https://man7.org/linux/man-pages/man7/namespaces.7.html

https://docs.kernel.org/bpf/prog_lsm.html

https://github.com/linux-lock/bpflock/tree/main/deploy/configs/

https://github.com/linux-lock/bpflock/tree/main/docs/

https://github.com/linux-lock/bpflock/tree/main/docs/memory-protections.md#3-bpf-protection

https://github.com/libbpf/bpftool

https://go.dev/doc/install

https://docs.docker.com/develop/develop-images/build_enhancements/

你可能想看:

KRIe: A Linux kernel runtime security detection tool with eBPF

It is possible to perform credible verification on the system boot program, system program, important configuration parameters, and application programs of computing devices based on a credible root,

In today's rapidly developing digital economy, data has become an important engine driving social progress and enterprise development. From being initially regarded as part of intangible assets to now

d) Adopt identification technologies such as passwords, password technologies, biometric technologies, and combinations of two or more to identify users, and at least one identification technology sho

Data security can be said to be a hot topic in recent years, especially with the rapid development of information security technologies such as big data and artificial intelligence, the situation of d

b) It should have a login failure handling function, and should configure and enable measures such as ending the session, limiting the number of illegal login attempts, and automatically logging out w

As announced today, Glupteba is a multi-component botnet targeting Windows computers. Google has taken action to disrupt the operation of Glupteba, and we believe this action will have a significant i

ebpf usage on development boards and bypassing root detection

b) It should have the login failure handling function, and should configure and enable measures such as ending the session, limiting the number of illegal logins, and automatically exiting when the lo

About the related technologies and implementations associated with tracing the source of posts by PDD employees

最后修改时间:
admin
上一篇 2025年03月27日 16:27
下一篇 2025年03月27日 16:49

评论已关闭