forked from boy-hack/ksubdomain
-
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
0 parents
commit 504cb1b
Showing
26 changed files
with
1,871 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: 🎉 Build Binary 哈哈 | ||
on: | ||
create: | ||
tags: | ||
- v* | ||
workflow_dispatch: | ||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- macos-latest | ||
steps: | ||
|
||
- name: Set up Go 1.13 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.16 | ||
id: go | ||
|
||
- name: Set up libpcap-dev | ||
if: matrix.os == 'ubuntu-latest' | ||
run: sudo apt-get install libpcap-dev -y | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get dependencies | ||
run: go mod download | ||
|
||
- name: Build | ||
run: go build -o ./ksubdomain_lastest_${{ runner.os }} ./cmd/ | ||
|
||
- name: Upload a build artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: ksubdomain_latest_${{ runner.os }}_amd64 | ||
path: ksubdomain* | ||
if-no-files-found: error |
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,3 @@ | ||
.idea | ||
#go.sum | ||
test2 |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Knownsec, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,18 @@ | ||
package main | ||
|
||
import ( | ||
"ksubdomain/gologger" | ||
"ksubdomain/runner" | ||
) | ||
|
||
func main() { | ||
options := runner.ParseOptions() | ||
|
||
r, err := runner.New(options) | ||
if err != nil { | ||
gologger.Fatalf("%s\n", err.Error()) | ||
return | ||
} | ||
r.RunEnumeration() | ||
r.Close() | ||
} |
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,20 @@ | ||
package core | ||
|
||
import ( | ||
"ksubdomain/gologger" | ||
) | ||
|
||
const Version = "1.0" | ||
const banner = ` | ||
_ _ _ _ | ||
| | _____ _ _| |__ __| | ___ _ __ ___ __ _(_)_ __ | ||
| |/ / __| | | | '_ \ / _' |/ _ \| '_ ' _ \ / _| | | '_ \ | ||
| <\__ \ |_| | |_) | (_| | (_) | | | | | | (_| | | | | | | ||
|_|\_\___/\__,_|_.__/ \__,_|\___/|_| |_| |_|\__,_|_|_| |_| | ||
` | ||
|
||
func ShowBanner() { | ||
gologger.Printf(banner) | ||
gologger.Infof("Current Version: %s\n", Version) | ||
} |
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,240 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/google/gopacket" | ||
"github.com/google/gopacket/layers" | ||
"github.com/google/gopacket/pcap" | ||
"ksubdomain/gologger" | ||
"net" | ||
"time" | ||
) | ||
|
||
func AutoGetDevices() EthTable { | ||
domain := RandomStr(4) + "paper.seebug.org" | ||
signal := make(chan EthTable) | ||
devices, err := pcap.FindAllDevs() | ||
if err != nil { | ||
gologger.Fatalf("获取网络设备失败:%s\n", err.Error()) | ||
} | ||
data := make(map[string]net.IP) | ||
keys := []string{} | ||
for _, d := range devices { | ||
for _, address := range d.Addresses { | ||
ip := address.IP | ||
if ip.To4() != nil && !ip.IsLoopback() { | ||
data[d.Name] = ip | ||
keys = append(keys, d.Name) | ||
} | ||
} | ||
} | ||
ctx := context.Background() | ||
// 在初始上下文的基础上创建一个有取消功能的上下文 | ||
ctx, cancel := context.WithCancel(ctx) | ||
for _, drviceName := range keys { | ||
go func(drviceName string, domain string, signal chan EthTable, ctx context.Context) { | ||
var ( | ||
snapshot_len int32 = 1024 | ||
promiscuous bool = false | ||
timeout time.Duration = -1 * time.Second | ||
handle *pcap.Handle | ||
) | ||
var err error | ||
handle, err = pcap.OpenLive( | ||
drviceName, | ||
snapshot_len, | ||
promiscuous, | ||
timeout, | ||
) | ||
if err != nil { | ||
gologger.Fatalf("pcap打开失败:%s\n", err.Error()) | ||
} | ||
defer handle.Close() | ||
// Use the handle as a packet source to process all packets | ||
packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
default: | ||
packet, err := packetSource.NextPacket() | ||
gologger.Printf(".") | ||
if err != nil { | ||
continue | ||
} | ||
if dnsLayer := packet.Layer(layers.LayerTypeDNS); dnsLayer != nil { | ||
dns, _ := dnsLayer.(*layers.DNS) | ||
if !dns.QR { | ||
continue | ||
} | ||
for _, v := range dns.Questions { | ||
if string(v.Name) == domain { | ||
ethLayer := packet.Layer(layers.LayerTypeEthernet) | ||
if ethLayer != nil { | ||
eth := ethLayer.(*layers.Ethernet) | ||
signal <- EthTable{SrcIp: data[drviceName], Device: drviceName, SrcMac: eth.DstMAC, DstMac: eth.SrcMAC} | ||
// 网关mac 和 本地mac | ||
return | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}(drviceName, domain, signal, ctx) | ||
} | ||
var c EthTable | ||
for { | ||
select { | ||
case c = <-signal: | ||
cancel() | ||
goto END | ||
default: | ||
_, _ = net.LookupHost(domain) | ||
time.Sleep(time.Millisecond * 20) | ||
} | ||
} | ||
END: | ||
gologger.Printf("\n") | ||
gologger.Infof("Use Device: %s\n", c.Device) | ||
gologger.Infof("Use IP:%s\n", c.SrcIp.String()) | ||
gologger.Infof("Local Mac:%s\n", c.SrcMac.String()) | ||
gologger.Infof("GateWay Mac:%s\n", c.DstMac.String()) | ||
return c | ||
} | ||
func GetIpv4Devices() (keys []string, data map[string]net.IP) { | ||
devices, err := pcap.FindAllDevs() | ||
data = make(map[string]net.IP) | ||
if err != nil { | ||
gologger.Fatalf("获取网络设备失败:%s\n", err.Error()) | ||
} | ||
for _, d := range devices { | ||
for _, address := range d.Addresses { | ||
ip := address.IP | ||
if ip.To4() != nil && !ip.IsLoopback() { | ||
gologger.Printf(" [%d] Name: %s\n", len(keys), d.Name) | ||
gologger.Printf(" Description: %s\n", d.Description) | ||
gologger.Printf(" Devices addresses: %s\n", d.Description) | ||
gologger.Printf(" IP address: %s\n", ip) | ||
gologger.Printf(" Subnet mask: %s\n\n", address.Netmask.String()) | ||
data[d.Name] = ip | ||
keys = append(keys, d.Name) | ||
} | ||
} | ||
} | ||
return | ||
} | ||
func GetDevices(defaultSelect int) EthTable { | ||
// Find all devices | ||
keys, data := GetIpv4Devices() | ||
|
||
if len(keys) == 0 { | ||
gologger.Fatalf("获取不到可用的设备名称\n") | ||
} else if len(keys) == 1 { | ||
defaultSelect = 0 | ||
} | ||
if defaultSelect == -1 { | ||
gologger.Infof("选择一个可用网卡ID:") | ||
var i int | ||
_, err2 := fmt.Scanln(&i) | ||
if err2 != nil { | ||
gologger.Fatalf("\n读入ID失败,确认输入的是数字?\n") | ||
} | ||
|
||
if i < 0 || i >= len(keys) { | ||
gologger.Fatalf("ID超出了范围\n") | ||
} | ||
defaultSelect = i | ||
} | ||
deviceName := keys[defaultSelect] | ||
ip := data[deviceName] | ||
gologger.Infof("Use Device: %s\n", deviceName) | ||
gologger.Infof("Use IP:%s\n", ip.String()) | ||
c := getGateMacAddress(deviceName) | ||
gologger.Infof("Local Mac:%s\n", c[1]) | ||
gologger.Infof("GateWay Mac:%s\n", c[0]) | ||
return EthTable{ip, deviceName, c[1], c[0]} | ||
} | ||
|
||
func getGateMacAddress(dvice string) [2]net.HardwareAddr { | ||
// 获取网关mac地址 | ||
domain := RandomStr(4) + "paper.seebug.org" | ||
_signal := make(chan [2]net.HardwareAddr) | ||
go func(device string, domain string, signal chan [2]net.HardwareAddr) { | ||
var ( | ||
snapshot_len int32 = 1024 | ||
promiscuous bool = false | ||
timeout time.Duration = -1 * time.Second | ||
handle *pcap.Handle | ||
) | ||
var err error | ||
handle, err = pcap.OpenLive( | ||
device, | ||
snapshot_len, | ||
promiscuous, | ||
timeout, | ||
) | ||
if err != nil { | ||
gologger.Fatalf("pcap打开失败:%s\n", err.Error()) | ||
} | ||
defer handle.Close() | ||
// Use the handle as a packet source to process all packets | ||
packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) | ||
for { | ||
packet, err := packetSource.NextPacket() | ||
gologger.Printf(".") | ||
if err != nil { | ||
continue | ||
} | ||
if dnsLayer := packet.Layer(layers.LayerTypeDNS); dnsLayer != nil { | ||
dns, _ := dnsLayer.(*layers.DNS) | ||
if !dns.QR { | ||
continue | ||
} | ||
for _, v := range dns.Questions { | ||
if string(v.Name) == domain { | ||
ethLayer := packet.Layer(layers.LayerTypeEthernet) | ||
if ethLayer != nil { | ||
eth := ethLayer.(*layers.Ethernet) | ||
srcMac := eth.SrcMAC | ||
dstMac := eth.DstMAC | ||
|
||
signal <- [2]net.HardwareAddr{srcMac, dstMac} | ||
// 网关mac 和 本地mac | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
}(dvice, domain, _signal) | ||
var c [2]net.HardwareAddr | ||
for { | ||
select { | ||
case c = <-_signal: | ||
gologger.Printf("\n") | ||
goto END | ||
default: | ||
_, _ = net.LookupHost(domain) | ||
time.Sleep(time.Millisecond * 10) | ||
} | ||
} | ||
END: | ||
return c | ||
} | ||
func PcapInit(devicename string) (*pcap.Handle, error) { | ||
var ( | ||
snapshot_len int32 = 1024 | ||
//promiscuous bool = false | ||
err error | ||
timeout time.Duration = -1 * time.Second | ||
) | ||
handle, err := pcap.OpenLive(devicename, snapshot_len, false, timeout) | ||
if err != nil { | ||
gologger.Fatalf("pcap初始化失败:%s\n", err.Error()) | ||
return nil, err | ||
} | ||
return handle, nil | ||
} |
Oops, something went wrong.