Skip to content

Commit aa996a9

Browse files
authored
Stop checks if already root (#37)
1 parent d3db221 commit aa996a9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Diff for: internal/cmd/root.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package cmd
33
import (
44
"context"
55
"fmt"
6-
"github.com/liamg/traitor/internal/version"
76
"os"
7+
"os/user"
8+
9+
"github.com/liamg/traitor/internal/version"
810

911
"github.com/liamg/traitor/pkg/logger"
1012
"github.com/liamg/traitor/pkg/state"
@@ -30,8 +32,8 @@ var rootCmd = &cobra.Command{
3032
Long: `An extensible privilege escalation framework for Linux
3133
Complete documentation is available at https://github.com/liamg/traitor`,
3234
Args: cobra.ExactArgs(0),
33-
PreRun: func(_ *cobra.Command, args[] string){
34-
fmt.Printf("\x1b[34m" + `
35+
PreRun: func(_ *cobra.Command, args []string) {
36+
fmt.Printf("\x1b[34m"+`
3537
3638
888 d8b 888
3739
888 Y8P 888
@@ -41,7 +43,7 @@ var rootCmd = &cobra.Command{
4143
888 888 .d888888 888 888 888 888 888
4244
Y88b. 888 888 888 888 Y88b. Y88..88P 888
4345
"Y888 888 "Y888888 888 "Y888 "Y88P" 888
44-
`+"\x1b[31m"+ ` %s | https://github.com/liamg/traitor
46+
`+"\x1b[31m"+` %s | https://github.com/liamg/traitor
4547
4648
`, version.Version)
4749
},
@@ -50,6 +52,11 @@ var rootCmd = &cobra.Command{
5052
ctx := context.Background()
5153
baseLog := logger.New()
5254

55+
if user, err := user.Current(); err == nil && user.Uid == "0" {
56+
baseLog.Printf("You are already root.")
57+
return
58+
}
59+
5360
baseLog.Printf("Assessing machine state...")
5461
localState := state.New()
5562
localState.HasPassword = promptForPassword
@@ -95,7 +102,7 @@ var rootCmd = &cobra.Command{
95102
}
96103
if exploitName != "" && !found {
97104
baseLog.Printf("No exploit found for '%s'", exploitName)
98-
}else if !vulnFound {
105+
} else if !vulnFound {
99106
baseLog.Printf("Nothing found to exploit.")
100107
}
101108
},

0 commit comments

Comments
 (0)