mirror of
https://github.com/almounah/superdeye
synced 2026-06-06 15:14:30 +00:00
Better error handling
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
module remoteInject
|
||||
|
||||
go 1.23.1
|
||||
@@ -1,6 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
"github.com/almounah/superdeye"
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
# Simple Shellcode Injector
|
||||
|
||||
This will chain Syscalls to:
|
||||
|
||||
- Allocate Memory in the current process
|
||||
- Write Shellcode in it (without encryption)
|
||||
- Run a new thread with the shellcode address
|
||||
|
||||
It uses SuperdEye.
|
||||
@@ -0,0 +1,10 @@
|
||||
module selfInject
|
||||
|
||||
go 1.23.1
|
||||
|
||||
replace github.com/almounah/superdeye => ../../
|
||||
|
||||
require (
|
||||
github.com/almounah/superdeye v0.0.0-00010101000000-000000000000
|
||||
golang.org/x/sys v0.27.0
|
||||
)
|
||||
@@ -0,0 +1,2 @@
|
||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/almounah/superdeye"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var enter string;
|
||||
|
||||
size := 100
|
||||
hSelf := uintptr(0xffffffffffffffff)
|
||||
var baseAddr uintptr;
|
||||
|
||||
_, err := superdeye.SuperdSyscall("NtAllocateVirtualMemory",
|
||||
hSelf,
|
||||
uintptr(unsafe.Pointer(&baseAddr)),
|
||||
uintptr(unsafe.Pointer(nil)),
|
||||
uintptr(unsafe.Pointer(&size)),
|
||||
windows.MEM_COMMIT|windows.MEM_RESERVE,
|
||||
windows.PAGE_EXECUTE_READWRITE,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
fmt.Scanln(&enter)
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"github.com/almounah/superdeye/internal/utils/superdwindows"
|
||||
)
|
||||
|
||||
var RANGE int = 200
|
||||
|
||||
/*
|
||||
* ssn in the ssn number
|
||||
* cleanSyscall is the Syscall address found in NTDLL
|
||||
@@ -20,7 +22,11 @@ type SuperdSyscallTool struct {
|
||||
|
||||
func LookupSSNAndTrampoline(syscallName string, hModule superdwindows.HANDLE) (superdSyscallTool SuperdSyscallTool, err error) {
|
||||
pBase := unsafe.Pointer(hModule)
|
||||
pImgExportDir := helper.GetImageExportDirectory(hModule)
|
||||
pImgExportDir, err := helper.GetImageExportDirectory(hModule)
|
||||
if err != nil {
|
||||
fmt.Println("Messed Up Getting Image Export Directory")
|
||||
return SuperdSyscallTool{}, err
|
||||
}
|
||||
numFunction := pImgExportDir.NumberOfFunctions
|
||||
|
||||
AddressOfFuntionArray := unsafe.Slice((*superdwindows.DWORD)(unsafe.Pointer(uintptr(pBase)+uintptr(pImgExportDir.AddressOfFunctions))), pImgExportDir.NumberOfFunctions)
|
||||
@@ -44,7 +50,7 @@ func LookupSSNAndTrampoline(syscallName string, hModule superdwindows.HANDLE) (s
|
||||
}
|
||||
|
||||
// Search the neighbors if SSN is hooked
|
||||
for neighborIndex := 1; neighborIndex < 200; neighborIndex++ {
|
||||
for neighborIndex := 1; neighborIndex < RANGE; neighborIndex++ {
|
||||
upNeighborFunctionAddress := uintptr(unsafe.Add(unsafe.Pointer(functionAddress), neighborIndex*32))
|
||||
if checkIfCleanSSN(upNeighborFunctionAddress) {
|
||||
low := *(*superdwindows.BYTE)(unsafe.Add(unsafe.Pointer(upNeighborFunctionAddress), 4))
|
||||
@@ -68,7 +74,7 @@ func LookupSSNAndTrampoline(syscallName string, hModule superdwindows.HANDLE) (s
|
||||
|
||||
}
|
||||
}
|
||||
return SuperdSyscallTool{0, 0}, nil
|
||||
return SuperdSyscallTool{}, errors.New("Did not find SSN. Double Check Syscall Name then report as a Github issue as this is very interesting.")
|
||||
}
|
||||
|
||||
func checkIfCleanSSN(functionAddress uintptr) bool {
|
||||
@@ -87,7 +93,7 @@ func checkIfCleanSSN(functionAddress uintptr) bool {
|
||||
}
|
||||
|
||||
func findSyscallAddress(functionAddress uintptr) (pAddress superdwindows.PVOID, err error) {
|
||||
for z := 1; z < 200; z++ {
|
||||
for z := 1; z < RANGE; z++ {
|
||||
pAddress := unsafe.Add(unsafe.Pointer(functionAddress), z)
|
||||
pAddressNext := unsafe.Add(unsafe.Pointer(functionAddress), z+1)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
"github.com/almounah/superdeye/internal/utils/superdwindows"
|
||||
@@ -9,34 +9,34 @@ import (
|
||||
|
||||
func GetPEB() uintptr
|
||||
|
||||
func GetImageExportDirectory(hModule superdwindows.HANDLE) superdwindows.PIMAGE_EXPORT_DIRECTORY {
|
||||
func GetImageExportDirectory(hModule superdwindows.HANDLE) (pImgExpDir superdwindows.PIMAGE_EXPORT_DIRECTORY, err error) {
|
||||
pBase := unsafe.Pointer(hModule)
|
||||
pImgDosHeader := superdwindows.PIMAGE_DOS_HEADER(pBase)
|
||||
if pImgDosHeader.E_magic != superdwindows.IMAGE_DOS_SIGNATURE {
|
||||
fmt.Println("Messed Up Getting the DosHeader")
|
||||
return nil, errors.New("Messed Up Getting the DosHeader")
|
||||
}
|
||||
|
||||
pImgNtHdrs := superdwindows.PIMAGE_NT_HEADERS32(unsafe.Pointer(uintptr(pBase) + uintptr(pImgDosHeader.E_lfanew)))
|
||||
if pImgNtHdrs.Signature != superdwindows.IMAGE_NT_SIGNATURE {
|
||||
fmt.Println("Messed Up getting NTHeader")
|
||||
return nil, errors.New("Messed Up Getting NtHeader")
|
||||
}
|
||||
|
||||
if pImgNtHdrs.FileHeader.Machine == superdwindows.IMAGE_FILE_MACHINE_AMD64 {
|
||||
pImgNtHdrs64 := superdwindows.PIMAGE_NT_HEADERS64(unsafe.Pointer(pImgNtHdrs))
|
||||
ImgOptHdr := pImgNtHdrs64.OptionalHeader
|
||||
if ImgOptHdr.Magic != superdwindows.IMAGE_NT_OPTIONAL_HDR64_MAGIC {
|
||||
fmt.Println("Messed Up getting Image Optional Header for x64 arch")
|
||||
return nil, errors.New("Messed Up getting Image Optional Header for x64 arch")
|
||||
}
|
||||
pImgExportDir := superdwindows.PIMAGE_EXPORT_DIRECTORY(unsafe.Pointer(uintptr(pBase) + uintptr(ImgOptHdr.DataDirectory.VirtualAddress)))
|
||||
|
||||
return pImgExportDir
|
||||
return pImgExportDir, nil
|
||||
}
|
||||
ImgOptHdr := pImgNtHdrs.OptionalHeader
|
||||
if ImgOptHdr.Magic != superdwindows.IMAGE_NT_OPTIONAL_HDR32_MAGIC {
|
||||
fmt.Println("Messed Up getting Image Optional Header for x64 arch")
|
||||
return nil, errors.New("Messed Up getting Image Optional Header for x32 arch")
|
||||
}
|
||||
pImgExportDir := superdwindows.PIMAGE_EXPORT_DIRECTORY(unsafe.Pointer(uintptr(pBase) + uintptr(ImgOptHdr.DataDirectory.VirtualAddress)))
|
||||
return pImgExportDir
|
||||
return pImgExportDir,nil
|
||||
}
|
||||
|
||||
func NameRvaToString(pBase uintptr, rva superdwindows.DWORD) string {
|
||||
|
||||
+4
-1
@@ -8,7 +8,10 @@ import (
|
||||
|
||||
func SuperdSyscall(syscallName string, argh ...uintptr) (NTSTATUS uint32, err error) {
|
||||
ntdllAddress := helper.GetNTDLLAddress()
|
||||
syscallTool, _ := manalocator.LookupSSNAndTrampoline(syscallName, ntdllAddress)
|
||||
syscallTool, err := manalocator.LookupSSNAndTrampoline(syscallName, ntdllAddress)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
NTSTATUS = superdsyscall.ExecIndirectSyscall(uint16(syscallTool.Ssn), uintptr(syscallTool.SyscallInstructionAddress), argh...)
|
||||
return NTSTATUS, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user