|
@@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
package kyoketsu
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"net"
|
|
@@ -92,7 +93,7 @@ Scans a single host on a single port
|
|
|
*/
|
|
|
func singlePortScan(addr string, port int) int {
|
|
|
|
|
|
- conn, err := net.DialTimeout("tcp", fmt.Sprintf("%v:%d", addr, port), 4*time.Second)
|
|
|
+ conn, err := net.DialTimeout("tcp", fmt.Sprintf("%v:%d", addr, port), 2*time.Second)
|
|
|
if err != nil {
|
|
|
return 0
|
|
|
// return PortScanResult{PortNumber: port, Protocol: "tcp", Listening: false}
|
|
@@ -111,19 +112,27 @@ Perform a port scan sweep across an entire subnet
|
|
|
func NetSweep(ips []net.IP, ports []int, scanned chan Host) {
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
+ killswitch, cancel := context.WithDeadline(context.Background(), time.Now().Add(18*time.Second))
|
|
|
+ defer cancel()
|
|
|
for i := range ips {
|
|
|
wg.Add(1)
|
|
|
- go func(target string, portnum []int, wgrp *sync.WaitGroup) {
|
|
|
- defer wgrp.Done()
|
|
|
- portscanned := PortWalk(target, portnum)
|
|
|
- scanned <- Host{
|
|
|
- Fqdn: getFqdn(target),
|
|
|
- IpAddress: target,
|
|
|
- ListeningPorts: portscanned,
|
|
|
- PortString: strings.Trim(strings.Join(strings.Fields(fmt.Sprint(portscanned)), ","), "[]"),
|
|
|
+ go func(target string, portnum []int, wgrp *sync.WaitGroup, output chan Host) {
|
|
|
+ select {
|
|
|
+ case <-killswitch.Done():
|
|
|
+ fmt.Println("UNTO DEATH :::: WHILE THE SUN BEAMS DOWN")
|
|
|
+ return
|
|
|
+ default:
|
|
|
+ defer wgrp.Done()
|
|
|
+ portscanned := PortWalk(target, portnum)
|
|
|
+ output <- Host{
|
|
|
+ Fqdn: getFqdn(target),
|
|
|
+ IpAddress: target,
|
|
|
+ ListeningPorts: portscanned,
|
|
|
+ PortString: strings.Trim(strings.Join(strings.Fields(fmt.Sprint(portscanned)), ","), "[]"),
|
|
|
+ }
|
|
|
}
|
|
|
+ }(ips[i].String(), ports, wg, scanned)
|
|
|
|
|
|
- }(ips[i].String(), ports, wg)
|
|
|
}
|
|
|
wg.Wait()
|
|
|
close(scanned)
|