You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+7
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,17 @@
7
7
8
8
Binwalk is a fast, easy to use tool for analyzing, reverse engineering, and extracting firmware images.
9
9
10
+
11
+
### *** Extraction Security Notice ***
12
+
13
+
Prior to Binwalk v2.3.3, extracted archives could create symlinks which point anywhere on the file system, potentially resulting in a directory traversal attack if subsequent extraction utilties blindly follow these symlinks. More generically, Binwalk makes use of many third-party extraction utilties which may have unpatched security issues; Binwalk v2.3.3 and later allows external extraction tools to be run as an unprivileged user using the `run-as` command line option (this requires Binwalk itself to be run with root privileges). Additionally, Binwalk v2.3.3 and later will refuse to perform extraction as root unless `--run-as=root` is specified.
14
+
15
+
10
16
### *** Python 2.7 Deprecation Notice ***
11
17
12
18
Even though many major Linux distros are still shipping Python 2.7 as the default interpreter in their currently stable release, we are making the difficult decision to move binwalk support exclusively to Python 3. This is likely to make many upset and others rejoice. If you need to install binwalk into a Python 2.7 environment we will be creating a tag `python27` that will be a snapshot of `master` before all of these major changes are made. Thank you for being patient with us through this transition process.
# Get some info about the current user we're running under
143
+
user_info=pwd.getpwuid(os.getuid())
144
+
145
+
# Don't run as root, unless explicitly instructed to
146
+
ifuser_info.pw_uid==0:
147
+
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)
148
+
149
+
# Run external applications as the current user
150
+
self.runas_uid=user_info.pw_uid
151
+
self.runas_gid=user_info.pw_gid
152
+
else:
153
+
# Run external applications as the specified user
154
+
user_info=pwd.getpwnam(self.runas_user)
155
+
self.runas_uid=user_info.pw_uid
156
+
self.runas_gid=user_info.pw_gid
157
+
158
+
# Make sure we'll have permissions to switch to the different user
159
+
ifself.runas_uid!=os.getuid() andos.getuid() !=0:
160
+
raiseModuleException("In order to execute third party applications as %s, binwalk must be run with root privileges."%self.runas_user)
161
+
124
162
# Holds a list of extraction rules loaded either from a file or when
125
163
# manually specified.
126
164
self.extract_rules= []
@@ -148,8 +186,8 @@ def load(self):
148
186
self.config.verbose=True
149
187
150
188
defadd_pending(self, f):
151
-
# Ignore symlinks
152
-
ifos.path.islink(f):
189
+
# Ignore symlinks, don't add new files unless recursion was requested
190
+
ifos.path.islink(f)ornotself.matryoshka:
153
191
return
154
192
155
193
# Get the file mode to check and see if it's a block/char device
@@ -260,30 +298,34 @@ def callback(self, r):
260
298
261
299
# If recursion was specified, and the file is not the same
262
300
# one we just dd'd
263
-
if (self.matryoshkaand
264
-
file_path!=dd_file_pathand
265
-
scan_extracted_filesand
266
-
self.directoryinreal_file_path):
267
-
# If the recursion level of this file is less than or
binwalk.core.common.warning("Extractor.execute failed to run external extractor '%s': %s, '%s' might not be installed correctly"% (str(cmd), str(e), str(cmd)))
910
952
retval=None
911
953
912
-
iftmpisnotNone:
913
-
tmp.close()
914
-
915
954
return (retval, '&&'.join(command_list))
955
+
956
+
defshell_call(self, command):
957
+
# If not in debug mode, redirect output to /dev/null
958
+
ifnotbinwalk.core.common.DEBUG:
959
+
tmp=subprocess.DEVNULL
960
+
else:
961
+
tmp=None
962
+
963
+
# If a run-as user is not the current user, we'll need to switch privileges to that user account
964
+
ifself.runas_uid!=os.getuid():
965
+
binwalk.core.common.debug("Switching privileges to %s (%d:%d)"% (self.runas_user, self.runas_uid, self.runas_gid))
966
+
967
+
# Fork a child process
968
+
child_pid=os.fork()
969
+
ifchild_pidis0:
970
+
# Switch to the run-as user privileges, if one has been set
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))
0 commit comments