Package: pymalleablec2
pyMalleableC2A Python interpreter for Cobalt Strike Malleable C2 profiles that allows you to parse, modify, build them programmatically and validate syntax.Supports all of the Cobalt Strike Malleable C2 Profile grammar starting from Cobalt Strike version 4.3.It's not backwards compatible with previous Cobalt Strike releases.What are the differences between pyMalleableC2 and other projects of this nature?Parses profiles withLarkusingeBNF notation. This approach is a lot more robust then user defined regexes, templating engines or similar methods.Turns profiles into anAbstract Syntax Tree (AST)which can then be reconstructed back into source code.Because of the above, pyMalleableC2 allows you to build profiles programmatically or modify them on the fly.Allows you to validate the syntax of Malleable C2 profiles (Does not perform runtime checks, see the warning below.)It has AI in the form of a lot ofifstatements.SponsorsTable of ContentspyMalleableC2Installing🚨 Warning! No runtime checks (yet!) 🚨AuthorOfficial Discord ChannelExamplesFAQInstallingpyMalleableC2 was built using Python 3.9, however it should be backwards compatible up to Python 3.6.Install using Pip:pip3 install pymalleablec2🚨 WARNING 🚨pyMalleableC2 treats you as a consenting adult and assumes you know how to write Malleable C2 Profiles. It's able to detect syntax errors, however there are no runtime checks implemented. It'll gladly generate profiles that don't actually work in production if instructed to do so. Always run the generated profiles throughc2lintbefore using them in production!(Technically you could build a Python version of c2lint using this library,*cough*PRs welcome*cough*)AuthorThe primary author of pyMalleableC2 is Marcello SalvatiTwitter:@byt3bl33d3r, Github:@byt3bl33d3rOfficial Discord ChannelCome hang out on Discord!Examples(See theexamplesfolder for more)Generate the AST for a Malleable C2 Profile located in a file, then reconstruct the source code from the AST:frommalleablec2importProfile# Parse a profile given its pathp=Profile.from_file("amazon.profile")# Print the generated ASTprint(p.ast.pretty())# Reconstruct source code from the AST and print to consoleprint(p.reconstruct())# Shortcut for the above :)print(p)Generate the AST for an 'inline' Malleable C2 Profile then reconstruct the source code from the AST:code='''set jitter "0";set sleeptime "3000";http-get {set uri "/wow/this/is/cool";}http-post {set uri "/pymalleablec2/is/the/shit";}'''# Parse a profile from a stringp=Profile.from_string(code)# Print the generated ASTprint(p.ast.pretty())# Reconstruct source code from the AST and print to consoleprint(p)Build a Malleable C2 profile programmatically from scratch:frommalleablec2importProfilefrommalleablec2.componentsimport*# Create an empty profilep=Profile.from_scratch()# Set some global optionsp.set_option("sleeptime","0")p.set_option("jitter","0")p.set_option("pipename","mojo__##")# Create an http-get blockhttp_get=HttpGetBlock()# Set the uri http-get optionhttp_get.set_option("uri","/wat/a/tease")# Create a client blockclient=ClientBlock()# Add a header statement to the client blockclient.add_statement("header","Accept","*/*")# Create a server blockserver=ServerBlock()# Add the client and server blocks to the http-get blockhttp_get.add_code_block(client)http_get.add_code_block(server)# Create a http-post blockhttp_post=HttpPostBlock()# Set the uri http-post optionhttp_post.set_option("uri","/wat/ucraycray")# Add the http-get and http-post blocks to the profilep.add_code_block(http_get)p.add_code_block(http_post)# Reconstruct source code from the generated AST and print to consoleprint(p)Super simple example showing how to programmatically randomize a Malleable C2 Profile:frommalleablec2importProfilefrommalleablec2.randomizerimportProfileRandomizerfromlarkimportTokenclassMyRandomizer(ProfileRandomizer):# We implement the global_option_set method which will get called on every parsed global option statement in the profiledefglobal_option_set(self,tree):option_name=tree.children[0]ifoption_name=="pipename":# "Randomize" the pipename valuetree.children[1].children[0]=Token('ESCAPED_STRING','"my_random_pipename_##"')# Parse a profile given its pathp=Profile.from_file("amazon.profile")r=MyRandomizer()# Walk through the generated profile AST and apply randomization rulesr.randomize(p)# Reconstruct source code then output the profile to the consoleprint(p)