Skip to content

Commit 8dae44e

Browse files
authored
libssl's path should not be hard coded (eunomia-bpf#123)
1 parent 21ed62b commit 8dae44e

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/30-sslsniff/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ int BPF_URETPROBE(probe_SSL_do_handshake_exit) {
315315
if (env.openssl) {
316316
char *openssl_path = find_library_path("libssl.so");
317317
printf("OpenSSL path: %s\n", openssl_path);
318-
attach_openssl(obj, "/lib/x86_64-linux-gnu/libssl.so.3");
318+
attach_openssl(obj, openssl_path);
319319
}
320320
if (env.gnutls) {
321321
char *gnutls_path = find_library_path("libgnutls.so");
@@ -343,7 +343,7 @@ int BPF_URETPROBE(probe_SSL_do_handshake_exit) {
343343
skel->links.prog_name = bpf_program__attach_uprobe_opts( \
344344
skel->progs.prog_name, env.pid, binary_path, 0, &uprobe_opts); \
345345
} while (false)
346-
346+
347347
int attach_openssl(struct sslsniff_bpf *skel, const char *lib) {
348348
ATTACH_UPROBE_CHECKED(skel, lib, SSL_write, probe_SSL_rw_enter);
349349
ATTACH_URETPROBE_CHECKED(skel, lib, SSL_write, probe_SSL_write_exit);
@@ -411,9 +411,9 @@ void print_event(struct probe_SSL_data_t *event, const char *evt) {
411411
if (buf_size != 0) {
412412
if (env.hexdump) {
413413
// 2 characters for each byte + null terminator
414-
char hex_data[MAX_BUF_SIZE * 2 + 1] = {0};
414+
char hex_data[MAX_BUF_SIZE * 2 + 1] = {0};
415415
buf_to_hex((uint8_t *)buf, buf_size, hex_data);
416-
416+
417417
printf("\n%s\n", s_mark);
418418
for (size_t i = 0; i < strlen(hex_data); i += 32) {
419419
printf("%.32s\n", hex_data + i);
@@ -477,7 +477,7 @@ curl https://example.com
477477
当执行 `curl` 命令后,`sslsniff` 会显示以下内容:
478478

479479
```txt
480-
READ/RECV 0.132786160 curl 47458 1256
480+
READ/RECV 0.132786160 curl 47458 1256
481481
----- DATA -----
482482
<!doctype html>
483483
...
@@ -503,7 +503,7 @@ OpenSSL path: /lib/x86_64-linux-gnu/libssl.so.3
503503
GnuTLS path: /lib/x86_64-linux-gnu/libgnutls.so.30
504504
NSS path: /lib/x86_64-linux-gnu/libnspr4.so
505505
FUNC TIME(s) COMM PID LEN LAT(ms)
506-
HANDSHAKE 0.000000000 curl 6460 1 1.384 WRITE/SEND 0.000115400 curl 6460 24 0.014
506+
HANDSHAKE 0.000000000 curl 6460 1 1.384 WRITE/SEND 0.000115400 curl 6460 24 0.014
507507
```
508508

509509
### 16进制输出
@@ -512,7 +512,7 @@ HANDSHAKE 0.000000000 curl 6460 1 1.384 WRITE/SEN
512512

513513
```console
514514
$ sudo ./sslsniff --hexdump
515-
WRITE/SEND 0.000000000 curl 16104 24
515+
WRITE/SEND 0.000000000 curl 16104 24
516516
----- DATA -----
517517
505249202a20485454502f322e300d0a
518518
0d0a534d0d0a0d0a

src/30-sslsniff/README_en.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ To achieve this functionality, the `find_library_path` function is first used to
325325
if (env.openssl) {
326326
char *openssl_path = find_library_path("libssl.so");
327327
printf("OpenSSL path: %s\n", openssl_path);
328-
attach_openssl(obj, "/lib/x86_64-linux-gnu/libssl.so.3");
328+
attach_openssl(obj, openssl_path);
329329
}
330330
if (env.gnutls) {
331331
char *gnutls_path = find_library_path("libgnutls.so");
@@ -353,7 +353,7 @@ The specific `attach` functions are as follows:
353353
skel->links.prog_name = bpf_program__attach_uprobe_opts( \
354354
skel->progs.prog_name, env.pid, binary_path, 0, &uprobe_opts); \
355355
} while (false)
356-
356+
357357
int attach_openssl(struct sslsniff_bpf *skel, const char *lib) {
358358
ATTACH_UPROBE_CHECKED(skel, lib, SSL_write, probe_SSL_rw_enter);
359359
ATTACH_URETPROBE_CHECKED(skel, lib, SSL_write, probe_SSL_write_exit);
@@ -421,9 +421,9 @@ void print_event(struct probe_SSL_data_t *event, const char *evt) {
421421
if (buf_size != 0) {
422422
if (env.hexdump) {
423423
// 2 characters for each byte + null terminator
424-
char hex_data[MAX_BUF_SIZE * 2 + 1] = {0};
424+
char hex_data[MAX_BUF_SIZE * 2 + 1] = {0};
425425
buf_to_hex((uint8_t *)buf, buf_size, hex_data);
426-
426+
427427
printf("\n%s\n", s_mark);
428428
for (size_t i = 0; i < strlen(hex_data); i += 32) {
429429
printf("%.32s\n", hex_data + i);
@@ -485,7 +485,7 @@ Under normal circumstances, you will see output similar to the following:
485485
After executing the `curl` command, `sslsniff` will display the following content:
486486

487487
```txt
488-
READ/RECV 0.132786160 curl 47458 1256
488+
READ/RECV 0.132786160 curl 47458 1256
489489
----- DATA -----
490490
<!doctype html>
491491
...
@@ -511,7 +511,7 @@ OpenSSL path: /lib/x86_64-linux-gnu/libssl.so.3
511511
GnuTLS path: /lib/x86_64-linux-gnu/libgnutls.so.30
512512
NSS path: /lib/x86_64-linux-gnu/libnspr4.so
513513
FUNC TIME(s) COMM PID LEN LAT(ms)
514-
HANDSHAKE 0.000000000 curl 6460 1 1.384 WRITE/SEND 0.000115400 curl 6460 24 0.014
514+
HANDSHAKE 0.000000000 curl 6460 1 1.384 WRITE/SEND 0.000115400 curl 6460 24 0.014
515515
```
516516

517517
### Hexadecimal Output
@@ -520,7 +520,7 @@ To display data in hexadecimal format, execute the following command:
520520

521521
```console
522522
$ sudo ./sslsniff --hexdump
523-
WRITE/SEND 0.000000000 curl 16104 24
523+
WRITE/SEND 0.000000000 curl 16104 24
524524
----- DATA -----
525525
505249202a20485454502f322e300d0a
526526
0d0a534d0d0a0d0a

src/30-sslsniff/sslsniff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ int main(int argc, char **argv) {
397397
if (env.openssl) {
398398
char *openssl_path = find_library_path("libssl.so");
399399
printf("OpenSSL path: %s\n", openssl_path);
400-
attach_openssl(obj, "/lib/x86_64-linux-gnu/libssl.so.3");
400+
attach_openssl(obj, openssl_path);
401401
}
402402
if (env.gnutls) {
403403
char *gnutls_path = find_library_path("libgnutls.so");

0 commit comments

Comments
 (0)