This commit is contained in:
2026-05-31 19:48:56 +01:00
parent 7f32417736
commit 68f8904282
39 changed files with 4519 additions and 5 deletions
+26
View File
@@ -0,0 +1,26 @@
package antidbi
func Check() bool {
if checkMemoryMaps() {
return true
}
if checkUnixSockets() {
return true
}
if checkFridaPort() {
return true
}
if checkThreadNames() {
return true
}
if checkLoadedImages() {
return true
}
if checkMachPorts() {
return true
}
if checkEnvironment() {
return true
}
return false
}
+166
View File
@@ -0,0 +1,166 @@
//go:build darwin
package antidbi
import (
"net"
"os"
"strings"
"syscall"
"time"
"unsafe"
)
var dylibSignatures = []string{
"frida-agent",
"frida-gadget",
"frida-tracer",
}
var dylibSearchPaths = []string{
"/usr/local/lib/",
"/usr/lib/",
"/Library/Frameworks/",
}
var machPortSignatures = []string{
"re.frida.server",
"re.frida.agent",
"linjector",
}
var darwinEnvSignatures = []string{
"frida",
"frida-agent",
"frida-gadget",
}
func checkMemoryMaps() bool {
return false
}
func checkUnixSockets() bool {
return false
}
func checkFridaPort() bool {
conn, err := net.DialTimeout("tcp", "127.0.0.1:27042", 200*time.Millisecond)
if err != nil {
return false
}
conn.Close()
return true
}
func checkThreadNames() bool {
return false
}
func checkLoadedImages() bool {
dyld := os.Getenv("DYLD_INSERT_LIBRARIES")
if dyld != "" {
lower := strings.ToLower(dyld)
for _, sig := range dylibSignatures {
if strings.Contains(lower, sig) {
return true
}
}
}
for _, dir := range dylibSearchPaths {
entries, err := os.ReadDir(dir)
if err != nil {
continue
}
for _, entry := range entries {
name := strings.ToLower(entry.Name())
for _, sig := range dylibSignatures {
if strings.Contains(name, sig) {
return true
}
}
}
}
return false
}
func checkMachPorts() bool {
taskSelf := machTaskSelf()
if taskSelf == 0 {
return false
}
var bootstrapPort uint32
ret, _, _ := syscall.Syscall(
uintptr(0x1000000+45),
uintptr(taskSelf),
uintptr(unsafe.Pointer(&bootstrapPort)),
0,
)
if ret != 0 || bootstrapPort == 0 {
return false
}
for _, portName := range machPortSignatures {
cname := append([]byte(portName), 0)
var port uint32
ret, _, _ := syscall.Syscall(
uintptr(0x2000000+410),
uintptr(unsafe.Pointer(&cname[0])),
uintptr(unsafe.Pointer(&port)),
0,
)
if ret == 0 && port != 0 {
return true
}
}
return false
}
func checkEnvironment() bool {
envVars := []string{
"DYLD_INSERT_LIBRARIES",
"DYLD_FRAMEWORK_PATH",
"DYLD_LIBRARY_PATH",
"DYLD_FALLBACK_FRAMEWORK_PATH",
"DYLD_FALLBACK_LIBRARY_PATH",
}
for _, v := range envVars {
val := os.Getenv(v)
if val == "" {
continue
}
lower := strings.ToLower(val)
for _, sig := range darwinEnvSignatures {
if strings.Contains(lower, sig) {
return true
}
}
}
return false
}
func machTaskSelf() uint32 {
ret, _, _ := syscall.Syscall(
uintptr(0x1000000+28),
0,
0,
0,
)
return uint32(ret)
}
func AntiAttach() {
go func() {
for {
time.Sleep(500 * time.Millisecond)
if checkLoadedImages() || checkMachPorts() || checkEnvironment() || checkFridaPort() {
syscall.Exit(66)
}
}
}()
}
+168
View File
@@ -0,0 +1,168 @@
//go:build linux
package antidbi
import (
"net"
"os"
"strings"
"syscall"
"time"
"unsafe"
)
var dbiSignatures = []string{
"frida-agent",
"frida-gadget",
"dynamorio",
"libdynamorio",
"libpin",
}
var socketSignatures = []string{
"frida",
"linjector",
}
var threadSignatures = []string{
"gmain",
"frida",
}
var linuxEnvSignatures = []string{
"frida",
"dynamorio",
"pin",
}
func readFileSyscall(path string) ([]byte, error) {
pathBytes := append([]byte(path), 0)
fd, _, errno := syscall.RawSyscall(
uintptr(syscall.SYS_OPEN),
uintptr(unsafe.Pointer(&pathBytes[0])),
uintptr(syscall.O_RDONLY),
0,
)
if fd == ^uintptr(0) || fd >= 0x7fffffffffff {
return nil, errno
}
defer syscall.Close(int(fd))
buf := make([]byte, 64*1024)
n, _, errno := syscall.RawSyscall(
uintptr(syscall.SYS_READ),
fd,
uintptr(unsafe.Pointer(&buf[0])),
uintptr(len(buf)),
)
if n == ^uintptr(0) || n >= 0x7fffffffffff {
return nil, errno
}
return buf[:n], nil
}
func checkMemoryMaps() bool {
data, err := readFileSyscall("/proc/self/maps")
if err != nil {
return false
}
content := string(data)
for _, sig := range dbiSignatures {
if strings.Contains(content, sig) {
return true
}
}
return false
}
func checkUnixSockets() bool {
data, err := readFileSyscall("/proc/net/unix")
if err != nil {
return false
}
content := string(data)
for _, sig := range socketSignatures {
if strings.Contains(content, sig) {
return true
}
}
return false
}
func checkFridaPort() bool {
conn, err := net.DialTimeout("tcp", "127.0.0.1:27042", 200*time.Millisecond)
if err != nil {
return false
}
conn.Close()
return true
}
func checkThreadNames() bool {
data, err := readFileSyscall("/proc/self/task")
if err != nil {
return false
}
lines := strings.Split(string(data), "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if line == "" || line == "." || line == ".." {
continue
}
commPath := "/proc/self/task/" + line + "/comm"
comm, err := readFileSyscall(commPath)
if err != nil {
continue
}
name := strings.TrimSpace(string(comm))
for _, sig := range threadSignatures {
if strings.Contains(name, sig) {
return true
}
}
}
return false
}
func checkLoadedImages() bool {
return false
}
func checkMachPorts() bool {
return false
}
func checkEnvironment() bool {
suspiciousVars := []string{
"LD_PRELOAD",
"FRIDA_DNS_SERVER",
"_JAVA_OPTIONS",
}
for _, v := range suspiciousVars {
val := strings.ToLower(os.Getenv(v))
if val == "" {
continue
}
for _, sig := range linuxEnvSignatures {
if strings.Contains(val, sig) {
return true
}
}
}
return false
}
func AntiAttach() {
go func() {
for {
time.Sleep(500 * time.Millisecond)
if checkMemoryMaps() || checkUnixSockets() || checkFridaPort() || checkThreadNames() {
syscall.Exit(66)
}
}
}()
}