MCPcopy
hub / github.com/bettercap/bettercap / TestArpSpooferBanMode

Function TestArpSpooferBanMode

modules/arp_spoof/arp_spoof_test.go:488–539  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

486}
487
488func TestArpSpooferBanMode(t *testing.T) {
489 mockSess, _, mockFirewall := createMockSession()
490 mod := NewArpSpoofer(mockSess.Session)
491
492 // Setup targets
493 targetIP := "192.168.1.10"
494 targetMAC, _ := net.ParseMAC("aa:aa:aa:aa:aa:aa")
495 mockSess.Lan.AddIfNew(targetIP, targetMAC.String())
496 mockSess.findMACResults[targetIP] = targetMAC
497
498 // Configure
499 mockSess.Env.Set("arp.spoof.targets", targetIP)
500
501 // Find and execute the ban handler
502 handlers := mod.Handlers()
503 for _, h := range handlers {
504 if h.Name == "arp.ban on" {
505 err := h.Exec([]string{})
506 if err != nil {
507 t.Fatalf("Failed to start ban mode: %v", err)
508 }
509 break
510 }
511 }
512
513 if !mod.ban {
514 t.Error("Ban mode should be enabled")
515 }
516
517 // Check that forwarding was NOT enabled
518 if mockFirewall.IsForwardingEnabled() {
519 t.Error("Forwarding should NOT be enabled in ban mode")
520 }
521
522 // Let it run for a bit
523 time.Sleep(100 * time.Millisecond)
524
525 // Stop using ban off handler
526 for _, h := range handlers {
527 if h.Name == "arp.ban off" {
528 err := h.Exec([]string{})
529 if err != nil {
530 t.Fatalf("Failed to stop ban mode: %v", err)
531 }
532 break
533 }
534 }
535
536 if mod.ban {
537 t.Error("Ban mode should be disabled after stop")
538 }
539}
540
541func TestArpSpooferWhitelisting(t *testing.T) {
542 mockSess, _, _ := createMockSession()

Callers

nothing calls this directly

Calls 9

NewArpSpooferFunction · 0.85
createMockSessionFunction · 0.70
HandlersMethod · 0.65
IsForwardingEnabledMethod · 0.65
AddIfNewMethod · 0.45
StringMethod · 0.45
SetMethod · 0.45
ExecMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected