Kaynağa Gözat

added another testcase and license info to the cli tool

AETH-erial 10 ay önce
ebeveyn
işleme
348e8759c8
3 değiştirilmiş dosya ile 80 ekleme ve 97 silme
  1. 18 0
      cmd/kyoketsu/kyoketsu.go
  2. 62 0
      pkg/local_test.go
  3. 0 97
      pkg/scanner.go

+ 18 - 0
cmd/kyoketsu/kyoketsu.go

@@ -32,17 +32,35 @@ import (
 	"fmt"
 	"log"
 	"net"
+	"os"
 	"strings"
 	"sync"
 
 	kyoketsu "git.aetherial.dev/aeth/kyoketsu/pkg"
 )
 
+var licenseMsg = "\n	http-wokou  Copyright (C) 2024  Russell Hrubesky, ChiralWorks Software LLC\n	This program comes with ABSOLUTELY NO WARRANTY; for details type `http-wokou --license`\n	This is free software, and you are welcome to redistribute it\n	under certain conditions; type `http-wokou --redist` for details.\n\n"
+
+var redistMsg = "\n	This program is free software: you can redistribute it and/or modify\n	it under the terms of the GNU General Public License as published by\n	the Free Software Foundation, either version 3 of the License, or\n	(at your option) any later version.\n\n"
+
+var licenseMsgLong = "\n		GNU GENERAL PUBLIC LICENSE\n		Version 3, 29 June 2007\n	Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n	Everyone is permitted to copy and distribute verbatim copies\n	of this license document, but changing it is not allowed.\n\n	http-wokou, An HTTP Proxying framework for bypassing DNS Security\n	Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC\n\n	This program is free software: you can redistribute it and/or modify\n	it under the terms of the GNU General Public License as published by\n	the Free Software Foundation, either version 3 of the License, or\n	(at your option) any later version.\n\n	This program is distributed in the hope that it will be useful,\n	but WITHOUT ANY WARRANTY; without even the implied warranty of\n	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n	GNU General Public License for more details.\n\n	You should have received a copy of the GNU General Public License\n	along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\n"
+
 func main() {
 
 	ip := flag.String("ips", "", "single ip address with CIDR notation to gather info about")
+	licenseInfo := flag.Bool("license", false, "Pass this flag to display license and warantee information.")
+	redistInfo := flag.Bool("redist", false, "Pass this flag to display redistribution information.")
 	flag.Parse()
 
+	if *licenseInfo {
+		fmt.Println(licenseMsgLong)
+		os.Exit(0)
+	}
+	if *redistInfo {
+		fmt.Println(redistMsg)
+		os.Exit(0)
+	}
+	fmt.Println(licenseMsg)
 	var err error
 	var addr *kyoketsu.IpSubnetMapper
 	addr, err = kyoketsu.GetNetworkAddresses(*ip)

+ 62 - 0
pkg/local_test.go

@@ -22,6 +22,7 @@ See the GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
+
 package kyoketsu
 
 import (
@@ -178,3 +179,64 @@ func TestGetNetwork(t *testing.T) {
 	}
 
 }
+
+func TestGetNetworkAddresses(t *testing.T) {
+	type TestCase struct {
+		Name       string
+		TestData   string
+		InputAddr  string
+		ShouldFail bool
+	}
+
+	tc := []TestCase{
+		TestCase{
+			Name:       "Passing testcase with valid IP address, returns all addresses.",
+			TestData:   "../test/local_ips.json",
+			InputAddr:  "192.168.50.50/24",
+			ShouldFail: false,
+		},
+		TestCase{
+			Name:       "Passing testcase with valid IP address that belongs to a /16 subnet",
+			TestData:   "../test/slash16_ips.json",
+			InputAddr:  "10.252.1.1/16",
+			ShouldFail: false,
+		},
+		TestCase{
+			Name:       "Failing testcase with invalid IP address.",
+			TestData:   "../test/slash16_ips.json",
+			InputAddr:  "abcdefgh1234455667",
+			ShouldFail: true,
+		},
+		TestCase{
+			Name:       "Failing testcase with valid IP address, but bad CIDR mask",
+			TestData:   "../test/slash16_ips.json",
+			InputAddr:  "192.168.50.1/deez",
+			ShouldFail: true,
+		},
+	}
+	for i := range tc {
+
+		got, err := GetNetworkAddresses(tc[i].InputAddr)
+		if err != nil {
+			if !tc[i].ShouldFail {
+				t.Errorf("Test: '%s' failed! Error: %s", tc[i].Name, err)
+			}
+			continue
+		}
+
+		want := LoadTestAddresses(tc[i].TestData)
+		for x := range got.Ipv4s {
+			gotip := got.Ipv4s[x]
+			_, ok := want[gotip.String()]
+			if !ok {
+				if !tc[i].ShouldFail {
+					t.Errorf("Test '%s' failed! Address: %s was not found in the test data: %s\n", tc[i].Name, gotip.String(), tc[i].TestData)
+				}
+			}
+
+		}
+		t.Logf("Test: '%s' passed!", tc[i].Name)
+
+	}
+
+}

+ 0 - 97
pkg/scanner.go

@@ -26,15 +26,9 @@ package kyoketsu
 
 import (
 	"fmt"
-	"log"
 	"net"
-	"os"
 	"sync"
 	"time"
-
-	"github.com/go-ping/ping"
-	"golang.org/x/net/icmp"
-	"golang.org/x/net/ipv4"
 )
 
 var PORT_MAP = map[int]string{
@@ -121,94 +115,3 @@ func singlePortScan(addr string, port int, svcs string) *PortScanResult {
 	conn.Close()
 	return &PortScanResult{PortNumber: port, Protocol: "tcp", Service: svcs, Listening: true}
 }
-
-/*
-This function makes use of an external dependency, may or may not keep. It still needs to be implemented
-
-	    :param addr: the ip address to send an ICMP request to
-		:param pinger: a pointer to a ping.Pinger struct to reuse
-*/
-func PingTarget(addr string, pinger *ping.Pinger) bool {
-	err := pinger.SetAddr(addr)
-	if err != nil {
-		log.Println(err)
-		return false
-	}
-	err = pinger.Run()
-	if err != nil {
-		log.Println(err)
-		return false
-	}
-	stats := pinger.Statistics()
-	if stats.PacketsRecv > 0 {
-		return true
-	}
-	return false
-
-}
-
-/*
-Listen for ICMP responses on a specific address
-
-	:param listening: the address of your server
-*/
-func IcmpListen(listening string) *icmp.PacketConn {
-	icmpSrv, err := icmp.ListenPacket("udp4", listening)
-	icmpSrv.SetDeadline(time.Now().Add(5 * time.Second))
-	if err != nil {
-		log.Println(err)
-	}
-	return icmpSrv
-
-}
-
-/*
-Send an ICMP request to an address and listen for a response (UNFINISHED/NON-FUNCTIONAL)
-
-	    :param icmpSrv: a pointer to an ICMP PacketConn struct, for reading and sending ICMP requests.
-		:param addr: the address to send the request to
-*/
-func icmpAsk(icmpSrv *icmp.PacketConn, addr string) bool {
-	icmpReq := icmp.Message{
-		Type: ipv4.ICMPTypeEcho, Code: 0,
-		Body: &icmp.Echo{
-			ID: os.Getpid() & 0xffff, Seq: 1,
-			Data: []byte("DIALING FROM KYOKETSU"),
-		},
-	}
-	icmpB, err := icmpReq.Marshal(nil)
-	if err != nil {
-		log.Println(err)
-		return false
-	}
-	if _, err := icmpSrv.WriteTo(icmpB, &net.UDPAddr{IP: net.ParseIP(addr)}); err != nil {
-		log.Println(err)
-		return false
-	}
-	respB := make([]byte, 1500)
-	n, peer, err := icmpSrv.ReadFrom(respB)
-	if err != nil {
-		log.Println(err)
-		return false
-	}
-	rm, err := icmp.ParseMessage(ipv4.ICMPTypeEcho.Protocol(), respB[:n])
-	if err != nil {
-		log.Println(err)
-		return false
-	}
-	switch rm.Type {
-	case ipv4.ICMPTypeEchoReply:
-		echo, ok := rm.Body.(*icmp.Echo)
-		if !ok {
-			return false
-		}
-		if peer.(*net.UDPAddr).IP.String() == addr && echo.Seq == 1 {
-			return true
-		}
-	default:
-		return false
-
-	}
-	return false
-
-}