-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cody0704
committed
Mar 26, 2022
1 parent
0ea5e7b
commit 0416e56
Showing
11 changed files
with
389 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var ( | ||
versionID string = "%VERSION%" | ||
version bool | ||
mode string | ||
timeout int | ||
concurrency int | ||
totalRequest int | ||
requestIP string | ||
requestPort string | ||
domainFile string | ||
) | ||
|
||
func init() { | ||
flag.BoolVar(&version, "v", false, "number of concurrency") | ||
flag.StringVar(&mode, "m", "dot", "dot / doh / dns") | ||
flag.IntVar(&timeout, "t", 3, "Last Recv Packet Timeout") | ||
flag.IntVar(&concurrency, "c", 1, "number of concurrency") | ||
flag.IntVar(&totalRequest, "n", 1, "number of request") | ||
flag.StringVar(&requestIP, "r", "", "request ip address") | ||
flag.StringVar(&requestPort, "p", "", "request port") | ||
flag.StringVar(&domainFile, "f", "", "domain list file") | ||
|
||
flag.Parse() | ||
|
||
if version { | ||
fmt.Println(versionID) | ||
os.Exit(0) | ||
} | ||
|
||
if concurrency == 0 || totalRequest == 0 || requestIP == "" || mode == "" { | ||
fmt.Println("Example: dotbomb -m dot -c 10 -n 100 -r 8.8.8.8 -p 853 -f domains.txt") | ||
fmt.Println("-v [Version]") | ||
fmt.Println("-m [Mode] Default: dot, Option: dot / doh / dns") | ||
fmt.Println("-c [Concurrency] <Number>") | ||
fmt.Println("-t [Timeout] <Second>") | ||
fmt.Println("-n [request] <Number>") | ||
fmt.Println("-r <Server IP>") | ||
fmt.Println("-p <Port: DoT 853 / DoH 443 / DNS 53>") | ||
fmt.Println("-f <DomainList File Path>") | ||
|
||
os.Exit(0) | ||
} | ||
|
||
switch mode { | ||
case "dns", "dot", "doh": | ||
default: | ||
fmt.Println("-m [Mode] Default: dot, Option: dot / doh / dns") | ||
os.Exit(0) | ||
} | ||
|
||
if requestPort == "" { | ||
switch mode { | ||
case "dns": | ||
requestPort = "53" | ||
case "dot": | ||
requestPort = "853" | ||
case "doh": | ||
requestPort = "443" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/cody0704/dotbomb/server/verify" | ||
|
||
rdns "github.com/folbricht/routedns" | ||
"github.com/miekg/dns" | ||
) | ||
|
||
func (b Bomb) DNS() { | ||
server := b.RequestIP + ":" + b.RequestPort | ||
if !verify.DNSServer(server) { | ||
log.Println("Cannot connect to DNS Server:", server) | ||
os.Exit(0) | ||
return | ||
} | ||
log.Println("DNS Server:", server) | ||
|
||
t1 := time.Now() | ||
|
||
wg.Add(b.Concurrency) | ||
var domainCount = len(b.DomainArray) | ||
finish := b.TotalRequest * b.Concurrency | ||
for count := 1; count <= b.Concurrency; count++ { | ||
go func(count, finish int) { | ||
// Build a query | ||
q := new(dns.Msg) | ||
|
||
// Resolve the query | ||
dnsClient, err := rdns.NewDNSClient("stress-dns-"+strconv.Itoa(count), server, "udp", rdns.DNSClientOptions{}) | ||
if err != nil { | ||
log.Println(err) | ||
wg.Done() | ||
return | ||
} | ||
|
||
for i := 0; i < b.TotalRequest; i++ { | ||
domain := b.DomainArray[i%domainCount] + "." | ||
|
||
q.SetQuestion(domain, dns.TypeA) | ||
atomic.AddUint64(&Result.SendCount, 1) | ||
fmt.Printf("Progress:\t%d/%d\r", Result.SendCount, finish) | ||
resp, err := dnsClient.Resolve(q, rdns.ClientInfo{}) | ||
if err != nil { | ||
if strings.Contains(err.Error(), "timed out") { | ||
atomic.AddUint64(&Result.TimeoutCount, 1) | ||
} else { | ||
atomic.AddUint64(&Result.OtherCount, 1) | ||
} | ||
continue | ||
} | ||
Result.LastTime = time.Since(t1) | ||
|
||
answers := resp.Answer | ||
if len(answers) > 0 { | ||
switch len(strings.Split(answers[0].String(), "\t")) { | ||
case 5: | ||
atomic.AddUint64(&Result.RecvAnsCount, 1) | ||
default: | ||
atomic.AddUint64(&Result.RecvNoAnsCount, 1) | ||
} | ||
} else { | ||
atomic.AddUint64(&Result.RecvNoAnsCount, 1) | ||
} | ||
|
||
} | ||
wg.Done() | ||
}(count, finish) | ||
} | ||
wg.Wait() | ||
StatusChan <- 0 | ||
} |
Oops, something went wrong.