# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['malleablec2']

package_data = \
{'': ['*']}

install_requires = \
['lark-parser>=0.11.1,<0.12.0']

setup_kwargs = {
    'name': 'pymalleablec2',
    'version': '0.1.0',
    'description': 'Python library that allows you to parse and build Cobalt Strike Malleable C2 Profiles programmatically.',
    'long_description': '<p align="center">\n  <img src="https://user-images.githubusercontent.com/5151193/110083243-b3f30700-7d4b-11eb-8b69-28116e5ea1c9.png" alt="pyMalleableC2" height=300 width=500/>\n</p>\n\n# pyMalleableC2\n\nA Python interpreter for Cobalt Strike Malleable C2 profiles that allows you to parse, modify, build them programmatically and validate syntax.\n\nSupports all of the Cobalt Strike Malleable C2 Profile grammar starting from Cobalt Strike version 4.3. \n\n**It\'s not backwards compatible with previous Cobalt Strike releases.**\n\nWhat are the differences between pyMalleableC2 and other projects of this nature? \n\n1. Parses profiles with [Lark](https://github.com/lark-parser/lark) using [eBNF notation](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form). This approach is a lot more robust then user defined regexes, templating engines or similar methods.\n2. Turns profiles into an [Abstract Syntax Tree (AST)](https://en.wikipedia.org/wiki/Abstract_syntax_tree) which can then be reconstructed back into source code.\n3. Because of the above, pyMalleableC2 allows you to build profiles programmatically or modify them on the fly.\n4. Allows you to validate the syntax of Malleable C2 profiles (Does not perform runtime checks, see the warning below.)\n5. It has AI in the form of a lot of `if` statements.\n\n# Sponsors\n[<img src="https://www.blackhillsinfosec.com/wp-content/uploads/2016/03/BHIS-logo-L-300x300.png" width="130" height="130"/>](https://www.blackhillsinfosec.com/)\n[<img src="https://handbook.volkis.com.au/assets/img/Volkis_Logo_Brandpack.svg" width="130" hspace="10"/>](https://volkis.com.au)\n[<img src="https://user-images.githubusercontent.com/5151193/85817125-875e0880-b743-11ea-83e9-764cd55a29c5.png" width="200" vspace="21"/>](https://qomplx.com/blog/cyber/)\n[<img src="https://user-images.githubusercontent.com/5151193/86521020-9f0f4e00-be21-11ea-9256-836bc28e9d14.png" width="250" hspace="20"/>](https://ledgerops.com)\n[<img src="https://user-images.githubusercontent.com/5151193/95542303-a27f1c00-09b2-11eb-8682-e10b3e0f0710.jpg" width="200" hspace="20"/>](https://lostrabbitlabs.com/)\n[<img src="https://user-images.githubusercontent.com/5151193/113820904-334f6e00-9730-11eb-9f26-128b0917f5c6.png" width="150" height="150" hspace="20"/>](https://kovert.no/)\n[<img src="https://user-images.githubusercontent.com/5151193/113820971-4c581f00-9730-11eb-91d6-01fe1e72f556.jpg" width="250" hspace="20"/>](https://www.ondefend.com/)\n\n# Table of Contents\n\n* [pyMalleableC2](#utinni)\n  + [Installing](#installing)\n  + [🚨 Warning! No runtime checks (yet!) 🚨](#-warning-)\n  + [Author](#author)\n  + [Official Discord Channel](#official-discord-channel)\n  + [Examples](#examples)\n  + [FAQ](#faq)\n\n# Installing\n\npyMalleableC2 was built using Python 3.9, however it should be backwards compatible up to Python 3.6.\n\nInstall using Pip:\n- `pip3 install pymalleablec2`\n\n# 🚨 WARNING 🚨\n\n**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 through [c2lint](https://www.cobaltstrike.com/help-malleable-c2) before using them in production!**\n\n(Technically you could build a Python version of c2lint using this library, *\\*cough\\** PRs welcome *\\*cough\\**)\n\n## Author \n\nThe primary author of pyMalleableC2 is Marcello Salvati \n\nTwitter: [@byt3bl33d3r](https://twitter.com/byt3bl33d3r), Github: [@byt3bl33d3r](https://github.com/byt3bl33d3r)\n\n## Official Discord Channel\n\nCome hang out on Discord!\n\n[![Porchetta Industries](https://discordapp.com/api/guilds/736724457258745996/widget.png?style=banner3)](https://discord.gg/AKrqt6J)\n\n## Examples\n\n(See the [examples](https://github.com/Porchetta-Industries/pyMalleableC2/tree/main/examples) folder for more)\n\nGenerate the AST for a Malleable C2 Profile located in a file, then reconstruct the source code from the AST:\n\n```python\nfrom malleablec2 import Profile\n\n# Parse a profile given its path\np = Profile.from_file("amazon.profile")\n\n# Print the generated AST\nprint(p.ast.pretty())\n\n# Reconstruct source code from the AST and print to console\nprint(p.reconstruct())\n\n# Shortcut for the above :)\nprint(p)\n```\n\nGenerate the AST for an \'inline\' Malleable C2 Profile then reconstruct the source code from the AST:\n\n```python\ncode = \'\'\'\nset jitter "0";\nset sleeptime "3000";\n\nhttp-get {\n    set uri "/wow/this/is/cool";\n}\n\nhttp-post {\n    set uri "/pymalleablec2/is/the/shit";\n}\n\'\'\'\n\n# Parse a profile from a string\np = Profile.from_string(code)\n\n# Print the generated AST\nprint(p.ast.pretty())\n\n# Reconstruct source code from the AST and print to console\nprint(p)\n```\n\nBuild a Malleable C2 profile programmatically from scratch:\n\n```python\nfrom malleablec2 import Profile\nfrom malleablec2.components import *\n\n# Create an empty profile\np = Profile.from_scratch()\n\n# Set some global options\np.set_option("sleeptime", "0")\np.set_option("jitter", "0")\np.set_option("pipename", "mojo__##")\n\n# Create an http-get block\nhttp_get = HttpGetBlock()\n# Set the uri http-get option\nhttp_get.set_option("uri", "/wat/a/tease")\n\n# Create a client block\nclient = ClientBlock()\n# Add a header statement to the client block\nclient.add_statement("header", "Accept", "*/*")\n\n# Create a server block\nserver = ServerBlock()\n\n# Add the client and server blocks to the http-get block\nhttp_get.add_code_block(client)\nhttp_get.add_code_block(server)\n\n# Create a http-post block\nhttp_post = HttpPostBlock()\n# Set the uri http-post option\nhttp_post.set_option("uri", "/wat/ucraycray")\n\n# Add the http-get and http-post blocks to the profile\np.add_code_block(http_get)\np.add_code_block(http_post)\n\n# Reconstruct source code from the generated AST and print to console\nprint(p)\n```\n\nSuper simple example showing how to programmatically randomize a Malleable C2 Profile:\n\n```python\nfrom malleablec2 import Profile\nfrom malleablec2.randomizer import ProfileRandomizer\nfrom lark import Token\n\nclass MyRandomizer(ProfileRandomizer):\n\n    # We implement the global_option_set method which will get called on every parsed global option statement in the profile\n    def global_option_set(self, tree):\n        option_name = tree.children[0]\n\n        if option_name == "pipename":\n            # "Randomize" the pipename value\n            tree.children[1].children[0] = Token(\'ESCAPED_STRING\', \'"my_random_pipename_##"\')\n\n# Parse a profile given its path\np = Profile.from_file("amazon.profile")\n\nr = MyRandomizer()\n\n# Walk through the generated profile AST and apply randomization rules\nr.randomize(p)\n\n# Reconstruct source code then output the profile to the console\nprint(p)\n```\n',
    'author': 'Marcello Salvati',
    'author_email': 'marcello@porchetta.industries',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/Porchetta-Industries/pyMalleableC2',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
