-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Teamserver/teamclient Sliver model #1359
Conversation
bind flags, completions, apply command filters, etc.
- Correctly connects/disconnects from the server (fixed race condition). - Correctly proposes completions where required. - Correctly executes commands. Problems: - The pre-run/post-run can be more efficient. - Pre-run/post-runs should be bound to leaf commands where required. - Logging is quite big.
- Move server-only commands in a dir. - Refactor client code with a single entrypoint function for all CLI modes, with pre-connect, loops and everything.
This reverts commit d31592b.
a53335f
to
08d26e9
Compare
I have to hand-pick a few things related to builder/crackstation permissions in the RPC middleware code, and this should be good. Lots of things have went in the last commits; the dependencies have now gotten rid of any |
…used to generate an implant.
Tagging a few persons on this as it's the last message I'll be able to send for a long time. End of my journey in computer science. You guys might be interested (or find out sooner or later that you should have been) by the work that is in there. Long story short: the most efficient and versatile command-line interface that you will get to see for a C2 program, nothing sort of that. It goes way beyond a closed-loop console. You might even get rid of the console itself. Video presentation of the interface (the 2nd part is the most interesting here):https://youtu.be/4rb82RDmmFg?si=y0INhdNySwMOX7Px Inspecting/discovering/understanding the code (videos done to go through the code, progressively):https://youtu.be/lUSTPFIfZmU (first part of code introduction) The entrypoint packages ( Teamclient/teamserver code/commandsLast note (sorry for this one): the Notes to each:@C-Sto : your extension code has been merged and should normally work like a charm. Merge conflicts at this very time (26/12/2023):
Be sure to check at least the first video. I bet a glass that you won't waste your time. |
hey @maxlandon I can see that some people will like it a lot, but it looks complicated to me and the interactive console is cross platform already so you wouldn't have to mess around with zsh,bash,powershell etc. |
This PR aims at consistently and systematically taking advantage of the Cobra CLI development API so as to:
versatile component (a teamclient/teamserver management system/library).
small features/commands to that effect.
Table of Contents
- client/
- server/
- protobuf/
- vendor/
I - Summary of Changes
new team library for teamclient/teamserver style software. This has numerous advantages, including
a much better inclusion into the cobra Command API, more efficient pre-run/pre-connect workflows,
and many benefits unravelling from this.
different major shell environments.
rpc error code = 2
and no message)at execution-time and in the interactive aspects. Custom generated errors (handled by dependencies)
indicate why a given command cannot be executed.
--id
flags have been replaced with positionalarguments). As well and related, all non-implant commands have completion for pretty much
everything, from file flags all the way to client-side network tools, extension commands, etc.
status display synchronization.
II - New features
Additionally, there a few new side-features going with this:
encapsulated both at the API level and at the CLI level with the
teamserver
andteamclient
commands.
sliver-client implant history
command, for diplaying command history per-implant, with variousfilters and display options.
Examples include network tools, beacon task spawning, management and cancelling, and much more.
without
&
will block until task is completed, or if another terminal receives atasks cancel
command: the terminal 1 will exit.
the completion context based on the target context (the implant type, capabilities and host).
III - Example worflows
Some very small examples of possible usage now, between many others. The ones below aim to be as
representative as possible of the new typical base workflows, at various points in operation.
The only dependency for optimal CLI usage is the carapace completion binary, sourced in your shell.
Various installation methods available, and a single one-liner in your "
.shell_rc
" will make the trick.https://github.com/rsteube/carapace-bin.
Aliases:
Sliver teamserver deployment:
Sliver server basic usage:
(Note that all these commands work identically both in
slc
andsls
binaries, althoughthe consistency in command behavior acrosss makes this more relatively useful than one thinks).
Sliver implant interactions:
IV - Codebase notes
I avoided the
implant/
directory like the plague.code/feature improvements, added options and bug fixes.
client/
The client code is obviously the one that has seen the most changes, where multiple packages
have been entirely refactored, strenghened and sometimes trimmed down to not much. Some things:
assets/
directory is now free of any teamclient/server config related stuff, logging, etc.console/
directory has been split into different files per main area (core, shell,commands, teamclient connections/loops, etc). It ensures to the best extent possible to
provide coherent backend functions for either
cli/
packages, or any importer of aconsole.SliverClient
in general.transport/
dir has been refactored in the same fashion as its server counterparts.cli/
directory is now mostly for last-minute assembly of components in other packages.(remove if wanted/needed).
command/
directory has naturally gone through many changes, thickening and refactoring.It includes a new
flags/
package with utility functions to register completions, commandtarget filters, flagsets, etc.
server/
The server code is however the one that has the highest quantity of removed code, since everything
teamclient/server related has been refactored out as a dependency module. Some packages have thus
entirely disappeared while a new one has been introduced for server-binary only commands.
daemon/
package has been removed and now handled byreeflective/team
.cli/
package has been trimmed down as much and in a same fashion as theclient/cli
.configs/
andassets
have been cleaned from everything everything teamserver-related.Assets unpacking is now called through a dedicated function called as cobra pre-run instead of init.
certs
package has simply been stripped out of all user cryptographic material functions.The teamserver library handles this (the code was simply ported/copied), while still using
sliver's DB. Same thing for exporting those files. There are now separate MTLS CAs: one for mTLS
implants, managed through the Sliver API, and the users' teamserver one, which is managed through
the teamserver API.
core/
package has seen a small but important change: theeventBufSize
channel size is now0, making it blocking. If it is not, the server will crash because of a race condition I could
not really pinpoint. I have not seen any notable difference in performance, but this might want
to be investigated a little further.
msf/
package has new functions that automatically cache some calls tomsfvenom
for a listof available encoders/payload/platforms when Sliver's assets are unpacked. Used by completions.
transport/
package has been refactored to fitreeflective/team
client/server interfaces.Overall, neither the size or the contents of the package or that of the API don't change much,
it's just a complete rewrite. Functionality stays strictly the same.
builder/
package has seen just as many changes as it needed to fit within the new code,including for handling CLI-style interrupts.
rpc/
package has new files for teamclient-related functions, and for implant history ones.Logging has also been enlarged for these purposes. Stuff for beacon tasks canceling and cmdline
descriptions, etc. Added code for MSF compilers data.
command/
directory is the equivalent of theclient/command
directory, with thesame structure and exported functions, to be used identically by entrypoints.
protobuf/
Metasploit modules data (used by stager commands), 3) attached command-lines to beacon tasks.
that you might want to reuse them with the
teamclient/teamserver
model down the road (that is,write tools which will leverage teamclients, the first of which being
sliver-crackstation
).vendor/
Usual
golang.org/x/sys
things and some filesystem stuff (the teamclients/teamserver have supportfor full in-memory operation mode, not used in Sliver obviously).
reeflective/team
dependency for teamclient/teamserver code.As also mentionned, it is still possible to just copy the repository code and use it with your
own import paths. A few sed directives should be enough to handle this.
V - Security
The default PR/issue template for Sliver includes a security section so as a matter of good habit,
several key things should be mentioned and reminded:
the data, that is they accept pre-connected databases, standard and audit loggers and will work
with them. These libraries and related code changes ultimately provide tools to manipulate user
and team data, enforcing and ensuring strong security defaults, and only this.
server/
directory (nor any in theclient/
onein fact). The
msfvenom
command is ran once at assets unpacking (if available) for caching somedata server-side, about payload modules.
from the
tcp
andnamed-pipe
commands being moved in the tree.purpose. See following notes on verbosity and log cluttering.
VI - Other related topics
taskmany
command is not functional anymore... It was clearly not leveragingour yielder functions the way they should/can be, anyway. It seems to me that this command is
not really needed anymore, nor would take a sound and consistent approach to multi-target command
execution, but I can be wrong obviously.
--os
and--arch
flags by a single--platform
flag with classic Go platform argumentsos/arch
.Multiparts completion is dead easy for this, and it will ensure that only valid combinations are
proposed at any given time.
grpc.Unary
requests are sliver.logged, notgrpc.Stream
ones. Maybe this is normal, and those requests are audit-logged anyway.opened, plus at least 1 request for each command core domain. This also applies to some extent
to the completions, when they need server-fetched data. Performance is not an issue here, just
that the logs get cluttered quickly, especially by gRPC logging middleware.
extremely useful to us for minimizing the heaviest data passed around (compilers info, modules,
etc). Caching is handled/managed per binary, so
sliver-server
,sliver-client
,sliver-crackstation
,etc, will all cache their own stuff, and everything will work smoothly.
VII - Remaining areas of work
Asciicast & history
The recording system is the least functional/mature part of the work, because the effects of the
latter put into question which scope should the recording process consider, both at record time as
well as in the replay one.
Good news first:
Less good news or things I've not checked/solved:
This means there are choices to make between recording asciicast output of straight out
command output bytes.
user or implant. Plus there can be concurrent work/commands on a given implant, with several users
generating session data. Not a problem in itself, just need to get the replay thing right.
io.MultiWriter
handles stream closings: given a streamA
and a streamB
, ifA
callsClose()
or is closed, theio.MultiWriter
will close all the otherstreams at once. This is not good as it messes with various things in various scenarios (one time
it will be the readline blocking, the other the completion system, etc, etc.)
Again, no big deal or serious dead-end here, just details to take care of.
Settle the dust
The entire migration to the cobra CLI is not trivial as it means full interfacing with the user OS.
As much as this present work has emphasized defining and ensuring a consistent and obvious behavior
for everything related, and despite its pretention to have encapsulated most of the utility and
boilerplate behind simple functions, there are still some things that will see some change:
for easy and safe development of the formers.
features to implement in the framework itself.
VIII - New paths
Quickly restructuring some command trees
It's easier than ever to play with the command tree, and it's probably why it should be done
now so as to provide a solid and clear one for the foreseeable future. Easier to extend, maintain
and to explore. Below are some examples, which I'll probably include in a separate issue/PR:
Same for C2 related commands:
Toward a single Sliver framework binary
The teamclient/server architecture and its management of directories emphasize the correct
segregation of command trees, APIs, but also of the working directories used by the binaries.
This in turn might enable to work from a single binary that is able to act as a server or
as client, at various points of execution or for specific tasks. A representative example is
the way Metasploit uses its own
.msf/
working directory to store user modules and such.In short:
their server.
and expose its implant code behind your personal builder, then use it with your CLI (which
automatically loads extension CLIs)
A significant advantage for Sliver is that the CLI is now efficient enought to provide analog
functionality, but with much more efficiency and UI confort. All of the following illustrate this:
msfconsole
, or when youmsfvenom
, you use different entrypoints, but they all points tothe same framework ruby core. As a result, the slightest invocation to it for even just the list
of available modules takes years.
it to a Metasploit teamserver is impossible.
There are lots of things to say about this that I won't list here, but I will humbly suggest to keep
this possibility at the back of the head.
You could imagine some commands that are similar to the
chezmoi
tool (dotfiles management):IX - Related issues
Below is a list of issues that might be solved/solvable thanks to the present PR.
some methods offered by the console and its readline to bind custom handlers.
should be added (even as an option itself ?).
the
--save
flag is a boolean. Cobra affords us to make it an optarg--flag=optvalue
, withno drawback on completion and help clarity (those are handled great with the new libs).
As well, the mere fact of having now full CLI support widens the number of possible approaches.
output formats possible. Maybe you will want to triage your
help
package a bit to fit withinthis better.