mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
Cleaning fw_windows
This commit is contained in:
parent
d54cac6355
commit
ce3302c359
1 changed files with 35 additions and 24 deletions
|
@ -21,43 +21,54 @@ func Make(iface *net.Endpoint) FirewallManager {
|
|||
redirections: make(map[string]*Redirection, 0),
|
||||
}
|
||||
|
||||
firewall.forwarding = firewall.IsForwardingEnabled()
|
||||
// firewall.forwarding = firewall.IsForwardingEnabled()
|
||||
|
||||
return firewall
|
||||
}
|
||||
|
||||
// TODO: This should be obsolete now .. Clean
|
||||
func (f WindowsFirewall) IsForwardingEnabled() bool {
|
||||
if out, err := core.Exec("netsh", []string{"interface", "ipv4", "dump"}); err != nil {
|
||||
fmt.Printf("%s\n", err)
|
||||
return false
|
||||
} else {
|
||||
return strings.Contains(out, "forwarding=enabled")
|
||||
}
|
||||
|
||||
fmt.Errorf("Forwarding is dead in Windows .. cleanup")
|
||||
return false
|
||||
|
||||
//if out, err := core.Exec("netsh", []string{"interface", "ipv4", "dump"}); err != nil {
|
||||
// fmt.Printf("%s\n", err)
|
||||
// return false
|
||||
//} else {
|
||||
// return strings.Contains(out, "forwarding=enabled")
|
||||
//}
|
||||
}
|
||||
|
||||
func (f WindowsFirewall) isSuccess(output string) bool {
|
||||
if trimmed := core.Trim(output); trimmed == "" || strings.Contains(trimmed, "OK") == true {
|
||||
if trimmed := core.Trim(output); trimmed == "" || strings.Contains(strings.ToUpper(trimmed), "OK") == true {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This should be obsolete now .. Clean
|
||||
func (f WindowsFirewall) EnableForwarding(enabled bool) error {
|
||||
v := "enabled"
|
||||
if enabled == false {
|
||||
v = "disabled"
|
||||
}
|
||||
out, err := core.Exec("netsh", []string{"interface", "ipv4", "set", "interface", fmt.Sprintf("%d", f.iface.Index), fmt.Sprintf("forwarding=\"%s\"", v)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if f.isSuccess(out) == false {
|
||||
return fmt.Errorf("Unexpected netsh output: %s", out)
|
||||
}
|
||||
|
||||
fmt.Errorf("Forwarding is dead in Windows .. cleanup")
|
||||
return nil
|
||||
|
||||
//
|
||||
//v := "enabled"
|
||||
//if enabled == false {
|
||||
// v = "disabled"
|
||||
//}
|
||||
//out, err := core.Exec("netsh", []string{"interface", "ipv4", "set", "interface", fmt.Sprintf("%d", f.iface.Index), fmt.Sprintf("forwarding=\"%s\"", v)})
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
//
|
||||
//if f.isSuccess(out) == false {
|
||||
// return fmt.Errorf("Unexpected netsh output: %s", out)
|
||||
//}
|
||||
//
|
||||
//return nil
|
||||
}
|
||||
|
||||
func (f WindowsFirewall) generateRule(r *Redirection, enabled bool) []string {
|
||||
|
@ -96,7 +107,7 @@ func (f *WindowsFirewall) AllowPort(port int, address string, proto string, allo
|
|||
}
|
||||
|
||||
if f.isSuccess(out) == false {
|
||||
return fmt.Errorf("Unexpected netsh output: %s", out)
|
||||
return fmt.Errorf("Unexpected netsh output in AllowPort: %s", out)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -134,7 +145,7 @@ func (f WindowsFirewall) Restore() {
|
|||
}
|
||||
}
|
||||
|
||||
if err := f.EnableForwarding(f.forwarding); err != nil {
|
||||
fmt.Printf("%s", err)
|
||||
}
|
||||
//if err := f.EnableForwarding(f.forwarding); err != nil {
|
||||
// fmt.Printf("%s", err)
|
||||
//}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue