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

Add Nikto boefje that scans for outdated software #3409

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
16726b1
Made base format for new boefje
Souf149 Jul 31, 2024
bc3a7c8
Fixed issue of nikto boefje not contacting boefje api
Souf149 Aug 7, 2024
09882a6
Added `oci_adapter.js` to better mirror the python's implementation
Souf149 Aug 13, 2024
022ac4e
generic cve normalier
noamblitz Aug 19, 2024
7572d1e
switch to generic cve normalizer
noamblitz Aug 19, 2024
a1765f1
also output orignal boefje output
noamblitz Aug 19, 2024
6f84904
update docs on generic cve normalizer
noamblitz Aug 19, 2024
0ce1f35
Merge branch 'main' into generic-cve-normalizer
noamblitz Aug 20, 2024
0e057bb
Cleaned up code
Souf149 Aug 22, 2024
50e85ae
Added normalizer to kat_nikto boefje
Souf149 Aug 22, 2024
6af750e
Update boefjes/boefjes/plugins/kat_cve_normalizer/normalizer.json
noamblitz Aug 22, 2024
7b62c25
Update boefjes/boefjes/plugins/kat_cve_normalizer/normalizer.json
noamblitz Aug 22, 2024
45c000f
Update docs/source/developer_documentation/development_tutorial/creat…
noamblitz Aug 22, 2024
ac6ca62
Update boefjes/boefjes/plugins/kat_cve_2023_34039/main.py
noamblitz Aug 22, 2024
5ae981e
allow comma seperated list of all findingtypes
noamblitz Aug 22, 2024
60570dd
Merge branch 'main' into generic-cve-normalizer
noamblitz Aug 22, 2024
09ea726
Added new OOI that has information about outdated software
Souf149 Aug 23, 2024
1322be6
use direct mapping
noamblitz Aug 23, 2024
d57565a
Rewrote `oci_adapter.js` to work like `oci_adapter.py` does
Souf149 Aug 23, 2024
0712f4d
Fixed example url
Souf149 Aug 23, 2024
b3a3252
Made base format for new boefje
Souf149 Jul 31, 2024
f8d3294
Fixed issue of nikto boefje not contacting boefje api
Souf149 Aug 7, 2024
4d790c7
Added `oci_adapter.js` to better mirror the python's implementation
Souf149 Aug 13, 2024
d4f92b7
Cleaned up code
Souf149 Aug 22, 2024
6d39582
Added normalizer to kat_nikto boefje
Souf149 Aug 22, 2024
723fd55
Added new OOI that has information about outdated software
Souf149 Aug 23, 2024
13ca4de
Rewrote `oci_adapter.js` to work like `oci_adapter.py` does
Souf149 Aug 23, 2024
cb8d136
Fixed example url
Souf149 Aug 23, 2024
0e74dac
Merge branch 'generic-cve-normalizer' into `feature/nikto-boefje`
Souf149 Aug 23, 2024
2d96eff
cleaned up dockerfiles to remove comments
Souf149 Aug 23, 2024
b050735
Removed new OOI type and sent the nikto message straight to the finding
Souf149 Aug 27, 2024
9954e62
Removed unused variable
Souf149 Aug 27, 2024
0ace647
Added new finding type and use this one instead for nikto boefje
Souf149 Aug 27, 2024
6858fc7
Merge branch 'main' into feature/nikto-boefje
Souf149 Aug 28, 2024
56df40a
Merge branch 'main' into feature/nikto-boefje
Souf149 Aug 28, 2024
491247d
Fixed merging mistake
Souf149 Aug 28, 2024
ef25331
Updated dev's cat'
Souf149 Aug 28, 2024
c6e90f1
Added tests for nikto normalizer
Souf149 Aug 28, 2024
c6647da
Refactored code
Souf149 Aug 28, 2024
0c169ba
Made nikto boefje run on `HostnameHTTPURL`
Souf149 Aug 30, 2024
346e170
Added env variables to nikto boefje
Souf149 Sep 4, 2024
8d5cba0
Moved config file creation to a seperate function
Souf149 Sep 4, 2024
e6cf370
Boefje uses env variable `HTTP_PROXY` instead of split version
Souf149 Oct 4, 2024
939b49c
Merge branch 'main' into feature/nikto-boefje
Souf149 Oct 4, 2024
0f65563
Added name to normalizer
Souf149 Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boefjes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ images: # Build the images for the containerized boefjes
# docker build -f images/base.Dockerfile -t ghcr.io/minvws/openkat/dns-records --build-arg BOEFJE_PATH=./boefjes/plugins/kat_dns .
docker build -f ./boefjes/plugins/kat_dnssec/boefje.Dockerfile -t ghcr.io/minvws/openkat/dns-sec:latest .
docker build -f ./boefjes/plugins/kat_nmap_tcp/boefje.Dockerfile -t ghcr.io/minvws/openkat/nmap:latest .

docker build -f ./boefjes/plugins/kat_nikto/boefje.Dockerfile -t openkat/nikto .

##
##|------------------------------------------------------------------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,5 +486,11 @@
"source": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers",
"impact": "Nonstandard headers may not be supported by all browsers and may not provide the security that is expected.",
"recommendation": "Remove the nonstandard headers from the response."
},
"KAT-OUTDATED-SOFTWARE": {
"description": "A newer version of existing software has been found.",
"risk": "recommendation",
"impact": "Depending on what software is outdated this can be critical.",
"recommendation": "Inspect the software version, determine if additional measures need to be taken and install updates to reduce the attack surface."
}
}
Empty file.
14 changes: 14 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/boefje.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:19-bullseye

WORKDIR /app
RUN apt update
RUN apt install -y git

RUN git clone https://github.com/sullo/nikto

ARG BOEFJE_PATH=./boefjes/plugins/kat_nikto
COPY $BOEFJE_PATH ./

RUN npm ci

ENTRYPOINT [ "node", "./" ]
14 changes: 14 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/boefje.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "nikto",
"name": "Nikto",
"description": "Uses Nikto",
"consumes": [
"IPAddressV4",
"IPAddressV6",
"Hostname"
Copy link
Contributor

@underdarknl underdarknl Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to start Nikto on Ipports that we know are talking http/https.
This way we avoid nikto on services that are not webservers, or even better:

It looks like there's also a way to differentiate between different hostnames on the same IP, so scanning on websites could also make sense as that would provide the best data-set including any differences between ipv4 and ipv6 addresses or the same host. Use the cli argument -host+ for this combined with -nolookup to make sure we connect only to the ip and -port we provide with the hostname we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have looked more into it and think using the OOI HostnameHTTPURL would be perfect. It has a hostname, port, and scheme which has everything. I was not able to find information from IpPort whether it was a webserver or not (unless you meant looking at the port's number).

-h+ is supposed to be an alias for -host+ although this is not specified in nikto's wiki. I will make sure to use -nolookup.

Copy link
Contributor Author

@Souf149 Souf149 Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The boefje now makes use of HostnameHTTPURL which tells the boefje whether its HTTP or HTTPS and contains a hostname as well.

In theory IPAddressHTTPURL could also be used, I plan to add this once the boefje is satisfactory.

In the current example -nolookup does not get used because I make use of the hostname.

],
"environment_keys": [],
"scan_level": 3,
"oci_image": "openkat/nikto",
"oci_arguments": []
}
Binary file added boefjes/boefjes/plugins/kat_nikto/cover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Nikto

Nikto 2.5 is an Open Source (GPL) web server scanner which performs comprehensive tests against web servers for multiple items, including over 7,000 potentially dangerous files/programs, checks for outdated versions of over 1250 servers, and version specific problems on over 270 servers. It also checks for server configuration items such as the presence of multiple index files, HTTP server options, and will attempt to identify installed web servers and software. Scan items and plugins are frequently updated and can be automatically updated.

(taken from [CIRT.net](https://cirt.net/Nikto2))

### Input OOIs

Nikto expects an IpAddress or a Hostname OOI.

### Output OOIs

Nikto outputs the following the found outdated software and a finding explaining that the software is outdated.

**Cat name**: Kitty
54 changes: 54 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import fs from "node:fs";
import { execSync } from "node:child_process";

/**
* @param {{}} boefje_meta The string input to base64 encode
* @returns {(string | string[])[][]}
*/
export default function (boefje_meta) {
// Depending on what OOI triggered this task, the hostname / address will be in a different location
const object_type = boefje_meta.arguments.input.object_type;
let ooi = "";
if (["IPAddressV4", "IPAddressV6"].includes(object_type))
ooi = boefje_meta.arguments.input.address;
else if (object_type == "Hostname") ooi = boefje_meta.arguments.input.name;
else throw new Error("Unexpected boefje_meta");

// Running nikto and outputting to a file
try {
execSync(`./nikto/program/nikto.pl -h ${ooi} -o ./output.json`, {
stdio: "inherit",
Souf149 marked this conversation as resolved.
Show resolved Hide resolved
});
} catch (e) {
console.error(e);
throw new Error(
"Something went wrong running the nikto command.\n" + e.message,
);
}

const raws = [];

// Reading the file created by nikto
try {
var file_contents = fs.readFileSync("./output.json").toString();
raws.push([["boefje/nikto-output"], file_contents]);
} catch (e) {
console.error(e.message);
throw new Error(
"Something went wrong reading the file from the nikto command.\n" +
e.message,
);
}

// Looking if outdated software has been found
try {
const data = JSON.parse(file_contents);
for (const vulnerability of data["vulnerabilities"])
if (vulnerability["id"].startsWith("6"))
raws.push([["openkat/finding"], "KAT-OUTDATED-SOFTWARE"]);
} catch (e) {
console.error(e.message);
}

return raws;
}
38 changes: 38 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/normalize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json
from collections.abc import Iterable

from boefjes.job_models import NormalizerOutput
from octopoes.models import Reference
from octopoes.models.ooi.findings import Finding, KATFindingType
from octopoes.models.ooi.software import Software, SoftwareInstance


def scan_outdated_software(data: dict, ooi_ref: Reference) -> Iterable[NormalizerOutput]:
for scan in data:
for vulnerability in scan["vulnerabilities"]:
# If the scanned vulnerability has to do with outdated software
if vulnerability["id"].startswith("6"):
# Example of `vulnerability["msg"]`
# @SOFTWARE/@RUNNING_VER appears to be outdated (current is at least @CURRENT_VER)
software_name, found_version = vulnerability["msg"].split()[0].split("/")

software = Software(name=software_name, version=found_version)
software_instance = SoftwareInstance(ooi=ooi_ref, software=software.reference)
yield software
yield software_instance

finding_type = KATFindingType(id="KAT-OUTDATED-SOFTWARE")
yield finding_type
yield Finding(
finding_type=finding_type.reference,
ooi=software_instance.reference,
description=vulnerability["msg"],
)


def run(input_ooi: dict, raw: bytes) -> Iterable[NormalizerOutput]:
data = json.loads(raw)

ooi_ref = Reference.from_str(input_ooi["primary_key"])

yield from scan_outdated_software(data, ooi_ref)
10 changes: 10 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/normalizer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "kat_nikto_normalize",
"consumes": [
"boefje/nikto-output"
],
"produces": [
"Software",
"SoftwareInstance"
]
}
62 changes: 62 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/oci_adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { execSync } from "node:child_process";
import run from "./main.js";

/**
* @param {string} inp The string input to base64
* @returns {string}
*/
function b64encode(inp) {
return Buffer.from(inp).toString("base64");
}

function main() {
const input_url = process.argv[process.argv.length - 1];

// Getting the boefje input
try {
var boefje_input = JSON.parse(
execSync(`curl --request GET --url ${input_url} -s`).toString(),
);
} catch (error) {
console.error(`Getting boefje input went wrong with URL: ${input_url}`);
throw new Error(error.message);
}

let out = undefined;
let output_url = boefje_input.output_url;
try {
// Getting the raw files
const raws = run(boefje_input.boefje_meta);
out = {
status: "COMPLETED",
files: raws.map((x) => ({
content: b64encode(x[1]),
tags: x[0],
})),
};
} catch (error) {
out = {
status: "FAILED",
files: [
{
content: b64encode("Boefje caught an error: " + error.message),
tags: ["error/boefje"],
},
],
};
}

// Example command
/*
curl --request POST \
--url http://boefje:8000/api/v0/tasks/7342e8dd-b945-4185-aaec-787205b7b664 \
--header 'Content-Type: application/json' \
--data '{"status":"COMPLETED","files":[{"content":"BASE_64_ENCODED_CONTENT","tags":[]}]}'
*/
const out_json = JSON.stringify(out);
const cmd = `curl --request POST --url ${output_url} --header "Content-Type: application/json" --data '${out_json}'`;

execSync(cmd);
}

main();
43 changes: 43 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "kat-nikto",
"version": "1.0.0",
"type": "module",
"main": "oci_adapter.js",
"author": "cynalytics",
"dependencies": {
"@types/node": "^22.1.0"
}
}
6 changes: 6 additions & 0 deletions boefjes/boefjes/plugins/kat_nikto/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "Arguments",
"type": "object",
"properties": {},
"required": []
}
Souf149 marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions boefjes/tests/examples/raw/nikto-example.com.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"host": "example.com",
"ip": "178.128.108.228",
"port": "80",
"banner": "",
"vulnerabilities": [
{
"id": "600575",
"method": "HEAD",
"url": "/",
"msg": "nginx/1.18.0 appears to be outdated (current is at least 1.25.3)."
},
{
"id": "999103",
"references": "https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/",
"method": "GET",
"url": "/",
"msg": "The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type."
}
]
}
]
16 changes: 16 additions & 0 deletions boefjes/tests/examples/raw/nikto-non-existing.com.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"host": "non-existing.com",
"ip": "2.1.3.5",
"port": "6667",
"banner": "",
"vulnerabilities": [
{
"id": "0",
"method": "GET",
"url": "/",
"msg": "Unable to connect to non-existing.com."
}
]
}
]
41 changes: 41 additions & 0 deletions boefjes/tests/test_nikto_normalizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from unittest import TestCase

from boefjes.plugins.kat_nikto.normalize import run
from octopoes.models import Reference
from octopoes.models.ooi.findings import KATFindingType
from octopoes.models.ooi.software import Software, SoftwareInstance
from octopoes.models.types import Finding
from tests.loading import get_dummy_data


class CVETest(TestCase):
def test_outdated_found(self):
input_ooi = {"primary_key": "Hostname|internet|example.com"}
ooi_ref = Reference.from_str(input_ooi["primary_key"])

oois = list(run(input_ooi, get_dummy_data("raw/nikto-example.com.json")))

software = Software(name="nginx", version="1.18.0")
finding_type = KATFindingType(id="KAT-OUTDATED-SOFTWARE")
software_instance = SoftwareInstance(ooi=ooi_ref, software=software.reference)
finding = Finding(
finding_type=finding_type.reference,
ooi=software_instance.reference,
description="nginx/1.18.0 appears to be outdated (current is at least 1.25.3).",
)

expected = [
software,
software_instance,
finding_type,
finding,
]

self.assertEqual(expected, oois)

def test_nothing_found(self):
input_ooi = {"primary_key": "Hostname|internet|non-existing.com"}

oois = list(run(input_ooi, get_dummy_data("raw/nikto-non-existing.com.json")))

self.assertEqual([], oois)
Loading