File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,15 @@ import (
1111 "os"
1212 "strconv"
1313 "strings"
14+ "bytes"
1415
1516 //"syscall"
1617 "syscall"
1718 "time"
1819
1920 portscanner "github.com/anvie/port-scanner"
2021 "github.com/jackpal/gateway"
22+ "golang.org/x/crypto/ssh"
2123)
2224
2325// GetGlobalIp is used to return the global Ip address of the machine.
@@ -305,4 +307,20 @@ func Url2Lines(url string) []string {
305307 lns = append (lns , scn .Text ())
306308 }
307309 return lns
310+ }
311+
312+ // Checks if an SSH client connection has a root context
313+ func CheckRootSSH (client ssh.Client ) bool {
314+ uid0_session := false
315+ session , err := client .NewSession ()
316+ defer session .Close ()
317+ Check (err )
318+ var user_id bytes.Buffer
319+ session .Stdout = & user_id
320+ if (session .Run ("id" ) != nil ){
321+ if (ContainsAny (user_id .String (), []string {"uid=0" , "gid=0" , "root" })){
322+ uid0_session = true
323+ }
324+ }
325+ return uid0_session
308326}
You can’t perform that action at this time.
0 commit comments