Browse Source

restructuring

AETH-erial 1 year ago
parent
commit
1633b64487
8 changed files with 25 additions and 51 deletions
  1. 1 7
      cmd/kyoketsu/kyoketsu.go
  2. 6 8
      pkg/local.go
  3. 1 0
      pkg/packer.go
  4. 0 1
      pkg/packer/packer.go
  5. 12 18
      pkg/scanner.go
  6. 3 16
      pkg/storage.go
  7. 2 0
      pkg/torrent.go
  8. 0 1
      pkg/torrent/torrent.go

+ 1 - 7
cmd/kyoketsu/kyoketsu.go

@@ -4,22 +4,16 @@ import (
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 	"os"
 	"os"
-
-	"git.aetherial.dev/aeth/kyoketsu/pkg/scan"
 )
 )
 
 
-
-
 func main() {
 func main() {
 	if len(os.Args) == 1 {
 	if len(os.Args) == 1 {
 		log.Fatal("Please pass in the name of an interface that belongs to the network to scan.")
 		log.Fatal("Please pass in the name of an interface that belongs to the network to scan.")
 	}
 	}
-	addr, err := scan.GetAllAddresses(os.Args[1])
+	addr, err := kyoketsu.GetAllAddresses(os.Args[1])
 	if err != nil {
 	if err != nil {
 		log.Fatal(err)
 		log.Fatal(err)
 	}
 	}
 	fmt.Printf("%+v\n", addr)
 	fmt.Printf("%+v\n", addr)
 
 
-
 }
 }
-

+ 6 - 8
pkg/scan/local.go → pkg/local.go

@@ -1,4 +1,4 @@
-package scan
+package kyoketsu
 
 
 import (
 import (
 	"fmt"
 	"fmt"
@@ -6,15 +6,13 @@ import (
 	"net"
 	"net"
 	"net/netip"
 	"net/netip"
 	"strings"
 	"strings"
-
 )
 )
 
 
-
 type AllAddress struct {
 type AllAddress struct {
-	Addr	[]net.IP `json:"addresses"`
+	Addr []net.IP `json:"addresses"`
 }
 }
 
 
-type NetworkInterfaceNotFound struct {Passed string}
+type NetworkInterfaceNotFound struct{ Passed string }
 
 
 // Implementing error interface
 // Implementing error interface
 func (n *NetworkInterfaceNotFound) Error() string {
 func (n *NetworkInterfaceNotFound) Error() string {
@@ -23,6 +21,7 @@ func (n *NetworkInterfaceNotFound) Error() string {
 
 
 /*
 /*
 Recursive function to get all of the IPv4 addresses for each IPv4 network that the host is on
 Recursive function to get all of the IPv4 addresses for each IPv4 network that the host is on
+
 	:param addr: the address to recursively find the next address for
 	:param addr: the address to recursively find the next address for
 	:param out: a pointer to a struct containing a list of addresses
 	:param out: a pointer to a struct containing a list of addresses
 */
 */
@@ -43,6 +42,7 @@ func addressRecurse(addr netip.Addr, out *AllAddress) {
 
 
 /*
 /*
 Retrieve the address of a specific interface
 Retrieve the address of a specific interface
+
 	:param name: the name of the interface to get the address of
 	:param name: the name of the interface to get the address of
 */
 */
 func getAddressByInterface(name string) ([]net.Addr, error) {
 func getAddressByInterface(name string) ([]net.Addr, error) {
@@ -58,12 +58,11 @@ func getAddressByInterface(name string) ([]net.Addr, error) {
 	return nil, &NetworkInterfaceNotFound{Passed: name}
 	return nil, &NetworkInterfaceNotFound{Passed: name}
 }
 }
 
 
-
 /*
 /*
 Utilized a recursive function to find all addresses in the address space that the host belongs.
 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
 Returns a pointer to an AllAddresses struct who has a list of net.IP structs inside
 */
 */
-func GetAllAddresses(name string) (*AllAddress, error){
+func GetAllAddresses(name string) (*AllAddress, error) {
 	addresses, err := getAddressByInterface(name)
 	addresses, err := getAddressByInterface(name)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
@@ -82,4 +81,3 @@ func GetAllAddresses(name string) (*AllAddress, error){
 	}
 	}
 	return out, nil
 	return out, nil
 }
 }
-

+ 1 - 0
pkg/packer.go

@@ -0,0 +1 @@
+package kyoketsu

+ 0 - 1
pkg/packer/packer.go

@@ -1 +0,0 @@
-package packer

+ 12 - 18
pkg/scan/scanner.go → pkg/scanner.go

@@ -1,4 +1,4 @@
-package scan
+package kyoketsu
 
 
 import (
 import (
 	"fmt"
 	"fmt"
@@ -6,8 +6,6 @@ import (
 	"net/netip"
 	"net/netip"
 	"sync"
 	"sync"
 	"time"
 	"time"
-
-
 )
 )
 
 
 var PORT_MAP = map[int]string{
 var PORT_MAP = map[int]string{
@@ -16,29 +14,29 @@ var PORT_MAP = map[int]string{
 }
 }
 
 
 type TcpScanHost struct {
 type TcpScanHost struct {
-	Host			string				`json:"host"`
-	Ipv4Address		netip.Addr			`json:"ipv4_address"`
-	PortsScanned	[]PortScanResult 	`json:"ports_scanned"`
+	Host         string           `json:"host"`
+	Ipv4Address  netip.Addr       `json:"ipv4_address"`
+	PortsScanned []PortScanResult `json:"ports_scanned"`
 }
 }
 
 
 type PortScanResult struct {
 type PortScanResult struct {
-	PortNumber	int		`json:"port_number"`
-	Service		string	`json:"service"`
-	Protocol	string	`json:"protocol"`
-	Listening	bool	`json:"listening"`
+	PortNumber int    `json:"port_number"`
+	Service    string `json:"service"`
+	Protocol   string `json:"protocol"`
+	Listening  bool   `json:"listening"`
 }
 }
 
 
 type PortScanDirective struct {
 type PortScanDirective struct {
-	Pairs	map[int]string
+	Pairs map[int]string
 }
 }
 
 
 func RetrieveScanDirectives() PortScanDirective {
 func RetrieveScanDirectives() PortScanDirective {
 	return PortScanDirective{Pairs: PORT_MAP}
 	return PortScanDirective{Pairs: PORT_MAP}
 }
 }
 
 
-
 /*
 /*
 Scans a single host on a single port
 Scans a single host on a single port
+
 	:param addr: the address to dial
 	:param addr: the address to dial
 	:param port: the port number to dial
 	:param port: the port number to dial
 */
 */
@@ -55,13 +53,14 @@ func singlePortScan(addr string, port int, svcs string) *PortScanResult {
 
 
 /*
 /*
 Perform a TCP scan on the pointers host
 Perform a TCP scan on the pointers host
+
 	:param posts: a list of ports to scan against a host
 	:param posts: a list of ports to scan against a host
 */
 */
 func (t *TcpScanHost) ScanPortRange(ports []int) []*PortScanResult {
 func (t *TcpScanHost) ScanPortRange(ports []int) []*PortScanResult {
 	wg := &sync.WaitGroup{}
 	wg := &sync.WaitGroup{}
 	out := make(chan *PortScanResult)
 	out := make(chan *PortScanResult)
 	var res []*PortScanResult
 	var res []*PortScanResult
-    wgOuter := &sync.WaitGroup{}
+	wgOuter := &sync.WaitGroup{}
 	wgOuter.Add(1)
 	wgOuter.Add(1)
 	go func() {
 	go func() {
 		defer wgOuter.Done()
 		defer wgOuter.Done()
@@ -90,14 +89,9 @@ func (t *TcpScanHost) ScanPortRange(ports []int) []*PortScanResult {
 
 
 }
 }
 
 
-
 /*
 /*
 Evaluate whether the host has an entry in the ARP table
 Evaluate whether the host has an entry in the ARP table
 */
 */
 func (h *TcpScanHost) IsOnline() bool {
 func (h *TcpScanHost) IsOnline() bool {
 	return false
 	return false
 }
 }
-
-
-
-

+ 3 - 16
pkg/storage/storage.go → pkg/storage.go

@@ -1,4 +1,4 @@
-package storage
+package kyoketsu
 
 
 import (
 import (
 	"context"
 	"context"
@@ -11,14 +11,13 @@ import (
 )
 )
 
 
 type TopologyDatabaseIO interface {
 type TopologyDatabaseIO interface {
-	AddHostToDb(*scan.TcpScanHost) error	// Add a host to the hosts table
+	AddHostToDb(*scan.TcpScanHost) error             // Add a host to the hosts table
 	UpdateHostEntry(string, *scan.TcpScanHost) error //Update a host entry, indexing by its ip address
 	UpdateHostEntry(string, *scan.TcpScanHost) error //Update a host entry, indexing by its ip address
 	RemoveHostEntry(string) error
 	RemoveHostEntry(string) error
 }
 }
 
 
-
 type MongoClient struct {
 type MongoClient struct {
-	conn	*mongo.Client
+	conn *mongo.Client
 }
 }
 
 
 func NewMongoClient(host string, port int) *MongoClient {
 func NewMongoClient(host string, port int) *MongoClient {
@@ -38,7 +37,6 @@ func (m *MongoClient) addDocument(id string, data interface{}) error {
 	return nil
 	return nil
 }
 }
 
 
-
 func (m *MongoClient) AddHostToDb(host *scan.TcpScanHost) error {
 func (m *MongoClient) AddHostToDb(host *scan.TcpScanHost) error {
 	return nil
 	return nil
 }
 }
@@ -50,14 +48,3 @@ func (m *MongoClient) UpdateHostEntry(id string, host *scan.TcpScanHost) error {
 func (m *MongoClient) RemoveHostEntry(id string) error {
 func (m *MongoClient) RemoveHostEntry(id string) error {
 	return nil
 	return nil
 }
 }
-
-
-
-
-
-
-
-
-
-
-

+ 2 - 0
pkg/torrent.go

@@ -0,0 +1,2 @@
+package kyoketsu
+

+ 0 - 1
pkg/torrent/torrent.go

@@ -1 +0,0 @@
-package torrent