diff options
author | cbdev <cb@cbcdn.com> | 2025-03-28 11:29:30 +0100 |
---|---|---|
committer | cbdev <cb@cbcdn.com> | 2025-03-28 11:29:30 +0100 |
commit | e45a0409039032c74b3aa851eb308a541264adcd (patch) | |
tree | 73ad113c3c607dba0f672fbd94e95428ae8716ab | |
download | preload-slowloris-e45a0409039032c74b3aa851eb308a541264adcd.tar.gz preload-slowloris-e45a0409039032c74b3aa851eb308a541264adcd.tar.bz2 preload-slowloris-e45a0409039032c74b3aa851eb308a541264adcd.zip |
Initial status
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | slowloris.c | 38 |
3 files changed, 53 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4d7ffa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.so +*.swp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fa8e2fb --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +CFLAGS += -fPIC +LDFLAGS += -shared +LDLIBS += -ldl + +%.so :: %.c + $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) $(LDLIBS) + +slowloris.so: slowloris.c + +all: slowloris.so + +clean: + $(RM) slowloris.so diff --git a/slowloris.c b/slowloris.c new file mode 100644 index 0000000..b4a7ac1 --- /dev/null +++ b/slowloris.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <sys/socket.h> +#include <dlfcn.h> +#include <netinet/tcp.h> +#include <netinet/in.h> + +int socket(int domain, int type, int protocol){ + static int (*real_socket) (int, int, int) = NULL; + if(!real_socket){ + real_socket = dlsym(RTLD_NEXT, "socket"); + } + + int fd = real_socket(domain, type, protocol); + int enable = 1; + + if(domain == AF_INET && type == SOCK_STREAM){ + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)); + } + return fd; +} + +ssize_t send(int sockfd, const void* buf, size_t len, int flags){ + static ssize_t (*real_send) (int, void*, size_t, int) = NULL; + if(!real_send){ + real_send = dlsym(RTLD_NEXT, "send"); + } + + ssize_t rv = 0; + + for(size_t u = 0; u < len; u++){ + ssize_t sent = real_send(sockfd, buf + u, 1, flags); + if(sent < 0){ + return 1; + } + rv += sent; + } + return rv; +} |