This repository was archived by the owner on Apr 10, 2024. It is now read-only.
forked from greenbone/gvm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-dummy-data.gmp.py
93 lines (72 loc) · 2.68 KB
/
create-dummy-data.gmp.py
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
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
# Copyright (C) 2017-2021 Greenbone Networks GmbH
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from random import choice
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_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, args):
# pylint: disable=undefined-variable
check_args(args)
create_data(gmp, int(args.script[1]))
if __name__ == '__gmp__':
main(gmp, args)