Repository navigation
Adds migrate command for Linux x64/x86 - #287
msutovsky-r7 wants to merge 19 commits into
Conversation
ae0de8e to
e5a87f0
Compare
There was a problem hiding this comment.
Pull request overview
Adds Linux x64/x86 support for the migrate command in mettle by introducing a ptrace-based injector and exposing transport/socket details needed to stage the new session.
Changes:
- Adds new TLV fields and core TLV handlers for
core_migrateandcore_transport_list. - Introduces a new ptrace-based injection implementation (
base_inject.*) and wires it into the build. - Adds APIs to retrieve the underlying socket FD from the active C2 transport.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| mettle/src/tlv_types.h | Adds migrate-related TLVs and adjusts transport-group TLV ID. |
| mettle/src/network_client.h | Exposes network_client accessors for bufferev and socket FD. |
| mettle/src/network_client.c | Implements the new network_client accessor functions. |
| mettle/src/coreapi.c | Adds core_migrate and core_transport_list handlers and registers them. |
| mettle/src/c2_tcp.c | Adds c2_transport_get_socket_fd() implementation (currently TCP-specific). |
| mettle/src/c2.h | Exposes c2_get_next_transport() and c2_transport_get_socket_fd() prototypes. |
| mettle/src/c2.c | Implements c2_get_next_transport() (and introduces an extra c2_get_fd stub). |
| mettle/src/bufferev.h | Adds bufferev_get_socket_fd() declaration. |
| mettle/src/bufferev.c | Implements bufferev_get_socket_fd(). |
| mettle/src/base_inject.h | Introduces injector header/API for migrate support. |
| mettle/src/base_inject.c | Adds ptrace-based injector implementation for Linux migrate. |
| mettle/src/Makefile.am | Adds base_inject.c to libmettle sources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| struct c2_transport * transport = c2_get_current_transport(c2); | ||
| int fd = c2_transport_get_socket_fd(transport); | ||
|
|
||
| if(migrate(pid, migrate_stub, stub_length, payload, payload_length, uuid, fd)) |
There was a problem hiding this comment.
c2_transport_get_socket_fd() is assumed to work for the current transport, but mettle supports non-TCP transports (e.g. http/https). The current implementation of c2_transport_get_socket_fd() casts the transport ctx to tcp_ctx, which will be invalid for HTTP and can crash or leak memory. Either (a) move this API behind transport callbacks so each transport type can implement it safely, or (b) explicitly restrict migrate to fd/tcp transports and fail cleanly for others; also handle fd == -1 before calling migrate().
| if(migrate(pid, migrate_stub, stub_length, payload, payload_length, uuid, fd)) | |
| /* Only attempt migration when we have a valid transport file descriptor. */ | |
| if (fd >= 0 && migrate(pid, migrate_stub, stub_length, payload, payload_length, uuid, fd)) |
efb6cfa to
0342dd8
Compare
This adds support for
migratecommand on Mettle side for Linux x64/x86. This PR only adds support for Mettle to inject migrate stub and execute payload, session handling needs to be taken care in Framework. Currently, themigrateneeds privilege to useptracesyscall.