sliver icon indicating copy to clipboard operation
sliver copied to clipboard

Single instance only

Open viencokhi opened this issue 3 years ago • 14 comments

We should implement some kind of mutex so only one instance of implant running at a time.

viencokhi avatar Aug 05 '20 09:08 viencokhi

Can you define a specific use case?

rkervella avatar Aug 05 '20 09:08 rkervella

Seems like a good idea to me, you may run into situations where your persistence technique results in multiple executions of a payload based on user activity and it would probably be a good idea to limit the number of sessions that get created.

moloch-- avatar Aug 06 '20 11:08 moloch--

Makes sense. I'll play with CreateMutexA and see what's the most convenient way to integrate that. We'll probably need to modify the generate command to have a common mutex name per implant build (or we could use the implant name as a mutex name too).

rkervella avatar Aug 06 '20 12:08 rkervella

Yea we'll want some way of doing this on MacOS and Linux too methinks. We'll want to consider if this gets enabled by default.

moloch-- avatar Aug 06 '20 13:08 moloch--

Good point.

rkervella avatar Aug 06 '20 13:08 rkervella

It may also be nice to have a scheme were we can limit execution n instances.

moloch-- avatar Aug 06 '20 13:08 moloch--

So basically a semaphore.

rkervella avatar Aug 06 '20 13:08 rkervella

Looks like we have a Linux compatible sample here, need to see what's needed for unix / OS X to make it work too: https://github.com/shubhros/drunkendeluge/blob/master/semaphore/semaphore.go

rkervella avatar Aug 06 '20 14:08 rkervella

Cool, let's make this per-generated-implant too, just randomize all the values.

moloch-- avatar Aug 06 '20 15:08 moloch--

Probably implement this in the existing limits package too.

moloch-- avatar Aug 06 '20 15:08 moloch--

Just a thought: should they be per-user on the host? So if you have an unprivileged sliver and then privesc, launch a 2nd sliver, it would be nice to not have this interfere.

Matir avatar Oct 10 '20 00:10 Matir

@rkervella Now that each host has a UUID, You can replace old connections instead of duplicating them. Ex. If there is already a session with the same UID, GID and UUID then replace the old one. (As long as it's not in use)

usiegl00 avatar Dec 20 '20 04:12 usiegl00

@usiegl00 I'm not fond of this solution two reasons:

  • we want to avoid the implant running multiple time on the same host, and that should be handled implant-side. Using mutexes / semaphores is what makes sense here.
  • there's an edge case where the same host can have multiple UUIDs, which would make this solution unreliable for this case

rkervella avatar Feb 08 '21 08:02 rkervella

Makes Sense.

UUIDs work well for persistence however, allowing the server to match based on UID in the edge cases.

usiegl00 avatar Feb 08 '21 10:02 usiegl00