Skip to content

Commit

Permalink
code cleanup 3
Browse files Browse the repository at this point in the history
  • Loading branch information
srozb committed Jul 16, 2024
1 parent 9f0a374 commit f558430
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 19 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,19 @@ nim --cpu:i386 -d:release c src\parasite.nim
* This project has been flagged as potentially malicious by certain antivirus vendors. This is likely because it has previously been weaponized and submitted to VT.
* The WMI module is still under development

## Tools

This project includes additional tools for testing its functionalities independently of DLL hijacking techniques.

|Tool|Description|
|-|-|
|`dumper.exe`|Dumps process memory using the `MiniDumpWriteDump` function.|
|`injector.exe`|Injects a DLL of your choice into a specified process via classic DLL injection.|
|`parahttp.exe`|Allow for testing web application features independently of any DLL injections|

---

**This project draws inspiration from:**

* The amazing [OffensiveNim](https://github.com/byt3bl33d3r/OffensiveNim) repository.
* Loader Lock unlocking technique haveily inspired on work of [@ElliotKillick](https://github.com/ElliotKillick) especially his [LdrLockLiberator](https://github.com/ElliotKillick/LdrLockLiberator) repository.
* The Loader Lock unlocking technique is heavily inspired by the work of [@ElliotKillick](https://github.com/ElliotKillick), particularly his [LdrLockLiberator](https://github.com/ElliotKillick/LdrLockLiberator) repository.
4 changes: 2 additions & 2 deletions parasite.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.4.0"
version = "0.4.1"
author = "srozb"
description = "dll injection/hijack made fun"
license = "MIT"
Expand All @@ -10,7 +10,7 @@ binDir = "release"
namedBin = {
"parasite" : "parasite.dll",
"injector" : "injector.exe",
"httpserv" : "para_http.exe",
"parahttp" : "parahttp.exe",
"dumper" : "dumper.exe"
}.toTable()

Expand Down
2 changes: 1 addition & 1 deletion src/dumper.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
when isMainModule:
import os
import strutils
import parasite/dumper
import parasite/procdump
if paramCount() != 2:
echo "usage: dumper <pid> <dump filename>"
quit(-1)
Expand Down
2 changes: 1 addition & 1 deletion src/injector.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
when isMainModule:
import os
import strutils
import parasite/injector
import parasite/dllinject

if paramCount() != 2:
echo "usage: injector <pid> <dll>"
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions src/parasite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ proc DllMain(hinstDLL: HINSTANCE, fdwReason: DWORD, lpvReserved: LPVOID): BOOL {
NimMain()

when defined(unlockloader):
unlockLoaderLock()
var hThread = CreateThread(
cast[LPSECURITY_ATTRIBUTES](NULL),
0.SIZE_T,
cast[LPTHREAD_START_ROUTINE](runHttpServ),
cast[LPVOID](NULL),
0.DWORD,
cast[LPDWORD](NULL)
)
WaitForSingleObject(hThread, 20000.DWORD)
lockLoaderLock()
withLoaderUnlocked:
let hThread = CreateThread(
cast[LPSECURITY_ATTRIBUTES](NULL),
0.SIZE_T,
cast[LPTHREAD_START_ROUTINE](runHttpServ),
cast[LPVOID](NULL),
0.DWORD,
cast[LPDWORD](NULL)
)
if hThread == NULL: return false
WaitForSingleObject(hThread, 20000.DWORD)
else:
runHttpServ()

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/parasite/httpserv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import shell
import environ
import strtabs
import net
import injector
import dllinject
import strutils
when defined(wmi):
import wmi
when defined(dumper):
import dumper
import procdump

proc pickPort(minPort = 5000, tries=64): Port {.inline.} =
## Try to bind a port to determine if it can be used by http module. If port
Expand Down
7 changes: 6 additions & 1 deletion src/parasite/lockpick.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ proc lockLoaderLock*() =
res = LdrLockLoaderLock(0.ULONG, disp, addr newCookie)
if res == 0:
discard "LoaderLock locked, obtained cookie: 0x" & newCookie.toHex
else: discard "Failed with: 0x" & res.toHex
else: discard "Failed with: 0x" & res.toHex

template withLoaderUnlocked*(body: untyped) =
unlockLoaderLock()
body
lockLoaderLock()
File renamed without changes.

0 comments on commit f558430

Please sign in to comment.