arp-spoofer: Use netip package
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
edb39c7b33
commit
4cf006c4f8
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -15,7 +16,7 @@ import (
|
||||
var ARPTable string = "/proc/net/arp"
|
||||
|
||||
type ARPEntry struct {
|
||||
IP net.IP
|
||||
IP netip.Addr
|
||||
HWType int
|
||||
Flags int
|
||||
HWAddress net.HardwareAddr
|
||||
@ -41,7 +42,9 @@ func ARPAnalyze() (ents []ARPEntry, err error) {
|
||||
continue
|
||||
}
|
||||
|
||||
e.IP = net.ParseIP(f[0])
|
||||
if e.IP, err = netip.ParseAddr(f[0]); err != nil {
|
||||
continue
|
||||
}
|
||||
if e.HWAddress, err = net.ParseMAC(f[3]); err != nil {
|
||||
continue
|
||||
}
|
||||
@ -55,9 +58,9 @@ func ARPAnalyze() (ents []ARPEntry, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func ARPContainsIP(ents []ARPEntry, ip net.IP) *ARPEntry {
|
||||
func ARPContainsIP(ents []ARPEntry, ip netip.Addr) *ARPEntry {
|
||||
for i, e := range ents {
|
||||
if e.IP.Equal(ip) && (e.Flags == 2 || e.Flags == 6) {
|
||||
if e.IP.Compare(ip) == 0 {
|
||||
return &ents[i]
|
||||
}
|
||||
}
|
||||
@ -65,7 +68,7 @@ func ARPContainsIP(ents []ARPEntry, ip net.IP) *ARPEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ARPSpoof(iface *net.Interface, ipS net.IP) {
|
||||
func ARPSpoof(iface *net.Interface, ipS netip.Addr) {
|
||||
clt, err := arp.Dial(iface)
|
||||
if err != nil {
|
||||
log.Println("Unable to initiate ARP spoofing:", err)
|
||||
@ -83,7 +86,7 @@ func ARPSpoof(iface *net.Interface, ipS net.IP) {
|
||||
randHW := net.HardwareAddr{0, byte(rand.Intn(255)), byte(rand.Intn(255)), byte(rand.Intn(255)), byte(rand.Intn(255)), byte(rand.Intn(255))}
|
||||
|
||||
for _, e := range ents {
|
||||
if e.IP[0] == ipS[0] && e.IP[1] == ipS[1] {
|
||||
if e.IP.As4()[0] == ipS.As4()[0] && e.IP.As4()[1] == ipS.As4()[1] {
|
||||
req := &arp.Packet{
|
||||
SenderHardwareAddr: e.HWAddress,
|
||||
SenderIP: e.IP,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"log"
|
||||
"net"
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -16,9 +17,9 @@ func main() {
|
||||
log.Fatal("Unable to find interface to do ARP spoof:", err)
|
||||
}
|
||||
|
||||
ipS := net.ParseIP(*ipspoof)
|
||||
if ipS == nil {
|
||||
log.Fatal("No IP given to ARP spoof. Skipping it")
|
||||
ipS, err := netip.ParseAddr(*ipspoof)
|
||||
if err != nil {
|
||||
log.Fatalf("No IP given to ARP spoof (%s). Skipping it", err.Error())
|
||||
}
|
||||
|
||||
// Start ARP spoofing
|
||||
|
Reference in New Issue
Block a user