Skip to content

Commit e14684d

Browse files
committed
docs(readme): fix demo commands and optimize code comments
- Update Quick Demo section with correct compilation and execution steps - Optimize comments in syscall_modifier.bpf.c for better readability - Add accurate descriptions for sentinel_loader and syscall_modifier_loader demos
1 parent 2de2534 commit e14684d

2 files changed

Lines changed: 36 additions & 19 deletions

File tree

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,25 @@ git clone https://github.com/harrison001/SentinelEdge.git
108108
cd SentinelEdge
109109
cargo build --release
110110

111-
# Run kernel monitoring demo (Linux only)
112-
sudo ./target/release/sentinel-edge --ebpf-demo
111+
# Compile eBPF programs (requires root)
112+
sudo -i
113+
cd /home/harrison/SentinelEdge/kernel-agent/src
114+
115+
# Compile sentinel monitoring program
116+
clang -O2 -g -target bpf \
117+
-D__TARGET_ARCH_x86 \
118+
-I. -I/usr/include/$(uname -m)-linux-gnu \
119+
-c sentinel.bpf.c -o sentinel.bpf.o
120+
121+
# Run system monitoring demo (process execution, network connections, file operations)
122+
sudo ../../target/release/sentinel_loader
123+
124+
# Compile syscall modifier program
125+
clang -O2 -target bpf -g -D__TARGET_ARCH_x86 \
126+
-c syscall_modifier.bpf.c -o syscall_modifier.bpf.o
127+
128+
# Run syscall security demo (protects sensitive files, threat scoring, security logging)
129+
../../target/release/syscall_modifier_loader
113130
```
114131

115132
## 📊 **Technical Specifications**

kernel-agent/src/syscall_modifier.bpf.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#define MAX_PROCESSES 1000
1111
#define MAX_RULES 100
1212

13-
// ========== 固定敏感路径放到 .rodata ==========
13+
// ========== Fixed sensitive paths in .rodata ==========
1414
const volatile char SENSITIVE_PASSWD[] SEC(".rodata") = "/etc/passwd";
1515
const volatile char SENSITIVE_SHADOW[] SEC(".rodata") = "/etc/shadow";
1616
const volatile char SENSITIVE_SUDOERS[] SEC(".rodata") = "/etc/sudoers";
1717
const volatile char SENSITIVE_ROOT[] SEC(".rodata") = "/root/";
1818

19-
// ========== map 结构 ==========
19+
// ========== Map structures ==========
2020
struct access_rule {
2121
char target_path[MAX_FILENAME_LEN];
2222
char redirect_path[MAX_FILENAME_LEN];
@@ -76,30 +76,30 @@ struct {
7676
__uint(max_entries, 256 * 1024);
7777
} syscall_events SEC(".maps");
7878

79-
// ========== helpers ==========
79+
// ========== Helper functions ==========
8080
static __always_inline void update_stats(__u32 idx) {
81-
// 可选统计map,略
81+
// Optional statistics map, omitted
8282
}
8383

8484
static __always_inline int bpf_prefix_match(const char *path, const volatile char *prefix, int len) {
8585
return bpf_strncmp(path, len, (const char *)prefix) == 0;
8686
}
8787

88-
// ✅ 简化字符串匹配避免verifier无限循环
88+
// ✅ Simplified string matching to avoid verifier infinite loops
8989
static __always_inline int match_rule_prefix(const char *path, const char *rule_path) {
90-
// 简化版本:只检查前16个字符以避免verifier复杂度
90+
// Simplified version: only check first 16 characters to avoid verifier complexity
9191
#pragma unroll
9292
for (int i = 0; i < 16; i++) {
9393
char a = path[i];
9494
char b = rule_path[i];
95-
if (b == '\0') return 1; // rule匹配完成
96-
if (a == '\0') return 0; // path结束但rule未完成
97-
if (a != b) return 0; // 字符不匹配
95+
if (b == '\0') return 1; // rule match completed
96+
if (a == '\0') return 0; // path ended but rule not completed
97+
if (a != b) return 0; // character mismatch
9898
}
9999
return 1;
100100
}
101101

102-
// ✅ 固定敏感路径检测(.rodata
102+
// ✅ Fixed sensitive path detection (.rodata)
103103
static __always_inline int is_sensitive_path(const char *path) {
104104
if (bpf_prefix_match(path, SENSITIVE_PASSWD, 11)) return 1;
105105
if (bpf_prefix_match(path, SENSITIVE_SHADOW, 11)) return 1;
@@ -108,7 +108,7 @@ static __always_inline int is_sensitive_path(const char *path) {
108108
return 0;
109109
}
110110

111-
// ✅ threat_score 简化
111+
// ✅ Simplified threat_score calculation
112112
static __always_inline int calc_threat_score(const char *path, __u32 uid) {
113113
int s = 0;
114114
if (is_sensitive_path(path)) s += 50;
@@ -117,7 +117,7 @@ static __always_inline int calc_threat_score(const char *path, __u32 uid) {
117117
return s;
118118
}
119119

120-
// ringbuf event 填充
120+
// ringbuf event population
121121
static __always_inline void log_event(__u32 pid, __u32 uid, __u32 gid,
122122
__u32 syscall_nr,
123123
const char *orig, const char *mod,
@@ -149,16 +149,16 @@ int tp_openat(struct trace_event_raw_sys_enter *ctx) {
149149
char fname[MAX_FILENAME_LEN];
150150
bpf_probe_read_user_str(fname, sizeof(fname), (void *)ctx->args[1]);
151151

152-
// threat_score
152+
// Calculate threat score
153153
__u32 score = calc_threat_score(fname, uid);
154154

155-
// 简化规则处理,先只记录事件
155+
// Simplified rule processing, only log events for now
156156
log_event(pid, uid, gid, 257, fname, fname, "OPENAT", 3, 0, score);
157157

158158
return 0;
159159
}
160160

161-
// ========== execve hook + 阻断 ==========
161+
// ========== execve hook + blocking ==========
162162
SEC("tp/syscalls/sys_enter_execve")
163163
int tp_execve(struct trace_event_raw_sys_enter *ctx) {
164164
__u32 pid = bpf_get_current_pid_tgid() >> 32;
@@ -168,10 +168,10 @@ int tp_execve(struct trace_event_raw_sys_enter *ctx) {
168168
char fname[MAX_FILENAME_LEN];
169169
bpf_probe_read_user_str(fname, sizeof(fname), (void *)ctx->args[0]);
170170

171-
// threat_score > 50 阻断
171+
// Block if threat score > 50
172172
__u32 score = calc_threat_score(fname, uid);
173173

174-
// 简化处理,只记录execve事件
174+
// Simplified processing, only log execve events
175175
log_event(pid, uid, gid, 59, fname, fname, "EXECVE", 3, 0, score);
176176

177177
return 0;

0 commit comments

Comments
 (0)