diff --git a/smoketest/Makefile b/smoketest/Makefile index c66af9db..ad0d751e 100644 --- a/smoketest/Makefile +++ b/smoketest/Makefile @@ -2,7 +2,7 @@ MAKEFILE_PATH := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) -ALTERNATIVE_HOSTS := smoketest.localdomain smoke.localdomain and.localdomain mirrors.localdomain +ALTERNATIVE_HOSTS := smoketest.localdomain smoke.localdomain and.localdomain mirrors.localdomain addhostname.localdomain ADD_HOST := $(addprefix --add-host ,$(addsuffix :127.0.0.1, ${ALTERNATIVE_HOSTS})) diff --git a/smoketest/data/plugins/add_host_name.nasl b/smoketest/data/plugins/add_host_name.nasl new file mode 100644 index 00000000..e2f4b6c1 --- /dev/null +++ b/smoketest/data/plugins/add_host_name.nasl @@ -0,0 +1,45 @@ +if(description) +{ + script_oid("0.0.0.0.0.0.0.0.0.3"); + script_version("2019-11-10T15:30:28+0000"); + script_name("test-add-host-name"); + script_category(ACT_SCANNER); + script_family("my test family"); + script_tag(name:"some", value:"tag"); + script_tag(name:"last_modification", value:"2019-11-10 15:30:28 +0000 (Tue, 10 Nov 2020)"); + script_tag(name:"creation_date", value:"2015-03-27 12:00:00 +0100 (Fri, 27 Mar 2015)"); + script_tag(name:"cvss_base", value:"0.0"); + script_tag(name:"cvss_base_vector", value:"AV:N/AC:L/Au:N/C:N/I:N/A:N"); + script_tag(name:"qod_type", value:"remote_app"); + script_tag(name:"qod", value:"0"); + + script_version("2021-08-19T02:25:52+0000"); + script_cve_id("CVE-0000-0000", "CVE-0000-0001"); + script_tag(name:"severity_vector", value:"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"); + script_tag(name:"severity_origin", value:"NVD"); + script_tag(name:"severity_date", value:"2020-08-07 19:36:00 +0000 (Fri, 07 Aug 2020)"); + script_xref(name:"Example", value:"GB-Test-1"); + script_xref(name:"URL", value:"https://www.greenbone.net"); + + + script_add_preference(name:"example", type:"entry", value:"a default string value"); + + script_tag(name:"vuldetect", value:"Describes what this plugin is doing to detect a vulnerability."); + + script_tag(name:"summary", value:"A short description of the problem"); + script_tag(name:"insight", value:"Some detailed insights of the problem"); + script_tag(name:"impact", value:"Some detailed about what is impacted"); + + script_tag(name:"affected", value:"Affected programs, operation system, ..."); + + script_tag(name:"solution", value:"Solution description"); + script_tag(name:"solution_type", value:"Type of solution (e.g. mitigation, vendor fix)"); + script_tag(name:"solution_method", value:"how to solve it (e.g. debian apt upgrade)"); + script_tag(name:"qod_type", value:"package"); + exit(0); +} +add_host_name(hostname: "addhostname.localdomain", source: "magic entry"); +hn = get_host_name(); +log_msg = hn; +log_message(data:log_msg); +exit(0); diff --git a/smoketest/scan/init.go b/smoketest/scan/init.go index 980f96b9..d07e8095 100644 --- a/smoketest/scan/init.go +++ b/smoketest/scan/init.go @@ -61,6 +61,16 @@ var ConsiderAlive AliveTestMethods = AliveTestMethods{ ConsiderAlive: 1, } + +var Alive = AliveTestMethods{ + ICMP: 1, + TCPSYN: 1, + TCPACK: 1, + ARP: 1, + ConsiderAlive: 0, +} + + type Target struct { XMLName xml.Name `xml:"target"` Hosts string `xml:"hosts,omitempty"` diff --git a/smoketest/usecases/scan/init.go b/smoketest/usecases/scan/init.go index 0fdca47e..831252f6 100644 --- a/smoketest/usecases/scan/init.go +++ b/smoketest/usecases/scan/init.go @@ -8,14 +8,7 @@ import ( "github.com/greenbone/ospd-openvas/smoketest/usecases" ) -var DefaultTargets = scan.Targets{Targets: []scan.Target{ - { - Hosts: "localhost,smoketest.localdomain,smoke.localdomain,and.localdomain,mirrors.localdomain", - Ports: "8080,443", - AliveTestMethods: scan.ConsiderAlive, - }, -}, -} +var DefaultTargets = Targets(scan.ConsiderAlive) var DefaultSelection = []scan.VTSelection{ {Single: []scan.VTSingle{{ @@ -28,25 +21,57 @@ var DefaultStart = scan.Start{ VTSelection: DefaultSelection, } +func Targets(alive scan.AliveTestMethods) scan.Targets { + return scan.Targets{Targets: []scan.Target{ + { + Hosts: "localhost,smoketest.localdomain,smoke.localdomain,and.localdomain,mirrors.localdomain", + Ports: "8080,443", + AliveTestMethods: alive, + }, + }, + } +} + +func addHostName() usecases.Test { + return usecases.Test{ + Title: "Add Host Name Function", + Run: func(o connection.OSPDSender) usecases.Response { + target := Targets(scan.Alive) + slowSelection := []scan.VTSelection{ + {Single: []scan.VTSingle{{ + ID: "0.0.0.0.0.0.0.0.0.3", + }}}, + } + startScan := scan.Start{ + ScannerParams: scan.DefaultScannerParams, + Targets: target, + VTSelection: slowSelection, + } + r := usecases.StartScanGetLastStatus(startScan, o) + if r.Resp.Scan.Status != "finished" { + return *usecases.WrongScanStatus("finished", r.Resp.Scan.Status) + } + for _, result := range r.Resp.Scan.Results.Results { + if result.HostName == "addhostname.localdomain" { + return usecases.Response{ + Success: true, + } + } + } + return usecases.Response{ + Description: fmt.Sprintf("addhost not found in %+v", r.Resp.Scan.Results.Results), + Success: false, + } + + }, + } +} + func stopDeleteWhenNoResults() usecases.Test { return usecases.Test{ Title: "When no results: Queue->Init->Running->Stop->Delete", Run: func(co connection.OSPDSender) usecases.Response { - testeach := scan.AliveTestMethods{ - ICMP: 1, - TCPSYN: 1, - TCPACK: 1, - ARP: 1, - ConsiderAlive: 0, - } - target := scan.Targets{Targets: []scan.Target{ - { - Hosts: "localhost,smoketest.localdomain,smoke.localdomain,and.localdomain,mirrors.localdomain", - Ports: "8080,443", - AliveTestMethods: testeach, - }, - }, - } + target := Targets(scan.Alive) slowSelection := []scan.VTSelection{ {Single: []scan.VTSingle{{ ID: "0.0.0.0.0.0.0.0.0.2", @@ -192,6 +217,7 @@ func Create() usecases.Tests { return usecases.Tests{ Title: "Scan", UseCases: []usecases.Test{ + addHostName(), startScan(), transitionQueueToRunning(), stopDeleteWhenNoResults(),