Browse Source

commiting the working code up

AETH-erial 10 months ago
parent
commit
af60d09d75
3 changed files with 23 additions and 13 deletions
  1. 1 0
      cmd/kyoketsu/kyoketsu.go
  2. 19 10
      pkg/scanner.go
  3. 3 3
      pkg/webserver.go

+ 1 - 0
cmd/kyoketsu/kyoketsu.go

@@ -80,6 +80,7 @@ func main() {
 	}
 	scanned := make(chan kyoketsu.Host)
 	go func() {
+
 		for x := range scanned {
 			if len(x.ListeningPorts) > 0 {
 				fmt.Print(" |-|-|-| :::: HOST FOUND :::: |-|-|-|\n==================||==================\n")

+ 19 - 10
pkg/scanner.go

@@ -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)

+ 3 - 3
pkg/webserver.go

@@ -71,10 +71,10 @@ func (e *ExecutionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		fmt.Fprintf(w, "There was an error processing your request: %s", err)
 	}
 	scanned := make(chan Host)
-	go func() {
+	go func(wr http.ResponseWriter, templ *template.Template) {
 		for x := range scanned {
 			if len(x.ListeningPorts) > 0 {
-				e.TableEntry.Execute(w, x)
+				templ.Execute(wr, x)
 
 				fmt.Print(" |-|-|-| :::: HOST FOUND :::: |-|-|-|\n==================||==================\n")
 				fmt.Printf("IPv4 Address: %s\nListening Ports: %v\n=====================================\n", x.IpAddress, x.ListeningPorts)
@@ -96,7 +96,7 @@ func (e *ExecutionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 
 			}
 		}
-	}()
+	}(w, e.TableEntry)
 	NetSweep(subnetMap.Ipv4s, RetrieveScanDirectives(), scanned)
 }