RFC: Bring Your Own Payloads (BYOP) #14490
-
ProblemEvasion has always been a problem for Metasploit and will remain a problem for the foreseeable future. This leads to user frustration as they can not leverage many of Metasploit payloads regardless of the exploit content the project provides, i.e. the exploit doesn't really matter if Meterpreter can't run. This has lead to a trend in the industry where users have written their own C2 servers and C2 payloads (see the ask.thec2matrix.com for a non-exhaustive list). They do this so their custom payloads are not detected by remote AVs/EDRs. This process often involves designing their own C2, writing their own C2 server, etc which has very little to do with the detection surface on the remote system. SolutionThe Metasploit framework could facilitate the current trends by allowing users to write their own payloads for Metasploit. This would remove the necessity for payload authors to write their own servers, protocols etc, thus enabling them to focus on the core of the problem which is the executable agent that runs on the target system. Metasploit currently encourages uses to write exploits for the framework, and there's a lot of documentation on how to do it leading to a relatively low barrier to entry. An exploit module for Metasploit can for example be written in as little as 80 lines of Ruby. A payload on the other hand has a very high barrier to entry for anything resembling a modern implant (something like Meterpreter vs a standard shell). Metasploit could document a C2 protocol and provide code samples in a variety of languages such as Python, .NET, Go etc. that allow users to focus on how they build their implant and execute their various tasks. The tasks provided by user payloads should be very limited and very well defined. While Meterpreter supports "everything and the kitchen sink" user payloads should be limited to a small subset of general functionality such as file I/O, code/command execution and host enumerating. This would require a hefty amount of abstraction of the transports / protocols and handlers implemented by Metasploit to ideally allow users to also implement their own handlers through a sort of middleware. Users should be able to implement a handler in Ruby that accepts commands from an arbitrary source (an S3 bucket, a Dropbox file, a Git repo, a Twitter Tweet, etc.) and place them into a common format for Metasploit to handle and dispatch to. Further ConsiderationsThe success of this would be closely aligned with adoption. By the nature of the goal however, the Metasploit project may not see user-payloads being contributed. The value in these projects will often be that they are custom. This will make it difficult to measure the success. To encourage adoption, the Metasploit project team members could provide training on how to develop payloads to encourage the community to get started. |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 10 replies
-
So my one question r.e this would be how would post modules that rely on RailGun or other Meterpreter specific functionality work? Would we not end up preventing a lot of this functionality from working? I imagine their is still the upgrade session route but that is more likely to be caught by AV. |
Beta Was this translation helpful? Give feedback.
-
I really like the idea of being able to write my own payload that would integrate with the framework. This would decrease the amount of time I take to create something new every time a blue team starts eating things I toss at them. I could see the use of some exploits built into the framework not functioning as they were built for Meterpreter. My recommendation is to add a check for the current session to see if that payload is compatible for the required actions like |
Beta Was this translation helpful? Give feedback.
-
This sort of necessitates those internal changes we discussed regarding disambiguation of platform, os, arch, runtime, and session semantics a few years ago at the hackathon. The internal wiring or how handlers->sessions happen is brittle, and needs to be deconstructed into relatively simple building blocks to permit composition of "head-ends" compatible with whatever payload/RAT/C2 users may want to leverage - sort of parallels the OpenSSL vs Noise programming trends. DNS tunneling for instance requires some serious gymnastics right now because you have to parse packets directly across TCP and UDP relayed from Tron knows where, to reassemble something that behaves like a synchronous session... |
Beta Was this translation helpful? Give feedback.
-
@wolfthefallen - being caught by EDR/AV and NIDS/proxies are different stories. The host-level stuff is generally watching for things like our ancient process injection or RWX allocations, that's at the execution tier. Throw in a different injector or change those RWX to RW->RX and you can walk around the static killchain they're looking for rather often. The linkage or transport problem is sort of what we're getting at in terms of "this is a giant PITA" :). There's this ghost of Christmas past problem where sessions and transports are grotesquely conjoined and none of us have ever had the time and relevant level of self-loathing to disambiguate, rewrite, survive review, and get up-streamed. Its probably the greatest sin within the codebase today. By having a transport handler and session handler as separate constructs running callbacks on recv until they produce a framework-compatible session output and back the other way on input (one of the 3 above), we could "absorb" other tools straight up, in plugins, etc. Think sessions through gdocs/gmaps or other complex encoding/decoding on long latency async mechanisms (hence that whole seqno effort on TLVs). Half the effort here is to dig in deep enough to untie the cat's cradle in session+transport stack. If someone is going to cave-dive that mess, we might as well go all the way and fix the problem once and for all - or at least tear the functions apart to make it easier for others to come in behind the first rank and fix it piece by piece. |
Beta Was this translation helpful? Give feedback.
-
Just curious. Is there any update on this idea, if at all? |
Beta Was this translation helpful? Give feedback.
-
Unfortunately we're not actively pursuing it at this time nor do we have plans to take it on soon. Things can change but at this point in time we are focusing our resources elsewhere. |
Beta Was this translation helpful? Give feedback.
-
I'm working on something to permit tunneling meterp over textual shells (STDIO on the target-side), so we might be able to leverage that (should i ever get it to anything useful) in conjunction with the |
Beta Was this translation helpful? Give feedback.
-
I know it's been a year now. But I'll ask it again. As the idea is interesting. Any updates on this? Most of the time (if an exploit ts found that can be used with Metasploit). It's gonna be using the download and execute payload to run our own implants on our own c2. This isn't bad per say. But would be a nice QOL improvement. Instead of switching between consistently. P.S. I need to get back to working on Metasploit again. I always made adjustments, and modules but never uploaded them as I felt they weren't good. |
Beta Was this translation helpful? Give feedback.
-
Nobody is preventing anything... We have had custom payloads since before r7 bought metasploit. If you're asking for commercial support from r7 for that, that's a sales discussion IMO. Implementation here requires proper code integration with sockets, handlers, etc to actually use metasploit vs some hacky CLI wrapper over another tool... IMO |
Beta Was this translation helpful? Give feedback.
-
I agree that people generally should not opensource their own private payload. Thats how these antiviruses and EDR solutions quickly lock down payloads and C2s in general. While I personally dislike it if Rapid7 locked this feature behind "pro/premium" purchases. I was thinking a paid course could help the upper management decide to dedicate resources to putting this feature into play. That way it remains open source and open the community at large, but allows them to recoupe some of the costs of tossing resources at the feature. Really if Rapid7 provided documentation on the exposed features for "Bring your own payload" and simple templates to get people started, people would not have to take the course. In general practice people would still take the course just to get started. Just food for thought on how to get upper management to buy into the idea. |
Beta Was this translation helpful? Give feedback.
-
People could also think of new techniques to go along with their own implants. Of course they're isn't gonna be many open-source private payloads. But they're will be articles on how to do XYZ while making implants. And when people find out how to do a technique whilst making they're own implant. You'd be surprised how many people want to share that knowledge of the technique they're creating. Whilst we're on the topic of techniques and tactics. People can make they're own implants good at doing particular things depending on the environment of the engagement. Meterpreter can do "anything under the kitchen sink", but whilst developing implants. You shouldn't have everything in one implant (the more suspicious it looks, the better chance AV/EDR will catch it). So people can get good at making implants do specific things. |
Beta Was this translation helpful? Give feedback.
-
That's a fine line - the SSM/ec2 stuff I pushed was 100% novel far as payloads go but they won't be detected by edr :). The PowerShell stuff I originally thought might get a few weeks of play... It all depends on whether you're talking about publishing some low entropy thing or engineering a truly dynamic and heuristically high entropy architecture to allow all sorts of payloads to be undetected. Some TTPs should be released only when industry is ready, but squirreling things away in corners and coveting them doesn't move the ball forward framework or industry-wise. |
Beta Was this translation helpful? Give feedback.
Unfortunately we're not actively pursuing it at this time nor do we have plans to take it on soon. Things can change but at this point in time we are focusing our resources elsewhere.