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 /slowloris.c | |
download | preload-slowloris-e45a0409039032c74b3aa851eb308a541264adcd.tar.gz preload-slowloris-e45a0409039032c74b3aa851eb308a541264adcd.tar.bz2 preload-slowloris-e45a0409039032c74b3aa851eb308a541264adcd.zip |
Initial status
Diffstat (limited to 'slowloris.c')
-rw-r--r-- | slowloris.c | 38 |
1 files changed, 38 insertions, 0 deletions
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; +} |