panda icon indicating copy to clipboard operation
panda copied to clipboard

guest plugins

Open lacraig2 opened this issue 3 years ago • 2 comments

This is a draft PR for tracking the new feature: guest plugins.

The PR includes several new PANDA plugins:

  • linjector - A hypervisor-based executable injector.
  • guest_plugin_manager - A general interface for PANDA plugins to interact with guest plugins.
  • hyperfuse - An example guest plugin for PANDA which exposes the internal guest file system to the host file system via FUSE.
  • guest_shell - An example guest plugin for PANDA which exposes an injected command line interface for the guest to the host.

TODO:

  • [x] Build generic interface for panda_require from rust and make use of it for guest_plugin_manager to load linjector
  • [ ] linjector port to MIPS and aarch64
  • [ ] Fix linjector on currently "supported" but broken architectures
    • [x] ARM
    • [ ] i386
  • [x] Add a PPP callback for "linjector injected" and a consumer in guest_plugin_manager
  • [x] Add a PPP callback for "guest agent loaded" and add consumer in PANDA guest plugins
  • [x] Remove hardcoded paths from linjector/hyperfuse
  • [x] Add a guest plugin retrieval-by-name mechanism
    • [x] Add load-by-name to guest_plugin_manager
    • [x] Add bindings to panda-rs
  • [x] Add guest plugin building to the build system (prereq for last 2)
    • [x] Add out-of-tree guest plugin building
  • [x] Add a Rust attribute for wrapping the message_recv callback
  • [x] PANDA API documentation
    • [x] Rust documentation (link)
    • [x] Add host plugin example (link, permalink)
    • [x] Add Guest Plugin Tutorial/Guide
    • [x] Add README to linjector
  • [ ] guest plugin API guide
  • [x] move guest_plugin_path function into panda-rs
  • [x] remove hardcoded path from rust_example guest plugin
    • [x] setup hyperchannels library for commit-agnostic versioning
      • [x] move to its own repo
      • [x] publish to crates.io
  • [x] Rewrite PANDA-side guest_shell plugin for readability
  • [ ] hyperfuse improvements
    • [x] Implement symlink resolution
      • [x] Rewrite list caching
        • [x] Rework to not invalidate on hit (links are resolved twice by ls, for example)
        • [x] Pre-fetch lookups of symlinks on directory listing
    • [x] Fix I/O error for /proc and /sys
    • [ ] Investigate which unimplemented features are important
    • [x] Have mount point be an environment variable

lacraig2 avatar Dec 09 '21 04:12 lacraig2

Instructions for trying hyperfuse/guest_shell today:

Setup

  1. Clone both panda-re/panda and panda-re/igloo-internal
  2. Checkout the linjector_base4 branch of panda
  3. Checkout the guest_agent branch of igloo-internal
  4. Set the EXTRA_GUEST_PLUGINS_PATH environment variable to point to igloo-internal/pie_idea/guest_code
  5. Ensure you have the musl target installed for Rust:
rustup target add x86_64-unknown-linux-musl
  1. Build PANDA for x86_64 (other architectures are currently broken)
cd build
../build.sh x86_64-softmmu

Using hyperfuse

  1. Create a directory to use as your mount point for the guest filesystem
  2. Set the HYPERFUSE_MOUNT environment variable to point to that directory
  3. Run panda/python/examples/hyperfuse.py

Give it a second to start up, then your mount point should now mirror the guest filesystem's state.

Using guest_shell

  1. Run panda/python/examples/guest_shell.py
  2. In another terminal (the one you want to use as the shell) run panda/plugins/guest_shell/guest_shell_pty.sh
  3. Give it a second to start up. You should see a # prompt in your second terminal and you can begin using the shell

jamcleod avatar Dec 20 '21 19:12 jamcleod

@panda.ppp("linjector", "before_guest_inject")
def linjector_finish(cpu):
    print("!!!! Injection finished !!!!")

@panda.ppp("guest_plugin_manager", "on_guest_agent_load")
def agent_loaded(cpu):
    print("!!!! Guest agent loaded !!!!")

Examples of the added PPP callbacks

jamcleod avatar Jan 13 '22 20:01 jamcleod