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

CVE-2007-4559 Patch #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 43 additions & 2 deletions node.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,29 @@ def bootstrap():
download_file("https://bismuth.cz/ledger.tar.gz", archive_path)

with tarfile.open(archive_path) as tar:
tar.extractall("static/") # NOT COMPATIBLE WITH CUSTOM PATH CONFS

import os

def is_within_directory(directory, target):

abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)

prefix = os.path.commonprefix([abs_directory, abs_target])

return prefix == abs_directory

def safe_extract(tar, path=".", members=None, *, numeric_owner=False):

for member in tar.getmembers():
member_path = os.path.join(path, member.name)
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")

tar.extractall(path, members, numeric_owner=numeric_owner)


safe_extract(tar, "static/")

except:
node.logger.app_log.warning("Something went wrong during bootstrapping, aborted")
Expand Down Expand Up @@ -1714,7 +1736,26 @@ def setup_net_type():
print(file, "deleted")
download_file("https://bismuth.cz/test.tar.gz", "static/test.tar.gz")
with tarfile.open("static/test.tar.gz") as tar:
tar.extractall("static/") # NOT COMPATIBLE WITH CUSTOM PATH CONFS
def is_within_directory(directory, target):

abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)

prefix = os.path.commonprefix([abs_directory, abs_target])

return prefix == abs_directory

def safe_extract(tar, path=".", members=None, *, numeric_owner=False):

for member in tar.getmembers():
member_path = os.path.join(path, member.name)
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")

tar.extractall(path, members, numeric_owner=numeric_owner)


safe_extract(tar, "static/")
else:
print("Not redownloading test db")

Expand Down
21 changes: 20 additions & 1 deletion static/untar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,23 @@
print(f, "deleted")

with tarfile.open("ledger.tar.gz") as tar:
tar.extractall("")
def is_within_directory(directory, target):

abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)

prefix = os.path.commonprefix([abs_directory, abs_target])

return prefix == abs_directory

def safe_extract(tar, path=".", members=None, *, numeric_owner=False):

for member in tar.getmembers():
member_path = os.path.join(path, member.name)
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")

tar.extractall(path, members, numeric_owner=numeric_owner)


safe_extract(tar, "")