# Don't run as root, unless explicitly instructed to
ifuser_info.pw_uid==0:
raiseModuleException("Binwalk extraction uses many third party utilities, which may not be secure.\nIf you wish to have extraction utilities executed as the current user, use --run-as=%s (binwalk itself must be run as root)."%user_info.pw_name)
raiseModuleException("Binwalk extraction uses many third party utilities, which may not be secure. If you wish to have extraction utilities executed as the current user, use '--run-as=%s' (binwalk itself must be run as root)."%user_info.pw_name)
# Run external applications as the current user
self.runas_uid=user_info.pw_uid
...
...
@@ -297,16 +297,19 @@ class Extractor(Module):
# If recursion was specified, and the file is not the same
# one we just dd'd
iffile_path!=dd_file_path:
# Symlinks can cause security issues if they point outside the extraction directory.
self.symlink_sanitizer(file_path)
# If this is a directory and we are supposed to process directories for this extractor,
# then add all files under that directory to the
# list of pending files.
ifos.path.isdir(file_path):
forroot,dirs,filesinos.walk(file_path):
# Symlinks can cause security issues if they point outside the extraction directory.
binwalk.core.common.warning("Symlink points outside of the extraction directory: %s -> %s; for security, changing link target to %s."%(symlink,linktarget,os.devnull))
os.remove(symlink)
os.symlink(os.devnull,symlink)
defsymlink_sanitizer(self,file_list):
# Allows either a single file path, or a list of file paths to be passed in for sanitization.
iftype(file_list)isnotlist:
file_list=[file_list]
# Sanitize any files in the list that are symlinks outside of the self.directory extraction directory.
binwalk.core.common.warning("Symlink points outside of the extraction directory: %s -> %s; changing link target to %s for security purposes."%(file_name,linktarget,os.devnull))