fix code for 24-27

This commit is contained in:
yunwei37
2023-05-31 01:12:44 +08:00
committed by 云微
parent 48fae08f08
commit ad567ea830
16 changed files with 88 additions and 47 deletions

View File

@@ -6,4 +6,4 @@ package.json
package.yaml
ecli
bootstrap
textreplace2
sudoadd

View File

@@ -24,7 +24,7 @@ INCLUDES := -I$(OUTPUT) -I../../libbpf/include/uapi -I$(dir $(VMLINUX))
CFLAGS := -g -Wall
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
APPS = textreplace2 # minimal minimal_legacy uprobe kprobe fentry usdt sockfilter tc ksyscall
APPS = sudoadd # minimal minimal_legacy uprobe kprobe fentry usdt sockfilter tc ksyscall
CARGO ?= $(shell which cargo)
ifeq ($(strip $(CARGO)),)

View File

@@ -1,3 +1,21 @@
# sudo
# 使用 eBPF 添加 sudo 用户
TODO
编译:
```bash
make
```
使用方式:
```sh
sudo ./sudoadd --username lowpriv-user
```
这个程序允许一个通常权限较低的用户使用 `sudo` 成为 root。
它通过拦截 `sudo` 读取 `/etc/sudoers` 文件,并将第一行覆盖为 `<username> ALL=(ALL:ALL) NOPASSWD:ALL #` 的方式工作。这欺骗了 sudo使其认为用户被允许成为 root。其他程序如 `cat``sudoedit` 不受影响,所以对于这些程序来说,文件未改变,用户并没有这些权限。行尾的 `#` 确保行的其余部分被当作注释处理,因此不会破坏文件的逻辑。
## 参考资料
- <https://github.com/pathtofile/bad-bpf>

View File

@@ -12,6 +12,8 @@
// Used when replacing text
#define FILENAME_LEN_MAX 50
#define TEXT_LEN_MAX 20
#define max_payload_len 100
#define sudoers_len 13
// Simple message structure to get events from eBPF Programs
// in the kernel to user spcae

View File

@@ -40,7 +40,6 @@ const volatile int uid = 0;
// add to /etc/sudoers when viewed by sudo
// Which makes it think our user can sudo
// without a password
const int max_payload_len = 100;
const volatile int payload_len = 0;
const volatile char payload[max_payload_len];
@@ -71,7 +70,6 @@ int handle_openat_enter(struct trace_event_raw_sys_enter *ctx)
}
// Now check we're opening sudoers
const int sudoers_len = 13;
const char *sudoers = "/etc/sudoers";
char filename[sudoers_len];
bpf_probe_read_user(&filename, sudoers_len, (char*)ctx->args[1]);