From e45a0409039032c74b3aa851eb308a541264adcd Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 28 Mar 2025 11:29:30 +0100 Subject: Initial status --- .gitignore | 2 ++ Makefile | 13 +++++++++++++ slowloris.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 slowloris.c 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 +#include +#include +#include +#include + +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; +} -- cgit v1.2.3