Browse Source

cleaned up the manual portscanner

AETH-erial 1 year ago
parent
commit
68b4cae29f
3 changed files with 29 additions and 76 deletions
  1. 9 1
      cmd/kyoketsu-web/kyoketsu-web.go
  2. 20 57
      cmd/kyoketsu/kyoketsu.go
  3. 0 18
      pkg/local.go

+ 9 - 1
cmd/kyoketsu-web/kyoketsu-web.go

@@ -1,12 +1,20 @@
 package main
 package main
 
 
 import (
 import (
+	"fmt"
+	"log"
 	"os"
 	"os"
 
 
 	kyoketsu "git.aetherial.dev/aeth/kyoketsu/pkg"
 	kyoketsu "git.aetherial.dev/aeth/kyoketsu/pkg"
 )
 )
 
 
 func main() {
 func main() {
-	kyoketsu.RefactorGetAllRemAddr(os.Args[1])
+
+	addrs, err := kyoketsu.GetNetworkAddresses(os.Args[1])
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	fmt.Printf("%+v\n", addrs)
 
 
 }
 }

+ 20 - 57
cmd/kyoketsu/kyoketsu.go

@@ -1,12 +1,10 @@
 package main
 package main
 
 
 import (
 import (
-	"encoding/json"
 	"flag"
 	"flag"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 	"net"
 	"net"
-	"os"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 
 
@@ -15,66 +13,31 @@ import (
 
 
 func main() {
 func main() {
 
 
-	local := flag.Bool("local", true, "set flag to false to run this in targeted remote mode")
-	remoteAddrs := flag.String("ips", "", "comma seperated list of ip addresses to gather info about")
-	iface := flag.String("iface", "eth0", "use this flag to specify the interface to autonomously use for scanning.")
+	ip := flag.String("ips", "", "single ip address with CIDR notation to gather info about")
 	flag.Parse()
 	flag.Parse()
 
 
-	if !*local {
-		spAddr := strings.Split(*remoteAddrs, ",")
-		addr, err := kyoketsu.GetAllRemoteAddresses(spAddr, 65535)
-		if err != nil {
-			log.Fatal(err)
-		}
-		b, err := json.Marshal(addr)
-		if err != nil {
-			log.Fatal(err)
-		}
-		os.WriteFile("test/slash16_ips.json", b, os.ModePerm)
-
-		log.Printf("Starting scan on %v devices.\n", len(addr.Addr))
-		var wg sync.WaitGroup
-		for i := range addr.Addr {
-			wg.Add(1)
-			go func(idx int, wg *sync.WaitGroup) {
-
-				out := kyoketsu.PortWalk(addr.Addr[idx].String(), kyoketsu.PORT_MAP)
-				if len(out.ListeningPorts) > 0 {
-					dns, _ := net.LookupAddr(out.IpAddress)
-					out.Fqdn = strings.Join(dns, ", ")
-
-					fmt.Printf("%+v\n", out)
-
-				}
-
-				wg.Done()
-			}(i, &wg)
-		}
-
-		wg.Wait()
-
-	} else {
-		addr, err := kyoketsu.GetAllAddresses(*iface, 65535)
-		if err != nil {
-			log.Fatal(err)
-		}
-		log.Printf("Starting scan on %v devices.\n", len(addr.Addr))
-		var wg sync.WaitGroup
-		for i := range addr.Addr {
-			wg.Add(1)
-			go func(idx int, wg *sync.WaitGroup) {
-
-				out := kyoketsu.PortWalk(addr.Addr[idx].String(), kyoketsu.PORT_MAP)
-				if len(out.ListeningPorts) > 0 {
-					fmt.Printf("%+v\n", out)
+	var err error
+	var addr *kyoketsu.IpSubnetMapper
+	addr, err = kyoketsu.GetNetworkAddresses(*ip)
+	if err != nil {
+		log.Fatal(err)
+	}
+	var wg sync.WaitGroup
+	for i := range addr.Ipv4s {
+		wg.Add(1)
+		go func(target string, wg *sync.WaitGroup) {
+			defer wg.Done()
+			out := kyoketsu.PortWalk(target, kyoketsu.PORT_MAP)
+			if len(out.ListeningPorts) > 0 {
+				dns, _ := net.LookupAddr(out.IpAddress)
+				out.Fqdn = strings.Join(dns, ", ")
 
 
-				}
+				fmt.Printf("%+v\n", out)
 
 
-				wg.Done()
-			}(i, &wg)
-		}
+			}
 
 
-		wg.Wait()
+		}(addr.Ipv4s[i].String(), &wg)
 
 
 	}
 	}
+	wg.Wait()
 }
 }

+ 0 - 18
pkg/local.go

@@ -82,24 +82,6 @@ func addressRecurse(ipmap *IpSubnetMapper, max int) {
 	addressRecurse(ipmap, max)
 	addressRecurse(ipmap, max)
 }
 }
 
 
-/*
-Retrieve the address of a specific interface
-
-	:param name: the name of the interface to get the address of
-*/
-func getAddressByInterface(name string) ([]net.Addr, error) {
-	interfaces, err := net.Interfaces()
-	if err != nil {
-		return nil, err
-	}
-	for idx := range interfaces {
-		if interfaces[idx].Name == name {
-			return interfaces[idx].Addrs()
-		}
-	}
-	return nil, &NetworkInterfaceNotFound{Passed: name}
-}
-
 /*
 /*
 Get all of the IPv4 addresses in the network that 'addr' belongs to. YOU MUST PASS THE ADDRESS WITH CIDR NOTATION
 Get all of the IPv4 addresses in the network that 'addr' belongs to. YOU MUST PASS THE ADDRESS WITH CIDR NOTATION
 i.e. '192.168.50.1/24'
 i.e. '192.168.50.1/24'