-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinterceptssl.c
62 lines (51 loc) · 1.46 KB
/
interceptssl.c
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
#include <openssl/ssl.h>
#include <dlfcn.h>
#include <stdio.h>
const int MAX_NAME = 1024;
static char *OUTPUT_DIR = ".";
static void set_output_dir() {
char *output_dir = getenv("INTERCEPT_SSL_OUTPUT_DIR");
if (output_dir) {
OUTPUT_DIR = output_dir;
}
}
static int (*next_SSL_read)(SSL *ssl, void *buf, int num) = NULL;
int SSL_read(SSL *ssl, void *buf, int num) {
if (next_SSL_read == NULL) {
next_SSL_read = dlsym(RTLD_NEXT, "SSL_read");
set_output_dir();
}
int ret = next_SSL_read(ssl, buf, num);
if (ret > 0) {
char filename[MAX_NAME];
FILE *file;
snprintf(filename, sizeof(filename),
"%s/SSL_read.%p", OUTPUT_DIR, ssl);
file = fopen(filename, "a");
if (file) {
fwrite(buf, 1, ret, file);
fclose(file);
}
}
return ret;
}
int (*next_SSL_write)(SSL *ssl, const void *buf, int num) = NULL;
int SSL_write(SSL *ssl, const void *buf, int num) {
if (next_SSL_write == NULL) {
next_SSL_write = dlsym(RTLD_NEXT, "SSL_write");
set_output_dir();
}
int ret = next_SSL_write(ssl, buf, num);
if (ret > 0) {
char filename[MAX_NAME];
FILE *file;
snprintf(filename, sizeof(filename),
"%s/SSL_write.%p", OUTPUT_DIR, ssl);
file = fopen(filename, "a");
if (file) {
fwrite(buf, 1, ret, file);
fclose(file);
}
}
return ret;
}