ChrisTheCoolHut / Firmware_Slap

Discovering vulnerabilities in firmware through concolic analysis and function clustering.
GNU General Public License v3.0
470 stars 79 forks source link

UnboundLocalError: local variable 'file_hash' referenced before assignment #4

Closed soaringswine closed 5 years ago

soaringswine commented 5 years ago

when running Pwn_Firmware_CGI.py, the firmware file is successfully extracted, root file system is discovered, and then I receive the following error:

python3 bin/Pwn_Firmware_CGI.py firmware.zip
/tmp/tmp6jej1eta [+] Extracting firmware.zip binwalk -Mre firmware.zip Extracting Firmware into /tmp/tmp6jej1eta [+] root file system discovered at /tmp/tmp6jej1eta/firmware.zip.extracted/firmware.bin.extracted/squashfs-root /tmp/tmp6jej1eta/firmware.zip.extracted/firmware.bin.extracted/squashfs-root [+] Reading Files 0%| | 0/39 [00:00<?, ?it/s] Traceback (most recent call last): File "bin/Pwn_Firmware_CGI.py", line 356, in main() File "bin/Pwn_Firmware_CGI.py", line 43, in main file_vulnerabilities = process_file_or_folder(args.FILE, dirpath) File "bin/Pwn_Firmware_CGI.py", line 110, in process_file_or_folder ld_path = get_libraries(root_fs, work_dir) File "bin/Pwn_Firmware_CGI.py", line 93, in get_libraries executables, libraries = fhc.get_executable_files(firmware_folder) File "/root/tools/Firmware_Slap/env/lib/python3.7/site-packages/Firmware_Slap-1.0-py3.7.egg/firmware_slap/firmware_clustering.py", line 51, in get_executable_files if file_hash not in hashes: UnboundLocalError: local variable 'file_hash' referenced before assignment

I tried globally declaring the variable in the for loop and declaring it again locally in the if statement, but still get the same error.

soaringswine commented 5 years ago

Oops, I was making the modification in the wrong firmware_clustering.py file.

Moving the "if file_hash not in hashes:" if block into the "if not os.path.islink(full_path):" if block, underneath the file_hash declaration seems to fix the issue since you don't want to be making file hashes of symlinks, but I don't know what other consequences this has.

ChrisTheCoolHut commented 5 years ago

You're solution is right! I had a commented out block of code that would just continue if it found a symlink and it appears the I forgot to uncomment it. bddd63e