Skip to content

Commit

Permalink
[v0.4] Pick up speed, Concurrent TCP and TLS and UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzyker committed Jun 1, 2022
1 parent bc30527 commit edcf125
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 87 deletions.
2 changes: 1 addition & 1 deletion configs/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Banner() {
"/ /_/ / _ / _(__ )_ / / / / / /_/ /__ /_/ /\n" +
"\\__,_/ /_/ /____/ /_/ /_/ /_/\\__,_/ _ .___/\n" +
" /_/"
s := " dismap version: 0.3 release\n" +
s := " dismap version: 0.4 release\n" +
" author: zhzyker && Nemophllist\n" +
" from: https://github.com/zhzyker/dismap\n"
fmt.Println(logger.Purple(b))
Expand Down
10 changes: 4 additions & 6 deletions configs/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package configs



var DefaultPorts = []int{21,22,25,53,69,79,80,81,82,83,84,85,86,87,88,89,110,135,137,138,139,143,389,443,445,554,587,631,800,801,808,880,888,1000,1024,1025,1080,1099,1389,1433,1521,2000,2001,2222,2601,3306,3307,3388,3389,3443,5800,5900,6379,7000,7001,7007,7010,7788,8000,8001,8002,8003,8004,8005,8006,8007,8008,8009,8010,8011,8030,8060,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8161,8175,8188,8189,8443,8445,8448,8554,8800,8848,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,9099,9443,9448,9600,9628,9800,9899,9981,9986,9988,9998,9999,11001,13443,15000,20000,33890,45554,49155,49156,50050,61616}
var DefaultPorts = []int{21, 22, 23, 25, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 110, 135, 137, 138, 139, 143, 389, 443, 445, 587, 631, 800, 801, 808, 880, 888, 1000, 1024, 1025, 1080, 1099, 1389, 1433, 1521, 3306, 3307, 3388, 3389, 3443, 5800, 5900, 6379, 7000, 7001, 7007, 7010, 7788, 8000, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009, 8010, 8011, 8030, 8060, 8070, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099, 8161, 8175, 8188, 8189, 8443, 8445, 8448, 8554, 8800, 8848, 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, 9099, 9443, 9600, 9628, 9800, 9999, 11001, 13443, 49155, 50050, 61616}

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",
"User-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36",
"Cookie": "rememberMe=int",
}
"User-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36",
"Cookie": "rememberMe=int",
}
71 changes: 35 additions & 36 deletions configs/rule.go

Large diffs are not rendered by default.

38 changes: 32 additions & 6 deletions internal/operate/flag_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,41 @@ func FlagNetwork(op *os.File, wg *sync.WaitGroup, lock *sync.Mutex, address stri
intIde := 0
for _, host := range actualHosts {
for _, port := range ports {
wg.Add(1)
wg.Add(3)
intSyncThread++
go func(host string, port int, Args map[string]interface{}) {
res := protocol.Discover(host, port, Args)
if res["status"].(string) == "open" {
resTls := protocol.DiscoverTls(host, port, Args)
if resTls["status"].(string) == "open" {
intAll++
parse.VerboseParse(res)
output.Write(res, op)
if strings.Contains(res["uri"].(string), "://") {
parse.VerboseParse(resTls)
output.Write(resTls, op)
if strings.Contains(resTls["uri"].(string), "://") {
intIde++
}
}
wg.Done()
}(host, port, Args)

go func(host string, port int, Args map[string]interface{}) {
resTcp := protocol.DiscoverTcp(host, port, Args)
if resTcp["status"].(string) == "open" {
intAll++
parse.VerboseParse(resTcp)
output.Write(resTcp, op)
if strings.Contains(resTcp["uri"].(string), "://") {
intIde++
}
}
wg.Done()
}(host, port, Args)

go func(host string, port int, Args map[string]interface{}) {
resUdp := protocol.DiscoverUdp(host, port, Args)
if resUdp["status"].(string) == "open" {
intAll++
parse.VerboseParse(resUdp)
output.Write(resUdp, op)
if strings.Contains(resUdp["uri"].(string), "://") {
intIde++
}
}
Expand Down
21 changes: 8 additions & 13 deletions internal/operate/flag_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@ func FlagUrl(op *os.File, uri string, Args map[string]interface{}) {
if logger.DebugError(err) {
return
}
if Args["FlagMode"] == Args["FlagType"] {
if scheme == "https" {
Args["FlagType"] = "tls"
Args["FlagMode"] = scheme
} else {
Args["FlagType"] = "tcp"
Args["FlagMode"] = scheme
}
}
res := protocol.Discover(host, port, Args)
if Args["FlagMode"] == Args["FlagType"] {
Args["FlagType"] = ""
Args["FlagMode"] = ""
var res map[string]interface{}
//Args["FlagMode"] = scheme
switch scheme {
case "http":
res = protocol.DiscoverTcp(host, port, Args)
case "https":
res = protocol.DiscoverTls(host, port, Args)
}
//Args["FlagMode"] = ""
parse.VerboseParse(res)
output.Write(res, op)
}
100 changes: 79 additions & 21 deletions internal/protocol/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package protocol
import (
"github.com/zhzyker/dismap/internal/parse"
"github.com/zhzyker/dismap/internal/protocol/get"
"github.com/zhzyker/dismap/pkg/logger"
)

func isContainInt(items []int, item int) bool {
Expand All @@ -14,6 +15,7 @@ func isContainInt(items []int, item int) bool {
return false
}

/*
func getTls(result map[string]interface{}, host string, port int, timeout int) bool {
b, err := get.TlsProtocol(host, port, timeout)
if err == nil {
Expand Down Expand Up @@ -48,9 +50,9 @@ func getUdp(result map[string]interface{}, host string, port int, timeout int) b
}
func getInfo(result map[string]interface{}, host string, port int, timeout int, pt string) {
var udpPort = []int{53,111,123,137,138,139,12345}
var udpPort = []int{53, 111, 123, 137, 138, 139, 12345}
switch pt {
case "" :
case "":
if getTls(result, host, port, timeout) {
return
}
Expand All @@ -62,15 +64,15 @@ func getInfo(result map[string]interface{}, host string, port int, timeout int,
return
}
}
case "tls" :
case "tls":
if getTls(result, host, port, timeout) {
return
}
case "tcp" :
case "tcp":
if getTcp(result, host, port, timeout) {
return
}
case "udp" :
case "udp":
if getUdp(result, host, port, timeout) {
return
}
Expand All @@ -81,29 +83,32 @@ func getInfo(result map[string]interface{}, host string, port int, timeout int,
return
}
*/

func setResult(host string, port int, Args map[string]interface{}) map[string]interface{} {
timeout := Args["FlagTimeout"].(int)
scheme := Args["FlagMode"].(string)
pt := Args["FlagType"].(string)
//timeout := Args["FlagTimeout"].(int)
//scheme := Args["FlagMode"].(string)
//pt := Args["FlagType"].(string)
var banner []byte
result := map[string]interface{}{
"status": "None",
"banner.byte": banner,
"banner.string": "None",
"protocol": scheme,
"type": pt,
"host": host,
"port": port,
"uri": "None",
"note": "None",
"path": "",
"identify.bool": false,
"status": "None",
"banner.byte": banner,
"banner.string": "None",
"protocol": Args["FlagMode"].(string),
"type": Args["FlagType"].(string),
"host": host,
"port": port,
"uri": "None",
"note": "None",
"path": "",
"identify.bool": false,
"identify.string": "None",
}
getInfo(result, host, port, timeout, pt)
//(result, host, port, timeout, pt)
return result
}

/*
func Discover(host string, port int, Args map[string]interface{}) map[string]interface{} {
result := setResult(host, port, Args)
if result["status"] != "open" {
Expand All @@ -127,4 +132,57 @@ func Discover(host string, port int, Args map[string]interface{}) map[string]int
}
}
return result
}
}
*/

func DiscoverTls(host string, port int, Args map[string]interface{}) map[string]interface{} {
result := setResult(host, port, Args)
b, err := get.TlsProtocol(host, port, Args["FlagTimeout"].(int))
if logger.DebugError(err) {
return result
}
result["type"] = "tls"
result["status"] = "open"
result["banner.byte"] = b
result["banner.string"] = parse.ByteToStringParse1(b)
if JudgeTls(result, Args) {
return result
}
return result
}

func DiscoverTcp(host string, port int, Args map[string]interface{}) map[string]interface{} {
result := setResult(host, port, Args)
b, err := get.TcpProtocol(host, port, Args["FlagTimeout"].(int))
if logger.DebugError(err) {
return result
}
result["type"] = "tcp"
result["status"] = "open"
result["banner.byte"] = b
result["banner.string"] = parse.ByteToStringParse1(b)
if JudgeTcp(result, Args) {
return result
}
return result
}

func DiscoverUdp(host string, port int, Args map[string]interface{}) map[string]interface{} {
result := setResult(host, port, Args)
var udpPort = []int{53, 111, 123, 137, 138, 139, 12345}
if isContainInt(udpPort, port) {
return result
}
b, err := get.UdpProtocol(host, port, Args["FlagTimeout"].(int))
if logger.DebugError(err) {
return result
}
result["type"] = "tcp"
result["status"] = "open"
result["banner.byte"] = b
result["banner.string"] = parse.ByteToStringParse1(b)
if JudgeUdp(result, Args) {
return result
}
return result
}
7 changes: 3 additions & 4 deletions internal/protocol/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func JudgeTcp(result map[string]interface{}, Args map[string]interface{}) bool {
status := result["status"].(string)
if status == "open" && runAll {
printFailed("TCP/unknown", result)
}
}
return false
}

Expand Down Expand Up @@ -183,7 +183,6 @@ func JudgeTls(result map[string]interface{}, Args map[string]interface{}) bool {
status := result["status"].(string)
if status == "open" && runAll {
printFailed("TLS/unknown", result)
//logger.Failed(fmt.Sprintf("[%s] %s [%s]", logger.Cyan("TLS/unknown"), parse.SchemeParse(result), logger.Blue(banner)))
}
return false
}
Expand Down Expand Up @@ -254,8 +253,8 @@ func printFailed(p string, result map[string]interface{}) {
logger.Cyan(p),
parse.SchemeParse(result),
logger.Blue(result["banner.string"].(string))),
)
)
result["identify.string"] = logger.Clean(result["identify.string"].(string))
result["note"] = logger.Clean(result["note"].(string))
}
}
}

0 comments on commit edcf125

Please sign in to comment.