Skip to content
Memphis Marshall edited this page Sep 19, 2024 · 15 revisions
  • LunaAPI
    • Add client and server stubs for the RPC to sync both sides of the protocol
  • Stabilise hooking
    • When loaded, sign the instance (PID + time started?) with a key from loader
      • Hook LoadLibraryA/W functions so they can check if LunaJuice is going to be loaded, and if so deny it unless there is authentication
      • LunaLib, when loaded, will check this signature and if it didn't sign the instance, load anyway
      • If it did sign the instance, logging should be set up already
        • In this case, ID is passed back to loader so monitoring/control can begin
  • Improve performance
    • Do log processing in separate thread so main code not interrupted
  • Log suppression
    • Equal events should not log twice, but should have quantity specifier
    • Log every second, and process / check for duplicates that can be grouped
  • RPC
    • Check for SHARED_GLOBAL_NAME and SHARED_SESSION_NAME on init, delete these as they may be deployed to mislead LunaJuice
    • Authentication via keys shared on injection
    • RPC control over implants for dynamic loading / updates / command & control
    • Should not be necessary to run, just an enhancement
      • Unsure if this is doable
  • Support for modules
    • Load individual functions dynamically and connect to hooks
    • Allows the ability to create quick actions
  • Support for rules
    • Quickly act on threats with configurable rules
    • Loaded functions can be executed to mitigate threats
    • Rules can define logging behaviour

Python Hooking

In the loader, take Python hooks as a file input:

# EXPR: a_sus_function
def my_wonderful_hook(a, b, c):
    builtins.print(globals.cool_variable)
    return original(a, b, c)

In the parser, parse line by line and take note of indents. When the indent gets below the function indent, stop parsing and add a null byte. Pass this buffer into the functions.

Commandline Spoofing

https://medium.com/@s12deff/command-line-spoofing-64ea1ef3f536

(Hook thread resume)

  1. Use thread handle to get process handle
  2. Read process memory of commandline arguments (same technique as article)
  3. Compare to OS-reported arguments

Alternatives:

  • Hook write process memory - very high volume

Ways around detection:

  • After resuming the thread the malicious process could try clean up now that the process has the arguments, but not sure how this would work in practice and could be prevented by blocking ResumeThread until the checks pass

Flows

Hook

  1. Hook called
  2. Rules evaluated to determine behaviour
  3. (?) Create logging thread with input data (communicate with throughout)
  4. (?) Call additional pre-call hooks
  5. (?) Call wrapper hooks (original function in middle)
  6. (?) Call post-call hooks
  7. (?) Pass return data and any changes to logging thread
  8. Exit hook

Load

  1. Check if RPC mode
  2. If RPC mode, check for implant name
    1. If implant name, start RPC connection
  3. If not RPC mode, try load
    1. Go through injection flow

To Consider

  • Do we record what gets changed by pre/post-call hooks too?

Clone this wiki locally