1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# SPDX-FileCopyrightText: 2017-2021 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
import sys
from argparse import Namespace
from random import choice
from gvm.protocols.gmp import Gmp
from gvmtools.helper import generate_id
def check_args(args):
len_args = len(args.script) - 1
if len_args != 1:
message = """
This script will create random data in the given GVM database
1. <count> -- Number of datasets to create
Example:
$ gvm-script --gmp-username name --gmp-password pass \
ssh --hostname <gsm> scripts/create-dummy-data.gmp.py <count>
"""
print(message)
sys.exit()
def create_data(gmp, count):
config_ids = []
target_ids = []
for _ in range(0, count):
name = generate_id()
gmp.create_credential(
name,
login=name,
password=name,
credential_type=gmp.types.CredentialType.PASSWORD_ONLY,
)
print(str(count) + " random credentials generated.")
for _ in range(0, count):
name = generate_id()
gmp.create_port_list(name, port_range="T:1-42")
print(str(count) + " random port lists generated.")
for _ in range(0, count):
name = generate_id()
res = gmp.create_scan_config(
"085569ce-73ed-11df-83c3-002264764cea", name
)
config_ids.append(res.xpath("@id")[0])
print(str(count) + " random scan configs generated.")
for _ in range(0, count):
name = generate_id()
res = gmp.create_target(name, hosts=["127.0.0.1"])
target_ids.append(res.xpath("@id")[0])
print(str(count) + " random targets generated.")
for _ in range(0, count):
name = generate_id()
config_id = choice(config_ids)
target_id = choice(target_ids)
gmp.create_task(
name, config_id, target_id, "08b69003-5fc2-4037-a479-93b440211c73"
)
print(str(count) + " random tasks generated.")
def main(gmp: Gmp, args: Namespace) -> None:
# pylint: disable=undefined-variable
check_args(args)
create_data(gmp, int(args.script[1]))
if __name__ == "__gmp__":
main(gmp, args)
|