Skip to content

Commit defbcc1

Browse files
fixed issue with prefix flag, removed checking for default interface and gateway
1 parent 9f672cf commit defbcc1

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Usage of nf:
3535
Enable NA (neighbor advertisement) spoofing
3636
-nocolor
3737
Disable colored output
38+
-p string
39+
IPv6 prefix for RA spoofing
3840
-ra
3941
Enable RA (router advertisement) spoofing. It is enabled when no spoof mode specified)
4042
-rdnss
@@ -49,3 +51,25 @@ Usage of nf:
4951
### Usage as a library
5052

5153
See [https://github.com/shadowy-pycoder/go-http-proxy-to-socks](https://github.com/shadowy-pycoder/go-http-proxy-to-socks)
54+
55+
### Example lab to test this tool
56+
57+
![Test RA lab](resources/RA_test.png)
58+
59+
1. Kali machine with Host-only network vboxnet0
60+
2. Mint machine with Host-only network vboxnet1
61+
3. Cisco IOS on Linux (IOL) Layer 2 Advanced Enterprise K9, Version 17.16.01a (x86_64)
62+
63+
On Kali machine run:
64+
65+
```shell
66+
nf -d -auto -ra -i eth0 -p 2001:db8:7a31:4400::/64
67+
```
68+
69+
On Mint machine run:
70+
71+
```shell
72+
ip -6 route
73+
```
74+
75+
You should see Kali machine link local IP as a default gateway

cmd/nf/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ func root(args []string) error {
7070
})
7171
flags.DurationVar(&conf.RouterLifetime, "rlt", time.Duration(600*time.Second), "Router lifetime for RA spoofing")
7272
flags.DurationVar(&conf.PacketInterval, "interval", time.Duration(5*time.Second), "Interval between sent packets")
73-
if err := flags.Parse(args); err != nil {
74-
return err
75-
}
7673
prefix := flags.String("p", "", "IPv6 prefix for RA spoofing")
7774
if err := flags.Parse(args); err != nil {
7875
return err

ndpspoof.go

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -322,25 +322,23 @@ func (nr *NDPSpoofer) NeighCache() *NeighCache {
322322

323323
func NewNDPSpoofer(conf *NDPSpoofConfig) (*NDPSpoofer, error) {
324324
ndpspoofer := &NDPSpoofer{}
325-
var iface *net.Interface
326325
var err error
327326
if !conf.RA && !conf.NA {
328327
return nil, fmt.Errorf("no attack vectors enabled")
329328
}
330-
iface, err = network.GetDefaultInterface()
331-
if err != nil {
332-
iface, err = network.GetDefaultInterfaceFromRouteIPv6()
333-
if err != nil {
334-
return nil, err
335-
}
336-
}
337329
if conf.Interface != "" {
338330
ndpspoofer.iface, err = net.InterfaceByName(conf.Interface)
339331
if err != nil {
340332
return nil, err
341333
}
342334
} else {
343-
ndpspoofer.iface = iface
335+
ndpspoofer.iface, err = network.GetDefaultInterface()
336+
if err != nil {
337+
ndpspoofer.iface, err = network.GetDefaultInterfaceFromRouteIPv6()
338+
if err != nil {
339+
return nil, err
340+
}
341+
}
344342
}
345343
prefixLocal, err := network.GetIPv6LinkLocalUnicastPrefixFromInterface(ndpspoofer.iface)
346344
if err != nil {
@@ -353,26 +351,6 @@ func NewNDPSpoofer(conf *NDPSpoofConfig) (*NDPSpoofer, error) {
353351
if err == nil {
354352
ndpspoofer.hostIPGlobal = &hostIPGlobal
355353
}
356-
if conf.Gateway != nil && network.Is6(*conf.Gateway) {
357-
ndpspoofer.gwIP = conf.Gateway
358-
} else {
359-
var gwIP netip.Addr
360-
if ndpspoofer.iface.Name != iface.Name {
361-
gwIP, err = network.GetGatewayIPv6FromInterface(ndpspoofer.iface.Name)
362-
if err != nil {
363-
return nil, fmt.Errorf("failed fetching gateway ip: %w", err)
364-
}
365-
} else {
366-
gwIP, err = network.GetDefaultGatewayIPv6()
367-
if err != nil {
368-
gwIP, err = network.GetDefaultGatewayIPv6FromRoute()
369-
if err != nil {
370-
return nil, fmt.Errorf("failed fetching gateway ip: %w", err)
371-
}
372-
}
373-
}
374-
ndpspoofer.gwIP = &gwIP
375-
}
376354
if conf.RA {
377355
ndpspoofer.raEnabled = true
378356
if conf.Prefix != nil {
@@ -418,6 +396,16 @@ func NewNDPSpoofer(conf *NDPSpoofConfig) (*NDPSpoofer, error) {
418396
}
419397
}
420398
if conf.NA {
399+
if conf.Gateway != nil && network.Is6(*conf.Gateway) {
400+
ndpspoofer.gwIP = conf.Gateway
401+
} else {
402+
var gwIP netip.Addr
403+
gwIP, err = network.GetGatewayIPv6FromInterface(ndpspoofer.iface.Name)
404+
if err != nil {
405+
return nil, fmt.Errorf("failed fetching gateway ip: %w", err)
406+
}
407+
ndpspoofer.gwIP = &gwIP
408+
}
421409
ndpspoofer.naEnabled = true
422410
ndpspoofer.neighCache = &NeighCache{Ifname: ndpspoofer.iface.Name, Entries: make(map[string]net.HardwareAddr)}
423411
err = ndpspoofer.neighCache.Refresh()

resources/RA_test.png

20.4 KB
Loading

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package ndpspoof
22

3-
const Version string = "nf v0.0.4"
3+
const Version string = "nf v0.0.5"

0 commit comments

Comments
 (0)