Пример #1
0
def resources(ctx, category, paid, free, output, output_file):
    """
    \b
    List all resources inventoried on rawsec, you can add category.
    Full documentation: https://rawsec-cli.readthedocs.io/
    \f

    Parameters
    ----------
    ctx: Context
        Click context.
    category: str, optional
        Category name.
    paid: bool, optional
        paid or not.
    free: bool, optional
        free or not.
    output: str, optional
        output format.
    output_file: str, optional
        output file name, extension file will override output parameter.

    Returns
    -------
    None
        Return in output format(Default: table) in output_file(Default: stdout) a list of rawsec resources.
    """
    wanted_keys = ["name", "website", "source", "description", "price"]
    if category and category not in get_resources_category(
            json=ctx.obj["json"], ):
        click.echo("Category available:")
        for category in get_resources_category(json=ctx.obj["json"]):
            click.echo(f"\t{category}")
        sys.exit("Not a good category")
    if category:
        projects = get_resources_by_category(ctx.obj["json"], category)
    else:
        projects = get_all_resources(ctx.obj["json"])

    projects = filter_projects(projects, paid=paid, free=free)
    resourcesList = list()
    for resource in projects:
        for link in resource["links"]:
            resource[list(link.keys())[0]] = link[list(link.keys())[0]]
        del resource["links"]

        resourceList = list()
        for keys in wanted_keys:
            if keys not in resource:
                resourceList.append("")
            else:
                resourceList.append(resource[keys])
        resourcesList.append(resourceList)
    print_output(
        projects=projects,
        output=output,
        file=output_file,
        wanted_keys=wanted_keys,
    )
Пример #2
0
def ctf(ctx, category, lang, paid, free, output, output_file):
    """
    \b
    List all ctf platforms inventoried on rawsec, you can add category.
    Full documentation: https://rawsec-cli.readthedocs.io/
    \f
    Parameters
    ----------
    ctx: Context
        Click context.
    category: str, optional
        Category name.
    lang: str, optional
        Language name
    paid: bool, optional
        paid or not.
    free: bool, optional
        free or not.
    output: str, optional
        output format.
    output_file: str, optional
        output file name, extension file will override output parameter.

    Returns
    -------
    None
        Return in output format(Default: table) in output_file(Default: stdout) a list of rawsec ctf.
    """
    wanted_keys = [
        "name",
        "website",
        "source",
        "description",
        "language",
        "price",
    ]
    if category and category not in get_ctf_category(json=ctx.obj["json"]):
        click.echo("Category available:")
        for category in get_ctf_category(json=ctx.obj["json"]):
            click.echo(f"\t{category}")
        sys.exit("Not a good category")
    if category:
        projects = get_ctf_by_category(ctx.obj["json"], category)
    else:
        projects = get_all_ctf(ctx.obj["json"])

    projects = [{k: tool[k] if k in tool else ""
                 for k in wanted_keys} for tool in projects]
    projects = filter_projects(projects, lang=lang, paid=paid, free=free)
    print_output(
        projects=projects,
        output=output,
        file=output_file,
        wanted_keys=wanted_keys,
    )
Пример #3
0
def test_print_output(capsys):
    """ test print_output function"""
    print_output(
        projects=[{
            "name": "test",
            "source": "test"
        }],
        output="table",
        wanted_keys=["name", "source"],
    )
    captured = capsys.readouterr()
    assert "Total projects found: 1" in captured.out

    print_output(projects=[], output="json")
    captured = capsys.readouterr()
    assert '{"projects": [], "total": 0}' in captured.out

    print_output(projects=[], output="csv", wanted_keys=["name", "source"])
    captured = capsys.readouterr()
    assert '"name","source"' in captured.out

    print_output(
        file="test.txt",
        projects=[{
            "name": "test",
            "source": "test"
        }],
        wanted_keys=["name", "source"],
    )
    assert os.path.exists("test.txt")
    with open("test.txt") as txt_file:
        text = txt_file.read()
        assert "name" in text
        assert "source" in text
    os.remove("test.txt")
Пример #4
0
def os(ctx, category, base, output, output_file):
    """
    \b
    List all os inventoried on rawsec, you can add category.
    Full documentation: https://rawsec-cli.readthedocs.io/
    \f
    Parameters
    ----------
    ctx: Context
        Click context.
    category: str, optional
        Category name.
    base: str, optional
        Base name(ex: Linux).
    output: str, optional
        output format.
    output_file: str, optional
        output file name, extension file will override output parameter.

    Returns
    -------
    None
        Return in output format(Default: table) in output_file(Default: stdout) a list of rawsec ctf.
    """
    wanted_keys = ["os", "base", "description", "link"]
    if category and category not in get_operating_category(
            json=ctx.obj["json"], ):
        click.echo("Category available:")
        for category in get_operating_category(json=ctx.obj["json"]):
            click.echo(f"\t{category}")
        sys.exit("Not a good category")
    if category:
        if category == "project_transferred":
            wanted_keys = ["from", "to"]
        projects = get_operating_by_category(ctx.obj["json"], category)
    else:
        projects = get_all_operating(ctx.obj["json"])
    projects = [{k: os[k] if k in os else ""
                 for k in wanted_keys} for os in projects]
    if base:
        projects = [
            os for os in projects if os["base"].lower() == base.lower()
        ]
    print_output(
        projects=projects,
        output=output,
        file=output_file,
        wanted_keys=wanted_keys,
    )
Пример #5
0
def search(
    ctx,
    project,
    lang,
    paid,
    free,
    online,
    offline,
    blackarch,
    output,
    output_file,
):
    """
    \b
    Search a project inventoried on rawsec.
    Search in name and description.
    Full documentation: https://rawsec-cli.readthedocs.io/
    \f

    Parameters
    ----------
    ctx: Context
        Click context.
    project: str, optional
        Keyword.
    lang: str, optional
        Language name.
    paid: bool, optional
        paid or not.
    free: bool, optional
        free or not.
    online: bool, optional
        online or not.
    offline: bool, optional
        offline or not.
    blackarch: bool, optional
        present on blackarch.
    output: str, optional
        output format.
    output_file: str, optional
        output file name, extension file will override output parameter.

    Returns
    -------
    None
        Return in output format(Default: table) in output_file(Default: stdout) a list of rawsec project within description or name project keyword.
    """
    projects = search_project(ctx.obj["json"], project)
    projects = filter_projects(
        projects,
        lang,
        paid,
        free,
        online,
        offline,
        blackarch,
    )
    wanted_keys = list()
    for project in projects:
        wanted_keys += project.keys()
    print_output(
        projects=projects,
        output=output,
        file=output_file,
        wanted_keys=list(dict.fromkeys(wanted_keys)),
    )