diff --git a/cmd/all.go b/cmd/all.go index dd518bf..aff9c91 100644 --- a/cmd/all.go +++ b/cmd/all.go @@ -25,7 +25,8 @@ var allCmd = &cobra.Command{ func init() { allCmd.Flags().StringVarP(&Hosts, "host", "H", "", "Set `hosts`(The format is similar to Nmap) or ips.txt file path") allCmd.Flags().StringVarP(&Ports, "ports", "P", "", "Set `ports`(The format is similar to Nmap)") - allCmd.Flags().BoolVar(&PingBool, "noping", true, "No use ping to scanner alive host") + allCmd.Flags().BoolVar(&PingBool, "noping", false, "No use ping to scanner alive host") + allCmd.Flags().BoolVar(&RunICMP, "icmp", false, "Use icmp to scanner alive host") allCmd.Flags().IntVar(&Runtime, "runtime", 100, "Set scanner ants pool thread") allCmd.Flags().StringVar(&ProxyHost, "proxy", "", "Set socks5 proxy") allCmd.Flags().DurationVar(&TimeDuration, "time", 1*time.Second, "Set timeout ") @@ -57,8 +58,9 @@ func allRun(hostString string, portString string, log bool, runtime int, noping } else { // 执行 ping 操作 fmt.Println("----- [Yasso] Start do ping scan -----") - alive = execute(ips) + alive = execute(ips, RunICMP) } + fmt.Println("[Yasoo get alive host] is", len(alive)) // 做漏洞扫描 if len(alive) > 0 { fmt.Println("----- [Yasso] Start do vuln scan -----") @@ -122,4 +124,5 @@ func allRun(hostString string, portString string, log bool, runtime int, noping fmt.Println("----- [Yasso] Start do web service scan -----") DisMapScan(alive, webports) } + fmt.Println("[Yasso] scan task is completed") } diff --git a/cmd/dismap.go b/cmd/dismap.go index 8a16642..7f7449f 100644 --- a/cmd/dismap.go +++ b/cmd/dismap.go @@ -33,8 +33,9 @@ var DisMapCmd = &cobra.Command{ var ports []int hosts, _ := ResolveIPS(Hosts) var runhosts []string + if PingBool == true { - runhosts = execute(hosts) + runhosts = execute(hosts, false) } else { runhosts = hosts } diff --git a/cmd/icmp.go b/cmd/icmp.go index f92d487..d6bc446 100644 --- a/cmd/icmp.go +++ b/cmd/icmp.go @@ -14,9 +14,8 @@ import ( ) var ( - tunnel = make(chan string, 20) - OS = runtime.GOOS - Alive []string // 存活的ip列表 + OS = runtime.GOOS // 系统架构 + Alive []string // 存活的ip列表 ) var pingCmd = &cobra.Command{ Use: "ping", @@ -34,7 +33,7 @@ var pingCmd = &cobra.Command{ return } Println(fmt.Sprintf("[Yasso] will ping %d host", len(ips))) - _ = execute(ips) + _ = execute(ips, RunICMP) }, } @@ -44,31 +43,26 @@ func init() { rootCmd.AddCommand(pingCmd) } -func execute(ips []string) []string { +func execute(ips []string, r bool) []string { var wg sync.WaitGroup - - go func() { - for _, ip := range ips { - tunnel <- ip - } - }() - for i := 0; i < len(ips); i++ { - wg.Add(1) - _ = ants.Submit(func() { - ip := <-tunnel - if RunICMP == true { - if icmp(ip) { - Println(fmt.Sprintf("[+] Find %v (icmp)", ip)) - Alive = append(Alive, ip) - } - } else { - if ping(ip) { - Println(fmt.Sprintf("[+] Find %v (ping)", ip)) - Alive = append(Alive, ip) - } + // 修改ants池的并发方式 + p, _ := ants.NewPoolWithFunc(len(ips), func(ip interface{}) { + if r == true { + if icmp(ip.(string)) { + Println(fmt.Sprintf("[+] Find %v (icmp)", ip)) + Alive = append(Alive, ip.(string)) } - wg.Done() - }) + } else { + if ping(ip.(string)) { + Println(fmt.Sprintf("[+] Find %v (ping)", ip)) + Alive = append(Alive, ip.(string)) + } + } + wg.Done() + }) + for _, ip := range ips { + wg.Add(1) + _ = p.Invoke(ip) } wg.Wait() return Alive diff --git a/cmd/ps.go b/cmd/ps.go index f15f579..cdf246d 100644 --- a/cmd/ps.go +++ b/cmd/ps.go @@ -61,23 +61,21 @@ func init() { func PortScan(host []string, ports []int) []PortResult { var tempPort []PortResult var wg sync.WaitGroup - go func() { - for _, ip := range host { - tunnel <- ip - } - }() - for i := 0; i < len(host); i++ { - wg.Add(1) + + p, _ := ants.NewPoolWithFunc(len(host), func(ip interface{}) { _ = ants.Submit(func() { - ip := <-tunnel - aport := EachScan(ip, ports) + aport := EachScan(ip.(string), ports) //Println()(aport) if len(aport) != 0 { // 扫描完成,加入扫描结果队列 - tempPort = append(tempPort, PortResult{ip, aport}) + tempPort = append(tempPort, PortResult{ip.(string), aport}) } // 将ip赋值给AlivePort*/ wg.Done() }) + }) + for _, ip := range host { + wg.Add(1) + _ = p.Invoke(ip) } wg.Wait() return tempPort diff --git a/cmd/vuln.go b/cmd/vuln.go index 93a0730..91a0d4f 100644 --- a/cmd/vuln.go +++ b/cmd/vuln.go @@ -48,31 +48,27 @@ func init() { func VulScan(ips []string, ms17010bool bool, allbool bool, smbGohstbool bool) { var wg sync.WaitGroup - go func() { - for _, ip := range ips { - tunnel <- ip + p, _ := ants.NewPoolWithFunc(len(ips), func(ip interface{}) { + if ms17010bool == true || allbool == true { + Ms17010Conn(config.HostIn{ + Host: ip.(string), + Port: 445, + TimeOut: TimeDuration, + }) } - }() - for i := 0; i < len(ips); i++ { + if smbGohstbool == true || allbool == true { + SmbGhostConn(config.HostIn{ + Host: ip.(string), + Port: 445, + TimeOut: TimeDuration, + }) + } + wg.Done() + }) + + for _, ip := range ips { wg.Add(1) - _ = ants.Submit(func() { - ip := <-tunnel - if ms17010bool == true || allbool == true { - Ms17010Conn(config.HostIn{ - Host: ip, - Port: 445, - TimeOut: TimeDuration, - }) - } - if smbGohstbool == true || allbool == true { - SmbGhostConn(config.HostIn{ - Host: ip, - Port: 445, - TimeOut: TimeDuration, - }) - } - wg.Done() - }) + _ = p.Invoke(ip) } wg.Wait() } diff --git a/ips.txt b/ips.txt index 3fd04ad..850cd61 100644 --- a/ips.txt +++ b/ips.txt @@ -1,4 +1,4 @@ -192.168.248.1 -192.168.248.219 -192.168.248.212 -192.168.248.128 +192.168.248.1 +192.168.248.219 +192.168.248.212 +192.168.248.128