我正在学习golang,我想在golang中实现一个简单的Linux反调试方法。我有一个 CPP 代码,它的工作方式与我的预期相同。但不能在 golang 中做同样的事情。你们能指导我如何在go中做同样的事情吗?
这是我用作引用的 C++ 代码。
#include <stdio.h>
#include <sys/ptrace.h>
bool isBeingTraced(){
return ptrace(PTRACE_TRACEME, 0, 1, 0) == -1;
}
int main()
{
if (isBeingTraced())
{
printf("don't trace me !!\n");
return 1;
}
printf("Not being traced... (maybe)\n");
return 0;
}
我想在 go lang 中做同样的事情。
甚至可以在 go 中做同样的事情吗?
package main
import "fmt"
func main() {
if isBeingTraced() {
fmt.Println("don't trace me !!")
return
}
fmt.Println("Not being traced... (maybe)")
}
func isBeingTraced() bool {
return true // How to Implement that Cpp Function here?
}
最佳答案
根据@MarkPlotnick 的评论,这里是我发布的 c++ 代码的 golang 等效代码。
package main
import (
"fmt"
"syscall"
)
func main() {
if isBeingTraced() {
fmt.Println("don't trace me !!")
return
}
fmt.Println("Not being traced... (maybe)")
}
func isBeingTraced() bool {
_, _, res := syscall.RawSyscall(syscall.SYS_PTRACE, uintptr(syscall.PTRACE_TRACEME), 0, 0)
return res == 1
}
引用:https://github.com/golang/go/blob/master/src/syscall/exec_linux.go#L511但是我遇到的问题是,在调用 PTRACE_TRACEME 之后不能调用 exec.Command()。
将尝试找到解决此问题的方法。如果有的话,我会在这里引用。
关于go - 如何检测 ptrace 是否已经在 golang linux 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58572777/