go fmt duh

This commit is contained in:
Jeffrey Paul 2018-08-25 12:07:33 -07:00
parent 5f3046319c
commit 596a551aa5

View File

@ -6,9 +6,9 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"os"
"github.com/akrennmair/gopcap" "github.com/akrennmair/gopcap"
"github.com/op/go-logging" "github.com/op/go-logging"
"os"
) )
var log = logging.MustGetLogger("gpk") var log = logging.MustGetLogger("gpk")
@ -28,15 +28,15 @@ const (
// it is dumb that go doesn't let me define additional methods // it is dumb that go doesn't let me define additional methods
// on the external package, now these have to be plain funcs // on the external package, now these have to be plain funcs
func isRST(tcp *pcap.Tcphdr) bool { func isRST(tcp *pcap.Tcphdr) bool {
return (tcp.Flags & TCP_RST) != 0 return (tcp.Flags & TCP_RST) != 0
} }
func isACK(tcp *pcap.Tcphdr) bool { func isACK(tcp *pcap.Tcphdr) bool {
return (tcp.Flags & TCP_ACK) != 0 return (tcp.Flags & TCP_ACK) != 0
} }
func isFIN(tcp *pcap.Tcphdr) bool { func isFIN(tcp *pcap.Tcphdr) bool {
return (tcp.Flags & TCP_FIN) != 0 return (tcp.Flags & TCP_FIN) != 0
} }
func min(x uint32, y uint32) uint32 { func min(x uint32, y uint32) uint32 {
@ -47,8 +47,8 @@ func min(x uint32, y uint32) uint32 {
} }
func usage() { func usage() {
fmt.Printf("usage: gopakketo [-d <device> | -r <file>]\n") fmt.Printf("usage: gopakketo [-d <device> | -r <file>]\n")
os.Exit(0) os.Exit(0)
} }
var logFormat = logging.MustStringFormatter( var logFormat = logging.MustStringFormatter(
@ -58,40 +58,40 @@ var logFormat = logging.MustStringFormatter(
func main() { func main() {
loggingBackend := logging.NewLogBackend(os.Stderr, "", 0) loggingBackend := logging.NewLogBackend(os.Stderr, "", 0)
backendFormatter := logging.NewBackendFormatter(loggingBackend, logFormat) backendFormatter := logging.NewBackendFormatter(loggingBackend, logFormat)
logging.SetBackend(backendFormatter) logging.SetBackend(backendFormatter)
var device *string = flag.String("d", "", "device") var device *string = flag.String("d", "", "device")
var targetlist *string = flag.String("t", "", "target list e.g. 192.168.0.0/16 or 192.168.0-255.0-255") var targetlist *string = flag.String("t", "", "target list e.g. 192.168.0.0/16 or 192.168.0-255.0-255")
var portlist *string = flag.String("p", "", "port list e.g. 0-1024 or 22,23,80 or 0-1024,6667") var portlist *string = flag.String("p", "", "port list e.g. 0-1024 or 22,23,80 or 0-1024,6667")
//var outfile *string = flag.String("o", "", "output file") //var outfile *string = flag.String("o", "", "output file")
//var expr *string = flag.String("e", "", "filter expression") //var expr *string = flag.String("e", "", "filter expression")
flag.Parse() flag.Parse()
go send(device, targetlist, portlist); go send(device, targetlist, portlist)
receive(device); receive(device)
} }
func parsePortList (pl *[]uint16, s *string) { func parsePortList(pl *[]uint16, s *string) {
} }
func parseTargetList (tl *[]uint32, s *string) { func parseTargetList(tl *[]uint32, s *string) {
} }
func send(device *string, targetlist *string, portlist *string) { func send(device *string, targetlist *string, portlist *string) {
pl := make([]uint16, 0) pl := make([]uint16, 0)
parsePortList(pl, portlist) parsePortList(pl, portlist)
tl := make([]uint32, 0) tl := make([]uint32, 0)
parseTargetList(tl, targetlist) parseTargetList(tl, targetlist)
} }
func sendSyn (device *string, sport uint16, dst uint32, dport uint16) { func sendSyn(device *string, sport uint16, dst uint32, dport uint16) {
} }
@ -104,7 +104,7 @@ func receive(device *string) {
panic(fmt.Sprintf("no interfaces found : %s\n", err)) panic(fmt.Sprintf("no interfaces found : %s\n", err))
} }
if *device != "" { if *device != "" {
pc, err = pcap.Openlive(*device, 65535, true, 0) pc, err = pcap.Openlive(*device, 65535, true, 0)
if pc == nil { if pc == nil {
log.Noticef("Openlive(%s) failed: %s\n", *device, err) log.Noticef("Openlive(%s) failed: %s\n", *device, err)
@ -113,9 +113,9 @@ func receive(device *string) {
if err != nil { if err != nil {
log.Criticalf("Openlive(%s) failed: %s\n", *device, err) log.Criticalf("Openlive(%s) failed: %s\n", *device, err)
return return
} }
} else { } else {
usage() usage()
return return
} }
defer pc.Close() defer pc.Close()
@ -123,22 +123,22 @@ func receive(device *string) {
log.Infof("pcap version: %s\n", pcap.Version()) log.Infof("pcap version: %s\n", pcap.Version())
for pkt := pc.Next(); pkt != nil; pkt = pc.Next() { for pkt := pc.Next(); pkt != nil; pkt = pc.Next() {
pkt.Decode() pkt.Decode()
if pkt.TCP == nil { if pkt.TCP == nil {
// we are only interested in TCP for scanning purposes rn // we are only interested in TCP for scanning purposes rn
continue continue
} }
if !isRST(pkt.TCP) && !isACK(pkt.TCP) { if !isRST(pkt.TCP) && !isACK(pkt.TCP) {
// for scanning we only want RSTs (closed) and ACKs (open) // for scanning we only want RSTs (closed) and ACKs (open)
continue continue
} }
if isACK(pkt.TCP) { if isACK(pkt.TCP) {
if isFIN(pkt.TCP) { if isFIN(pkt.TCP) {
continue continue
} }
} }
fmt.Printf("%s\n", pkt.String()) fmt.Printf("%s\n", pkt.String())
} }