ソースを参照

playing around with different ip address targets

AETH-erial 1 年間 前
コミット
fc894e40e5
2 ファイル変更75 行追加20 行削除
  1. 48 20
      cmd/kyoketsu/kyoketsu.go
  2. 27 0
      pkg/local.go

+ 48 - 20
cmd/kyoketsu/kyoketsu.go

@@ -1,9 +1,10 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"log"
-	"os"
+	"strings"
 	"sync"
 
 	kyoketsu "git.aetherial.dev/aeth/kyoketsu/pkg"
@@ -13,28 +14,55 @@ func main() {
 	//	kyoketsu.PingWithDependency(os.Args[1])
 	//	os.Exit(1)
 
-	if len(os.Args) == 1 {
-		log.Fatal("Please pass in the name of an interface that belongs to the network to scan.")
-	}
-	addr, err := kyoketsu.GetAllAddresses(os.Args[1])
-	if err != nil {
-		log.Fatal(err)
-	}
-	var wg sync.WaitGroup
-	for i := range addr.Addr {
-		wg.Add(1)
-		go func(idx int, wg *sync.WaitGroup) {
+	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.")
+	flag.Parse()
 
-			out := kyoketsu.PortWalk(addr.Addr[idx].String(), kyoketsu.PORT_MAP)
-			if len(out.ListeningPorts) > 0 {
-				fmt.Printf("%+v\n", out)
+	if !*local {
+		spAddr := strings.Split(*remoteAddrs, ",")
+		addr, err := kyoketsu.GetAllRemoteAddresses(spAddr)
+		if err != nil {
+			log.Fatal(err)
+		}
+		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)
 
-			wg.Done()
-		}(i, &wg)
-	}
+				}
+
+				wg.Done()
+			}(i, &wg)
+		}
+
+		wg.Wait()
 
-	wg.Wait()
+	} else {
+		addr, err := kyoketsu.GetAllAddresses(*iface)
+		if err != nil {
+			log.Fatal(err)
+		}
+		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)
+
+				}
+
+				wg.Done()
+			}(i, &wg)
+		}
+
+		wg.Wait()
+
+	}
 }

+ 27 - 0
pkg/local.go

@@ -81,3 +81,30 @@ func GetAllAddresses(name string) (*AllAddress, error) {
 	}
 	return out, nil
 }
+
+/*
+Utilized a recursive function to find all addresses in the address space that the host belongs.
+Returns a pointer to an AllAddresses struct who has a list of net.IP structs inside
+*/
+func GetAllRemoteAddresses(addrs []string) (*AllAddress, error) {
+	out := &AllAddress{}
+	var addresses []net.IP
+	for i := range addrs {
+		addresses = append(addresses, net.ParseIP(addrs[i]))
+	}
+
+	for idx := range addresses {
+
+		ip := net.ParseIP(strings.Split(addresses[idx].String(), "/")[0])
+		root, err := netip.ParseAddr(ip.Mask(ip.DefaultMask()).String())
+		if err != nil {
+			continue
+		}
+		if root.IsLoopback() {
+			continue
+		}
+		addressRecurse(root, out)
+
+	}
+	return out, nil
+}