Skip to content

Commit

Permalink
update dismap 0.2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzyker committed Sep 27, 2021
1 parent ed1c384 commit 6653da5
Show file tree
Hide file tree
Showing 10 changed files with 4,990 additions and 615 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config



var DefaultPorts = []int{80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,443,800,801,808,880,888,889,1000,1080,2601,7001,7007,7010,8000,8001,8002,8003,8004,8005,8006,8007,8008,8009,8010,8011,8012,8016,8017,8018,8019,8022,8029,8030,8060,8069,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8100,8101,8108,81110,8161,8175,8188,8189,8200,8222,8300,8360,8443,8445,8448,8484,8800,8848,8879,8880,8881,8888,8899,8983,8989,9000,9001,9002,9008,9010,9043,9060,9080,9081,9082,9083,9084,9085,9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9200,9443,9448,9800,9981,9986,9988,9998,9999}
var DefaultPorts = []int{80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,443,800,801,808,880,888,889,1000,1080,1880,1881,2000,2001,2601,3443,7001,7007,7010,7070,7878,8000,8001,8002,8003,8004,8005,8006,8007,8008,8009,8010,8011,8012,8016,8017,8018,8019,8022,8029,8030,8060,8069,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8100,8101,8105,8108,81110,8161,8175,8188,8189,8200,8201,8222,8300,8360,8443,8445,8448,8484,8499,8500,8800,8848,8879,8880,8881,8888,8899,8983,8989,9000,9001,9002,9008,9010,9043,9060,9080,9081,9082,9083,9084,9085,9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9200,9300,9443,9448,9500,9628,9800,9899,9981,9986,9988,9998,9999,11001}

var DefaultHeader = map[string]string{
"Accept-Language": "zh,zh-TW;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6",
Expand Down
4,986 changes: 4,591 additions & 395 deletions config/rule.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func banner() {
"/ /_/ / _ / _(__ )_ / / / / / /_/ /__ /_/ /\n" +
"\\__,_/ /_/ /____/ /_/ /_/ /_/\\__,_/ _ .___/\n" +
" /_/"
infor := " dismap version: 0.1 release\n" +
infor := " dismap version: 0.2 release\n" +
" author: zhzyker && Nemophllist\n" +
" from: https://github.com/zhzyker/dismap\n"
fmt.Println(logger.Purple(banners))
Expand Down
306 changes: 152 additions & 154 deletions lib/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func ManageFlag() {
flag.Parse()
Ports := ParsePort(Port)
//runtime.GOMAXPROCS(4)
wg := sync.WaitGroup{}
wg := &sync.WaitGroup{}
lock := &sync.Mutex{}
// output files
_, err := os.Stat(OutPut)
if err != nil {
var dismap_header string
dismap_header =
"###### dismap 0.1 output file ######\r\n" +
"###### dismap 0.2 output file ######\r\n" +
"###### asset discovery and identification tools ######\r\n" +
"###### by:https://github.com/zhzyker/dismap ######\r\n"
f, _ := os.Create(OutPut)
Expand All @@ -37,153 +37,27 @@ func ManageFlag() {
panic(err)
}
}
fl, _ := os.OpenFile(OutPut, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if NetWork != "" {
// Start detecting surviving hosts
logger.Info("Start to detect host from " + NetWork)
var SurviveHosts []string
IntAllHost := 0
IntSurHost := 0
IntSyncHost := 0
IntSyncUrl := 0
hosts, _ := ParseNetHosts(NetWork)
var ActualHosts []string
if NoIcmp == false {
for _, host := range hosts {
wg.Add(1)
IntAllHost++
IntSyncHost++
go func(host string) {
if PingHost(host, TimeOut) == true {
IntSurHost++
logger.Info("PING found alive host " + host)
lock.Lock()
SurviveHosts = append(SurviveHosts, host)
lock.Unlock()
}
wg.Done()
}(host)
if IntSyncHost >= Thread {
IntSyncHost = 0
wg.Wait()
}
}
wg.Wait()
ActualHosts = SurviveHosts
logger.Info(
logger.LightGreen("There are total of ") +
logger.White(strconv.Itoa(IntAllHost)) +
logger.LightGreen(" hosts, and ") +
logger.White(strconv.Itoa(IntSurHost)) +
logger.LightGreen(" are surviving"))
if IntSurHost <= 5 {
logger.Warn(logger.Yellow("Too few surviving hosts"))
}
} else {
ActualHosts = hosts
logger.Warn(logger.Yellow("Not use ICMP/PING to detect surviving hosts"))
}
logger.Info("Start to identify the targets")
IntAllUrl := 0
IntIdeUrl := 0
for _, host := range ActualHosts {
for _, port := range Ports {
wg.Add(1)
IntSyncUrl++
url := ParseUrl(host, strconv.Itoa(port))
go func(url string) {
var res_type string
var res_code string
var res_result string
var res_result_nc string
var res_url string
var res_title string
for _, results := range Identify(url, TimeOut) {
res_type = results.Type
res_code = results.RespCode
res_result = results.Result
res_result_nc = results.ResultNc
res_url = results.Url
res_title = results.Title
}
lock.Lock()
if len(res_result) != 0 {
IntIdeUrl++
IntAllUrl++
logger.Success("[" + logger.Purple(res_code) + "] " + res_result + res_url + " [" + logger.Blue(res_title) + "]")
//output(OutPut, lock, "[+] ["+res_code+"] "+ res_result_nc + "{ " + res_url + " } ["+res_title+"]\n")
content := "[+] [" + res_code + "] " + res_result_nc + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
_, err = fl.Write(text)
//fmt.Printf("[%s] [%s] [%s] %s%s [%s]\n", now_time, succes, RespCode, identify_result, url, title)
} else if res_code != "" {
IntAllUrl++
logger.Failed("[" + logger.Purple(res_code) + "] " + res_url + " [" + logger.Blue(res_title) + "]")
//output(OutPut, lock, "[-] ["+res_code+"] " + "{ " + res_url + " } ["+res_title+"]\n")
content := "[-] [" + res_code + "] " + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
_, err = fl.Write(text)
}
lock.Unlock()

if 1 == 2 { // ahhhhhhhhhhhhhh
fmt.Println(res_type)
}
wg.Done()
}(url)
if IntSyncUrl >= Thread {
IntSyncUrl = 0
wg.Wait()
}
}
}
wg.Wait()
logger.Info(logger.LightGreen("A total of ") +
logger.White(strconv.Itoa(IntAllUrl)) +
logger.LightGreen(" urls, the rule base hits ") +
logger.White(strconv.Itoa(IntIdeUrl)) +
logger.LightGreen(" urls"))
if NetWork != "" {
TargetNetwork(wg, lock, Ports, NetWork)

} else if Url != "" || Files == "" {
var res_type string
var res_code string
var res_result string
var res_result_nc string
var res_url string
var res_title string
for _, results := range Identify(Url, TimeOut) {
res_type = results.Type
res_code = results.RespCode
res_result = results.Result
res_result_nc = results.ResultNc
res_url = results.Url
res_title = results.Title
}
//lock.Lock()
if len(res_result) != 0 {
logger.Success("[" + logger.Purple(res_code) + "] " + res_result + res_url + " [" + logger.Blue(res_title) + "]")
//output(OutPut, lock, "[+] ["+res_code+"] "+ res_result_nc + "{ " + res_url + " } ["+res_title+"]\n")
content := "[+] [" + res_code + "] " + res_result_nc + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
_, err = fl.Write(text)
} else if res_code != "" {
logger.Failed("[" + logger.Purple(res_code) + "] " + res_url + " [" + logger.Blue(res_title) + "]")
//output(OutPut, lock, "[-] ["+res_code+"] " + "{ " + res_url + " } ["+res_title+"]\n")
content := "[-] [" + res_code + "] " + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
_, err = fl.Write(text)
} else if InUrl != "" || Files == "" {
if_url, err := JudgeUrl(InUrl)
if err == nil {
TargetUrl(wg, lock, Ports, if_url)
}
//lock.Unlock()
if 1 == 2 { // ahhhhhhhhhhhhhh
fmt.Println(res_type)
}
} else if Url == "" || Files != "" {
} else if InUrl == "" || Files != "" {
files, err := os.Open(Files)
if err != nil {
logger.Error("There is no " + logger.LightRed(Files) + " file or the directory does not exist")
} else {
if Thread == 508 {
logger.Info("The default number of threads is 500")
}
logger.Info(logger.LightGreen("Batch scan the targets in " + logger.Yellow(Files) + logger.LightGreen(", priority network segment")))
}
buf := bufio.NewReader(files)
IntSyncUrl := 0
var urls []string
for {
line, err := buf.ReadString('\n')
line = strings.TrimSpace(line)
Expand All @@ -193,18 +67,109 @@ func ManageFlag() {
if line == "" {
continue
}
IntAllUrl := 0
IntIdeUrl := 0
_, err = JudgeNet(line)
if err == nil {
TargetNetwork(wg, lock, Ports, line)
continue
}
if_url, err := JudgeUrl(line)
if err == nil {
urls = append(urls, if_url)
} else {
logger.Warning(logger.Yellow(line) + " is not a legal url, please check")
}
}
logger.Info(logger.LightGreen("Start batch identify urls"))
IntSync := 0
IntAll := 0
for _, target := range urls {
IntSync++
IntAll++
wg.Add(1)
go func(target string) {
lock.Lock()
TargetUrl(wg, lock, Ports, target)
lock.Unlock()
wg.Done()
}(target)
if IntSync >= Thread {
IntSync = 0
wg.Wait()
}
}
wg.Wait()
logger.Info(
logger.LightGreen("A total of ") +
logger.LightWhite(strconv.Itoa(IntAll)) +
logger.LightGreen(" url targets"))
files.Close()
}
logger.Info("The identification results are saved in " + logger.Yellow(OutPut))
logger.Info("Identification completed and ended")
}

func TargetNetwork(wg *sync.WaitGroup, lock *sync.Mutex, Ports []int, Targets string) {
fl, _ := os.OpenFile(OutPut, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
// Start detecting surviving hosts
logger.Info("Start to detect host from " + Targets)
var SurviveHosts []string
IntAllHost := 0
IntSurHost := 0
IntSyncHost := 0
IntSyncUrl := 0
hosts, _ := ParseNetHosts(Targets)
var ActualHosts []string
if NoIcmp == false {
for _, host := range hosts {
wg.Add(1)
IntAllHost++
IntSyncHost++
go func(host string) {
if PingHost(host, TimeOut) == true {
IntSurHost++
logger.Info("PING found alive host " + host)
lock.Lock()
SurviveHosts = append(SurviveHosts, host)
lock.Unlock()
}
wg.Done()
}(host)
if IntSyncHost >= Thread {
IntSyncHost = 0
wg.Wait()
}
}
wg.Wait()
ActualHosts = SurviveHosts
logger.Info(
logger.LightGreen("There are total of ") +
logger.White(strconv.Itoa(IntAllHost)) +
logger.LightGreen(" hosts, and ") +
logger.White(strconv.Itoa(IntSurHost)) +
logger.LightGreen(" are surviving"))
if IntSurHost <= 5 {
logger.Warning(logger.Yellow("Too few surviving hosts"))
}
} else {
ActualHosts = hosts
logger.Warning(logger.Yellow("Not use ICMP/PING to detect surviving hosts"))
}
logger.Info("Start to identify the targets")
IntAllUrl := 0
IntIdeUrl := 0
for _, host := range ActualHosts {
for _, port := range Ports {
wg.Add(1)
IntSyncUrl++
url := ParseUrl(host, strconv.Itoa(port))
go func(url string) {
var res_type string
var res_code string
var res_result string
var res_result_nc string
var res_url string
var res_title string
for _, results := range Identify(line, TimeOut) {
for _, results := range Identify(url, TimeOut) {
res_type = results.Type
res_code = results.RespCode
res_result = results.Result
Expand All @@ -217,36 +182,69 @@ func ManageFlag() {
IntIdeUrl++
IntAllUrl++
logger.Success("[" + logger.Purple(res_code) + "] " + res_result + res_url + " [" + logger.Blue(res_title) + "]")
//output(OutPut, lock, "[+] ["+res_code+"] "+ res_result_nc + "{ " + res_url + " } ["+res_title+"]\n")
content := "[+] [" + res_code + "] " + res_result_nc + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
_, err = fl.Write(text)
//fmt.Printf("[%s] [%s] [%s] %s%s [%s]\n", now_time, succes, RespCode, identify_result, url, title)
fl.Write(text)
} else if res_code != "" {
IntAllUrl++
logger.Failed("[" + logger.Purple(res_code) + "] " + res_url + " [" + logger.Blue(res_title) + "]")
//output(OutPut, lock, "[-] ["+res_code+"] " + "{ " + res_url + " } ["+res_title+"]\n")
content := "[-] [" + res_code + "] " + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
_, err = fl.Write(text)
fl.Write(text)
}
lock.Unlock()

if 1 == 2 { // ahhhhhhhhhhhhhh
fmt.Println(res_type)
}
wg.Done()
}(line)
}(url)
if IntSyncUrl >= Thread {
IntSyncUrl = 0
wg.Wait()
}
}
wg.Wait()
files.Close()
}
wg.Wait()
logger.Info(logger.LightGreen("A total of ") +
logger.White(strconv.Itoa(IntAllUrl)) +
logger.LightGreen(" urls, the rule base hits ") +
logger.White(strconv.Itoa(IntIdeUrl)) +
logger.LightGreen(" urls"))
fl.Close()
}

func TargetUrl(wg *sync.WaitGroup, lock *sync.Mutex, Ports []int, Targets string) {
fl, _ := os.OpenFile(OutPut, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
var res_type string
var res_code string
var res_result string
var res_result_nc string
var res_url string
var res_title string
for _, results := range Identify(Targets, TimeOut) {
res_type = results.Type
res_code = results.RespCode
res_result = results.Result
res_result_nc = results.ResultNc
res_url = results.Url
res_title = results.Title
}
if len(res_result) != 0 {
logger.Success("[" + logger.Purple(res_code) + "] " + res_result + res_url + " [" + logger.Blue(res_title) + "]")
content := "[+] [" + res_code + "] " + res_result_nc + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
fl.Write(text)
} else if res_code != "" {
logger.Failed("[" + logger.Purple(res_code) + "] " + res_url + " [" + logger.Blue(res_title) + "]")
content := "[-] [" + res_code + "] " + "{ " + res_url + " } [" + res_title + "]"
var text = []byte(content + "\n")
fl.Write(text)
}
if 1 == 2 { // ahhhhhhhhhhhhhh
fmt.Println(res_type)
}
fl.Close()
logger.Info("The identification results are saved in " + OutPut)
logger.Info("Identification completed and ended")
}

func PingHost(host string, timeout int) bool {
Expand Down
Loading

0 comments on commit 6653da5

Please sign in to comment.