Skip to content

Commit

Permalink
新增daydaymap模块
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowabi committed May 15, 2024
1 parent e826877 commit 38917a3
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# AutoDomain
自动提取主域名/IP,并调用fofa、quake、hunter搜集子域名,可配合指纹扫描工具达到快速资产整理
自动提取域名/IP,并调用fofa、quake、hunter等测绘工具搜集子域名,可配合指纹扫描工具达到快速资产整理

本项目所使用的fofa、quake API参考自https://github.com/EASY233/Finger
hunter API参考自https://github.com/W01fh4cker/hunter-to-excel/
Expand All @@ -25,6 +25,7 @@ config.json的填写内容应该如下:
"HunterKey": "",
"ZoomeyeKey": "",
"PulsediveKey": ""
"DaydaymapKey": ""
}
```
填入的对应内容可使用对应的指定模块
Expand All @@ -42,6 +43,7 @@ Usage:
Available Commands:
all search domain from all engine
daydaymap search domain from daydaymap
fofa search domain from fofa
help Help about any command
hunter search domain from hunter
Expand Down
2 changes: 2 additions & 0 deletions cmd/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package all

import (
"github.com/shadowabi/AutoDomain_rebuild/cmd"
"github.com/shadowabi/AutoDomain_rebuild/cmd/daydaymap"
"github.com/shadowabi/AutoDomain_rebuild/cmd/fofa"
"github.com/shadowabi/AutoDomain_rebuild/cmd/hunter"
"github.com/shadowabi/AutoDomain_rebuild/cmd/netlas"
Expand All @@ -23,6 +24,7 @@ func init() {
AllCmd.AddCommand(quake.QuakeCmd)
AllCmd.AddCommand(virustotal.VirusTotalCmd)
AllCmd.AddCommand(zoomeye.ZoomeyeCmd)
AllCmd.AddCommand(daydaymap.DaydayMapCmd)
}

var AllCmd = &cobra.Command{
Expand Down
49 changes: 49 additions & 0 deletions cmd/daydaymap/daydaymap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package daydaymap

import (
"errors"
"fmt"
"github.com/shadowabi/AutoDomain_rebuild/cmd"
"github.com/shadowabi/AutoDomain_rebuild/config"
"github.com/shadowabi/AutoDomain_rebuild/define"
"github.com/shadowabi/AutoDomain_rebuild/pkg"
"github.com/shadowabi/AutoDomain_rebuild/pkg/daydaymap"
"github.com/spf13/cobra"
)

func init() {
cmd.RootCmd.AddCommand(DaydayMapCmd)
}

var DaydayMapCmd = &cobra.Command{
Use: "daydaymap",
Short: "search domain from daydaymap",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if config.C.DaydaymapKey == "" {
return errors.New("未配置 daydaymap 相关的凭证")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
define.Once.Do(pkg.GlobalRun)
fmt.Printf("[+] daydaymap is working...\n")

client := pkg.GenerateHTTPClient(define.TimeOut)
reqString := daydaymap.MergeReqListToReqString(define.ReqIpList, define.ReqDomainList)
reqBody := daydaymap.DayDayMapRequest(client, reqString, 1) // find result total
reqResult := daydaymap.ParseDaydaymapResult(reqBody...)
reqBody = daydaymap.DayDayMapRequest(client, reqString, reqResult[0].Data.Total) // real query
reqResult = daydaymap.ParseDaydaymapResult(reqBody...)

chanNum := cap(reqResult)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
resultChannel <- daydaymap.PurgeDomainResult(reqResult...)
close(resultChannel)

pkg.FetchResultFromChanel(resultChannel)
}

fmt.Printf("[+] daydaymap search complete\n")
},
}
2 changes: 1 addition & 1 deletion cmd/fofa/fofa.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var FofaCmd = &cobra.Command{
reqResult = append(reqResult, reqResult2...)
}

chanNum := len(reqResult)
chanNum := cap(reqResult)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
resultChannel <- fofa.PurgeDomainResult(reqResult...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/hunter/hunter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var HunterCmd = &cobra.Command{
reqResult = append(reqResult, reqResult2...)
}

chanNum := len(reqResult)
chanNum := cap(reqResult)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
resultChannel <- hunter.PurgeDomainResult(reqResult...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/netlas/netlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var NetlasCmd = &cobra.Command{
reqIpBody := netlas.NetlasIpRequest(client, define.ReqIpList...)
reqIpResultList := netlas.ParseNetlasIpResult(reqIpBody...)

chanNum := len(reqDomainResultList) + len(reqIpResultList)
chanNum := cap(reqDomainResultList) + cap(reqIpResultList)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
if len(reqDomainResultList) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/pulsedive/pulsedive.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var PulsediveCmd = &cobra.Command{
reqDomainBody := pulsedive.PulsediveDomainRequest(client, define.ReqDomainList...)
reqDomainResultList := pulsedive.ParsePulsediveDomainResult(reqDomainBody...)

chanNum := len(reqDomainResultList)
chanNum := cap(reqDomainResultList)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
resultChannel <- pulsedive.PurgeDomainResult(reqDomainResultList...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/quake/quake.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var QuakeCmd = &cobra.Command{
reqResult = append(reqResult, reqResult2...)
}

chanNum := len(reqResult)
chanNum := cap(reqResult)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
resultChannel <- quake.PurgeDomainResult(reqResult...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/virustotal/virustotal.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var VirusTotalCmd = &cobra.Command{
reqDomainBody := virustotal.VirusTotalDomainRequest(client, define.ReqDomainList...)
reqDomainResultList := virustotal.ParseVirusTotalDomainResult(reqDomainBody...)

chanNum := len(reqDomainResultList)
chanNum := cap(reqDomainResultList)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
resultChannel <- virustotal.PurgeDomainResult(reqDomainResultList...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoomeye/zoomeye.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var ZoomeyeCmd = &cobra.Command{
reqDomainBody := zoomeye.ZoomeyeDomainRequest(client, define.ReqDomainList...)
reqDomainResultList := zoomeye.ParseZoomeyeDomainResult(reqDomainBody...)

chanNum := len(reqDomainResultList) + len(reqIpResultList)
chanNum := cap(reqDomainResultList) + cap(reqIpResultList)
if chanNum != 0 {
resultChannel := make(chan []string, chanNum)
if len(reqDomainResultList) != 0 {
Expand Down
1 change: 1 addition & 0 deletions define/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Configure struct {
HunterKey string `mapstructure:"HunterKey" json:"HunterKey" yaml:"HunterKey"`
ZoomeyeKey string `mapstructure:"ZoomeyeKey" json:"ZoomeyeKey" yaml:"ZoomeyeKey"`
PulsediveKey string `mapstructure:"PulsediveKey" json:"PulsediveKey" yaml:"PulsediveKey"`
DaydaymapKey string `mapstructure:"DaydaymapKey" json:"DaydaymapKey" yaml:"DaydaymapKey"`
}

var ModeToGrammar = map[string]string{
Expand Down
1 change: 1 addition & 0 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"github.com/shadowabi/AutoDomain_rebuild/cmd"
_ "github.com/shadowabi/AutoDomain_rebuild/cmd/all"
_ "github.com/shadowabi/AutoDomain_rebuild/cmd/daydaymap"
_ "github.com/shadowabi/AutoDomain_rebuild/cmd/fofa"
_ "github.com/shadowabi/AutoDomain_rebuild/cmd/hunter"
_ "github.com/shadowabi/AutoDomain_rebuild/cmd/netlas"
Expand Down
8 changes: 4 additions & 4 deletions pkg/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func ConvertToReqDomainList(param ...string) (reqDomainList []string) {
func MergeReqListToReqString(mode string, reqIpList []string, reqDomainList []string) (reqString string) {
grammar := define.ModeToGrammar[mode]
if grammar != "" {
for _, ip := range reqIpList {
reqString += "ip" + grammar + ip + " || "
for _, host := range reqIpList {
reqString += "ip" + grammar + host + " || "
}
for _, ip := range reqDomainList {
reqString += "domain" + grammar + ip + " || "
for _, host := range reqDomainList {
reqString += "domain" + grammar + host + " || "
}
}
reqString = strings.TrimSuffix(reqString, " || ")
Expand Down
47 changes: 47 additions & 0 deletions pkg/daydaymap/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package daydaymap

import (
"encoding/base64"
"encoding/json"
"github.com/shadowabi/AutoDomain_rebuild/utils/Error"
"strings"
)

func MergeReqListToReqString(reqIpList []string, reqDomainList []string) (reqString string) {
for _, host := range reqIpList {
reqString += "ip:" + "\"" + host + "\"" + " || "
}
for _, host := range reqDomainList {
reqString += "domain:" + "\"" + host + "\"" + " || "
}
reqString = strings.TrimSuffix(reqString, " || ")
reqString = base64.URLEncoding.EncodeToString([]byte(reqString))
return reqString
}

type ArrElement struct {
Domain string `json:"domain"`
Port int `json:"port"`
Ip string `json:"ip"`
Service string `json:"service"`
}

type Data struct {
List []ArrElement `json:"list"`
Total int `json:"total"`
}

type DaydaymapResponse struct {
Data Data `json:"data"`
}

func ParseDaydaymapResult(reqBody ...string) (daydaymapRespList []DaydaymapResponse) {
if len(reqBody) != 0 {
for _, response := range reqBody {
var daydaymapResponse DaydaymapResponse
Error.HandleError(json.Unmarshal([]byte(response), &daydaymapResponse))
daydaymapRespList = append(daydaymapRespList, daydaymapResponse)
}
}
return daydaymapRespList
}
24 changes: 24 additions & 0 deletions pkg/daydaymap/output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package daydaymap

import (
"fmt"
)

func PurgeDomainResult(daydaymapResponse ...DaydaymapResponse) (daydaymapDomainResult []string) {
if len(daydaymapResponse) != 0 {
for _, response := range daydaymapResponse {
for _, v := range response.Data.List {
if v.Service == "http" || v.Service == "https" {
result := ""
if v.Domain != "" {
result = fmt.Sprintf("%s://%s:%v", v.Service, v.Domain, v.Port)
} else {
result = fmt.Sprintf("%s://%v:%v", v.Service, v.Ip, v.Port)
}
daydaymapDomainResult = append(daydaymapDomainResult, result)
}
}
}
}
return daydaymapDomainResult
}
40 changes: 40 additions & 0 deletions pkg/daydaymap/req.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package daydaymap

import (
"bytes"
"encoding/json"
"github.com/shadowabi/AutoDomain_rebuild/config"
"github.com/shadowabi/AutoDomain_rebuild/define"
"github.com/shadowabi/AutoDomain_rebuild/utils/Error"
net2 "github.com/shadowabi/AutoDomain_rebuild/utils/response"
"net/http"
"time"
)

func DayDayMapRequest(client *http.Client, reqString string, totalList ...int) (respBody []string) {
if len(totalList) != 0 {
for _, total := range totalList {
data := struct {
Page int `json:"page"`
Size int `json:"page_size"`
Keyword string `json:"keyword"`
}{
Page: 1,
Size: total,
Keyword: reqString,
}
dataJson, _ := json.Marshal(data)
dataReq := bytes.NewBuffer(dataJson)
req, _ := http.NewRequest("POST", "https://www.daydaymap.com/api/v1/raymap/search/all", dataReq)
req.Header.Set("User-Agent", define.UserAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("api-key", config.C.DaydaymapKey)
resp, err := client.Do(req)
time.Sleep(500 * time.Millisecond)
Error.HandleError(err)
respBody = append(respBody, net2.HandleResponse(resp))
resp.Body.Close()
}
}
return respBody
}

0 comments on commit 38917a3

Please sign in to comment.