├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── examples ├── builder.py ├── parser.py ├── randomizer.py └── urlgrep.py ├── malleablec2 ├── __init__.py ├── components.py ├── grammar.lark └── randomizer.py ├── poetry.lock ├── pyproject.toml ├── requirements-dev.txt ├── requirements.txt └── tests ├── __init__.py ├── profiles ├── amazon.profile ├── reference.profile └── template.profile ├── test_builder.py └── test_parser.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: byt3bl33d3r -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vscode 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | share/python-wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | MANIFEST 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .nox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | *.py,cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | cover/ 55 | 56 | # Translations 57 | *.mo 58 | *.pot 59 | 60 | # Django stuff: 61 | *.log 62 | local_settings.py 63 | db.sqlite3 64 | db.sqlite3-journal 65 | 66 | # Flask stuff: 67 | instance/ 68 | .webassets-cache 69 | 70 | # Scrapy stuff: 71 | .scrapy 72 | 73 | # Sphinx documentation 74 | docs/_build/ 75 | 76 | # PyBuilder 77 | .pybuilder/ 78 | target/ 79 | 80 | # Jupyter Notebook 81 | .ipynb_checkpoints 82 | 83 | # IPython 84 | profile_default/ 85 | ipython_config.py 86 | 87 | # pyenv 88 | # For a library or package, you might want to ignore these files since the code is 89 | # intended to run in multiple environments; otherwise, check them in: 90 | # .python-version 91 | 92 | # pipenv 93 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 94 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 95 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 96 | # install all needed dependencies. 97 | #Pipfile.lock 98 | 99 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 100 | __pypackages__/ 101 | 102 | # Celery stuff 103 | celerybeat-schedule 104 | celerybeat.pid 105 | 106 | # SageMath parsed files 107 | *.sage.py 108 | 109 | # Environments 110 | .env 111 | .venv 112 | env/ 113 | venv/ 114 | ENV/ 115 | env.bak/ 116 | venv.bak/ 117 | 118 | # Spyder project settings 119 | .spyderproject 120 | .spyproject 121 | 122 | # Rope project settings 123 | .ropeproject 124 | 125 | # mkdocs documentation 126 | /site 127 | 128 | # mypy 129 | .mypy_cache/ 130 | .dmypy.json 131 | dmypy.json 132 | 133 | # Pyre type checker 134 | .pyre/ 135 | 136 | # pytype static type analyzer 137 | .pytype/ 138 | 139 | # Cython debug symbols 140 | cython_debug/ 141 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: tests 2 | 3 | default: build 4 | 5 | clean: 6 | rm -f -r build/ 7 | rm -f -r bin/ 8 | rm -f -r dist/ 9 | find . -name '*.pyc' -exec rm -f {} + 10 | find . -name '*.pyo' -exec rm -f {} + 11 | find . -name '*~' -exec rm -f {} + 12 | find . -name '__pycache__' -exec rm -rf {} + 13 | find . -name '.pytest_cache' -exec rm -rf {} + 14 | 15 | tests: 16 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 17 | pytest 18 | 19 | requirements: 20 | poetry export -f requirements.txt -o requirements.txt 21 | poetry export --dev -f requirements.txt -o requirements-dev.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | pyMalleableC2 3 |

4 | 5 | # pyMalleableC2 6 | 7 | A Python interpreter for Cobalt Strike Malleable C2 profiles that allows you to parse, modify, build them programmatically and validate syntax. 8 | 9 | Supports all of the Cobalt Strike Malleable C2 Profile grammar starting from Cobalt Strike version 4.3. 10 | 11 | **It's not backwards compatible with previous Cobalt Strike releases.** 12 | 13 | What are the differences between pyMalleableC2 and other projects of this nature? 14 | 15 | 1. 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. 16 | 2. 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. 17 | 3. Because of the above, pyMalleableC2 allows you to build profiles programmatically or modify them on the fly. 18 | 4. Allows you to validate the syntax of Malleable C2 profiles (Does not perform runtime checks, see the warning below.) 19 | 5. It has AI in the form of a lot of `if` statements. 20 | 21 | # Table of Contents 22 | 23 | * [pyMalleableC2](#utinni) 24 | + [Installing](#installing) 25 | + [🚨 Warning! No runtime checks (yet!) 🚨](#-warning-) 26 | + [Author](#author) 27 | + [Official Discord Channel](#official-discord-channel) 28 | + [Examples](#examples) 29 | + [FAQ](#faq) 30 | 31 | # Installing 32 | 33 | pyMalleableC2 was built using Python 3.9, however it should be backwards compatible up to Python 3.6. 34 | 35 | Install using Pip: 36 | - `pip3 install pymalleablec2` 37 | 38 | # 🚨 WARNING 🚨 39 | 40 | **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!** 41 | 42 | (Technically you could build a Python version of c2lint using this library, *\*cough\** PRs welcome *\*cough\**) 43 | 44 | ## Author 45 | 46 | The primary author of pyMalleableC2 is Marcello Salvati 47 | 48 | Twitter: [@byt3bl33d3r](https://twitter.com/byt3bl33d3r), Github: [@byt3bl33d3r](https://github.com/byt3bl33d3r) 49 | 50 | ## Examples 51 | 52 | (See the [examples](https://github.com/Porchetta-Industries/pyMalleableC2/tree/main/examples) folder for more) 53 | 54 | Generate the AST for a Malleable C2 Profile located in a file, then reconstruct the source code from the AST: 55 | 56 | ```python 57 | from malleablec2 import Profile 58 | 59 | # Parse a profile given its path 60 | p = Profile.from_file("amazon.profile") 61 | 62 | # Print the generated AST 63 | print(p.ast.pretty()) 64 | 65 | # Reconstruct source code from the AST and print to console 66 | print(p.reconstruct()) 67 | 68 | # Shortcut for the above :) 69 | print(p) 70 | ``` 71 | 72 | Generate the AST for an 'inline' Malleable C2 Profile then reconstruct the source code from the AST: 73 | 74 | ```python 75 | code = ''' 76 | set jitter "0"; 77 | set sleeptime "3000"; 78 | 79 | http-get { 80 | set uri "/wow/this/is/cool"; 81 | } 82 | 83 | http-post { 84 | set uri "/pymalleablec2/is/the/shit"; 85 | } 86 | ''' 87 | 88 | # Parse a profile from a string 89 | p = Profile.from_string(code) 90 | 91 | # Print the generated AST 92 | print(p.ast.pretty()) 93 | 94 | # Reconstruct source code from the AST and print to console 95 | print(p) 96 | ``` 97 | 98 | Build a Malleable C2 profile programmatically from scratch: 99 | 100 | ```python 101 | from malleablec2 import Profile 102 | from malleablec2.components import * 103 | 104 | # Create an empty profile 105 | p = Profile.from_scratch() 106 | 107 | # Set some global options 108 | p.set_option("sleeptime", "0") 109 | p.set_option("jitter", "0") 110 | p.set_option("pipename", "mojo__##") 111 | 112 | # Create an http-get block 113 | http_get = HttpGetBlock() 114 | # Set the uri http-get option 115 | http_get.set_option("uri", "/wat/a/tease") 116 | 117 | # Create a client block 118 | client = ClientBlock() 119 | # Add a header statement to the client block 120 | client.add_statement("header", "Accept", "*/*") 121 | 122 | # Create a server block 123 | server = ServerBlock() 124 | 125 | # Add the client and server blocks to the http-get block 126 | http_get.add_code_block(client) 127 | http_get.add_code_block(server) 128 | 129 | # Create a http-post block 130 | http_post = HttpPostBlock() 131 | # Set the uri http-post option 132 | http_post.set_option("uri", "/wat/ucraycray") 133 | 134 | # Add the http-get and http-post blocks to the profile 135 | p.add_code_block(http_get) 136 | p.add_code_block(http_post) 137 | 138 | # Reconstruct source code from the generated AST and print to console 139 | print(p) 140 | ``` 141 | 142 | Super simple example showing how to programmatically randomize a Malleable C2 Profile: 143 | 144 | ```python 145 | from malleablec2 import Profile 146 | from malleablec2.randomizer import ProfileRandomizer 147 | from lark import Token 148 | 149 | class MyRandomizer(ProfileRandomizer): 150 | 151 | # We implement the global_option_set method which will get called on every parsed global option statement in the profile 152 | def global_option_set(self, tree): 153 | option_name = tree.children[0] 154 | 155 | if option_name == "pipename": 156 | # "Randomize" the pipename value 157 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"my_random_pipename_##"') 158 | 159 | # Parse a profile given its path 160 | p = Profile.from_file("amazon.profile") 161 | 162 | r = MyRandomizer() 163 | 164 | # Walk through the generated profile AST and apply randomization rules 165 | r.randomize(p) 166 | 167 | # Reconstruct source code then output the profile to the console 168 | print(p) 169 | ``` 170 | -------------------------------------------------------------------------------- /examples/builder.py: -------------------------------------------------------------------------------- 1 | from malleablec2 import Profile 2 | from malleablec2.components import * 3 | 4 | profile = Profile.from_scratch() 5 | profile.set_option("sleeptime", "5000") 6 | profile.set_option("jitter", "0") 7 | profile.set_option("pipename", "buildtest_##") 8 | 9 | http_config = HttpConfigBlock() 10 | http_config.set_option("headers", "Date, Server, Content-Length, Keep-Alive, Connection, Content-Type") 11 | http_config.set_option("block_useragents", "curl*,lynx*,wget*") 12 | http_config.add_statement("header", "Connection", "Keep-Alive") 13 | 14 | profile.add_code_block(http_config) 15 | 16 | dns_beacon = DnsBeaconBlock() 17 | dns_beacon.set_option("dns_idle", "1.2.3.4") 18 | dns_beacon.set_option("get_A", "doc.la.") 19 | 20 | profile.add_code_block(dns_beacon) 21 | 22 | http_get = HttpGetBlock() 23 | http_get.set_option("uri", "/test/wat") 24 | 25 | client = ClientBlock() 26 | client.add_statement("header", "Accept", "*/*") 27 | 28 | server = ServerBlock() 29 | server.add_statement("header", "Server", "Apache") 30 | 31 | http_get.add_code_block(client) 32 | http_get.add_code_block(server) 33 | 34 | http_post = HttpPostBlock() 35 | http_post.set_option("uri", "/test/okurrr") 36 | 37 | profile.add_code_block(http_get) 38 | profile.add_code_block(http_post) 39 | 40 | print(profile) -------------------------------------------------------------------------------- /examples/parser.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from malleablec2 import Profile 3 | 4 | p = Profile.from_file( 5 | sys.argv[1] 6 | if len(sys.argv) == 2 else 7 | "amazon.profile" 8 | ) 9 | 10 | print("++ Dumping AST\n") 11 | print(p.ast.pretty()) 12 | 13 | print('-------------------\n') 14 | 15 | print("++ Source Reconstructed from AST\n") 16 | print(p) # shortcut for p.reconstruct() -------------------------------------------------------------------------------- /examples/randomizer.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from malleablec2 import Profile 3 | from malleablec2.randomizer import ProfileRandomizer 4 | from lark import Token 5 | 6 | class MyExampleRandomizer(ProfileRandomizer): 7 | """ 8 | This shows you how to randomize a Malleable C2 profile. 9 | This example 'randomizes' certain values with the word 'wat'. Obviously implement your own logic to randomize the values to something useful. 10 | 11 | Subclassed methods get called based on the parsed AST tokens. 12 | E.g 'local_option_set' method will get called when a "set " statement in the profile is encountered. 13 | 14 | For a full list of tokens that you can subclass here see the grammar.lark file: you can generally subclass anything after the alias (->) statements. 15 | """ 16 | 17 | def local_option_set(self, tree): 18 | """ 19 | Randomize some common local options 20 | 21 | 'set uri' in http-get/post-blocks 22 | 'set uri_x86/uri_x64' in http-stager blocks 23 | 'set headers' in http-config block 24 | 'set pipename' in post-ex block 25 | 'set dns_stager_subhost' in dns-beacon blocks 26 | """ 27 | 28 | option_name = tree.children[0] 29 | 30 | if option_name in ["uri", "uri_x86", "uri_x64"]: 31 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"wat"') 32 | elif option_name == "pipename": 33 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"wat"') 34 | elif option_name == "headers": 35 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"wat"') 36 | elif option_name == "dns_stager_subhost": 37 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"wat"') 38 | 39 | def global_option_set(self, tree): 40 | """ 41 | Randomize some common global options 42 | """ 43 | option_name = tree.children[0] 44 | 45 | if option_name in ["pipename", "ssh_pipename", "pipename_stager"]: 46 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"wat"') 47 | elif option_name == "ssh_banner": 48 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"wat"') 49 | 50 | def header(self, tree): 51 | """ 52 | Randomize the header statements in http-get/http-post blocks 53 | """ 54 | 55 | if len(tree.children) == 3: 56 | tree.children[1].children[0] = Token('ESCAPED_STRING', '"wat"') 57 | 58 | def parameter(self, tree): 59 | """ 60 | Randomize the parameter statement in http-get/http-post blocks 61 | """ 62 | 63 | tree.children[0].children[0] = Token('ESCAPED_STRING', '"wat"') 64 | 65 | if __name__ == "__main__": 66 | p = Profile.from_file( 67 | sys.argv[1] 68 | if len(sys.argv) == 2 else 69 | "amazon.profile" 70 | ) 71 | 72 | r = MyExampleRandomizer() 73 | r.randomize(p) 74 | 75 | print(p) -------------------------------------------------------------------------------- /examples/urlgrep.py: -------------------------------------------------------------------------------- 1 | from malleablec2 import Profile 2 | 3 | def get_all_urls(items): 4 | collect_next_item = False 5 | for item in items: 6 | if collect_next_item: 7 | collect_next_item = False 8 | urls = set([url.strip() for url in item[1:-1].split()]) 9 | for url in urls: 10 | yield url + "\n" 11 | 12 | if isinstance(item, Token) and item.type in ["HTTP_LOCAL_OPTION", "HTTP_STAGER_LOCAL_OPTION"]: 13 | if item != "verb": 14 | collect_next_item = True 15 | continue 16 | 17 | if __name__ == "__main__": 18 | 19 | profile_code = ''' 20 | # Profile with all code blocks that are allowed to define a URL 21 | 22 | http-get { 23 | set uri "/wat/test"; 24 | } 25 | 26 | http-get "variant_get_1" { 27 | set uri "/wat/test/1"; 28 | } 29 | 30 | http-post { 31 | set uri "/test/okurrr"; 32 | } 33 | 34 | http-stage { 35 | set uri_x86 "/test/stager86"; 36 | set uri_x64 "/test/stager64"; 37 | } 38 | ''' 39 | 40 | p = Profile.from_string(profile_code) 41 | urls = p.reconstruct(postproc=get_all_urls) 42 | print(urls) 43 | -------------------------------------------------------------------------------- /malleablec2/__init__.py: -------------------------------------------------------------------------------- 1 | import pathlib 2 | import pkg_resources 3 | from lark import Lark, Tree, Token 4 | from lark.reconstruct import Reconstructor 5 | 6 | _grammar_file_path = pathlib.Path( 7 | pkg_resources.resource_filename(__name__, "grammar.lark") 8 | ) 9 | 10 | _lark_parser = Lark.open(_grammar_file_path, parser="lalr") # LALR parser is faster than the default one 11 | 12 | _reconstructor = Reconstructor(_lark_parser) 13 | 14 | class Profile: 15 | def __init__(self, ast): 16 | self.ast = ast 17 | 18 | @classmethod 19 | def from_scratch(cls): 20 | return cls( 21 | Tree("start", []) 22 | ) 23 | 24 | @classmethod 25 | def from_file(cls, profile_path): 26 | profile_path = pathlib.Path(profile_path) 27 | with profile_path.open() as profile: 28 | return cls( 29 | _lark_parser.parse(profile.read()) 30 | ) 31 | 32 | @classmethod 33 | def from_string(cls, profile_code): 34 | return cls(_lark_parser.parse(profile_code)) 35 | 36 | def set_option(self, option_name, value): 37 | tree = Tree('global_option_set', 38 | [ 39 | Token('GLOBAL_OPTION', option_name), 40 | Tree('string', 41 | [ 42 | Token('ESCAPED_STRING', f'"{value}"') 43 | ] 44 | ), 45 | Token('DELIM', ';') 46 | ] 47 | ) 48 | self.ast.children.append(tree) 49 | 50 | def add_code_block(self, tree): 51 | self.ast.children.append(tree.ast) 52 | 53 | def _postproc_indent(self, items): 54 | """ 55 | Lark doesn't preserve whitespaces and has no way of keeping track of them in the AST so you need to build your grammar accordingly if you need/want them. 56 | This function's sole purpose is to output 'pretty' source code with indentation/spacing so your eyes don't bleed when you try to read the reconstructed profile. 57 | """ 58 | stack = [] 59 | indent_char = " " 60 | indent_n = 0 61 | 62 | yield "# Automatically generated with pyMalleableC2\n" 63 | yield "# https://github.com/Porchetta-Industries/pyMalleableC2\n" 64 | yield "#\n" 65 | yield "# !!! Make sure to run this profile through c2lint before using !!!\n" 66 | yield "\n" 67 | 68 | for item in items: 69 | if isinstance(item, Token) and item.type == "BEGIN_CODE_BLOCK_DELIM": 70 | stack.append(" " + item + "\n") 71 | indent_n += 4 72 | 73 | elif isinstance(item, Token) and item.type == "END_CODE_BLOCK_DELIM": 74 | indent_n -= 4 75 | stack.append( (indent_char * indent_n) + item + "\n" ) 76 | 77 | elif isinstance(item, Token) and item.type == "DELIM": 78 | stack.append(item + "\n") 79 | 80 | elif isinstance(item, Token) and item.type == "ESCAPED_STRING": 81 | stack.append(" " + item) 82 | 83 | elif isinstance(item, Token) and item.type.endswith("LOCAL_OPTION"): 84 | stack.append(item) 85 | else: 86 | stack.append( (indent_char * indent_n) + item ) 87 | 88 | yield " ".join(stack) 89 | stack = [] 90 | 91 | def reconstruct(self, postproc=None): 92 | return _reconstructor.reconstruct( 93 | self.ast, 94 | postproc or self._postproc_indent 95 | ) 96 | 97 | def __str__(self): 98 | return self.reconstruct() 99 | -------------------------------------------------------------------------------- /malleablec2/components.py: -------------------------------------------------------------------------------- 1 | from lark import Token, Tree 2 | 3 | class CodeBlock: 4 | def set_option(self, name, value): 5 | if not hasattr(self, 'option_block_token') or not self.option_block_token: 6 | raise NotImplementedError 7 | 8 | tree = Tree('local_option_set', 9 | [Token(self.option_block_token, f'{name}'), Tree('string', [Token('ESCAPED_STRING', f'"{value}"')]), Token('DELIM', ';')] 10 | ) 11 | 12 | self.ast.children[0].children.insert(-1, tree) 13 | 14 | def add_statement(self, name, *values): 15 | tree = Tree(f'{name}', []) 16 | if values: 17 | inner_tree = [ 18 | Tree('string', [ Token('ESCAPED_STRING', f'"{value}"') ]) 19 | for value in values 20 | ] 21 | inner_tree.append(Token('DELIM', ';')) 22 | tree.children.extend(inner_tree) 23 | else: 24 | tree.children.append(Token('DELIM', ';')) 25 | 26 | self.ast.children[0].children.insert(-1, tree) 27 | 28 | def add_code_block(self, tree): 29 | self.ast.children[0].children.insert(-1, tree.ast) 30 | 31 | class HttpGetBlock(CodeBlock): 32 | def __init__(self, variant_name=None): 33 | self.option_block_token = 'HTTP_LOCAL_OPTION' 34 | self.ast = Tree("http_get", 35 | [ 36 | Tree(f"http_get_block", 37 | [ 38 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 39 | Token('END_CODE_BLOCK_DELIM', '}') 40 | ]) 41 | ]) 42 | 43 | if variant_name: 44 | self.ast.children[0].insert(0, 45 | Tree('string', 46 | [ Token('ESCAPED_STRING', f'"{variant_name}"')] 47 | ) 48 | ) 49 | 50 | class HttpPostBlock(CodeBlock): 51 | def __init__(self, variant_name=None): 52 | self.option_block_token = 'HTTP_LOCAL_OPTION' 53 | self.ast = Tree("http_post", 54 | [ 55 | Tree(f"http_post_block", 56 | [ 57 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 58 | Token('END_CODE_BLOCK_DELIM', '}') 59 | ]) 60 | ]) 61 | 62 | if variant_name: 63 | self.ast.children[0].insert(0, 64 | Tree('string', 65 | [ Token('ESCAPED_STRING', f'"{variant_name}"') ] 66 | ) 67 | ) 68 | 69 | class ClientBlock(CodeBlock): 70 | def __init__(self): 71 | self.ast = Tree('client', 72 | [ 73 | Tree('client_block', 74 | [ 75 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 76 | Token('END_CODE_BLOCK_DELIM', '}') 77 | ]) 78 | ]) 79 | 80 | class IdBlock(CodeBlock): 81 | def __init__(self): 82 | self.ast = Tree('id', 83 | [ 84 | Tree('id_block', 85 | [ 86 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 87 | Token('END_CODE_BLOCK_DELIM', '}') 88 | ]) 89 | ]) 90 | 91 | class DnsBeaconBlock(CodeBlock): 92 | def __init__(self): 93 | self.option_block_token = 'DNS_BEACON_LOCAL_OPTION' 94 | self.ast = Tree('dns_beacon', 95 | [ 96 | Tree('dns_beacon_block', 97 | [ 98 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 99 | Token('END_CODE_BLOCK_DELIM', '}') 100 | ]) 101 | ]) 102 | 103 | class OutputBlock(CodeBlock): 104 | def __init__(self): 105 | self.ast = Tree('output', 106 | [ 107 | Tree('output_block', 108 | [ 109 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 110 | Token('END_CODE_BLOCK_DELIM', '}') 111 | ]) 112 | ]) 113 | 114 | class MetadataBlock(CodeBlock): 115 | def __init__(self): 116 | self.ast = Tree('metadata', 117 | [ 118 | Tree('metadata_block', 119 | [ 120 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 121 | Token('END_CODE_BLOCK_DELIM', '}') 122 | ]) 123 | ]) 124 | 125 | class ServerBlock(CodeBlock): 126 | def __init__(self): 127 | self.ast = Tree('server', 128 | [ 129 | Tree('server_block', 130 | [ 131 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 132 | Token('END_CODE_BLOCK_DELIM', '}') 133 | ]) 134 | ]) 135 | 136 | class HttpConfigBlock(CodeBlock): 137 | def __init__(self): 138 | self.option_block_token = 'HTTP_CONFIG_LOCAL_OPTION' 139 | self.ast = Tree('http_config', 140 | [ 141 | Tree('http_config_block', 142 | [ 143 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 144 | Token('END_CODE_BLOCK_DELIM', '}') 145 | ]) 146 | ]) 147 | 148 | class ProcessInjectBlock(CodeBlock): 149 | def __init__(self): 150 | self.option_block_token = 'PROCESS_INJECT_LOCAL_OPTION' 151 | self.ast = Tree('process_inject', 152 | [ 153 | Tree('process_inject_block', 154 | [ 155 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 156 | Token('END_CODE_BLOCK_DELIM', '}') 157 | ]) 158 | ]) 159 | 160 | class Transform86Block(CodeBlock): 161 | def __init__(self): 162 | self.option_block_token = 'PROCESS_INJECT_LOCAL_OPTION' 163 | self.ast = Tree('transform_x86', 164 | [ 165 | Tree('transform_block', 166 | [ 167 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 168 | Token('END_CODE_BLOCK_DELIM', '}') 169 | ]) 170 | ]) 171 | 172 | class Transform64Block(CodeBlock): 173 | def __init__(self): 174 | self.option_block_token = 'PROCESS_INJECT_LOCAL_OPTION' 175 | self.ast = Tree('transform_x64', 176 | [ 177 | Tree('transform_block', 178 | [ 179 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 180 | Token('END_CODE_BLOCK_DELIM', '}') 181 | ]) 182 | ]) 183 | 184 | class ExecuteBlock(CodeBlock): 185 | def __init__(self): 186 | self.option_block_token = 'EXECUTE_STATEMENT_OPTION' 187 | self.ast = Tree('execute', 188 | [ 189 | Tree('execute_block', 190 | [ 191 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 192 | Token('END_CODE_BLOCK_DELIM', '}') 193 | ]) 194 | ]) 195 | 196 | def add_statement(self, name, *values): 197 | tree = Tree('execute_statement', []) 198 | 199 | children = [Token('EXECUTE_STATEMENT_OPTION', f'{name}')] 200 | if values: 201 | children.append( 202 | Tree('string', [Token('ESCAPED_STRING', f'"{values[0]}"')]) 203 | ) 204 | 205 | children.append(Token('DELIM', ';')) 206 | tree.children.extend(children) 207 | 208 | self.ast.children[0].children.insert(-1, tree) 209 | 210 | class PostExBlock(CodeBlock): 211 | def __init__(self): 212 | self.option_block_token = 'POST_EX_LOCAL_OPTION' 213 | self.ast = Tree('post_ex', 214 | [ 215 | Tree('post_ex_block', 216 | [ 217 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 218 | Token('END_CODE_BLOCK_DELIM', '}') 219 | ]) 220 | ]) 221 | 222 | class HttpStagerBlock(CodeBlock): 223 | def __init__(self): 224 | self.option_block_token = 'HTTP_STAGER_LOCAL_OPTION' 225 | self.ast = Tree('http_stager', 226 | [ 227 | Tree('http_stager_block', 228 | [ 229 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 230 | Token('END_CODE_BLOCK_DELIM', '}') 231 | ]) 232 | ]) 233 | 234 | class StageBlock(CodeBlock): 235 | def __init__(self): 236 | self.option_block_token = 'STAGE_LOCAL_OPTION' 237 | self.ast = Tree('stage', 238 | [ 239 | Tree('stage_block', 240 | [ 241 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 242 | Token('END_CODE_BLOCK_DELIM', '}') 243 | ]) 244 | ]) 245 | 246 | class CodeSignerBlock(CodeBlock): 247 | def __init__(self): 248 | self.option_block_token = 'CODE_SIGNER_LOCAL_OPTION' 249 | self.ast = Tree('code_signer', 250 | [ 251 | Tree('code_signer_block', 252 | [ 253 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 254 | Token('END_CODE_BLOCK_DELIM', '}') 255 | ]) 256 | ]) 257 | 258 | class HttpsCertificateBlock(CodeBlock): 259 | def __init__(self): 260 | self.option_block_token = 'HTTPS_CERTIFICATE_LOCAL_OPTION' 261 | self.ast = Tree('https_certificate', 262 | [ 263 | Tree('https_certificate_block', 264 | [ 265 | Token('BEGIN_CODE_BLOCK_DELIM', '{'), 266 | Token('END_CODE_BLOCK_DELIM', '}') 267 | ]) 268 | ]) 269 | -------------------------------------------------------------------------------- /malleablec2/grammar.lark: -------------------------------------------------------------------------------- 1 | // Only compatible with Malleable C2's starting from Cobalt Strike >= 4.3 2 | 3 | // This is the grammar definition, we technically wouldn't need the *DELIM terminals as 4 | // the malleable c2 language isn't space sensitive, however, this allows us to reconstruct source code 5 | // from the AST preserving indentation which makes the output'ed code a lot more perty 6 | 7 | start: value+ 8 | 9 | // transform-x86 & transform-x64 10 | transform_statement: "prepend" string DELIM -> prepend 11 | | "append" string DELIM -> append 12 | | "strrep" string string DELIM -> strrep 13 | 14 | transform_block: BEGIN_CODE_BLOCK_DELIM transform_statement+ END_CODE_BLOCK_DELIM 15 | 16 | // data transform statements 17 | data_transform: "append" string DELIM -> append 18 | | "base64" DELIM -> base64 19 | | "base64url" DELIM -> base64url 20 | | "mask" DELIM -> mask 21 | | "netbios" DELIM -> netbios 22 | | "netbiosu" DELIM -> netbiosu 23 | | "prepend" string DELIM -> prepend 24 | // Termination Statements 25 | | "header" string DELIM -> header 26 | | "parameter" string DELIM -> parameter 27 | | "print" DELIM -> print 28 | | "uri-append" DELIM -> uri_append 29 | 30 | // metadata 31 | metadata_block: BEGIN_CODE_BLOCK_DELIM data_transform+ END_CODE_BLOCK_DELIM 32 | 33 | // output 34 | output_block: BEGIN_CODE_BLOCK_DELIM data_transform+ END_CODE_BLOCK_DELIM 35 | 36 | // id 37 | id_block: BEGIN_CODE_BLOCK_DELIM data_transform+ END_CODE_BLOCK_DELIM 38 | 39 | // server 40 | server_statement: "header" string string DELIM -> header 41 | | "output" output_block -> output 42 | 43 | server_block: BEGIN_CODE_BLOCK_DELIM server_statement+ END_CODE_BLOCK_DELIM 44 | 45 | // http-post { client {} } 46 | post_client_statement: "header" string string DELIM -> header 47 | | "parameter" string string DELIM -> parameter 48 | | "id" id_block -> id 49 | | "output" output_block -> output 50 | 51 | post_client_block: BEGIN_CODE_BLOCK_DELIM post_client_statement+ END_CODE_BLOCK_DELIM -> client_block 52 | 53 | // http-post 54 | http_post_statement: "set" HTTP_LOCAL_OPTION string DELIM -> local_option_set 55 | | "client" post_client_block -> client 56 | | "server" server_block -> server 57 | 58 | http_post_block: BEGIN_CODE_BLOCK_DELIM http_post_statement+ END_CODE_BLOCK_DELIM 59 | 60 | // http-get { client {} } 61 | get_client_statement: "header" string string DELIM -> header 62 | | "parameter" string string DELIM -> parameter 63 | | "metadata" metadata_block -> metadata 64 | 65 | get_client_block: BEGIN_CODE_BLOCK_DELIM get_client_statement+ END_CODE_BLOCK_DELIM -> client_block 66 | 67 | // http-get 68 | http_get_statement: "set" HTTP_LOCAL_OPTION string DELIM -> local_option_set 69 | | "client" get_client_block -> client 70 | | "server" server_block -> server 71 | 72 | http_get_block: BEGIN_CODE_BLOCK_DELIM http_get_statement+ END_CODE_BLOCK_DELIM 73 | 74 | //dns-beacon 75 | dns_beacon_statement: "set" DNS_BEACON_LOCAL_OPTION string DELIM -> local_option_set 76 | 77 | dns_beacon_block: BEGIN_CODE_BLOCK_DELIM dns_beacon_statement+ END_CODE_BLOCK_DELIM 78 | 79 | // http-config 80 | http_config_statement: "set" HTTP_CONFIG_LOCAL_OPTION string DELIM -> local_option_set 81 | | "header" string string DELIM -> header 82 | 83 | http_config_block: BEGIN_CODE_BLOCK_DELIM http_config_statement+ END_CODE_BLOCK_DELIM 84 | 85 | // https-certificate 86 | https_certificate_statement: "set" HTTPS_CERTIFICATE_LOCAL_OPTION string DELIM -> local_option_set 87 | 88 | https_certificate_block: BEGIN_CODE_BLOCK_DELIM https_certificate_statement+ END_CODE_BLOCK_DELIM 89 | 90 | // http-stager 91 | http_stager_data_transform: "prepend" string DELIM -> prepend 92 | | "append" string DELIM -> append 93 | | "print" DELIM -> print 94 | 95 | http_stager_output_block: BEGIN_CODE_BLOCK_DELIM http_stager_data_transform+ END_CODE_BLOCK_DELIM 96 | 97 | http_stager_client_block_statement: "parameter" string string DELIM -> parameter 98 | | "header" string string DELIM -> header 99 | 100 | http_stager_client_block: BEGIN_CODE_BLOCK_DELIM http_stager_client_block_statement+ END_CODE_BLOCK_DELIM 101 | 102 | http_stager_server_block_statement: "parameter" string string DELIM -> parameter 103 | | "header" string string DELIM -> header 104 | | "output" http_stager_output_block -> output 105 | 106 | http_stager_server_block: BEGIN_CODE_BLOCK_DELIM http_stager_server_block_statement+ END_CODE_BLOCK_DELIM 107 | 108 | http_stager_statement: "set" HTTP_STAGER_LOCAL_OPTION string DELIM -> local_option_set 109 | | "client" http_stager_client_block -> client 110 | | "server" http_stager_server_block -> server 111 | 112 | http_stager_block: BEGIN_CODE_BLOCK_DELIM http_stager_statement+ END_CODE_BLOCK_DELIM 113 | 114 | // code-signer 115 | code_signer_statement: "set" CODE_SIGNER_LOCAL_OPTION string DELIM -> local_option_set 116 | 117 | code_signer_block: BEGIN_CODE_BLOCK_DELIM code_signer_statement+ END_CODE_BLOCK_DELIM 118 | 119 | // stage 120 | stage_statement: "set" STAGE_LOCAL_OPTION string DELIM -> local_option_set 121 | | "transform-x86" transform_block -> transform_x86 122 | | "transform-x64" transform_block -> transform_x64 123 | | "stringw" string DELIM -> stringw 124 | | "string" string DELIM -> string 125 | | "data" string DELIM -> data 126 | 127 | stage_block: BEGIN_CODE_BLOCK_DELIM stage_statement+ END_CODE_BLOCK_DELIM 128 | 129 | // process-inject 130 | execute_statement: EXECUTE_STATEMENT_OPTION [string] DELIM 131 | 132 | execute_block: BEGIN_CODE_BLOCK_DELIM execute_statement+ END_CODE_BLOCK_DELIM 133 | 134 | process_inject_statement: "set" PROCESS_INJECT_LOCAL_OPTION string DELIM -> local_option_set 135 | | "transform-x86" transform_block -> transform_x86 136 | | "transform-x64" transform_block -> transform_x64 137 | | "execute" execute_block -> execute 138 | 139 | process_inject_block: BEGIN_CODE_BLOCK_DELIM process_inject_statement+ END_CODE_BLOCK_DELIM 140 | 141 | // post-ex 142 | post_ex_statement: "set" POST_EX_LOCAL_OPTION string DELIM -> local_option_set 143 | 144 | post_ex_block: BEGIN_CODE_BLOCK_DELIM post_ex_statement+ END_CODE_BLOCK_DELIM 145 | 146 | // Profile grammar 147 | ?value: "set" GLOBAL_OPTION string DELIM -> global_option_set 148 | | "http-get" [string] http_get_block -> http_get 149 | | "http-post" [string] http_post_block -> http_post 150 | | "http-config" http_config_block -> http_config 151 | | "https-certificate" [string] https_certificate_block -> https_certificate 152 | | "http-stager" [string] http_stager_block -> http_stager 153 | | "code-signer" code_signer_block -> code_signer 154 | | "stage" stage_block -> stage 155 | | "process-inject" process_inject_block -> process_inject 156 | | "post-ex" post_ex_block -> post_ex 157 | | "dns-beacon" dns_beacon_block -> dns_beacon 158 | 159 | COMMENT: /#.*/ 160 | 161 | DELIM: ";" 162 | 163 | BEGIN_CODE_BLOCK_DELIM: "{" 164 | END_CODE_BLOCK_DELIM: "}" 165 | 166 | HTTP_LOCAL_OPTION: ("uri"|"verb") 167 | HTTP_CONFIG_LOCAL_OPTION: ("headers"|"trust_x_forwarded_for"|"block_useragents") 168 | HTTP_STAGER_LOCAL_OPTION: ("uri_x86"|"uri_x64") 169 | 170 | HTTPS_CERTIFICATE_LOCAL_OPTION: "CN" 171 | | "C" 172 | | "L" 173 | | "OU" 174 | | "O" 175 | | "ST" 176 | | "validity" 177 | | "keystore" 178 | | "password" 179 | 180 | STAGE_LOCAL_OPTION: "allocator" 181 | | "cleanup" 182 | | "magic_mz_x86" 183 | | "magic_mz_x64" 184 | | "magic_pe" 185 | | "module_x64" 186 | | "module_x86" 187 | | "obfuscate" 188 | | "sleep_mask" 189 | | "smartinject" 190 | | "userwx" 191 | | "stomppe" 192 | | "syscall_method" 193 | // Options generated by peclone 194 | | "checksum" 195 | | "compile_time" 196 | | "entry_point" 197 | | "image_size_x64" 198 | | "image_size_x86" 199 | | "name" 200 | | "rich_header" 201 | 202 | EXECUTE_STATEMENT_OPTION: "CreateThread" 203 | | "CreateRemoteThread" 204 | | "NtQueueApcThread-s" 205 | | "NtQueueApcThread" 206 | | "RtlCreateUserThread" 207 | | "SetThreadContext" 208 | 209 | PROCESS_INJECT_LOCAL_OPTION: "allocator" 210 | | "bof_allocator" 211 | | "bof_reuse_memory" 212 | | "min_alloc" 213 | | "startrwx" 214 | | "userwx" 215 | 216 | POST_EX_LOCAL_OPTION: "spawnto_x86" 217 | | "spawnto_x64" 218 | | "obfuscate" 219 | | "pipename" 220 | | "smartinject" 221 | | "thread_hint" 222 | | "amsi_disable" 223 | | "keylogger" 224 | | "cleanup" 225 | 226 | CODE_SIGNER_LOCAL_OPTION: "alias" 227 | | "digest_algorithm" 228 | | "keystore" 229 | | "password" 230 | | "timestamp_url" 231 | | "timestamp" 232 | 233 | DNS_BEACON_LOCAL_OPTION: "dns_idle" 234 | | "dns_max_txt" 235 | | "dns_sleep" 236 | | "dns_ttl" 237 | | "maxdns" 238 | | "dns_stager_prepend" 239 | | "dns_stager_subhost" 240 | // Options added in 4.3 241 | | "beacon" 242 | | "get_AAAA" 243 | | "get_A" 244 | | "get_TXT" 245 | | "put_metadata" 246 | | "put_output" 247 | | "ns_response" 248 | 249 | GLOBAL_OPTION: "data_jitter" 250 | | "headers_remove" 251 | | "host_stage" 252 | | "jitter" 253 | | "pipename_stager" 254 | | "pipename" 255 | | "sample_name" 256 | | "sleeptime" 257 | | "smb_frame_header" 258 | | "ssh_banner" 259 | | "ssh_pipename" 260 | | "steal_token_access_mask" 261 | | "tasks_max_size" 262 | | "tasks_proxy_max_size" 263 | | "tasks_dns_proxy_max_size" 264 | | "tcp_frame_header" 265 | | "tcp_port" 266 | | "useragent" 267 | 268 | string: ESCAPED_STRING 269 | %import common.ESCAPED_STRING 270 | %import common.WS 271 | %ignore COMMENT 272 | %ignore WS 273 | -------------------------------------------------------------------------------- /malleablec2/randomizer.py: -------------------------------------------------------------------------------- 1 | from malleablec2 import Profile 2 | from lark import Visitor, Tree 3 | from typing import Union 4 | 5 | class ProfileRandomizer(Visitor): 6 | def visit(self, profile_or_tree: Union[Profile, Tree]): 7 | if isinstance(profile_or_tree, Profile) and hasattr(profile_or_tree, "ast"): 8 | return super().visit(profile_or_tree.ast) 9 | 10 | return super().visit(profile_or_tree) 11 | 12 | def randomize(self, profile: Profile): 13 | return self.visit(profile) -------------------------------------------------------------------------------- /poetry.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "appdirs" 3 | version = "1.4.4" 4 | description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." 5 | category = "dev" 6 | optional = false 7 | python-versions = "*" 8 | 9 | [[package]] 10 | name = "atomicwrites" 11 | version = "1.4.0" 12 | description = "Atomic file writes." 13 | category = "dev" 14 | optional = false 15 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 16 | 17 | [[package]] 18 | name = "attrs" 19 | version = "20.3.0" 20 | description = "Classes Without Boilerplate" 21 | category = "dev" 22 | optional = false 23 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 24 | 25 | [package.extras] 26 | dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "furo", "sphinx", "pre-commit"] 27 | docs = ["furo", "sphinx", "zope.interface"] 28 | tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"] 29 | tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six"] 30 | 31 | [[package]] 32 | name = "black" 33 | version = "20.8b1" 34 | description = "The uncompromising code formatter." 35 | category = "dev" 36 | optional = false 37 | python-versions = ">=3.6" 38 | 39 | [package.dependencies] 40 | appdirs = "*" 41 | click = ">=7.1.2" 42 | dataclasses = {version = ">=0.6", markers = "python_version < \"3.7\""} 43 | mypy-extensions = ">=0.4.3" 44 | pathspec = ">=0.6,<1" 45 | regex = ">=2020.1.8" 46 | toml = ">=0.10.1" 47 | typed-ast = ">=1.4.0" 48 | typing-extensions = ">=3.7.4" 49 | 50 | [package.extras] 51 | colorama = ["colorama (>=0.4.3)"] 52 | d = ["aiohttp (>=3.3.2)", "aiohttp-cors"] 53 | 54 | [[package]] 55 | name = "click" 56 | version = "7.1.2" 57 | description = "Composable command line interface toolkit" 58 | category = "dev" 59 | optional = false 60 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" 61 | 62 | [[package]] 63 | name = "colorama" 64 | version = "0.4.4" 65 | description = "Cross-platform colored terminal text." 66 | category = "dev" 67 | optional = false 68 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" 69 | 70 | [[package]] 71 | name = "dataclasses" 72 | version = "0.8" 73 | description = "A backport of the dataclasses module for Python 3.6" 74 | category = "dev" 75 | optional = false 76 | python-versions = ">=3.6, <3.7" 77 | 78 | [[package]] 79 | name = "flake8" 80 | version = "3.8.4" 81 | description = "the modular source code checker: pep8 pyflakes and co" 82 | category = "dev" 83 | optional = false 84 | python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" 85 | 86 | [package.dependencies] 87 | importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} 88 | mccabe = ">=0.6.0,<0.7.0" 89 | pycodestyle = ">=2.6.0a1,<2.7.0" 90 | pyflakes = ">=2.2.0,<2.3.0" 91 | 92 | [[package]] 93 | name = "importlib-metadata" 94 | version = "3.4.0" 95 | description = "Read metadata from Python packages" 96 | category = "dev" 97 | optional = false 98 | python-versions = ">=3.6" 99 | 100 | [package.dependencies] 101 | typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} 102 | zipp = ">=0.5" 103 | 104 | [package.extras] 105 | docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] 106 | testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "pytest-enabler", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] 107 | 108 | [[package]] 109 | name = "iniconfig" 110 | version = "1.1.1" 111 | description = "iniconfig: brain-dead simple config-ini parsing" 112 | category = "dev" 113 | optional = false 114 | python-versions = "*" 115 | 116 | [[package]] 117 | name = "lark-parser" 118 | version = "0.11.1" 119 | description = "a modern parsing library" 120 | category = "main" 121 | optional = false 122 | python-versions = "*" 123 | 124 | [package.extras] 125 | nearley = ["js2py"] 126 | regex = ["regex"] 127 | 128 | [[package]] 129 | name = "mccabe" 130 | version = "0.6.1" 131 | description = "McCabe checker, plugin for flake8" 132 | category = "dev" 133 | optional = false 134 | python-versions = "*" 135 | 136 | [[package]] 137 | name = "mypy-extensions" 138 | version = "0.4.3" 139 | description = "Experimental type system extensions for programs checked with the mypy typechecker." 140 | category = "dev" 141 | optional = false 142 | python-versions = "*" 143 | 144 | [[package]] 145 | name = "packaging" 146 | version = "20.9" 147 | description = "Core utilities for Python packages" 148 | category = "dev" 149 | optional = false 150 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 151 | 152 | [package.dependencies] 153 | pyparsing = ">=2.0.2" 154 | 155 | [[package]] 156 | name = "pathspec" 157 | version = "0.8.1" 158 | description = "Utility library for gitignore style pattern matching of file paths." 159 | category = "dev" 160 | optional = false 161 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" 162 | 163 | [[package]] 164 | name = "pluggy" 165 | version = "0.13.1" 166 | description = "plugin and hook calling mechanisms for python" 167 | category = "dev" 168 | optional = false 169 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 170 | 171 | [package.dependencies] 172 | importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} 173 | 174 | [package.extras] 175 | dev = ["pre-commit", "tox"] 176 | 177 | [[package]] 178 | name = "py" 179 | version = "1.10.0" 180 | description = "library with cross-python path, ini-parsing, io, code, log facilities" 181 | category = "dev" 182 | optional = false 183 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 184 | 185 | [[package]] 186 | name = "pycodestyle" 187 | version = "2.6.0" 188 | description = "Python style guide checker" 189 | category = "dev" 190 | optional = false 191 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 192 | 193 | [[package]] 194 | name = "pyflakes" 195 | version = "2.2.0" 196 | description = "passive checker of Python programs" 197 | category = "dev" 198 | optional = false 199 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 200 | 201 | [[package]] 202 | name = "pyparsing" 203 | version = "2.4.7" 204 | description = "Python parsing module" 205 | category = "dev" 206 | optional = false 207 | python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" 208 | 209 | [[package]] 210 | name = "pytest" 211 | version = "6.2.2" 212 | description = "pytest: simple powerful testing with Python" 213 | category = "dev" 214 | optional = false 215 | python-versions = ">=3.6" 216 | 217 | [package.dependencies] 218 | atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} 219 | attrs = ">=19.2.0" 220 | colorama = {version = "*", markers = "sys_platform == \"win32\""} 221 | importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} 222 | iniconfig = "*" 223 | packaging = "*" 224 | pluggy = ">=0.12,<1.0.0a1" 225 | py = ">=1.8.2" 226 | toml = "*" 227 | 228 | [package.extras] 229 | testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] 230 | 231 | [[package]] 232 | name = "regex" 233 | version = "2020.11.13" 234 | description = "Alternative regular expression module, to replace re." 235 | category = "dev" 236 | optional = false 237 | python-versions = "*" 238 | 239 | [[package]] 240 | name = "toml" 241 | version = "0.10.2" 242 | description = "Python Library for Tom's Obvious, Minimal Language" 243 | category = "dev" 244 | optional = false 245 | python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" 246 | 247 | [[package]] 248 | name = "typed-ast" 249 | version = "1.4.2" 250 | description = "a fork of Python 2 and 3 ast modules with type comment support" 251 | category = "dev" 252 | optional = false 253 | python-versions = "*" 254 | 255 | [[package]] 256 | name = "typing-extensions" 257 | version = "3.7.4.3" 258 | description = "Backported and Experimental Type Hints for Python 3.5+" 259 | category = "dev" 260 | optional = false 261 | python-versions = "*" 262 | 263 | [[package]] 264 | name = "zipp" 265 | version = "3.4.0" 266 | description = "Backport of pathlib-compatible object wrapper for zip files" 267 | category = "dev" 268 | optional = false 269 | python-versions = ">=3.6" 270 | 271 | [package.extras] 272 | docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] 273 | testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] 274 | 275 | [metadata] 276 | lock-version = "1.1" 277 | python-versions = "^3.6" 278 | content-hash = "b67a0e6fadfe7dcd6e8a2849ba8d280845eac5b49734e441aa4531305883acd1" 279 | 280 | [metadata.files] 281 | appdirs = [ 282 | {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, 283 | {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, 284 | ] 285 | atomicwrites = [ 286 | {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, 287 | {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, 288 | ] 289 | attrs = [ 290 | {file = "attrs-20.3.0-py2.py3-none-any.whl", hash = "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6"}, 291 | {file = "attrs-20.3.0.tar.gz", hash = "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700"}, 292 | ] 293 | black = [ 294 | {file = "black-20.8b1-py3-none-any.whl", hash = "sha256:70b62ef1527c950db59062cda342ea224d772abdf6adc58b86a45421bab20a6b"}, 295 | {file = "black-20.8b1.tar.gz", hash = "sha256:1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea"}, 296 | ] 297 | click = [ 298 | {file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"}, 299 | {file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"}, 300 | ] 301 | colorama = [ 302 | {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, 303 | ] 304 | dataclasses = [ 305 | {file = "dataclasses-0.8-py3-none-any.whl", hash = "sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"}, 306 | {file = "dataclasses-0.8.tar.gz", hash = "sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97"}, 307 | ] 308 | flake8 = [ 309 | {file = "flake8-3.8.4-py2.py3-none-any.whl", hash = "sha256:749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839"}, 310 | {file = "flake8-3.8.4.tar.gz", hash = "sha256:aadae8761ec651813c24be05c6f7b4680857ef6afaae4651a4eccaef97ce6c3b"}, 311 | ] 312 | importlib-metadata = [ 313 | {file = "importlib_metadata-3.4.0-py3-none-any.whl", hash = "sha256:ace61d5fc652dc280e7b6b4ff732a9c2d40db2c0f92bc6cb74e07b73d53a1771"}, 314 | {file = "importlib_metadata-3.4.0.tar.gz", hash = "sha256:fa5daa4477a7414ae34e95942e4dd07f62adf589143c875c133c1e53c4eff38d"}, 315 | ] 316 | iniconfig = [ 317 | {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, 318 | {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, 319 | ] 320 | lark-parser = [ 321 | {file = "lark-parser-0.11.1.tar.gz", hash = "sha256:20bdefdf1b6e9bcb38165ea5cc4f27921a99c6f4c35264a3a953fd60335f1f8c"}, 322 | {file = "lark_parser-0.11.1-py2.py3-none-any.whl", hash = "sha256:8b747e1f544dcc2789e3feaddd2a50c6a73bed69d62e9c69760c1e1f7d23495f"}, 323 | ] 324 | mccabe = [ 325 | {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, 326 | {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, 327 | ] 328 | mypy-extensions = [ 329 | {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, 330 | {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, 331 | ] 332 | packaging = [ 333 | {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, 334 | {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, 335 | ] 336 | pathspec = [ 337 | {file = "pathspec-0.8.1-py2.py3-none-any.whl", hash = "sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d"}, 338 | {file = "pathspec-0.8.1.tar.gz", hash = "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd"}, 339 | ] 340 | pluggy = [ 341 | {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, 342 | {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, 343 | ] 344 | py = [ 345 | {file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"}, 346 | {file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"}, 347 | ] 348 | pycodestyle = [ 349 | {file = "pycodestyle-2.6.0-py2.py3-none-any.whl", hash = "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367"}, 350 | {file = "pycodestyle-2.6.0.tar.gz", hash = "sha256:c58a7d2815e0e8d7972bf1803331fb0152f867bd89adf8a01dfd55085434192e"}, 351 | ] 352 | pyflakes = [ 353 | {file = "pyflakes-2.2.0-py2.py3-none-any.whl", hash = "sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92"}, 354 | {file = "pyflakes-2.2.0.tar.gz", hash = "sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8"}, 355 | ] 356 | pyparsing = [ 357 | {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, 358 | {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, 359 | ] 360 | pytest = [ 361 | {file = "pytest-6.2.2-py3-none-any.whl", hash = "sha256:b574b57423e818210672e07ca1fa90aaf194a4f63f3ab909a2c67ebb22913839"}, 362 | {file = "pytest-6.2.2.tar.gz", hash = "sha256:9d1edf9e7d0b84d72ea3dbcdfd22b35fb543a5e8f2a60092dd578936bf63d7f9"}, 363 | ] 364 | regex = [ 365 | {file = "regex-2020.11.13-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:8b882a78c320478b12ff024e81dc7d43c1462aa4a3341c754ee65d857a521f85"}, 366 | {file = "regex-2020.11.13-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:a63f1a07932c9686d2d416fb295ec2c01ab246e89b4d58e5fa468089cab44b70"}, 367 | {file = "regex-2020.11.13-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:6e4b08c6f8daca7d8f07c8d24e4331ae7953333dbd09c648ed6ebd24db5a10ee"}, 368 | {file = "regex-2020.11.13-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:bba349276b126947b014e50ab3316c027cac1495992f10e5682dc677b3dfa0c5"}, 369 | {file = "regex-2020.11.13-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:56e01daca75eae420bce184edd8bb341c8eebb19dd3bce7266332258f9fb9dd7"}, 370 | {file = "regex-2020.11.13-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:6a8ce43923c518c24a2579fda49f093f1397dad5d18346211e46f134fc624e31"}, 371 | {file = "regex-2020.11.13-cp36-cp36m-manylinux2014_i686.whl", hash = "sha256:1ab79fcb02b930de09c76d024d279686ec5d532eb814fd0ed1e0051eb8bd2daa"}, 372 | {file = "regex-2020.11.13-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:9801c4c1d9ae6a70aeb2128e5b4b68c45d4f0af0d1535500884d644fa9b768c6"}, 373 | {file = "regex-2020.11.13-cp36-cp36m-win32.whl", hash = "sha256:49cae022fa13f09be91b2c880e58e14b6da5d10639ed45ca69b85faf039f7a4e"}, 374 | {file = "regex-2020.11.13-cp36-cp36m-win_amd64.whl", hash = "sha256:749078d1eb89484db5f34b4012092ad14b327944ee7f1c4f74d6279a6e4d1884"}, 375 | {file = "regex-2020.11.13-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b2f4007bff007c96a173e24dcda236e5e83bde4358a557f9ccf5e014439eae4b"}, 376 | {file = "regex-2020.11.13-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:38c8fd190db64f513fe4e1baa59fed086ae71fa45083b6936b52d34df8f86a88"}, 377 | {file = "regex-2020.11.13-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:5862975b45d451b6db51c2e654990c1820523a5b07100fc6903e9c86575202a0"}, 378 | {file = "regex-2020.11.13-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:262c6825b309e6485ec2493ffc7e62a13cf13fb2a8b6d212f72bd53ad34118f1"}, 379 | {file = "regex-2020.11.13-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:bafb01b4688833e099d79e7efd23f99172f501a15c44f21ea2118681473fdba0"}, 380 | {file = "regex-2020.11.13-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:e32f5f3d1b1c663af7f9c4c1e72e6ffe9a78c03a31e149259f531e0fed826512"}, 381 | {file = "regex-2020.11.13-cp37-cp37m-manylinux2014_i686.whl", hash = "sha256:3bddc701bdd1efa0d5264d2649588cbfda549b2899dc8d50417e47a82e1387ba"}, 382 | {file = "regex-2020.11.13-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:02951b7dacb123d8ea6da44fe45ddd084aa6777d4b2454fa0da61d569c6fa538"}, 383 | {file = "regex-2020.11.13-cp37-cp37m-win32.whl", hash = "sha256:0d08e71e70c0237883d0bef12cad5145b84c3705e9c6a588b2a9c7080e5af2a4"}, 384 | {file = "regex-2020.11.13-cp37-cp37m-win_amd64.whl", hash = "sha256:1fa7ee9c2a0e30405e21031d07d7ba8617bc590d391adfc2b7f1e8b99f46f444"}, 385 | {file = "regex-2020.11.13-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:baf378ba6151f6e272824b86a774326f692bc2ef4cc5ce8d5bc76e38c813a55f"}, 386 | {file = "regex-2020.11.13-cp38-cp38-manylinux1_i686.whl", hash = "sha256:e3faaf10a0d1e8e23a9b51d1900b72e1635c2d5b0e1bea1c18022486a8e2e52d"}, 387 | {file = "regex-2020.11.13-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:2a11a3e90bd9901d70a5b31d7dd85114755a581a5da3fc996abfefa48aee78af"}, 388 | {file = "regex-2020.11.13-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:d1ebb090a426db66dd80df8ca85adc4abfcbad8a7c2e9a5ec7513ede522e0a8f"}, 389 | {file = "regex-2020.11.13-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:b2b1a5ddae3677d89b686e5c625fc5547c6e492bd755b520de5332773a8af06b"}, 390 | {file = "regex-2020.11.13-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:2c99e97d388cd0a8d30f7c514d67887d8021541b875baf09791a3baad48bb4f8"}, 391 | {file = "regex-2020.11.13-cp38-cp38-manylinux2014_i686.whl", hash = "sha256:c084582d4215593f2f1d28b65d2a2f3aceff8342aa85afd7be23a9cad74a0de5"}, 392 | {file = "regex-2020.11.13-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:a3d748383762e56337c39ab35c6ed4deb88df5326f97a38946ddd19028ecce6b"}, 393 | {file = "regex-2020.11.13-cp38-cp38-win32.whl", hash = "sha256:7913bd25f4ab274ba37bc97ad0e21c31004224ccb02765ad984eef43e04acc6c"}, 394 | {file = "regex-2020.11.13-cp38-cp38-win_amd64.whl", hash = "sha256:6c54ce4b5d61a7129bad5c5dc279e222afd00e721bf92f9ef09e4fae28755683"}, 395 | {file = "regex-2020.11.13-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:1862a9d9194fae76a7aaf0150d5f2a8ec1da89e8b55890b1786b8f88a0f619dc"}, 396 | {file = "regex-2020.11.13-cp39-cp39-manylinux1_i686.whl", hash = "sha256:4902e6aa086cbb224241adbc2f06235927d5cdacffb2425c73e6570e8d862364"}, 397 | {file = "regex-2020.11.13-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:7a25fcbeae08f96a754b45bdc050e1fb94b95cab046bf56b016c25e9ab127b3e"}, 398 | {file = "regex-2020.11.13-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:d2d8ce12b7c12c87e41123997ebaf1a5767a5be3ec545f64675388970f415e2e"}, 399 | {file = "regex-2020.11.13-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:f7d29a6fc4760300f86ae329e3b6ca28ea9c20823df123a2ea8693e967b29917"}, 400 | {file = "regex-2020.11.13-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:717881211f46de3ab130b58ec0908267961fadc06e44f974466d1887f865bd5b"}, 401 | {file = "regex-2020.11.13-cp39-cp39-manylinux2014_i686.whl", hash = "sha256:3128e30d83f2e70b0bed9b2a34e92707d0877e460b402faca908c6667092ada9"}, 402 | {file = "regex-2020.11.13-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:8f6a2229e8ad946e36815f2a03386bb8353d4bde368fdf8ca5f0cb97264d3b5c"}, 403 | {file = "regex-2020.11.13-cp39-cp39-win32.whl", hash = "sha256:f8f295db00ef5f8bae530fc39af0b40486ca6068733fb860b42115052206466f"}, 404 | {file = "regex-2020.11.13-cp39-cp39-win_amd64.whl", hash = "sha256:a15f64ae3a027b64496a71ab1f722355e570c3fac5ba2801cafce846bf5af01d"}, 405 | {file = "regex-2020.11.13.tar.gz", hash = "sha256:83d6b356e116ca119db8e7c6fc2983289d87b27b3fac238cfe5dca529d884562"}, 406 | ] 407 | toml = [ 408 | {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, 409 | {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, 410 | ] 411 | typed-ast = [ 412 | {file = "typed_ast-1.4.2-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:7703620125e4fb79b64aa52427ec192822e9f45d37d4b6625ab37ef403e1df70"}, 413 | {file = "typed_ast-1.4.2-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c9aadc4924d4b5799112837b226160428524a9a45f830e0d0f184b19e4090487"}, 414 | {file = "typed_ast-1.4.2-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:9ec45db0c766f196ae629e509f059ff05fc3148f9ffd28f3cfe75d4afb485412"}, 415 | {file = "typed_ast-1.4.2-cp35-cp35m-win32.whl", hash = "sha256:85f95aa97a35bdb2f2f7d10ec5bbdac0aeb9dafdaf88e17492da0504de2e6400"}, 416 | {file = "typed_ast-1.4.2-cp35-cp35m-win_amd64.whl", hash = "sha256:9044ef2df88d7f33692ae3f18d3be63dec69c4fb1b5a4a9ac950f9b4ba571606"}, 417 | {file = "typed_ast-1.4.2-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:c1c876fd795b36126f773db9cbb393f19808edd2637e00fd6caba0e25f2c7b64"}, 418 | {file = "typed_ast-1.4.2-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:5dcfc2e264bd8a1db8b11a892bd1647154ce03eeba94b461effe68790d8b8e07"}, 419 | {file = "typed_ast-1.4.2-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:8db0e856712f79c45956da0c9a40ca4246abc3485ae0d7ecc86a20f5e4c09abc"}, 420 | {file = "typed_ast-1.4.2-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:d003156bb6a59cda9050e983441b7fa2487f7800d76bdc065566b7d728b4581a"}, 421 | {file = "typed_ast-1.4.2-cp36-cp36m-win32.whl", hash = "sha256:4c790331247081ea7c632a76d5b2a265e6d325ecd3179d06e9cf8d46d90dd151"}, 422 | {file = "typed_ast-1.4.2-cp36-cp36m-win_amd64.whl", hash = "sha256:d175297e9533d8d37437abc14e8a83cbc68af93cc9c1c59c2c292ec59a0697a3"}, 423 | {file = "typed_ast-1.4.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:cf54cfa843f297991b7388c281cb3855d911137223c6b6d2dd82a47ae5125a41"}, 424 | {file = "typed_ast-1.4.2-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:b4fcdcfa302538f70929eb7b392f536a237cbe2ed9cba88e3bf5027b39f5f77f"}, 425 | {file = "typed_ast-1.4.2-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:987f15737aba2ab5f3928c617ccf1ce412e2e321c77ab16ca5a293e7bbffd581"}, 426 | {file = "typed_ast-1.4.2-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:37f48d46d733d57cc70fd5f30572d11ab8ed92da6e6b28e024e4a3edfb456e37"}, 427 | {file = "typed_ast-1.4.2-cp37-cp37m-win32.whl", hash = "sha256:36d829b31ab67d6fcb30e185ec996e1f72b892255a745d3a82138c97d21ed1cd"}, 428 | {file = "typed_ast-1.4.2-cp37-cp37m-win_amd64.whl", hash = "sha256:8368f83e93c7156ccd40e49a783a6a6850ca25b556c0fa0240ed0f659d2fe496"}, 429 | {file = "typed_ast-1.4.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:963c80b583b0661918718b095e02303d8078950b26cc00b5e5ea9ababe0de1fc"}, 430 | {file = "typed_ast-1.4.2-cp38-cp38-manylinux1_i686.whl", hash = "sha256:e683e409e5c45d5c9082dc1daf13f6374300806240719f95dc783d1fc942af10"}, 431 | {file = "typed_ast-1.4.2-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:84aa6223d71012c68d577c83f4e7db50d11d6b1399a9c779046d75e24bed74ea"}, 432 | {file = "typed_ast-1.4.2-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:a38878a223bdd37c9709d07cd357bb79f4c760b29210e14ad0fb395294583787"}, 433 | {file = "typed_ast-1.4.2-cp38-cp38-win32.whl", hash = "sha256:a2c927c49f2029291fbabd673d51a2180038f8cd5a5b2f290f78c4516be48be2"}, 434 | {file = "typed_ast-1.4.2-cp38-cp38-win_amd64.whl", hash = "sha256:c0c74e5579af4b977c8b932f40a5464764b2f86681327410aa028a22d2f54937"}, 435 | {file = "typed_ast-1.4.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:07d49388d5bf7e863f7fa2f124b1b1d89d8aa0e2f7812faff0a5658c01c59aa1"}, 436 | {file = "typed_ast-1.4.2-cp39-cp39-manylinux1_i686.whl", hash = "sha256:240296b27397e4e37874abb1df2a608a92df85cf3e2a04d0d4d61055c8305ba6"}, 437 | {file = "typed_ast-1.4.2-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:d746a437cdbca200622385305aedd9aef68e8a645e385cc483bdc5e488f07166"}, 438 | {file = "typed_ast-1.4.2-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:14bf1522cdee369e8f5581238edac09150c765ec1cb33615855889cf33dcb92d"}, 439 | {file = "typed_ast-1.4.2-cp39-cp39-win32.whl", hash = "sha256:cc7b98bf58167b7f2db91a4327da24fb93368838eb84a44c472283778fc2446b"}, 440 | {file = "typed_ast-1.4.2-cp39-cp39-win_amd64.whl", hash = "sha256:7147e2a76c75f0f64c4319886e7639e490fee87c9d25cb1d4faef1d8cf83a440"}, 441 | {file = "typed_ast-1.4.2.tar.gz", hash = "sha256:9fc0b3cb5d1720e7141d103cf4819aea239f7d136acf9ee4a69b047b7986175a"}, 442 | ] 443 | typing-extensions = [ 444 | {file = "typing_extensions-3.7.4.3-py2-none-any.whl", hash = "sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f"}, 445 | {file = "typing_extensions-3.7.4.3-py3-none-any.whl", hash = "sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918"}, 446 | {file = "typing_extensions-3.7.4.3.tar.gz", hash = "sha256:99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c"}, 447 | ] 448 | zipp = [ 449 | {file = "zipp-3.4.0-py3-none-any.whl", hash = "sha256:102c24ef8f171fd729d46599845e95c7ab894a4cf45f5de11a44cc7444fb1108"}, 450 | {file = "zipp-3.4.0.tar.gz", hash = "sha256:ed5eee1974372595f9e416cc7bbeeb12335201d8081ca8a0743c954d4446e5cb"}, 451 | ] 452 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "pyMalleableC2" 3 | version = "0.1.0" 4 | description = "Python library that allows you to parse and build Cobalt Strike Malleable C2 Profiles programmatically." 5 | authors = ["Marcello Salvati "] 6 | readme = "README.md" 7 | license = "GPL-3.0-only" 8 | homepage = "https://github.com/Porchetta-Industries/pyMalleableC2" 9 | repository = "https://github.com/Porchetta-Industries/pyMalleableC2" 10 | exclude = ["tests/", "examples/"] 11 | include = ["README.md", "LICENSE", "malleablec2/grammar.lark"] 12 | classifiers = [ 13 | "Topic :: Security", 14 | ] 15 | 16 | packages = [ 17 | { include = "malleablec2"} 18 | ] 19 | 20 | [tool.poetry.dependencies] 21 | python = "^3.6" 22 | lark-parser = "^0.11.1" 23 | 24 | [tool.poetry.dev-dependencies] 25 | flake8 = "*" 26 | black = "^20.8b1" 27 | pytest = "*" 28 | 29 | [build-system] 30 | requires = ["poetry-core>=1.0.0"] 31 | build-backend = "poetry.core.masonry.api" 32 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4; python_version >= "3.6" \ 2 | --hash=sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128 \ 3 | --hash=sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41 4 | atomicwrites==1.4.0; python_version >= "3.6" and python_full_version < "3.0.0" and sys_platform == "win32" or sys_platform == "win32" and python_version >= "3.6" and python_full_version >= "3.4.0" \ 5 | --hash=sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197 \ 6 | --hash=sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a 7 | attrs==20.3.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6" \ 8 | --hash=sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6 \ 9 | --hash=sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700 10 | black==20.8b1; python_version >= "3.6" \ 11 | --hash=sha256:70b62ef1527c950db59062cda342ea224d772abdf6adc58b86a45421bab20a6b \ 12 | --hash=sha256:1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea 13 | click==7.1.2; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6" \ 14 | --hash=sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc \ 15 | --hash=sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a 16 | colorama==0.4.4; python_version >= "3.6" and python_full_version < "3.0.0" and sys_platform == "win32" or sys_platform == "win32" and python_version >= "3.6" and python_full_version >= "3.5.0" \ 17 | --hash=sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2 18 | dataclasses==0.8; python_version >= "3.6" and python_version < "3.7" \ 19 | --hash=sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf \ 20 | --hash=sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97 21 | flake8==3.8.4; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0") \ 22 | --hash=sha256:749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839 \ 23 | --hash=sha256:aadae8761ec651813c24be05c6f7b4680857ef6afaae4651a4eccaef97ce6c3b 24 | importlib-metadata==3.4.0; python_version >= "3.6" and python_full_version < "3.0.0" and python_version < "3.8" or python_full_version >= "3.4.0" and python_version < "3.8" and python_version >= "3.6" \ 25 | --hash=sha256:ace61d5fc652dc280e7b6b4ff732a9c2d40db2c0f92bc6cb74e07b73d53a1771 \ 26 | --hash=sha256:fa5daa4477a7414ae34e95942e4dd07f62adf589143c875c133c1e53c4eff38d 27 | iniconfig==1.1.1; python_version >= "3.6" \ 28 | --hash=sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3 \ 29 | --hash=sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32 30 | lark-parser==0.11.1 \ 31 | --hash=sha256:20bdefdf1b6e9bcb38165ea5cc4f27921a99c6f4c35264a3a953fd60335f1f8c \ 32 | --hash=sha256:8b747e1f544dcc2789e3feaddd2a50c6a73bed69d62e9c69760c1e1f7d23495f 33 | mccabe==0.6.1; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" \ 34 | --hash=sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42 \ 35 | --hash=sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f 36 | mypy-extensions==0.4.3; python_version >= "3.6" \ 37 | --hash=sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d \ 38 | --hash=sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8 39 | packaging==20.9; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6" \ 40 | --hash=sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a \ 41 | --hash=sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5 42 | pathspec==0.8.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6" \ 43 | --hash=sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d \ 44 | --hash=sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd 45 | pluggy==0.13.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6" \ 46 | --hash=sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d \ 47 | --hash=sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0 48 | py==1.10.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6" \ 49 | --hash=sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a \ 50 | --hash=sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3 51 | pycodestyle==2.6.0; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" \ 52 | --hash=sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367 \ 53 | --hash=sha256:c58a7d2815e0e8d7972bf1803331fb0152f867bd89adf8a01dfd55085434192e 54 | pyflakes==2.2.0; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" \ 55 | --hash=sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92 \ 56 | --hash=sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8 57 | pyparsing==2.4.7; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6" \ 58 | --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ 59 | --hash=sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1 60 | pytest==6.2.2; python_version >= "3.6" \ 61 | --hash=sha256:b574b57423e818210672e07ca1fa90aaf194a4f63f3ab909a2c67ebb22913839 \ 62 | --hash=sha256:9d1edf9e7d0b84d72ea3dbcdfd22b35fb543a5e8f2a60092dd578936bf63d7f9 63 | regex==2020.11.13; python_version >= "3.6" \ 64 | --hash=sha256:8b882a78c320478b12ff024e81dc7d43c1462aa4a3341c754ee65d857a521f85 \ 65 | --hash=sha256:a63f1a07932c9686d2d416fb295ec2c01ab246e89b4d58e5fa468089cab44b70 \ 66 | --hash=sha256:6e4b08c6f8daca7d8f07c8d24e4331ae7953333dbd09c648ed6ebd24db5a10ee \ 67 | --hash=sha256:bba349276b126947b014e50ab3316c027cac1495992f10e5682dc677b3dfa0c5 \ 68 | --hash=sha256:56e01daca75eae420bce184edd8bb341c8eebb19dd3bce7266332258f9fb9dd7 \ 69 | --hash=sha256:6a8ce43923c518c24a2579fda49f093f1397dad5d18346211e46f134fc624e31 \ 70 | --hash=sha256:1ab79fcb02b930de09c76d024d279686ec5d532eb814fd0ed1e0051eb8bd2daa \ 71 | --hash=sha256:9801c4c1d9ae6a70aeb2128e5b4b68c45d4f0af0d1535500884d644fa9b768c6 \ 72 | --hash=sha256:49cae022fa13f09be91b2c880e58e14b6da5d10639ed45ca69b85faf039f7a4e \ 73 | --hash=sha256:749078d1eb89484db5f34b4012092ad14b327944ee7f1c4f74d6279a6e4d1884 \ 74 | --hash=sha256:b2f4007bff007c96a173e24dcda236e5e83bde4358a557f9ccf5e014439eae4b \ 75 | --hash=sha256:38c8fd190db64f513fe4e1baa59fed086ae71fa45083b6936b52d34df8f86a88 \ 76 | --hash=sha256:5862975b45d451b6db51c2e654990c1820523a5b07100fc6903e9c86575202a0 \ 77 | --hash=sha256:262c6825b309e6485ec2493ffc7e62a13cf13fb2a8b6d212f72bd53ad34118f1 \ 78 | --hash=sha256:bafb01b4688833e099d79e7efd23f99172f501a15c44f21ea2118681473fdba0 \ 79 | --hash=sha256:e32f5f3d1b1c663af7f9c4c1e72e6ffe9a78c03a31e149259f531e0fed826512 \ 80 | --hash=sha256:3bddc701bdd1efa0d5264d2649588cbfda549b2899dc8d50417e47a82e1387ba \ 81 | --hash=sha256:02951b7dacb123d8ea6da44fe45ddd084aa6777d4b2454fa0da61d569c6fa538 \ 82 | --hash=sha256:0d08e71e70c0237883d0bef12cad5145b84c3705e9c6a588b2a9c7080e5af2a4 \ 83 | --hash=sha256:1fa7ee9c2a0e30405e21031d07d7ba8617bc590d391adfc2b7f1e8b99f46f444 \ 84 | --hash=sha256:baf378ba6151f6e272824b86a774326f692bc2ef4cc5ce8d5bc76e38c813a55f \ 85 | --hash=sha256:e3faaf10a0d1e8e23a9b51d1900b72e1635c2d5b0e1bea1c18022486a8e2e52d \ 86 | --hash=sha256:2a11a3e90bd9901d70a5b31d7dd85114755a581a5da3fc996abfefa48aee78af \ 87 | --hash=sha256:d1ebb090a426db66dd80df8ca85adc4abfcbad8a7c2e9a5ec7513ede522e0a8f \ 88 | --hash=sha256:b2b1a5ddae3677d89b686e5c625fc5547c6e492bd755b520de5332773a8af06b \ 89 | --hash=sha256:2c99e97d388cd0a8d30f7c514d67887d8021541b875baf09791a3baad48bb4f8 \ 90 | --hash=sha256:c084582d4215593f2f1d28b65d2a2f3aceff8342aa85afd7be23a9cad74a0de5 \ 91 | --hash=sha256:a3d748383762e56337c39ab35c6ed4deb88df5326f97a38946ddd19028ecce6b \ 92 | --hash=sha256:7913bd25f4ab274ba37bc97ad0e21c31004224ccb02765ad984eef43e04acc6c \ 93 | --hash=sha256:6c54ce4b5d61a7129bad5c5dc279e222afd00e721bf92f9ef09e4fae28755683 \ 94 | --hash=sha256:1862a9d9194fae76a7aaf0150d5f2a8ec1da89e8b55890b1786b8f88a0f619dc \ 95 | --hash=sha256:4902e6aa086cbb224241adbc2f06235927d5cdacffb2425c73e6570e8d862364 \ 96 | --hash=sha256:7a25fcbeae08f96a754b45bdc050e1fb94b95cab046bf56b016c25e9ab127b3e \ 97 | --hash=sha256:d2d8ce12b7c12c87e41123997ebaf1a5767a5be3ec545f64675388970f415e2e \ 98 | --hash=sha256:f7d29a6fc4760300f86ae329e3b6ca28ea9c20823df123a2ea8693e967b29917 \ 99 | --hash=sha256:717881211f46de3ab130b58ec0908267961fadc06e44f974466d1887f865bd5b \ 100 | --hash=sha256:3128e30d83f2e70b0bed9b2a34e92707d0877e460b402faca908c6667092ada9 \ 101 | --hash=sha256:8f6a2229e8ad946e36815f2a03386bb8353d4bde368fdf8ca5f0cb97264d3b5c \ 102 | --hash=sha256:f8f295db00ef5f8bae530fc39af0b40486ca6068733fb860b42115052206466f \ 103 | --hash=sha256:a15f64ae3a027b64496a71ab1f722355e570c3fac5ba2801cafce846bf5af01d \ 104 | --hash=sha256:83d6b356e116ca119db8e7c6fc2983289d87b27b3fac238cfe5dca529d884562 105 | toml==0.10.2; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.6" \ 106 | --hash=sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b \ 107 | --hash=sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f 108 | typed-ast==1.4.2; python_version >= "3.6" \ 109 | --hash=sha256:7703620125e4fb79b64aa52427ec192822e9f45d37d4b6625ab37ef403e1df70 \ 110 | --hash=sha256:c9aadc4924d4b5799112837b226160428524a9a45f830e0d0f184b19e4090487 \ 111 | --hash=sha256:9ec45db0c766f196ae629e509f059ff05fc3148f9ffd28f3cfe75d4afb485412 \ 112 | --hash=sha256:85f95aa97a35bdb2f2f7d10ec5bbdac0aeb9dafdaf88e17492da0504de2e6400 \ 113 | --hash=sha256:9044ef2df88d7f33692ae3f18d3be63dec69c4fb1b5a4a9ac950f9b4ba571606 \ 114 | --hash=sha256:c1c876fd795b36126f773db9cbb393f19808edd2637e00fd6caba0e25f2c7b64 \ 115 | --hash=sha256:5dcfc2e264bd8a1db8b11a892bd1647154ce03eeba94b461effe68790d8b8e07 \ 116 | --hash=sha256:8db0e856712f79c45956da0c9a40ca4246abc3485ae0d7ecc86a20f5e4c09abc \ 117 | --hash=sha256:d003156bb6a59cda9050e983441b7fa2487f7800d76bdc065566b7d728b4581a \ 118 | --hash=sha256:4c790331247081ea7c632a76d5b2a265e6d325ecd3179d06e9cf8d46d90dd151 \ 119 | --hash=sha256:d175297e9533d8d37437abc14e8a83cbc68af93cc9c1c59c2c292ec59a0697a3 \ 120 | --hash=sha256:cf54cfa843f297991b7388c281cb3855d911137223c6b6d2dd82a47ae5125a41 \ 121 | --hash=sha256:b4fcdcfa302538f70929eb7b392f536a237cbe2ed9cba88e3bf5027b39f5f77f \ 122 | --hash=sha256:987f15737aba2ab5f3928c617ccf1ce412e2e321c77ab16ca5a293e7bbffd581 \ 123 | --hash=sha256:37f48d46d733d57cc70fd5f30572d11ab8ed92da6e6b28e024e4a3edfb456e37 \ 124 | --hash=sha256:36d829b31ab67d6fcb30e185ec996e1f72b892255a745d3a82138c97d21ed1cd \ 125 | --hash=sha256:8368f83e93c7156ccd40e49a783a6a6850ca25b556c0fa0240ed0f659d2fe496 \ 126 | --hash=sha256:963c80b583b0661918718b095e02303d8078950b26cc00b5e5ea9ababe0de1fc \ 127 | --hash=sha256:e683e409e5c45d5c9082dc1daf13f6374300806240719f95dc783d1fc942af10 \ 128 | --hash=sha256:84aa6223d71012c68d577c83f4e7db50d11d6b1399a9c779046d75e24bed74ea \ 129 | --hash=sha256:a38878a223bdd37c9709d07cd357bb79f4c760b29210e14ad0fb395294583787 \ 130 | --hash=sha256:a2c927c49f2029291fbabd673d51a2180038f8cd5a5b2f290f78c4516be48be2 \ 131 | --hash=sha256:c0c74e5579af4b977c8b932f40a5464764b2f86681327410aa028a22d2f54937 \ 132 | --hash=sha256:07d49388d5bf7e863f7fa2f124b1b1d89d8aa0e2f7812faff0a5658c01c59aa1 \ 133 | --hash=sha256:240296b27397e4e37874abb1df2a608a92df85cf3e2a04d0d4d61055c8305ba6 \ 134 | --hash=sha256:d746a437cdbca200622385305aedd9aef68e8a645e385cc483bdc5e488f07166 \ 135 | --hash=sha256:14bf1522cdee369e8f5581238edac09150c765ec1cb33615855889cf33dcb92d \ 136 | --hash=sha256:cc7b98bf58167b7f2db91a4327da24fb93368838eb84a44c472283778fc2446b \ 137 | --hash=sha256:7147e2a76c75f0f64c4319886e7639e490fee87c9d25cb1d4faef1d8cf83a440 \ 138 | --hash=sha256:9fc0b3cb5d1720e7141d103cf4819aea239f7d136acf9ee4a69b047b7986175a 139 | typing-extensions==3.7.4.3; python_version >= "3.6" and python_full_version < "3.0.0" and python_version < "3.8" or python_full_version >= "3.4.0" and python_version < "3.8" and python_version >= "3.6" \ 140 | --hash=sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f \ 141 | --hash=sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918 \ 142 | --hash=sha256:99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c 143 | zipp==3.4.0; python_version >= "3.6" and python_full_version < "3.0.0" and python_version < "3.8" or python_full_version >= "3.4.0" and python_version < "3.8" and python_version >= "3.6" \ 144 | --hash=sha256:102c24ef8f171fd729d46599845e95c7ab894a4cf45f5de11a44cc7444fb1108 \ 145 | --hash=sha256:ed5eee1974372595f9e416cc7bbeeb12335201d8081ca8a0743c954d4446e5cb 146 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | lark-parser==0.11.1 \ 2 | --hash=sha256:20bdefdf1b6e9bcb38165ea5cc4f27921a99c6f4c35264a3a953fd60335f1f8c \ 3 | --hash=sha256:8b747e1f544dcc2789e3feaddd2a50c6a73bed69d62e9c69760c1e1f7d23495f 4 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byt3bl33d3r/pyMalleableC2/3ab8be298bb9e19288c3ba1f998263593c77ec9a/tests/__init__.py -------------------------------------------------------------------------------- /tests/profiles/amazon.profile: -------------------------------------------------------------------------------- 1 | # 2 | # Amazon browsing traffic profile 3 | # 4 | # Author: @harmj0y 5 | # 6 | 7 | set sleeptime "5000"; 8 | set jitter "0"; 9 | set useragent "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"; 10 | 11 | # Updated for 4.3 12 | dns-beacon { 13 | set maxdns "255"; 14 | } 15 | 16 | http-get { 17 | 18 | set uri "/s/ref=nb_sb_noss_1/167-3294888-0262949/field-keywords=books"; 19 | 20 | client { 21 | 22 | header "Accept" "*/*"; 23 | header "Host" "www.amazon.com"; 24 | 25 | metadata { 26 | base64; 27 | prepend "session-token="; 28 | prepend "skin=noskin;"; 29 | append "csm-hit=s-24KU11BB82RZSYGJ3BDK|1419899012996"; 30 | header "Cookie"; 31 | } 32 | } 33 | 34 | server { 35 | 36 | header "Server" "Server"; 37 | header "x-amz-id-1" "THKUYEZKCKPGY5T42PZT"; 38 | header "x-amz-id-2" "a21yZ2xrNDNtdGRsa212bGV3YW85amZuZW9ydG5rZmRuZ2tmZGl4aHRvNDVpbgo="; 39 | header "X-Frame-Options" "SAMEORIGIN"; 40 | header "Content-Encoding" "gzip"; 41 | 42 | output { 43 | print; 44 | } 45 | } 46 | } 47 | 48 | http-post { 49 | 50 | set uri "/N4215/adj/amzn.us.sr.aps"; 51 | 52 | client { 53 | 54 | header "Accept" "*/*"; 55 | header "Content-Type" "text/xml"; 56 | header "X-Requested-With" "XMLHttpRequest"; 57 | header "Host" "www.amazon.com"; 58 | 59 | parameter "sz" "160x600"; 60 | parameter "oe" "oe=ISO-8859-1;"; 61 | 62 | id { 63 | parameter "sn"; 64 | } 65 | 66 | parameter "s" "3717"; 67 | parameter "dc_ref" "http%3A%2F%2Fwww.amazon.com"; 68 | 69 | output { 70 | base64; 71 | print; 72 | } 73 | } 74 | 75 | server { 76 | 77 | header "Server" "Server"; 78 | header "x-amz-id-1" "THK9YEZJCKPGY5T42OZT"; 79 | header "x-amz-id-2" "a21JZ1xrNDNtdGRsa219bGV3YW85amZuZW9zdG5rZmRuZ2tmZGl4aHRvNDVpbgo="; 80 | header "X-Frame-Options" "SAMEORIGIN"; 81 | header "x-ua-compatible" "IE=edge"; 82 | 83 | output { 84 | print; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /tests/profiles/reference.profile: -------------------------------------------------------------------------------- 1 | #This profile tries to get all available options in one place for unit testing purposes. 2 | 3 | set sample_name "Test Profile"; 4 | set host_stage "true"; 5 | set jitter "0"; 6 | set pipename "msagent_###"; 7 | set pipename_stager "status_##"; 8 | set sleeptime "60000"; 9 | set smb_frame_header ""; 10 | set ssh_banner "Cobalt Strike 4.2"; 11 | set ssh_pipename "postex_ssh_####"; 12 | set tcp_frame_header ""; 13 | set tcp_port "4444"; 14 | set data_jitter "0"; 15 | 16 | #This is used only in http-get and http-post and not during stage 17 | set useragent "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"; 18 | 19 | dns-beacon { 20 | # Options moved into 'dns-beacon' group in 4.3: 21 | set dns_idle "1.2.3.4"; 22 | set dns_max_txt "199"; 23 | set dns_sleep "1"; 24 | set dns_ttl "5"; 25 | set maxdns "200"; 26 | set dns_stager_prepend "doc-stg-prepend"; 27 | set dns_stager_subhost "doc-stg-sh."; 28 | # DNS subhost override options added in 4.3: 29 | set beacon "doc.bc."; 30 | set get_A "doc.1a."; 31 | set get_AAAA "doc.4a."; 32 | set get_TXT "doc.tx."; 33 | set put_metadata "doc.md."; 34 | set put_output "doc.po."; 35 | 36 | set ns_response "zero"; 37 | } 38 | 39 | http-config { 40 | set headers "Date, Server, Content-Length, Keep-Alive, Connection, Content-Type"; 41 | header "Server" "Apache"; 42 | header "Keep-Alive""timeout=5, max=100"; 43 | header "Connection""Keep-Alive"; 44 | set trust_x_forwarded_for "true"; 45 | set block_useragents "curl*,lynx*,wget*"; 46 | } 47 | 48 | https-certificate { 49 | set C "US"; 50 | set CN "localhost"; 51 | set L "San Francisco"; 52 | set OU "IT Services"; 53 | set O "FooCorp"; 54 | set ST "CA"; 55 | set validity "365"; 56 | set keystore "domain.store"; 57 | set password "mypassword"; 58 | } 59 | 60 | code-signer { 61 | set keystore "keystore.jks"; 62 | set password "password"; 63 | set alias "server"; 64 | set digest_algorithm "SHA256"; 65 | set timestamp "false"; 66 | set timestamp_url "set://timestamp.digicert.com"; 67 | } 68 | 69 | http-stager { 70 | set uri_x86 "/api/v1/GetLicence"; 71 | set uri_x64 "/api/v2/GetLicence"; 72 | client { 73 | parameter "uuid" "96c5f1e1-067b-492e-a38b-4f6290369121"; 74 | #header "headername" "headervalue"; 75 | } 76 | server { 77 | header "Content-Type" "application/octet-stream"; 78 | header "Content-Encoding" "gzip"; 79 | output { 80 | #GZIP headers and footers 81 | prepend "\x1F\x8B\x08\x08\xF0\x70\xA3\x50\x00\x03"; 82 | append "\x7F\x01\xDD\xAF\x58\x52\x07\x00"; 83 | #AFAICT print is the only supported terminator 84 | print; 85 | } 86 | } 87 | } 88 | 89 | # define indicators for an set GET 90 | http-get { 91 | # we require a stub URI to attach the rest of our data to. 92 | set uri "/api/v1/Updates"; 93 | 94 | client { 95 | 96 | header "Accept-Encoding" "deflate, gzip;q=1.0, *;q=0.5"; 97 | metadata { 98 | mask; 99 | #base64url; 100 | base64; 101 | #netbios; 102 | 103 | #netbiosu; 104 | append ";" ; 105 | 106 | # Prepend a string 107 | prepend "SESSION="; 108 | # Terminator statements - these say where the metadata goes 109 | # Pick one 110 | 111 | # Append to URI 112 | #uri-append; 113 | 114 | 115 | 116 | #Set in a header 117 | header "Cookie"; 118 | 119 | #Send data as transaction body 120 | #print 121 | 122 | #Store data in a URI parameter 123 | #parameter "someparam" 124 | 125 | } 126 | } 127 | 128 | server { 129 | header "Content-Type" "application/octet-stream"; 130 | header "Content-Encoding" "gzip"; 131 | # prepend some text in case the GET is empty. 132 | output { 133 | mask; 134 | base64; 135 | prepend "\x1F\x8B\x08\x08\xF0\x70\xA3\x50\x00\x03"; 136 | append "\x7F\x01\xDD\xAF\x58\x52\x07\x00"; 137 | print; 138 | } 139 | } 140 | } 141 | 142 | # define indicators for an set POST 143 | http-post { 144 | set uri "/api/v1/Telemetry/Id/"; 145 | set verb "POST"; 146 | 147 | client { 148 | # make it look like we're posting something cool. 149 | header "Content-Type" "application/json"; 150 | header "Accept-Encoding" "deflate, gzip;q=1.0, *;q=0.5"; 151 | 152 | # ugh, our data has to go somewhere! 153 | output { 154 | 155 | mask; 156 | base64url; 157 | uri-append; 158 | } 159 | 160 | # randomize and post our session ID 161 | id { 162 | mask; 163 | base64url; 164 | prepend "{version: 1, d=\x22"; 165 | append "\x22}\n"; 166 | print; 167 | } 168 | } 169 | 170 | # The server's response to our set POST 171 | server { 172 | header "Content-Type" "application/octet-stream"; 173 | header "Content-Encoding" "gzip"; 174 | 175 | # post usually sends nothing, so let's prepend a string, mask it, and 176 | # base64 encode it. We'll get something different back each time. 177 | output { 178 | mask; 179 | base64; 180 | prepend "\x1F\x8B\x08\x08\xF0\x70\xA3\x50\x00\x03"; 181 | append "\x7F\x01\xDD\xAF\x58\x52\x07\x00"; 182 | print; 183 | } 184 | 185 | 186 | } 187 | } 188 | 189 | 190 | stage { 191 | 192 | 193 | # The transform-x86 and transform-x64 blocks pad and transform Beacon’s 194 | # Reflective DLL stage. These blocks support three commands: prepend, append, and strrep. 195 | transform-x86 { 196 | prepend "\x90\x90"; 197 | strrep "ReflectiveLoader" "DoLegitStuff"; 198 | } 199 | 200 | #transform-x64 { 201 | # transform the x64 rDLL stage, same options as with 202 | #} 203 | stringw "I am not Beacon"; 204 | 205 | set allocator "MapViewOfFile"; # HeapAlloc,MapViewOfFile, and VirtualAlloc. 206 | set cleanup "true"; # Ask Beacon to attempt to free memory associated with 207 | # the Reflective DLL package that initialized it. 208 | 209 | # Override the first bytes (MZ header included) of Beacon's Reflective DLL. 210 | # Valid x86 instructions are required. Follow instructions that change 211 | # CPU state with instructions that undo the change. 212 | 213 | # set magic_mz_x86 "MZRE"; 214 | # set magic_mz_x86 "MZAR"; 215 | 216 | set magic_pe "PE"; #Override PE marker with something else 217 | 218 | # Ask the x86 ReflectiveLoader to load the specified library and overwrite 219 | # its space instead of allocating memory with VirtualAlloc. 220 | # Only works with VirtualAlloc 221 | #set module_x86 "xpsservices.dll"; 222 | #set module_x64 "xpsservices.dll"; 223 | 224 | # Obfuscate the Reflective DLL’s import table, overwrite unused header content, 225 | # and ask ReflectiveLoader to copy Beacon to new memory without its DLL headers. 226 | set obfuscate "false"; 227 | 228 | # Obfuscate Beacon, in-memory, prior to sleeping 229 | set sleep_mask "false"; 230 | 231 | # Use embedded function pointer hints to bootstrap Beacon agent without 232 | # walking kernel32 EAT 233 | set smartinject "true"; 234 | 235 | # Ask ReflectiveLoader to stomp MZ, PE, and e_lfanew values after 236 | # it loads Beacon payload 237 | set stomppe "true"; 238 | 239 | 240 | # Ask ReflectiveLoader to use (true) or avoid RWX permissions (false) for Beacon DLL in memory 241 | set userwx "false"; 242 | 243 | # PE header cloning - see "petool", skipped for now 244 | set compile_time "14 Jul 2018 8:14:00"; 245 | # set image_size_x86 "512000"; 246 | # set image_size_x64 "512000"; 247 | set entry_point "92145"; 248 | 249 | #The Exported name of the Beacon DLL 250 | #set name "beacon.x64.dll" 251 | 252 | #set rich_header # I don't understand this yet TODO: fixme 253 | 254 | #TODO: add examples process-inject 255 | } 256 | process-inject { 257 | # set how memory is allocated in a remote process 258 | # VirtualAllocEx or NtMapViewOfSection. The 259 | # NtMapViewOfSection option is for same-architecture injection only. 260 | # VirtualAllocEx is always used for cross-arch memory allocations. 261 | 262 | set allocator "VirtualAllocEx"; 263 | # shape the memory characteristics and content 264 | set min_alloc "16384"; 265 | set startrwx "true"; 266 | set userwx "false"; 267 | transform-x86 { 268 | prepend "\x90\x90"; 269 | } 270 | #transform-x64 { 271 | # transform x64 injected content 272 | #} 273 | # determine how to execute the injected code 274 | execute { 275 | CreateThread "ntdll.dll!RtlUserThreadStart"; 276 | SetThreadContext; 277 | RtlCreateUserThread; 278 | } 279 | } 280 | post-ex { 281 | # control the temporary process we spawn to 282 | set spawnto_x86 "%windir%\\syswow64\\WerFault.exe"; 283 | set spawnto_x64 "%windir%\\sysnative\\WerFault.exe"; 284 | # change the permissions and content of our post-ex DLLs 285 | set obfuscate "true"; 286 | # change our post-ex output named pipe names... 287 | set pipename "msrpc_####, win\\msrpc_##"; 288 | # pass key function pointers from Beacon to its child jobs 289 | set smartinject "true"; 290 | # disable AMSI in powerpick, execute-assembly, and psinject 291 | set amsi_disable "true"; 292 | 293 | 294 | #The thread_hint option allows multi-threaded post-ex DLLs to spawn 295 | # threads with a spoofed start address. Specify the thread hint as 296 | # “module!function+0x##” to specify the start address to spoof. 297 | # The optional 0x## part is an offset added to the start address. 298 | # set thread_hint "....TODO:FIXME" 299 | 300 | # options are: GetAsyncKeyState (def) or SetWindowsHookEx 301 | set keylogger "GetAsyncKeyState"; 302 | } 303 | 304 | 305 | 306 | 307 | -------------------------------------------------------------------------------- /tests/profiles/template.profile: -------------------------------------------------------------------------------- 1 | #template profile - updated with 4.2 options. 2 | #options from https://www.cobaltstrike.com/help-malleable-c2 and https://www.cobaltstrike.com/help-malleable-postex 3 | #attempt to get everything in one place with examples. 4 | #xx0hcd 5 | 6 | ###global options### 7 | 8 | #shows profile name in reports. 9 | set sample_name "whatever.profile"; 10 | 11 | set sleeptime "37500"; 12 | set jitter "33"; 13 | set useragent "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/587.38 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"; 14 | 15 | #set true to use staged payloads, false to disable staged payloads. 16 | set host_stage "false"; 17 | 18 | dns-beacon { 19 | ###DNS options### 20 | set dns_idle "8.8.8.8"; 21 | set maxdns "245"; 22 | set dns_sleep "0"; 23 | set dns_stager_prepend ""; 24 | set dns_stager_subhost ""; 25 | set dns_max_txt "252"; 26 | set dns_ttl "1"; 27 | } 28 | 29 | ###SMB options### 30 | #use different strings for pipename and pipename_stager. 31 | set pipename "ntsvcs##"; 32 | set pipename_stager "scerpc##"; 33 | set smb_frame_header ""; 34 | 35 | ###TCP options### 36 | set tcp_port "8000"; 37 | set tcp_frame_header ""; 38 | 39 | ###SSH options### 40 | set ssh_banner "Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-1065-aws x86_64)"; 41 | set ssh_pipename "SearchTextHarvester##"; 42 | 43 | ###SSL Options### 44 | #custom cert 45 | #https-certificate { 46 | #set keystore "your_store_file.store"; 47 | #set password "your_store_pass"; 48 | #} 49 | 50 | #self sign cert 51 | https-certificate { 52 | set C "US"; 53 | set CN "whatever.com"; 54 | set L "California"; 55 | set O "whatever LLC."; 56 | set OU "local.org"; 57 | set ST "CA"; 58 | set validity "365"; 59 | } 60 | 61 | ###HTTPS_CERTIFICATE VARIANT### 62 | #https-certificate "varinat_name_self" { 63 | # set C "US"; 64 | # set CN "whatever2.com"; 65 | # set L "Florida"; 66 | # set O "whatever2 LLC."; 67 | # set OU "local.org"; 68 | # set ST "FL"; 69 | # set validity "365"; 70 | #} 71 | 72 | #code sign cert. 73 | #code-signer { 74 | #set keystore "your_keystore.jks"; 75 | #set password "your_password"; 76 | #set alias "server"; 77 | #} 78 | 79 | ###HTTP-Config Block### 80 | #Order of server response headers. Or you can just fill them in manually under the server blocks. 81 | #c2lint msg -> .http-config should not set header 'Content-Type'. Let the web server set the value for this field. 82 | http-config { 83 | set headers "Server, Content-Type, Cache-Control, Connection"; 84 | header "Connection" "close"; 85 | header "Cache-Control" "max-age=2"; 86 | header "Server" "nginx"; 87 | #set "true" if teamserver is behind redirector 88 | set trust_x_forwarded_for "false"; 89 | } 90 | 91 | ###HTTP-GET Block### 92 | #the http-get block checks if there are tasks queued. 93 | 94 | http-get { 95 | 96 | #You can specifiy multiple URI's with space between them. 97 | set uri "/login /config /admin"; 98 | 99 | #default method is GET. 100 | set verb "GET"; 101 | #set verb "POST"; 102 | 103 | client { 104 | 105 | #Set headers based on traffic capture/Burp/etc. 106 | header "Host" "whatever.com"; 107 | header "Accept" "*/*"; 108 | header "Accept-Language" "en-US"; 109 | header "Connection" "close"; 110 | 111 | 112 | metadata { 113 | #Encoding options = append "string", base64, base64url, mask, netbios, netbiosu, prepend "string". 114 | #base64 115 | base64url; 116 | #mask; 117 | #netbios; 118 | #netbiosu; 119 | #prepend "TEST123"; 120 | append ".php"; 121 | 122 | #Termination statements = header "header", parameter "key", print, uri-append. 123 | parameter "file"; 124 | #header "Cookie"; 125 | #uri-append; 126 | #Have to set verb to POST if you want to use print in the client GET block. 127 | #print; 128 | 129 | 130 | } 131 | 132 | #You can also add parameter values just to help mimic your site traffic. 133 | parameter "test1" "test2"; 134 | 135 | } 136 | 137 | server { 138 | #headers are defined in the http-config block above, or you can set them manually here. 139 | #header "Server" "nginx"; 140 | 141 | #the output keyword allows you to prepend/append data, to add site traffic, etc. 142 | output { 143 | 144 | netbios; 145 | #netbiosu; 146 | #base64; 147 | #base64url; 148 | #mask; 149 | 150 | 151 | #Use prepend and append to mix your data in with normal looking site traffic. Escape double quotes and you can also use '\n'. c2lint shows '\n' as a period, but you can run it through Burp or pcap a HTTP payload to make sure everything is lining up correctly. Prepend strings need to be entered in reverse order, so the first string here is '"\n";'. 152 | #Havent updated this in awhile, at some point MC2 profiles started displaying copy/paste traffic from Burp 'correctly'. I used to have to play around with spacing, etc. but now usually just copy entire lines in 'prepend' and 'append' terminating correctly. 153 | prepend "content="; 154 | prepend "\n"; 156 | prepend "\n"; 157 | prepend "\n"; 158 | prepend "Online Meeting Software with HD Video Conferencing | GoToMeeting\n"; 159 | prepend " \n"; 160 | prepend " \n"; 161 | prepend "\n"; 162 | prepend "\n"; 163 | 164 | append "\n\n"; 165 | append "\n"; 176 | append "\n"; 177 | append "\n"; 178 | 179 | #All server blocks use 'print' to termintate. 180 | print; 181 | } 182 | } 183 | } 184 | 185 | ###HTTP-GET VARIANT### 186 | #variants allow you to use multiple traffic profiles with a single teamserver. Define the block as normal adding a name for the variant in quotes. 187 | 188 | http-get "variant_name_get" { 189 | 190 | set uri "/index"; 191 | 192 | client { 193 | 194 | header "Accept" "*/*"; 195 | header "Connection" "Keep-Alive"; 196 | 197 | metadata { 198 | 199 | base64url; 200 | parameter "id"; 201 | 202 | } 203 | 204 | parameter "param_key" "value"; 205 | 206 | } 207 | 208 | server { 209 | 210 | header "Server" "Apache"; 211 | 212 | output { 213 | netbios; 214 | 215 | prepend "\n"; 216 | 217 | append "'\n"; 218 | 219 | print; 220 | } 221 | 222 | } 223 | 224 | } 225 | 226 | 227 | ###HTTP-Post Block### 228 | #The same transform and termination rules apply as the client GET section above. 229 | #if tasks are queued then http-post block processes them. 230 | 231 | http-post { 232 | 233 | #URI's cannot be the same as the http-get block URI's, even changing one case is fine. 234 | set uri "/Login /Config /Admin"; 235 | set verb "GET"; 236 | #set verb "POST"; 237 | 238 | client { 239 | 240 | 241 | header "Host" "whatever.com"; 242 | header "Accept" "*/*"; 243 | header "Accept-Language" "en"; 244 | header "Connection" "close"; 245 | 246 | output { 247 | base64url; 248 | parameter "testParam"; 249 | } 250 | 251 | #You can put the beacon id in - parameter "key", header "header", 252 | #cannot add transform statements to beacon id. 253 | id { 254 | base64url; 255 | parameter "id"; 256 | #header "ID-Header": 257 | 258 | } 259 | } 260 | 261 | server { 262 | #headers are defined in the http-config block above, or you can set them manually here. 263 | #header "Server" "nginx"; 264 | 265 | output { 266 | netbios; 267 | 268 | prepend "content="; 269 | prepend "\n"; 271 | prepend "\n"; 272 | prepend "\n"; 273 | prepend "Online Meeting Software with HD Video Conferencing | GoToMeeting\n"; 274 | prepend " \n"; 275 | prepend " \n"; 276 | prepend "\n"; 277 | prepend "\n"; 278 | 279 | append "\n\n"; 280 | append "\n"; 291 | append "\n"; 292 | append "\n"; 293 | print; 294 | } 295 | } 296 | } 297 | 298 | ###HTTP-POST VARIANT### 299 | #variants allow you to use multiple traffic profiles with a single teamserver. Define the block as normal adding a name for the variant in quotes. 300 | 301 | http-post "variant_name_post" { 302 | 303 | set uri "/html"; 304 | #set verb "GET"; 305 | set verb "POST"; 306 | 307 | client { 308 | 309 | header "Accept" "*/*"; 310 | header "Connection" "Keep-Alive"; 311 | 312 | output { 313 | base64url; 314 | parameter "name"; 315 | 316 | } 317 | 318 | id { 319 | base64url; 320 | parameter "id"; 321 | 322 | } 323 | } 324 | 325 | server { 326 | 327 | header "Server" "Apache"; 328 | 329 | output { 330 | netbios; 331 | print; 332 | } 333 | } 334 | } 335 | 336 | 337 | ###HTTP-Stager Block### 338 | #Options to set if you are using a staged payload. 339 | http-stager { 340 | 341 | #Same URI rules apply as above, can't have URI's that match in any other client block. 342 | set uri_x86 "/Console"; 343 | set uri_x64 "/console"; 344 | 345 | client { 346 | header "Host" "whatever.com"; 347 | header "Accept" "*/*"; 348 | header "Accept-Language" "en-US"; 349 | header "Connection" "close"; 350 | 351 | #can use a parameter as well 352 | parameter "test1" "test2"; 353 | } 354 | 355 | server { 356 | #headers are defined in the http-config block above, or you can set them manually here. 357 | #header "Server" "nginx"; 358 | 359 | output { 360 | 361 | prepend "content="; 362 | 363 | append "\n"; 364 | print; 365 | } 366 | 367 | } 368 | 369 | 370 | } 371 | 372 | ###HTTP-Stager Variant### 373 | #variants allow you to use multiple traffic profiles with a single teamserver. Define the block as normal adding a name for the variant in quotes. 374 | 375 | http-stager "variant_name_stager" { 376 | 377 | set uri_x86 "/uri1"; 378 | set uri_x64 "/uri2"; 379 | 380 | client { 381 | header "Host" "whatever.com"; 382 | header "Accept" "*/*"; 383 | header "Accept-Language" "en-US"; 384 | header "Connection" "close"; 385 | 386 | #can use a parameter as well 387 | parameter "test1" "test2"; 388 | } 389 | 390 | server { 391 | #headers are defined in the http-config block above, or you can set them manually here. 392 | #header "Server" "nginx"; 393 | 394 | output { 395 | 396 | prepend "content="; 397 | 398 | append "\n"; 399 | print; 400 | } 401 | 402 | } 403 | 404 | 405 | } 406 | 407 | 408 | 409 | ###Malleable PE/Stage Block### 410 | #use peclone on the dll you want to use, this example uses wwanmm.dll. You can also set the values manually. 411 | #don't use 'set image_size_xx' if using 'set module_xx'. During testing it seemed to double the size of my payload causing module stomp to fail, need to test it out more though. 412 | stage { 413 | set checksum "0"; 414 | set compile_time "25 Oct 2016 01:57:23"; 415 | set entry_point "170000"; 416 | #set image_size_x86 "6586368"; 417 | #set image_size_x64 "6586368"; 418 | #set name "WWanMM.dll"; 419 | set userwx "false"; 420 | set cleanup "true"; 421 | set sleep_mask "true"; 422 | set stomppe "true"; 423 | set obfuscate "true"; 424 | set rich_header "\xee\x50\x19\xcf\xaa\x31\x77\x9c\xaa\x31\x77\x9c\xaa\x31\x77\x9c\xa3\x49\xe4\x9c\x84\x31\x77\x9c\x1e\xad\x86\x9c\xae\x31\x77\x9c\x1e\xad\x85\x9c\xa7\x31\x77\x9c\xaa\x31\x76\x9c\x08\x31\x77\x9c\x1e\xad\x98\x9c\xa3\x31\x77\x9c\x1e\xad\x84\x9c\x98\x31\x77\x9c\x1e\xad\x99\x9c\xab\x31\x77\x9c\x1e\xad\x80\x9c\x6d\x31\x77\x9c\x1e\xad\x9a\x9c\xab\x31\x77\x9c\x1e\xad\x87\x9c\xab\x31\x77\x9c\x52\x69\x63\x68\xaa\x31\x77\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; 425 | 426 | #obfuscate beacon before sleep. 427 | set sleep_mask "true"; 428 | 429 | #https://www.cobaltstrike.com/releasenotes.txt -> + Added option to bootstrap Beacon in-memory without walking kernel32 EAT 430 | set smartinject "true"; 431 | 432 | #new 4.2. options 433 | #set allocator "HeapAlloc"; 434 | #set magic_mx_x86 "MZRE"; 435 | #set magic_mz_x64 "MZAR"; 436 | #set magic_pe "PE"; 437 | 438 | #module stomp. Make sure the dll you use is bigger than your payload and test it with post exploit options to make sure everything is working. 439 | 440 | set module_x86 "wwanmm.dll"; 441 | set module_x64 "wwanmm.dll"; 442 | 443 | #transform allows you to remove, replace, and add strings to beacon's reflective dll stage. 444 | transform-x86 { 445 | prepend "\x90\x90\x90"; 446 | strrep "ReflectiveLoader" ""; 447 | strrep "beacon.dll" ""; 448 | } 449 | 450 | transform-x64 { 451 | prepend "\x90\x90\x90"; 452 | strrep "ReflectiveLoader" ""; 453 | strrep "beacon.x64.dll" ""; 454 | } 455 | 456 | #can set a string in the .rdata section of the beacon dll. 457 | #adds a zero-terminated string 458 | #string "something"; 459 | 460 | #adds a string 'as-is' 461 | #data "something"; 462 | 463 | #adds a wide (UTF-16LE encoded) string 464 | stringw "something"; 465 | } 466 | 467 | ###Process Inject Block### 468 | #controls process injection behavior 469 | process-inject { 470 | 471 | #Can use NtMapViewOfSection or VirtualAllocEx 472 | #NtMapViewOfSection only allows same arch to same arch process injection. 473 | set allocator "NtMapViewOfSection"; 474 | 475 | set min_alloc "16700"; 476 | 477 | set userwx "false"; 478 | 479 | set startrwx "true"; 480 | 481 | #prepend has to be valid code for current arch 482 | transform-x86 { 483 | prepend "\x90\x90\x90"; 484 | } 485 | transform-x64 { 486 | prepend "\x90\x90\x90"; 487 | } 488 | 489 | execute { 490 | #Options to spoof start address for CreateThread and CreateRemoteThread, +0x for offset added to start address. docs recommend ntdll and kernel32 using remote process. 491 | 492 | #start address does not point to the current process space, fires SYSMON 8 events 493 | #CreateThread; 494 | #CreateRemoteThread; 495 | 496 | #self injection 497 | CreateThread "ntdll.dll!RtlUserThreadStart+0x1000"; 498 | 499 | #suspended process in post-ex jobs, takes over primary thread of temp process 500 | SetThreadContext; 501 | 502 | #early bird technique, creates a suspended process, queues an APC call to the process, resumes main thread to execute the APC. 503 | #NtQueueApcThread-s; 504 | 505 | #uses an RWX stub, uses CreateThread with start address that stands out, same arch injection only. 506 | NtQueueApcThread; 507 | 508 | #no cross session 509 | CreateRemoteThread "kernel32.dll!LoadLibraryA+0x1000"; 510 | 511 | #uses an RWX stub, fires SYSMON 8 events, does allow x86->x64 injection. 512 | #c2lint msg -> .process-inject.execute RtlCreateUserThread will cause unpredictable behavior with cross-session injects on XP/200 513 | RtlCreateUserThread; 514 | } 515 | } 516 | 517 | ###Post-Ex Block### 518 | post-ex { 519 | 520 | set spawnto_x86 "%windir%\\syswow64\\gpupdate.exe"; 521 | set spawnto_x64 "%windir%\\sysnative\\gpupdate.exe"; 522 | 523 | set obfuscate "true"; 524 | 525 | set smartinject "true"; 526 | 527 | set amsi_disable "true"; 528 | 529 | #new 4.2 options 530 | set thread_hint "ntdll.dll!RtlUserThreadStart"; 531 | set pipename "DserNamePipe##"; 532 | set keylogger "SetWindowsHookEx"; 533 | 534 | } 535 | -------------------------------------------------------------------------------- /tests/test_builder.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from malleablec2 import Profile 3 | from malleablec2.components import * 4 | 5 | def test_builder(): 6 | profile = Profile.from_scratch() 7 | profile.set_option("sleeptime", "5000") 8 | profile.set_option("jitter", "0") 9 | profile.set_option("pipename", "buildtest_##") 10 | 11 | http_config = HttpConfigBlock() 12 | http_config.set_option("headers", "Date, Server, Content-Length, Keep-Alive, Connection, Content-Type") 13 | http_config.set_option("block_useragents", "curl*,lynx*,wget*") 14 | http_config.add_statement("header", "Connection", "Keep-Alive") 15 | 16 | profile.add_code_block(http_config) 17 | 18 | http_stager = HttpStagerBlock() 19 | http_stager.set_option("uri_x86", "/pymalleablec2/ftw") 20 | http_stager.set_option("uri_x64", "/pymalleablec2/is/the/shizzle") 21 | 22 | profile.add_code_block(http_stager) 23 | 24 | stage = StageBlock() 25 | stage.add_statement("stringw", "I am not Beacon") 26 | stage.set_option("allocator", "MapViewOfFile") 27 | 28 | profile.add_code_block(stage) 29 | 30 | http_get = HttpGetBlock() 31 | http_get.set_option("uri", "/test/wat") 32 | 33 | client = ClientBlock() 34 | client.add_statement("header", "Accept", "*/*") 35 | 36 | server = ServerBlock() 37 | server.add_statement("header", "Server", "Server") 38 | 39 | http_get.add_code_block(client) 40 | http_get.add_code_block(server) 41 | 42 | http_post = HttpPostBlock() 43 | http_post.set_option("uri", "/test/okurrr") 44 | 45 | process_inject = ProcessInjectBlock() 46 | process_inject.set_option("min_alloc", "16384") 47 | 48 | transform86 = Transform86Block() 49 | transform86.add_statement("prepend", r"\x90\x90") 50 | 51 | execute = ExecuteBlock() 52 | execute.add_statement("CreateThread", "ntdll.dll!RtlUserThreadStart") 53 | execute.add_statement("SetThreadContext") 54 | 55 | process_inject.add_code_block(execute) 56 | process_inject.add_code_block(transform86) 57 | 58 | postex = PostExBlock() 59 | postex.set_option("spawnto_x86", r"%windir%\syswow64\calc.exe") 60 | postex.set_option("spawnto_x64", r"%windir%\syswow64\calc.exe") 61 | postex.set_option("obfuscate", "true") 62 | 63 | https_certificate = HttpsCertificateBlock() 64 | https_certificate.set_option("C", "US") 65 | https_certificate.set_option("CN", "localhost") 66 | 67 | code_signer = CodeSignerBlock() 68 | code_signer.set_option("keystore", "keystore.jks") 69 | code_signer.set_option("password", "my_keystore_password") 70 | 71 | profile.add_code_block(code_signer) 72 | profile.add_code_block(https_certificate) 73 | profile.add_code_block(postex) 74 | profile.add_code_block(process_inject) 75 | profile.add_code_block(http_get) 76 | profile.add_code_block(http_post) 77 | 78 | assert len(profile.ast.children) > 0 79 | c = profile.reconstruct() 80 | assert len(c) > 0 81 | print(c) -------------------------------------------------------------------------------- /tests/test_parser.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import pathlib 3 | from malleablec2 import Profile 4 | 5 | def test_parsing(): 6 | path = pathlib.Path('.') 7 | profiles = path.glob("tests/profiles/*.profile") 8 | 9 | for profile in profiles: 10 | p = Profile.from_file(profile) 11 | assert len(p.ast.children) > 0 12 | c = p.reconstruct() 13 | assert len(c) > 0 14 | --------------------------------------------------------------------------------