Package: kharma
pip3 install kharmaInstallation>Usage>Templates>ContactKharma is a state-of-the-artgrammar fuzzer. It can generate many random documents based on a grammar, which can be used to improve your testing corpus by increasing code coverage and to find bugs/vulnerabilities in many kinds of applications (interpreters, files parsers, etc...).RequirementsPython 3InstallationInstall with pip (recommended)pip3installkharmaInstall with Docker/bin/bash./scripts/docker_install.shOr build from sourceRecommended for developers. It automatically clones the main branch from the kharma repo, and installs from source.# Automatically clone the Kharma repository and install Kharma from sourcebash<(wget-qhttps://raw.githubusercontent.com/Rog3rSm1th/Kharma/main/scripts/autoinstall.sh-O-)Usageusage: kharma [-h] [-v] -t TEMPLATE -c COUNT [-s] {output} ...

positional arguments:
  {output}              sub-command help
    output              output help

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -t TEMPLATE, --template TEMPLATE
                        template path, e.g. ./path/to/file.kg
  -c COUNT, --count COUNT
                        number of documents to generate
  -s, --safe-mode       disallow call statementsBasic usageFor example if you want to generate 10 documents based on thejavascript.kgtemplate:kharma-t./javascript.kg-c10The documents will then be printed onstdout.Generate files documentsOtherwise, if you want to save the documents into files you should use theoutputoption.usage: kharma output [-h] -d DIRECTORY
                     [-e EXTENSION]For example if you want to output the documents in ajs_documentsfolder with the.jsextension:kharma-t./javascript.kg-c10output-d./js_documents-ejsTemplatesKharma generates random documents based on grammars defined in templates, those templates are based on theYAMLformat and are divided into different sections.Comments# This is a comment# This is a# Multi-line commentImports (optional section)It is possible to import variables, constants and functions defined in other templates using theimportssection.imports:# You must specify the import name as well as the relative path of the templateimport:"import.kg"Functions (optional section)Thefunctionsection allows you to define python functions inside your template.functions:# Here we define the "multiply" function.multiply:|<%python (factor_1, factor_2)factor_1_int = int(factor_1)factor_2_int = int(factor_2)product = factor_1_int*factor_2_intreturn product%>Constants (optional section)Theconstssection allows to define values with only one possible value. Constants can use references to variables and vice versa.consts:const_0:"Thisisaconstant"const_1:|Multiple linesconstantconst_2:"++import:int8++"const_3:"++variable_0++"const_4:"++const_0++"const_5:"@@element_@@"const_6:"[%%range%%](0,1337)"const_7:"[%%regexp:[A-Za-z0-9]+%%]"const_8:"[%%call~multiply%%](3,4)"const_9:"[##repeat:1:5:dup:##]{%loopedstring%}"Variables (optional section)Thevariablessection allows you to define values with several possible values.variables:# A variable can have several possible valuesvariable_0:-"doublequotedvariable"-'singlequotedvariable'-"Unicodestring:\u0398\u039f\u03b4"-"Hexadecimalstring:\x49\x4a\x4b"-|variable can be writtenon multipleslines !# An anchor is a reference to another variablevariable_anchor:# The anchor will be replaced by one of the possibles values of the variable-"++variable_0++"# Variable can use references to constantsvariable_const_anchor:-"++const_0++"-"++const_1++"-"++const_2++"-"++const_3++"-"++const_4++"-"++const_5++"-"++const_6++"-"++const_7++"-"++const_8++"-"++const_9++"# You can access variables/consts defined in imported filesvariable_import_anchor:-"++import:int8++"-"++import:uint8++"-"++import:int16++"-"++import:uint16++"-"++import:int32++"-"++import:uint32++"-"++import:int32++"-"++import:uint32++"# An element has a name and a counter.variable_element:# The first time we call it, the result will be "element_0", the next time# "element_1", and so on-"@@element_@@"# You can use id parameter to reuse same element value# element_id_0 element_id_1 element_id_0 element_id_2-"@@element_id_@@#id=test@@element_id_@@@@element_id_@@#id=test@@element_id_@@"# Selection of a random value within the rangevariable_range:-"[%%range%%](0,1337)"-"[%%range%%](-100,100)"-"[%%range%%](-infinity,infinity)"# Generate a random valid input for the regular expressionvariable_regexp:-"[%%regexp:[A-Za-z0-9]+%%]"# Calls a function defined within the template and gets the return valuevariable_call:-"[%%call~multiply%%](3,4)"-"[%%call~multiply%%](++import:int8++,++import:int8++)"-"[%%call~multiply%%]([%%range%%](-100,100),[%%range%%](-infinity,infinity))"# Calls a function defined in an imported template and gets the return valuevariable_import_call:-"[%%call~import:sum%%](3,4)"-"[%%call~import:sum%%](++import:int8++,++import:int8++)"-"[%%call~import:sum%%]([%%range%%](-100,100),[%%range%%](-infinity,infinity))"# Loop a stringvariable_loop:# Repeat a string between 1 and 5 times-"[##repeat:1:5:dup:##]{%loopedstring%}"# Use a custom separator-"[##repeat:1:5:dup:,##]{%loopedstring%}"# Repeat an anchor-"[##repeat:1:5:dup:##]{%++variable_anchor++%}"# Remove duplicates-"[##repeat:1:5:nodup:##]{%++variable_anchor++%}"# Repeat an imported anchor-"[##repeat:1:5:dup:##]{%++variable_import_anchor++%}"# Repeat an element reference-"[##repeat:1:5:dup:##]{%++variable_element++%}"# Repeat a range statement-"[##repeat:1:5:dup:##]{%[%%range%%](-100,100)%}"# Repeat a regexp statement-"[##repeat:1:5:dup:##]{%++variable_regexp++%}"# It is possible to define a static variable by giving it a name starting# with "static_"# A static variable will be evaluated only once and will take the# same value at each callstatic_variable:-"thisisastaticvalue"-"++import:int8++"-"@@element_@@"-"[%%range%%](0,1337)"-"[%%regexp:[A-Za-z0-9]+%%]"-"[%%call~multiply%%](3,4)"-"[##repeat:1:5:dup:##]{%loopedstring%}"# It is possible to use several statements/referencesseveral_statements_variables:-"++variable_0++++import:int8++@@element_@@[%%range%%](0,1337)[%%regexp:[A-Za-z0-9]+%%][%%call~multiply%%](3,4)[##repeat:1:5:dup:##]{%loopedstring%}"Variance (optional section)Thevariancesection contains themainvariable which is the entry point of the template.variance:# Main is the entry point of the template# it works like a regular variablemain:# Happy template generating ! ヽ(o＾▽＾o)ノ-"++several_statements_variables++"IMPORTANT: The order in which the sections are defined isnot importantand all sections areoptionals.You can find a demo templatehere.Contactfor any remark, suggestion, bug report, or if you found a bug using Kharma, you can contact me atr0g3r5@protonmail.comor on twitter@Rog3rSm1th