Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to scan host doesn't work #800

Open
diocanelebbrosobastardo opened this issue Oct 19, 2022 · 1 comment
Open

Script to scan host doesn't work #800

diocanelebbrosobastardo opened this issue Oct 19, 2022 · 1 comment
Labels
bug This issue or pull request already exists

Comments

@diocanelebbrosobastardo

hi I'm using openvas that I installed on kali linux (installed on virtual box) ...

what i would like to do is scan my system .... i found this script, only once i give it the command to run it, which is suggested by the script itself, i get this:

usage: gvm-script [-h] [-c [CONFIG]] [--log [{DEBUG, INFO, WARNING, ERROR, CRITICAL}]] [--timeout TIMEOUT] [--gmp-username GMP_USERNAME]
                  [--gmp-password GMP_PASSWORD] [-V] [--protocol {GMP, OSP}]
                  CONNECTION_TYPE ...
gvm-script: error: the following arguments are required: CONNECTION_TYPE
unknown option - -
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:] port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user @] host [: port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host: port]
           [-w local_tun [: remote_tun]] destination [command [argument ...]]

this is the script I used, found in the openVAS github page:

https://github.com/greenbone/gvm-tools/blob/main/scripts/scan-new-system.gmp.py

import datetime
import sys
from argparse import Namespace

from gvm.protocols.gmp import Gmp


def check_args(args):
    len_args = len(args.script) - 1
    message = """
        This script starts a new scan on the given host.
        It needs one parameters after the script name.
        1. <host_ip>        IP Address of the host system
        2. <port_list_id>   Port List UUID for scanning the host system. 
                            Preconfigured UUID might be under 
                            /var/lib/gvm/data-objects/gvmd/20.08/port_lists/. 
                            ex. iana-tcp-udp is 
                            "4a4717fe-57d2-11e1-9a26-406186ea4fc5".
        
                Example:
            $ gvm-script --gmp-username name --gmp-password pass \
ssh --hostname <gsm> scripts/scan-new-system.gmp.py <host_ip> <port_list_id>
    """
    if len_args != 2:
        print(message)
        sys.exit()


def create_target(gmp, ipaddress, port_list_id):
    # create a unique name by adding the current datetime
    name = f"Suspect Host {ipaddress} {str(datetime.datetime.now())}"

    response = gmp.create_target(
        name=name, hosts=[ipaddress], port_list_id=port_list_id
    )
    return response.get("id")


def create_task(gmp, ipaddress, target_id, scan_config_id, scanner_id):
    name = f"Scan Suspect Host {ipaddress}"
    response = gmp.create_task(
        name=name,
        config_id=scan_config_id,
        target_id=target_id,
        scanner_id=scanner_id,
    )
    return response.get("id")


def start_task(gmp, task_id):
    response = gmp.start_task(task_id)
    # the response is
    # <start_task_response><report_id>id</report_id></start_task_response>
    return response[0].text


def main(gmp: Gmp, args: Namespace) -> None:

    check_args(args)

    ipaddress = args.argv[1]
    port_list_id = args.argv[2]

    target_id = create_target(gmp, ipaddress, port_list_id)

    full_and_fast_scan_config_id = "daba56c8-73ec-11df-a475-002264764cea"
    openvas_scanner_id = "08b69003-5fc2-4037-a479-93b440211c73"
    task_id = create_task(
        gmp,
        ipaddress,
        target_id,
        full_and_fast_scan_config_id,
        openvas_scanner_id,
    )

    report_id = start_task(gmp, task_id)

    print(
        f"Started scan of host {ipaddress}. "
        f"Corresponding report ID is {report_id}"
    )


   
if __name__ == "__gmp__":
    # pylint: disable=undefined-variable
    main(gmp, args) 

2 problems are also reported: "gmp" is not defined, ln87 "args" is not defined, ln87

can anyone please help me ?

@diocanelebbrosobastardo diocanelebbrosobastardo added the bug This issue or pull request already exists label Oct 19, 2022
@bjoernricks bjoernricks transferred this issue from greenbone/openvas-scanner Oct 20, 2022
@bjoernricks bjoernricks changed the title script to scan host doesn't work [OpenVAS] Script to scan host doesn't work Oct 20, 2022
@bjoernricks
Copy link
Contributor

You need to run a GMP script via gvm-script [connection type] /path/to/script.gmp.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants