Skip to content

Commit

Permalink
Merge pull request #2 from knownsec/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
boy-hack authored Aug 27, 2020
2 parents c0d23dd + b6cafc3 commit ae7592b
Show file tree
Hide file tree
Showing 13 changed files with 96,469 additions and 192 deletions.
70 changes: 0 additions & 70 deletions cmd/cmd.go

This file was deleted.

46 changes: 46 additions & 0 deletions cmd/ksubdomain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"fmt"
"ksubdomain/core"
"net"
"os"
"time"
)

func test(options *core.Options) {
sendog := core.SendDog{}
ether := core.GetDevices(options.NetworkId)
ether.DstMac = net.HardwareAddr{0x5c, 0xc9, 0x09, 0x33, 0x34, 0x80}
sendog.Init(ether, []string{"8.8.8.8"}, 404)
defer sendog.Close()
var index int64 = 0
start := time.Now().UnixNano() / 1e6
flag := int64(15) // 15s
var now int64
for {
sendog.Send("seebug.org", "8.8.8.8", 1234, 1)
index++
now = time.Now().UnixNano() / 1e6
tickTime := (now - start) / 1000
if tickTime >= flag {
break
}
if (now-start)%1000 == 0 && now-start >= 900 {
tickIndex := index / tickTime
fmt.Printf("\r %ds 总发送:%d Packet 平均每秒速度:%dpps", tickTime, index, tickIndex)
}
}
now = time.Now().UnixNano() / 1e6
tickTime := (now - start) / 1000
tickIndex := index / tickTime
fmt.Printf("\r %ds 总发送:%d Packet 平均每秒速度:%dpps\n", tickTime, index, tickIndex)
}
func main() {
options := core.ParseOptions()
if options.Test {
test(options)
os.Exit(0)
}
core.Start(options)
}
2 changes: 2 additions & 0 deletions core/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import "fmt"

const Version = "0.1"
const banner = `
_ __ _____ _ _ _
| |/ / / ____| | | | | (_)
Expand All @@ -13,4 +14,5 @@ const banner = `

func ShowBanner() {
fmt.Println(banner)
fmt.Println("Current Version: ", Version)
}
94 changes: 94 additions & 0 deletions core/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package core

import (
"flag"
"fmt"
"log"
"os"
"strconv"
)

type Options struct {
Rate int64
Domain string
FileName string
Resolvers []string
Output string
Test bool
NetworkId int
Silent bool
TTL bool
Verify bool
Stdin bool
Debug bool
}

// ParseOptions parses the command line flags provided by a user
func ParseOptions() *Options {
ShowBanner()
options := &Options{}
bandwith := flag.String("b", "1M", "宽带的下行速度,可以5M,5K,5G")
flag.StringVar(&options.Domain, "d", "", "爆破域名")
flag.StringVar(&options.FileName, "f", "", "字典路径,-d下文件为子域名字典,-verify下文件为需要验证的域名")
resolvers := flag.String("s", "", "resolvers文件路径,默认使用内置DNS")
flag.StringVar(&options.Output, "o", "", "输出文件路径")
flag.BoolVar(&options.Test, "test", false, "测试本地最大发包数")
flag.IntVar(&options.NetworkId, "e", -1, "默认网络设备ID,默认-1,如果有多个网络设备会在命令行中选择")
flag.BoolVar(&options.Silent, "silent", false, "使用后屏幕将不会输出结果")
flag.BoolVar(&options.TTL, "ttl", false, "导出格式中包含TTL选项")
flag.BoolVar(&options.Verify, "verify", false, "验证模式")
flag.Parse()
options.Stdin = hasStdin()
// handle resolver
if *resolvers != "" {
rs, err := LinesInFile(*resolvers)
if err != nil {
log.Panic(err)
}
options.Resolvers = rs
} else {
defaultDns := []string{"223.5.5.5", "223.6.6.6", "180.76.76.76", "119.29.29.29", "182.254.116.116", "114.114.114.115"}
options.Resolvers = defaultDns
}
var rate int64
suffix := string([]rune(*bandwith)[len(*bandwith)-1])
rate, _ = strconv.ParseInt(string([]rune(*bandwith)[0:len(*bandwith)-1]), 10, 64)
switch suffix {
case "G":
fallthrough
case "g":
rate *= 1000000000
case "M":
fallthrough
case "m":
rate *= 1000000
case "K":
fallthrough
case "k":
rate *= 1000
default:
fmt.Printf("unknown bandwith suffix '%s' (supported suffixes are G,M and K)\n", suffix)
}
packSize := int64(100) // 一个DNS包大概有74byte
rate = rate / packSize
options.Rate = rate
if options.Domain == "" && !hasStdin() && (!options.Verify && options.FileName == "") && !options.Test {
flag.Usage()
os.Exit(0)
}
if options.FileName != "" && !FileExists(options.FileName) {
fmt.Printf("文件:%s不存在!\n", options.FileName)
os.Exit(0)
}
return options
}
func hasStdin() bool {
fi, err := os.Stdin.Stat()
if err != nil {
return false
}
if fi.Mode()&os.ModeNamedPipe == 0 {
return false
}
return true
}
48 changes: 28 additions & 20 deletions core/recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@ import (
"log"
"os"
"strconv"
"strings"
"sync/atomic"
"time"
)

func Recv(device string, output string) {
func Recv(device string, options *Options, flagID uint16) {
var (
snapshot_len int32 = 1024
promiscuous bool = false
timeout time.Duration = -1 * time.Second
handle *pcap.Handle
snapshotLen int32 = 1024
promiscuous bool = false
timeout time.Duration = -1 * time.Second
)
handle, _ = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
handle, _ := pcap.OpenLive(device, snapshotLen, promiscuous, timeout)
err := handle.SetBPFFilter("udp and port 53")
if err != nil {
log.Fatal(err)
}
// Use the handle as a packet source to process all packets
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
defer handle.Close()
success := 0 // 成功个数

var udp layers.UDP
var dns layers.DNS
Expand All @@ -38,12 +36,14 @@ func Recv(device string, output string) {
parser := gopacket.NewDecodingLayerParser(
layers.LayerTypeEthernet, &eth, &ipv4, &udp, &dns)
var isWrite bool = false
if output != "" {
var isttl bool = options.TTL
var issilent bool = options.Silent
if options.Output != "" {
isWrite = true
}
var foutput *os.File
if isWrite {
foutput, err = os.OpenFile(output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
foutput, err = os.OpenFile(options.Output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
if err != nil {
log.Panicln(err)
}
Expand All @@ -56,36 +56,45 @@ func Recv(device string, output string) {
var decoded []gopacket.LayerType
err = parser.DecodeLayers(packet.Data(), &decoded)
if err != nil {
fmt.Println(err)
continue
}
if !dns.QR {
continue
}
if dns.ID == 404 {
if dns.ID/100 == flagID {
atomic.AddUint64(&RecvIndex, 1)
upd, _ := packet.Layer(layers.LayerTypeUDP).(*layers.UDP)
if _data, ok := LocalStauts.Load(uint32(upd.DstPort)); ok {
udp, _ := packet.Layer(layers.LayerTypeUDP).(*layers.UDP)
index := GenerateMapIndex(dns.ID%100, uint16(udp.DstPort))
if _data, ok := LocalStauts.Load(uint32(index)); ok {
data := _data.(StatusTable)
dnsName := data.Dns
if dnsnum, ok2 := DnsChoice.Load(dnsName); !ok2 {
DnsChoice.Store(dnsName, 1)
} else {
DnsChoice.Store(dnsName, dnsnum.(int)+1)
}
LocalStack.Push(uint32(upd.DstPort))
LocalStauts.Delete(uint32(upd.DstPort))
if LocalStack.Len() <= 50000 {
LocalStack.Push(uint32(index))
}
LocalStauts.Delete(uint32(index))
}
if dns.ANCount > 0 {
atomic.AddUint64(&SuccessIndex, 1)
msg := ""
for _, v := range dns.Questions {
msg += string(v.Name) + " => "
}
for _, v := range dns.Answers {
msg += v.String() + " ttl:" + strconv.Itoa(int(v.TTL)) + " "
msg += v.String()
if isttl {
msg += " ttl:" + strconv.Itoa(int(v.TTL))
}
msg += " => "
}
msg = strings.Trim(msg, " => ")
if !issilent {
fmt.Println("\r" + msg)
}
success++
fmt.Println("\r" + msg)
if isWrite {
w := bufio.NewWriter(foutput)
_, err = w.WriteString(msg + "\n")
Expand All @@ -95,7 +104,6 @@ func Recv(device string, output string) {
w.Flush()
}
}
fmt.Printf("\rSuccess:%d Recv:%d ", success, RecvIndex)
}
}
}
Loading

0 comments on commit ae7592b

Please sign in to comment.