mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Clean up the Linux security code a bit
This commit is contained in:
parent
a88a909e10
commit
9a532a4660
@ -8,12 +8,30 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
|
func DnsServers() []string {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
return dnsLinux()
|
||||||
|
case "darwin":
|
||||||
|
return dnsMacOS()
|
||||||
|
default:
|
||||||
|
return []string{runtime.GOOS}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func dnsLinux() []string {
|
func dnsLinux() []string {
|
||||||
// This may be very Ubuntu specific
|
// This may be very Ubuntu specific
|
||||||
cmd := exec.Command("nmcli", "device", "show")
|
cmd := exec.Command("nmcli", "device", "show")
|
||||||
out := wtf.ExecuteCommand(cmd)
|
out := wtf.ExecuteCommand(cmd)
|
||||||
|
|
||||||
lines := strings.Split(out, "\n")
|
lines := strings.Split(out, "\n")
|
||||||
|
|
||||||
dns := []string{}
|
dns := []string{}
|
||||||
|
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
if strings.HasPrefix(l, "IP4.DNS") {
|
if strings.HasPrefix(l, "IP4.DNS") {
|
||||||
parts := strings.Split(l, ":")
|
parts := strings.Split(l, ":")
|
||||||
@ -26,22 +44,12 @@ func dnsLinux() []string {
|
|||||||
func dnsMacOS() []string {
|
func dnsMacOS() []string {
|
||||||
cmd := exec.Command("networksetup", "-getdnsservers", "Wi-Fi")
|
cmd := exec.Command("networksetup", "-getdnsservers", "Wi-Fi")
|
||||||
out := wtf.ExecuteCommand(cmd)
|
out := wtf.ExecuteCommand(cmd)
|
||||||
records := strings.Split(out, "\n")
|
|
||||||
|
|
||||||
if len(records) > 0 {
|
lines := strings.Split(out, "\n")
|
||||||
return records
|
|
||||||
|
if len(lines) > 0 {
|
||||||
|
return lines
|
||||||
} else {
|
} else {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DnsServers() []string {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "linux":
|
|
||||||
return dnsLinux()
|
|
||||||
case "darwin":
|
|
||||||
return dnsMacOS()
|
|
||||||
default:
|
|
||||||
return []string{runtime.GOOS}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -12,17 +12,6 @@ const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw"
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func firewallStateLinux() string {
|
|
||||||
return "[red]NA[white]"
|
|
||||||
}
|
|
||||||
|
|
||||||
func firewallStateMacOS() string {
|
|
||||||
cmd := exec.Command(osxFirewallCmd, "--getglobalstate")
|
|
||||||
str := wtf.ExecuteCommand(cmd)
|
|
||||||
|
|
||||||
return status(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
func FirewallState() string {
|
func FirewallState() string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
@ -34,17 +23,6 @@ func FirewallState() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func firewallStealthStateLinux() string {
|
|
||||||
return "[red]NA[white]"
|
|
||||||
}
|
|
||||||
|
|
||||||
func firewallStealthStateMacOS() string {
|
|
||||||
cmd := exec.Command(osxFirewallCmd, "--getstealthmode")
|
|
||||||
str := wtf.ExecuteCommand(cmd)
|
|
||||||
|
|
||||||
return status(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
func FirewallStealthState() string {
|
func FirewallStealthState() string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
@ -58,6 +36,28 @@ func FirewallStealthState() string {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func firewallStateLinux() string {
|
||||||
|
return "[red]NA[white]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func firewallStateMacOS() string {
|
||||||
|
cmd := exec.Command(osxFirewallCmd, "--getglobalstate")
|
||||||
|
str := wtf.ExecuteCommand(cmd)
|
||||||
|
|
||||||
|
return status(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func firewallStealthStateLinux() string {
|
||||||
|
return "[red]NA[white]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func firewallStealthStateMacOS() string {
|
||||||
|
cmd := exec.Command(osxFirewallCmd, "--getstealthmode")
|
||||||
|
str := wtf.ExecuteCommand(cmd)
|
||||||
|
|
||||||
|
return status(str)
|
||||||
|
}
|
||||||
|
|
||||||
func status(str string) string {
|
func status(str string) string {
|
||||||
icon := "[red]off[white]"
|
icon := "[red]off[white]"
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package security
|
package security
|
||||||
|
|
||||||
|
// http://applehelpwriter.com/2017/05/21/how-to-reveal-hidden-users/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -8,38 +10,7 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loggedInUsersLinux() []string {
|
/* -------------------- Exported Functions -------------------- */
|
||||||
cmd := exec.Command("who", "-us")
|
|
||||||
users := wtf.ExecuteCommand(cmd)
|
|
||||||
|
|
||||||
cleaned := []string{}
|
|
||||||
for _, u := range strings.Split(users, "\n") {
|
|
||||||
clean := true
|
|
||||||
col := strings.Split(u, " ")
|
|
||||||
if len(col) > 0 {
|
|
||||||
for _, cleanedU := range cleaned {
|
|
||||||
if strings.Compare(cleanedU, col[0]) == 0 {
|
|
||||||
clean = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if clean {
|
|
||||||
cleaned = append(cleaned, col[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return cleaned
|
|
||||||
}
|
|
||||||
|
|
||||||
func loggedInUsersMacOs() []string {
|
|
||||||
cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...)
|
|
||||||
users := wtf.ExecuteCommand(cmd)
|
|
||||||
|
|
||||||
return cleanUsers(strings.Split(users, "\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://applehelpwriter.com/2017/05/21/how-to-reveal-hidden-users/
|
|
||||||
|
|
||||||
func LoggedInUsers() []string {
|
func LoggedInUsers() []string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
@ -52,6 +23,8 @@ func LoggedInUsers() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func cleanUsers(users []string) []string {
|
func cleanUsers(users []string) []string {
|
||||||
rejects := []string{"_", "root", "nobody", "daemon", "Guest"}
|
rejects := []string{"_", "root", "nobody", "daemon", "Guest"}
|
||||||
cleaned := []string{}
|
cleaned := []string{}
|
||||||
@ -73,3 +46,37 @@ func cleanUsers(users []string) []string {
|
|||||||
|
|
||||||
return cleaned
|
return cleaned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loggedInUsersLinux() []string {
|
||||||
|
cmd := exec.Command("who", "-us")
|
||||||
|
users := wtf.ExecuteCommand(cmd)
|
||||||
|
|
||||||
|
cleaned := []string{}
|
||||||
|
|
||||||
|
for _, user := range strings.Split(users, "\n") {
|
||||||
|
clean := true
|
||||||
|
col := strings.Split(user, " ")
|
||||||
|
|
||||||
|
if len(col) > 0 {
|
||||||
|
for _, cleanedU := range cleaned {
|
||||||
|
if strings.Compare(cleanedU, col[0]) == 0 {
|
||||||
|
clean = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if clean {
|
||||||
|
cleaned = append(cleaned, col[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleaned
|
||||||
|
}
|
||||||
|
|
||||||
|
func loggedInUsersMacOs() []string {
|
||||||
|
cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...)
|
||||||
|
users := wtf.ExecuteCommand(cmd)
|
||||||
|
|
||||||
|
return cleanUsers(strings.Split(users, "\n"))
|
||||||
|
}
|
||||||
|
@ -46,9 +46,9 @@ func (widget *Widget) contentFrom(data *SecurityData) string {
|
|||||||
str = str + fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName)
|
str = str + fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName)
|
||||||
str = str + fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption)
|
str = str + fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption)
|
||||||
str = str + "\n"
|
str = str + "\n"
|
||||||
str = str + " [red]Firewall[white] [red]DNS[white]\n"
|
str = str + " [red]Firewall[white] [red]DNS[white]\n"
|
||||||
str = str + fmt.Sprintf(" %8s: %4s %12s\n", "Enabled", data.FirewallEnabled, data.DnsAt(0))
|
str = str + fmt.Sprintf(" %8s: %4s %-16s\n", "Enabled", data.FirewallEnabled, data.DnsAt(0))
|
||||||
str = str + fmt.Sprintf(" %8s: %4s %12s\n", "Stealth", data.FirewallStealth, data.DnsAt(1))
|
str = str + fmt.Sprintf(" %8s: %4s %-16s\n", "Stealth", data.FirewallStealth, data.DnsAt(1))
|
||||||
str = str + "\n"
|
str = str + "\n"
|
||||||
str = str + " [red]Users[white]\n"
|
str = str + " [red]Users[white]\n"
|
||||||
str = str + fmt.Sprintf(" %s", strings.Join(data.LoggedInUsers, ", "))
|
str = str + fmt.Sprintf(" %s", strings.Join(data.LoggedInUsers, ", "))
|
||||||
|
@ -13,47 +13,17 @@ const osxWifiArg = "-I"
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func wifiEncryptionLinux() string {
|
|
||||||
cmd := exec.Command("nmcli", "-t", "-f", "active,security", "dev", "wifi")
|
|
||||||
out := wtf.ExecuteCommand(cmd)
|
|
||||||
name := wtf.FindMatch(`yes:(.+)`, out)
|
|
||||||
if len(name) > 0 {
|
|
||||||
return name[0][1]
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func wifkEncryptionMacOS() string {
|
|
||||||
name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo())
|
|
||||||
return matchStr(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func WifiEncryption() string {
|
func WifiEncryption() string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
return wifiEncryptionLinux()
|
return wifiEncryptionLinux()
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return wifkEncryptionMacOS()
|
return wifiEncryptionMacOS()
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func wifiNameMacOS() string {
|
|
||||||
name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo())
|
|
||||||
return matchStr(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func wifiNameLinux() string {
|
|
||||||
cmd := exec.Command("nmcli", "-t", "-f", "active,ssid", "dev", "wifi")
|
|
||||||
out := wtf.ExecuteCommand(cmd)
|
|
||||||
name := wtf.FindMatch(`yes:(.+)`, out)
|
|
||||||
if len(name) > 0 {
|
|
||||||
return name[0][1]
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func WifiName() string {
|
func WifiName() string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
@ -67,11 +37,44 @@ func WifiName() string {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func wifiEncryptionLinux() string {
|
||||||
|
cmd := exec.Command("nmcli", "-t", "-f", "active,security", "dev", "wifi")
|
||||||
|
out := wtf.ExecuteCommand(cmd)
|
||||||
|
|
||||||
|
name := wtf.FindMatch(`yes:(.+)`, out)
|
||||||
|
|
||||||
|
if len(name) > 0 {
|
||||||
|
return name[0][1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func wifiEncryptionMacOS() string {
|
||||||
|
name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo())
|
||||||
|
return matchStr(name)
|
||||||
|
}
|
||||||
|
|
||||||
func wifiInfo() string {
|
func wifiInfo() string {
|
||||||
cmd := exec.Command(osxWifiCmd, osxWifiArg)
|
cmd := exec.Command(osxWifiCmd, osxWifiArg)
|
||||||
return wtf.ExecuteCommand(cmd)
|
return wtf.ExecuteCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wifiNameLinux() string {
|
||||||
|
cmd := exec.Command("nmcli", "-t", "-f", "active,ssid", "dev", "wifi")
|
||||||
|
out := wtf.ExecuteCommand(cmd)
|
||||||
|
name := wtf.FindMatch(`yes:(.+)`, out)
|
||||||
|
if len(name) > 0 {
|
||||||
|
return name[0][1]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func wifiNameMacOS() string {
|
||||||
|
name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo())
|
||||||
|
return matchStr(name)
|
||||||
|
}
|
||||||
|
|
||||||
func matchStr(data [][]string) string {
|
func matchStr(data [][]string) string {
|
||||||
if len(data) <= 1 {
|
if len(data) <= 1 {
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user