-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit implements the macgonuts golang bind. Besides build tasks (--with-gobind, with-gobind=yes) related to it and some documentation. Building and usage. A little sample, too.
- Loading branch information
1 parent
ee8392e
commit 1616e54
Showing
12 changed files
with
390 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// Copyright (c) 2023, Rafael Santiago | ||
// All rights reserved. | ||
// | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// | ||
// INFO(Rafael): If you want to build this sample just run `go build` | ||
package main | ||
|
||
import ( | ||
"../v1" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 4 { | ||
fmt.Fprintf(os.Stderr, "use: %s <iface> <target-ip> <address-to-spoof> [ <packets-total> <timeout in mss> ]", | ||
os.Args[0]) | ||
os.Exit(1) | ||
} | ||
var packetsTotal int = 0 | ||
var err error = nil | ||
if len(os.Args) > 4 { | ||
packetsTotal, err = strconv.Atoi(os.Args[4]) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
if packetsTotal < 0 { | ||
fmt.Fprintf(os.Stderr, "error: packets-total must be a positive integer.\n") | ||
os.Exit(1) | ||
} | ||
} | ||
var timeoutInMss int = 0 | ||
if len(os.Args) > 5 { | ||
timeoutInMss, err = strconv.Atoi(os.Args[5]) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
if timeoutInMss < 0 { | ||
fmt.Fprintf(os.Stderr, "error: timeout must be a positive integer.\n") | ||
os.Exit(1) | ||
} | ||
} | ||
err = macgonuts.Spoof(os.Args[1], os.Args[2], os.Args[3], packetsTotal, timeoutInMss) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
err = macgonuts.UndoSpoof(os.Args[1], os.Args[2], os.Args[3]) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/rafael-santiago/macgonuts/src/binds/go/v1 | ||
|
||
go 1.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// Copyright (c) 2023, Rafael Santiago | ||
// All rights reserved. | ||
// | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// | ||
package macgonuts | ||
|
||
/* | ||
#cgo CFLAGS: -I../../.. | ||
#cgo LDFLAGS: -L../../../../lib -L../../../libs/accacia/lib -lmacgonuts -lmacgonutssock -laccacia | ||
#include <binds/macgonuts_binds.h> | ||
#include <binds/macgonuts_binds.c> | ||
*/ | ||
import "C" | ||
import "unsafe" | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Indicates the current version of the bind stuff. Always it is directly | ||
// linked to Macgonuts main release version. | ||
const kMacgonutsGoBindVersion string = "v1" | ||
|
||
// The Golang bind for macgonuts_spoof() function from libmacgonuts. | ||
// By using this function you can easily promote a spoofing attack based on IPv4 or IPv6. It receives: | ||
// - the local interface label (loIface) | ||
// - the target IPv4/IPv6 address (targetAddr) | ||
// - the IPv4/IPv6 address which will be spoofed at the target host (addr2Spoof) | ||
// - the amount of fake address resolution packets to be sent (fakePktsAmount, when zero it defaults to one) | ||
// - the timeout amount between the current packet and the next (timeout, its default is no timeout) | ||
// It returns nil on success and an error on failure, besides writing some error description to stderr. | ||
func Spoof(loIface, targetAddr, addr2Spoof string, fakePktsAmount, timeout int) error { | ||
if len(loIface) == 0 || len(targetAddr) == 0 || len(addr2Spoof) == 0 { | ||
return fmt.Errorf("invalid argument(s) passed to MacgonutsSpoof().") | ||
} | ||
lo_iface := C.CString(loIface) | ||
defer C.free(unsafe.Pointer(lo_iface)) | ||
target_addr := C.CString(targetAddr) | ||
defer C.free(unsafe.Pointer(target_addr)) | ||
addr2spoof := C.CString(addr2Spoof) | ||
defer C.free(unsafe.Pointer(addr2spoof)) | ||
var fake_pkts_amount C.int = 1 | ||
if fakePktsAmount > 0 { | ||
fake_pkts_amount = C.int(fakePktsAmount) | ||
} | ||
if C.macgonuts_binds_spoof(lo_iface, | ||
target_addr, | ||
addr2spoof, fake_pkts_amount, C.int(timeout)) != 0 { | ||
return fmt.Errorf("error when spoofing.") | ||
} | ||
return nil | ||
} | ||
|
||
// The Golang bind for macgonuts_undo_spoof() function from libmacgonuts. | ||
// By using this function you can easily undo a previous promoted spoofing attack based on IPv4 or IPV6. It receives: | ||
// - the local interface used during the spoofing attack (loIface) | ||
// - the target IPv4/IPv6 address of the spoofing attack (targetAddr) | ||
// - the IPv4/IPv6 address which was spoofed at the target host (addr2Spoof) | ||
// It returns zero on success and non-zero value on failure, besides writing some error description to stderr. | ||
func UndoSpoof(loIface, targetAddr, addr2Spoof string) error { | ||
if len(loIface) == 0 || len(targetAddr) == 0 || len(addr2Spoof) == 0 { | ||
return fmt.Errorf("invalid argument(s) passed to MacgonutsSpoof().") | ||
} | ||
lo_iface := C.CString(loIface) | ||
defer C.free(unsafe.Pointer(lo_iface)) | ||
target_addr := C.CString(targetAddr) | ||
defer C.free(unsafe.Pointer(target_addr)) | ||
addr2spoof := C.CString(addr2Spoof) | ||
defer C.free(unsafe.Pointer(addr2spoof)) | ||
if C.macgonuts_binds_undo_spoof(lo_iface, target_addr, addr2spoof) != 0 { | ||
return fmt.Errorf("error when undoing spoof.") | ||
} | ||
return nil | ||
} | ||
|
||
// Returns the version of the bind stuff. | ||
func Version() string { | ||
return kMacgonutsGoBindVersion | ||
} |
Oops, something went wrong.