-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add zw exports parsing logic to resolver
- Loading branch information
Showing
13 changed files
with
175 additions
and
186 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
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 |
---|---|---|
@@ -1,14 +1,8 @@ | ||
package resolver | ||
|
||
import ( | ||
wt "github.com/f1zm0/acheron/internal/types" | ||
) | ||
|
||
const SYSCALL_STUB_SIZE = 0x20 | ||
|
||
// FindSyscallRetGadgets finds syscall;ret gadgets in ntdll.dll | ||
// that can be "recycled" to ensure syscalls goes through ntdll. | ||
func FindSyscallRetGadgets(hNtdll *wt.PEModule) []uintptr { | ||
func FindSyscallRetGadgets(stubs map[int64]*ZwStub) []uintptr { | ||
// TODO: do implementation | ||
return []uintptr{} | ||
} |
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
package resolver | ||
|
||
import ( | ||
"github.com/f1zm0/acheron/pkg/hashing" | ||
"github.com/f1zm0/acheron/pkg/memory" | ||
) | ||
|
||
type NtModule struct { | ||
BaseAddr uintptr | ||
ExportsBaseAddr uintptr | ||
NumberOfNames uint32 | ||
AddressOfFunctions uintptr | ||
AddressOfNames uintptr | ||
AddressOfNameOrdinals uintptr | ||
ZwStubs map[int64]*ZwStub | ||
} | ||
|
||
type ZwStub struct { | ||
RVA uint32 | ||
VA uintptr | ||
SSN uint16 | ||
} | ||
|
||
// ParseNtdllModule returns a NtModule struct with the relevant information | ||
// about the in-memory ntdll.dll module. | ||
func ParseNtdllModule(hashFn hashing.Hasher) *NtModule { | ||
var m NtModule | ||
|
||
m.BaseAddr = getNtdllBaseAddr() | ||
m.ExportsBaseAddr = getModuleExportsDirAddr(m.BaseAddr) | ||
m.NumberOfNames = getExportsNumberOfNames(m.ExportsBaseAddr) | ||
m.AddressOfFunctions = getExportsAddressOfFunctions(m.BaseAddr, m.ExportsBaseAddr) | ||
m.AddressOfNames = getExportsAddressOfNames(m.BaseAddr, m.ExportsBaseAddr) | ||
m.AddressOfNameOrdinals = getExportsAddressOfNameOrdinals(m.BaseAddr, m.ExportsBaseAddr) | ||
|
||
m.ZwStubs = make( | ||
map[int64]*ZwStub, | ||
m.NumberOfNames/4, // Zw* functions are less than ~25% of the total so we can save some memory | ||
) | ||
|
||
for i := uint32(0); i < m.NumberOfNames; i++ { | ||
fn := memory.ReadCStringAt(m.BaseAddr, memory.ReadDwordAt(m.AddressOfNames, i*4)) | ||
if fn[0] != 'Z' || fn[1] != 'w' { | ||
continue | ||
} | ||
fnHash := hashFn.HashByteString(fn) | ||
|
||
nameOrd := memory.ReadWordAt(m.AddressOfNameOrdinals, i*2) | ||
rva := memory.ReadDwordAt(m.AddressOfFunctions, uint32(nameOrd*4)) | ||
|
||
m.ZwStubs[fnHash] = &ZwStub{ | ||
RVA: rva, | ||
VA: memory.RVA2VA(m.BaseAddr, uint32(rva)), | ||
} | ||
} | ||
|
||
return &m | ||
} |
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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
package resolver | ||
|
||
// getNtdllBase signature. | ||
func getNtdllBaseAddr() uintptr | ||
|
||
// getModuleEATAddr signature. | ||
func getModuleEATAddr(modBaseAddr uintptr) uintptr | ||
func getModuleExportsDirAddr(modBaseAddr uintptr) uintptr | ||
|
||
// getEATNumberOfFunctions signature. | ||
func getEATNumberOfFunctions(exportsBase uintptr) uint32 | ||
func getExportsNumberOfNames(exportsBase uintptr) uint32 | ||
|
||
// getEATAddressOfFunctions signature. | ||
func getEATAddressOfFunctions(moduleBase, exportsBase uintptr) uintptr | ||
func getExportsAddressOfFunctions(moduleBase, exportsBase uintptr) uintptr | ||
|
||
// getEATAddressOfNames signature. | ||
func getEATAddressOfNames(moduleBase, exportsBase uintptr) uintptr | ||
func getExportsAddressOfNames(moduleBase, exportsBase uintptr) uintptr | ||
|
||
func getExportsAddressOfNameOrdinals(moduleBase, exportsBase uintptr) uintptr |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
#include "textflag.h" | ||
|
||
// func RVA2VA(moduleBase uintptr, rva uint32) uintptr | ||
TEXT ·RVA2VA(SB),NOSPLIT,$0-16 | ||
MOVQ moduleBase+0(FP), AX | ||
XORQ DI, DI | ||
|
||
MOVL rva+8(FP), DI | ||
ADDQ DI, AX | ||
|
||
MOVQ AX, ret+16(FP) | ||
RET | ||
|
||
|
||
// func ReadDwordAt(start uintptr, offset uint32) uint32 | ||
TEXT ·ReadDwordAt(SB),NOSPLIT,$0-16 | ||
MOVQ start+0(FP), AX | ||
MOVL offset+8(FP), R8 | ||
|
||
XORQ DI, DI | ||
ADDQ R8, AX | ||
MOVL (AX), DI | ||
|
||
MOVL DI, ret+16(FP) | ||
RET | ||
|
||
|
||
// func ReadWordAt(start uintptr, offset uint32) uint16 | ||
TEXT ·ReadWordAt(SB),NOSPLIT,$0-16 | ||
MOVQ start+0(FP), AX | ||
MOVL offset+8(FP), R8 | ||
|
||
XORQ DI, DI | ||
ADDQ R8, AX | ||
MOVW (AX), DI | ||
|
||
MOVW DI, ret+16(FP) | ||
RET | ||
|
||
|
||
// func ReadByteAt(start uintptr, offset uint32) uint8 | ||
TEXT ·ReadByteAt(SB),NOSPLIT,$0-16 | ||
MOVQ start+0(FP), AX | ||
MOVL offset+8(FP), R8 | ||
|
||
XORQ DI, DI | ||
ADDQ R8, AX | ||
MOVB (AX), DI | ||
|
||
MOVB DI, ret+16(FP) | ||
RET |
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,15 @@ | ||
package memory | ||
|
||
// ReadCStringAt reads a null-terminated ANSI string from memory. | ||
func ReadCStringAt(start uintptr, offset uint32) []byte { | ||
var buf []byte | ||
for { | ||
ch := ReadByteAt(start, offset) | ||
if ch == 0 { | ||
break | ||
} | ||
buf = append(buf, ch) | ||
offset++ | ||
} | ||
return buf | ||
} |
Oops, something went wrong.