From 818102a8149edd51461fefb909cb3653211e2bae Mon Sep 17 00:00:00 2001 From: shadow1ng Date: Thu, 3 Dec 2020 23:20:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ip=E6=AE=B5=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E3=80=81=E7=AB=AF=E5=8F=A3=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugins/icmp.go | 1 + Plugins/portscan.go | 26 +++++--------------------- Plugins/scanner.go | 4 ++-- README.md | 2 +- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/Plugins/icmp.go b/Plugins/icmp.go index c92c5d2..55bab53 100644 --- a/Plugins/icmp.go +++ b/Plugins/icmp.go @@ -78,6 +78,7 @@ func isping(ip string) bool { if err != nil { return false } + defer conn.Close() _, err = conn.Write(buffer.Bytes()) if err != nil { return false diff --git a/Plugins/portscan.go b/Plugins/portscan.go index 0a7db53..638a07d 100644 --- a/Plugins/portscan.go +++ b/Plugins/portscan.go @@ -35,12 +35,9 @@ func ParsePort(ports string) []int { return scanPorts } -func ProbeHosts(host string, ports <-chan int, respondingHosts chan<- string, done chan<- bool, model string, adjustedTimeout int) { - Timeout := time.Duration(adjustedTimeout) * time.Second +func ProbeHosts(host string, ports <-chan int, respondingHosts chan<- string, done chan<- bool, adjustedTimeout int) { for port := range ports { - start := time.Now() con, err := net.DialTimeout("tcp4", fmt.Sprintf("%s:%d", host, port), time.Duration(adjustedTimeout)*time.Second) - duration := time.Now().Sub(start) if err == nil { defer con.Close() address := host + ":" + strconv.Itoa(port) @@ -48,21 +45,17 @@ func ProbeHosts(host string, ports <-chan int, respondingHosts chan<- string, do common.LogSuccess(result) respondingHosts <- address } - if duration < Timeout { - difference := Timeout - duration - Timeout = Timeout - (difference / 2) - } } done <- true } -func ScanAllports(address string, probePorts []int, threads int, timeout time.Duration, model string, adjustedTimeout int) ([]string, error) { +func ScanAllports(address string, probePorts []int, threads int, adjustedTimeout int) ([]string, error) { ports := make(chan int, 20) results := make(chan string, 10) done := make(chan bool, threads) for worker := 0; worker < threads; worker++ { - go ProbeHosts(address, ports, results, done, model, adjustedTimeout) + go ProbeHosts(address, ports, results, done, adjustedTimeout) } for _, port := range probePorts { @@ -80,13 +73,11 @@ func ScanAllports(address string, probePorts []int, threads int, timeout time.Du if threads == 0 { return responses, nil } - case <-time.After(timeout): - return responses, nil } } } -func TCPportScan(hostslist []string, ports string, model string, timeout int) ([]string, []string) { +func TCPportScan(hostslist []string, ports string, timeout int) ([]string, []string) { var AliveAddress []string var aliveHosts []string probePorts := ParsePort(ports) @@ -119,18 +110,12 @@ func TCPportScan(hostslist []string, ports string, model string, timeout int) ([ var wg sync.WaitGroup mutex := &sync.Mutex{} limiter := make(chan struct{}, lm) - aliveHost := make(chan string, lm/2) - go func() { - for s := range aliveHost { - fmt.Println(s) - } - }() for _, host := range hostslist { wg.Add(1) limiter <- struct{}{} go func(host string) { defer wg.Done() - if aliveAdd, err := ScanAllports(host, probePorts, thread, 5*time.Second, model, timeout); err == nil && len(aliveAdd) > 0 { + if aliveAdd, err := ScanAllports(host, probePorts, thread, timeout); err == nil && len(aliveAdd) > 0 { mutex.Lock() aliveHosts = append(aliveHosts, host) for _, addr := range aliveAdd { @@ -142,6 +127,5 @@ func TCPportScan(hostslist []string, ports string, model string, timeout int) ([ }(host) } wg.Wait() - close(aliveHost) return aliveHosts, AliveAddress } diff --git a/Plugins/scanner.go b/Plugins/scanner.go index d6df00d..40294db 100644 --- a/Plugins/scanner.go +++ b/Plugins/scanner.go @@ -40,8 +40,8 @@ func Scan(info common.HostInfo) { Hosts = ICMPRun(Hosts, info.IcmpThreads, info.Ping) fmt.Println("icmp alive hosts len is:", len(Hosts)) } - _, AlivePorts := TCPportScan(Hosts, info.Ports, "icmp", 3) //return AliveHosts,AlivePorts - var severports []string //severports := []string{"21","22","135"."445","1433","3306","5432","6379","9200","11211","27017"...} + _, AlivePorts := TCPportScan(Hosts, info.Ports, 3) //return AliveHosts,AlivePorts + var severports []string //severports := []string{"21","22","135"."445","1433","3306","5432","6379","9200","11211","27017"...} for _, port := range common.PORTList { severports = append(severports, strconv.Itoa(port)) } diff --git a/README.md b/README.md index 5aa8280..7b1d9fd 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 因为用习惯了f-scrack,习惯一条命令跑完所有模块,省去一个个模块单独调用的时间,当然我附加了-m 指定模块的功能。 ## 最近更新 -[+] 2020/12/03 优化ip段处理模块,新增支持192.168.1.1-192.168.255.255 +[+] 2020/12/03 优化ip段处理模块、icmp、端口扫描模块。新增支持192.168.1.1-192.168.255.255。 [+] 2020/11/17 增加-ping 参数,作用是存活探测模块用ping代替icmp发包。 [+] 2020/11/17 增加WebScan模块,新增shiro简单识别。https访问时,跳过证书认证。将服务模块和web模块的超时分开,增加-wt 参数(WebTimeout)。 [+] 2020/11/16 对icmp模块进行优化,增加-it 参数(IcmpThreads),默认11000,适合扫B段