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