-
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: ported ntdll module parsing to go assembly
- Loading branch information
Showing
7 changed files
with
193 additions
and
136 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,32 +1,93 @@ | ||
// func GetInMemoryOrderModuleListPtr() uintptr | ||
TEXT ·GetInMemoryOrderModuleListPtr(SB),$0-8 | ||
// PEB | ||
MOVQ 0x60(GS), AX | ||
// func getNtdllBaseAddr() uintptr | ||
TEXT ·getNtdllBaseAddr(SB),$0 | ||
|
||
// TEB->ProcessEnvironmentBlock | ||
XORQ AX, AX | ||
MOVQ 0x30(GS), AX | ||
MOVQ 0x60(AX), AX | ||
|
||
// PEB->Ldr | ||
MOVQ 0x18(AX), AX | ||
|
||
// PEB->Ldr->InMemoryOrderModuleList | ||
MOVQ 0x20(AX), AX | ||
|
||
// PEB->Ldr->InMemoryOrderModuleList->Flink (ntdll.dll) | ||
MOVQ (AX), AX | ||
|
||
// PEB->Ldr->InMemoryOrderModuleList->Flink DllBase | ||
MOVQ 0x20(AX), AX | ||
|
||
MOVQ AX, ret+0(FP) | ||
RET | ||
|
||
// func GetLdrTableEntryPtr(listptr uintptr, i int64) *LdrDataTableEntry | ||
TEXT ·GetLdrTableEntryPtr(SB),$0-24 | ||
|
||
MOVQ listptr+0(FP), AX | ||
// func getModuleEATAddr (moduleBase uintptr) uintptr | ||
TEXT ·getModuleEATAddr(SB),$0-8 | ||
MOVQ moduleBase+0(FP), AX | ||
|
||
XORQ R10, R10 | ||
next_entry: | ||
CMPQ R10, i+8(FP) | ||
JE endloop | ||
XORQ R15, R15 | ||
XORQ R14, R14 | ||
|
||
// next Flink | ||
MOVQ (AX), AX | ||
INCQ R10 | ||
JMP next_entry | ||
// AX = IMAGE_DOS_HEADER->e_lfanew offset | ||
MOVB 0x3C(AX), R15 | ||
|
||
endloop: | ||
MOVQ AX, CX | ||
// start of LDR_DATA_TABLE_ENTRY struct | ||
SUBQ $0x10, CX | ||
MOVQ CX, ret+16(FP) | ||
RET | ||
// R15 = ntdll base + R15 | ||
ADDQ AX, R15 | ||
|
||
// R15 = R15 + OptionalHeader + DataDirectory offset | ||
ADDQ $0x88, R15 | ||
|
||
// AX = ntdll base + IMAGE_DATA_DIRECTORY.VirtualAddress | ||
ADDL 0x0(R15), R14 | ||
ADDQ R14, AX | ||
|
||
MOVQ AX, ret+8(FP) | ||
RET | ||
|
||
|
||
// func getEATNumberOfFunctions(exportsBase uintptr) uint32 | ||
TEXT ·getEATNumberOfFunctions(SB),$0-8 | ||
MOVQ exportsBase+0(FP), AX | ||
|
||
XORQ R15, R15 | ||
|
||
// R15 = exportsBase + IMAGE_EXPORT_DIRECTORY.NumberOfFunctions | ||
MOVL 0x14(AX), R15 | ||
|
||
MOVL R15, ret+8(FP) | ||
RET | ||
|
||
|
||
// func getEATAddressOfFunctions(moduleBase,exportsBase uintptr) uintptr | ||
TEXT ·getEATAddressOfFunctions(SB),$0-16 | ||
MOVQ moduleBase+0(FP), AX | ||
MOVQ exportsBase+8(FP), R8 | ||
|
||
XORQ SI, SI | ||
|
||
// R15 = exportsBase + IMAGE_EXPORT_DIRECTORY.AddressOfFunctions | ||
MOVL 0x1c(R8), SI | ||
|
||
// AX = exportsBase + AddressOfFunctions offset | ||
ADDQ SI, AX | ||
|
||
MOVQ AX, ret+16(FP) | ||
RET | ||
|
||
|
||
// func getEATAddressOfNames(moduleBase,exportsBase uintptr) uintptr | ||
TEXT ·getEATAddressOfNames(SB),$0-16 | ||
MOVQ moduleBase+0(FP), AX | ||
MOVQ exportsBase+8(FP), R8 | ||
|
||
XORQ SI, SI | ||
|
||
// SI = exportsBase + IMAGE_EXPORT_DIRECTORY.AddressOfNames | ||
MOVL 0x20(R8), SI | ||
|
||
// AX = exportsBase + AddressOfNames offset | ||
ADDQ SI, AX | ||
|
||
MOVQ AX, 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,14 @@ | ||
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 { | ||
// TODO: do implementation | ||
return []uintptr{} | ||
} |
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,41 +1,40 @@ | ||
package resolver | ||
|
||
import ( | ||
"unsafe" | ||
"fmt" | ||
|
||
wt "github.com/f1zm0/acheron/internal/types" | ||
) | ||
|
||
// GetLdrTableEntryPtr signature. | ||
func GetLdrTableEntryPtr(listptr uintptr, i int64) *wt.LdrDataTableEntry | ||
|
||
// GetInMemoryOrderModuleListPtr signature. | ||
func GetInMemoryOrderModuleListPtr() uintptr | ||
|
||
// GetLdrTableEntries returns a slice of LdrDataTableEntries for | ||
// custom implementation of GetModuleHandle function. | ||
func GetLdrTableEntries() []*wt.LdrDataTableEntry { | ||
entries := []*wt.LdrDataTableEntry{} | ||
var ( | ||
entry *wt.LdrDataTableEntry | ||
firstEntry *wt.LdrDataTableEntry | ||
) | ||
|
||
// addr of Ldr->InMemoryOrderModuleList | ||
modListPtr := GetInMemoryOrderModuleListPtr() | ||
|
||
firstEntry = GetLdrTableEntryPtr(modListPtr, 0) | ||
entries = append(entries, firstEntry) | ||
|
||
i := int64(1) | ||
for { | ||
entry = GetLdrTableEntryPtr(modListPtr, i) | ||
if entry == firstEntry || unsafe.Pointer(entry.DllBase) == unsafe.Pointer(nil) { | ||
break | ||
} | ||
entries = append(entries, entry) | ||
i = i + 1 | ||
} | ||
|
||
return entries | ||
// GetNtdlloduleHandle returns a PEModule struct with information about in-memory | ||
// ntdll.dll's module, or an error if for some reason an error occur while reading it. | ||
func GetNtdllModuleHandle() (*wt.PEModule, error) { | ||
moduleBase := getNtdllBaseAddr() | ||
fmt.Printf("ntdll base: 0x%x\r\n\r\n", moduleBase) | ||
|
||
exportsBase := getModuleEATAddr(moduleBase) | ||
fmt.Printf("EAT base: 0x%x\r\n\r\n", exportsBase) | ||
|
||
numberOfFunctions := getEATNumberOfFunctions(exportsBase) | ||
fmt.Printf("Number of functions: %d\r\n\r\n", numberOfFunctions) | ||
|
||
addressOfFunctions := getEATAddressOfFunctions(moduleBase, exportsBase) | ||
fmt.Printf("Address of functions: 0x%x\r\n\r\n", addressOfFunctions) | ||
|
||
addressOfNames := getEATAddressOfNames(moduleBase, exportsBase) | ||
fmt.Printf("Address of names: 0x%x\r\n\r\n", addressOfNames) | ||
|
||
// rr := rrd.NewRawReader(modBaseAddr, modSize) | ||
|
||
// p, err := pe.NewFileFromMemory(rr) | ||
// if err != nil { | ||
// return nil, errors.New("error reading module from memory") | ||
// } | ||
|
||
// return &wt.PEModule{ | ||
// BaseAddr: modBaseAddr, | ||
// File: p, | ||
// }, nil | ||
|
||
return &wt.PEModule{}, nil | ||
} |
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,16 @@ | ||
package resolver | ||
|
||
// getNtdllBase signature. | ||
func getNtdllBaseAddr() uintptr | ||
|
||
// getModuleEATAddr signature. | ||
func getModuleEATAddr(modBaseAddr uintptr) uintptr | ||
|
||
// getEATNumberOfFunctions signature. | ||
func getEATNumberOfFunctions(exportsBase uintptr) uint32 | ||
|
||
// getEATAddressOfFunctions signature. | ||
func getEATAddressOfFunctions(moduleBase, exportsBase uintptr) uintptr | ||
|
||
// getEATAddressOfNames signature. | ||
func getEATAddressOfNames(moduleBase, exportsBase uintptr) uintptr |
This file was deleted.
Oops, something went wrong.