
Intérprete de Python para perfiles C2 modificables de Cobalt Strike. Te permite analizarlos, construirlos y modificarlos mediante programación.
Un intérprete de Python para perfiles Malleable C2 de Cobalt Strike que te permite analizarlos, modificarlos, construirlos programáticamente y validar su sintaxis.
Soporta toda la gramática de perfiles Malleable C2 de Cobalt Strike a partir de la versión 4.3.
No es compatible hacia atrás con versiones anteriores de Cobalt Strike.
¿Cuáles son las diferencias entre pyMalleableC2 y otros proyectos similares?
if.pyMalleableC2 fue construido con Python 3.9, sin embargo debería ser compatible hacia atrás hasta Python 3.6.
Instalar usando Pip:
pip3 install pymalleablec2pyMalleableC2 te trata como un adulto responsable y asume que sabes cómo escribir perfiles Malleable C2. Es capaz de detectar errores de sintaxis, pero no hay comprobaciones en tiempo de ejecución implementadas. Generará alegremente perfiles que no funcionan en producción si se le indica que lo haga. ¡Siempre ejecuta los perfiles generados a través de c2lint antes de usarlos en producción!
(Técnicamente podrías construir una versión en Python de c2lint usando esta librería, **tos* PRs bienvenidos *tos*)
El autor principal de pyMalleableC2 es Marcello Salvati
Twitter: @byt3bl33d3r, Github: @byt3bl33d3r
(Consulte la carpeta examples para más)
Generar el AST para un perfil Malleable C2 ubicado en un archivo, luego reconstruir el código fuente a partir del AST:
from malleablec2 import Profile
# Parse a profile given its path
p = Profile.from_file("amazon.profile")
# Print the generated AST
print(p.ast.pretty())
# Reconstruct source code from the AST and print to console
print(p.reconstruct())
# Shortcut for the above :)
print(p)
Generar el AST para un perfil Malleable C2 'inline' y luego reconstruir el código fuente a partir del 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 string
p = Profile.from_string(code)
# Print the generated AST
print(p.ast.pretty())
# Reconstruct source code from the AST and print to console
print(p)
Construir un perfil Malleable C2 programáticamente desde cero:
from malleablec2 import Profile
from malleablec2.components import *
# Create an empty profile
p = Profile.from_scratch()
# Set some global options
p.set_option("sleeptime", "0")
p.set_option("jitter", "0")
p.set_option("pipename", "mojo__##")
# Create an http-get block
http_get = HttpGetBlock()
# Set the uri http-get option
http_get.set_option("uri", "/wat/a/tease")
# Create a client block
client = ClientBlock()
# Add a header statement to the client block
client.add_statement("header", "Accept", "*/*")
# Create a server block
server = ServerBlock()
# Add the client and server blocks to the http-get block
http_get.add_code_block(client)
http_get.add_code_block(server)
# Create a http-post block
http_post = HttpPostBlock()
# Set the uri http-post option
http_post.set_option("uri", "/wat/ucraycray")
# Add the http-get and http-post blocks to the profile
p.add_code_block(http_get)
p.add_code_block(http_post)
# Reconstruct source code from the generated AST and print to console
print(p)
Ejemplo súper simple que muestra cómo aleatorizar programáticamente un perfil Malleable C2:
from malleablec2 import Profile
from malleablec2.randomizer import ProfileRandomizer
from lark import Token
class MyRandomizer(ProfileRandomizer):
# We implement the global_option_set method which will get called on every parsed global option statement in the profile
def global_option_set(self, tree):
option_name = tree.children[0]
if option_name == "pipename":
# "Randomize" the pipename value
tree.children[1].children[0] = Token('ESCAPED_STRING', '"my_random_pipename_##"')
# Parse a profile given its path
p = Profile.from_file("amazon.profile")
r = MyRandomizer()
# Walk through the generated profile AST and apply randomization rules
r.randomize(p)
# Reconstruct source code then output the profile to the console
print(p)