-
Notifications
You must be signed in to change notification settings - Fork 58
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
Souf149
wants to merge
45
commits into
minvws:main
Choose a base branch
from
Cynalytics:feature/nikto-boefje
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 bc3a7c8
Fixed issue of nikto boefje not contacting boefje api
Souf149 09882a6
Added `oci_adapter.js` to better mirror the python's implementation
Souf149 022ac4e
generic cve normalier
noamblitz 7572d1e
switch to generic cve normalizer
noamblitz a1765f1
also output orignal boefje output
noamblitz 6f84904
update docs on generic cve normalizer
noamblitz 0ce1f35
Merge branch 'main' into generic-cve-normalizer
noamblitz 0e057bb
Cleaned up code
Souf149 50e85ae
Added normalizer to kat_nikto boefje
Souf149 6af750e
Update boefjes/boefjes/plugins/kat_cve_normalizer/normalizer.json
noamblitz 7b62c25
Update boefjes/boefjes/plugins/kat_cve_normalizer/normalizer.json
noamblitz 45c000f
Update docs/source/developer_documentation/development_tutorial/creat…
noamblitz ac6ca62
Update boefjes/boefjes/plugins/kat_cve_2023_34039/main.py
noamblitz 5ae981e
allow comma seperated list of all findingtypes
noamblitz 60570dd
Merge branch 'main' into generic-cve-normalizer
noamblitz 09ea726
Added new OOI that has information about outdated software
Souf149 1322be6
use direct mapping
noamblitz d57565a
Rewrote `oci_adapter.js` to work like `oci_adapter.py` does
Souf149 0712f4d
Fixed example url
Souf149 b3a3252
Made base format for new boefje
Souf149 f8d3294
Fixed issue of nikto boefje not contacting boefje api
Souf149 4d790c7
Added `oci_adapter.js` to better mirror the python's implementation
Souf149 d4f92b7
Cleaned up code
Souf149 6d39582
Added normalizer to kat_nikto boefje
Souf149 723fd55
Added new OOI that has information about outdated software
Souf149 13ca4de
Rewrote `oci_adapter.js` to work like `oci_adapter.py` does
Souf149 cb8d136
Fixed example url
Souf149 0e74dac
Merge branch 'generic-cve-normalizer' into `feature/nikto-boefje`
Souf149 2d96eff
cleaned up dockerfiles to remove comments
Souf149 b050735
Removed new OOI type and sent the nikto message straight to the finding
Souf149 9954e62
Removed unused variable
Souf149 0ace647
Added new finding type and use this one instead for nikto boefje
Souf149 6858fc7
Merge branch 'main' into feature/nikto-boefje
Souf149 56df40a
Merge branch 'main' into feature/nikto-boefje
Souf149 491247d
Fixed merging mistake
Souf149 ef25331
Updated dev's cat'
Souf149 c6e90f1
Added tests for nikto normalizer
Souf149 c6647da
Refactored code
Souf149 0c169ba
Made nikto boefje run on `HostnameHTTPURL`
Souf149 346e170
Added env variables to nikto boefje
Souf149 8d5cba0
Moved config file creation to a seperate function
Souf149 e6cf370
Boefje uses env variable `HTTP_PROXY` instead of split version
Souf149 939b49c
Merge branch 'main' into feature/nikto-boefje
Souf149 0f65563
Added name to normalizer
Souf149 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "./" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
], | ||
"environment_keys": [], | ||
"scan_level": 3, | ||
"oci_image": "openkat/nikto", | ||
"oci_arguments": [] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 fromIpPort
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
.There was a problem hiding this comment.
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.