attify / firmware-analysis-toolkit

Toolkit to emulate firmware and analyse it for security vulnerabilities
MIT License
1.32k stars 252 forks source link

Image extraction failed #50

Closed CaledoniaProject closed 4 years ago

CaledoniaProject commented 4 years ago

I'm trying to emulate the firmware provided in your blog post

And it failed somewhere:

[+] Firmware: WNAP320.zip
[+] Extracting the firmware...
[!] Image extraction failed

What can I do now?

extremecoders-re commented 4 years ago

Are you using the latest Firmware Analysis Toolkit? FAT has been updated since the blog post. In particular the PostGreSQL dependency has been removed.

CaledoniaProject commented 4 years ago

Steps to reproduce:

  1. Start Ubuntu 20.04
  2. Download master branch and execute setup.sh with ROOT

And I see this error (Ubuntu is shipped with python3 now)

sudo: pip: command not found

And in setup.sh both pip and pip3 are used, is that a mistake?

sudo -H pip3 install git+https://github.com/ahupp/python-magic
sudo -H pip install git+https://github.com/sviehb/jefferson
cd ..

I executed pip3 for jefferson manually and it runs into another error

Traceback (most recent call last):
  File "./fat.py", line 5, in <module>
    import pexpect
ModuleNotFoundError: No module named 'pexpect'

So I manually installed pexpect with pip3

pip3 install pexpect

And started emulation.

# ./fat.py WNAP320\ Firmware\ Version\ 2.0.3.zip

                               __           _
                              / _|         | |
                             | |_    __ _  | |_
                             |  _|  / _` | | __|
                             | |   | (_| | | |_
                             |_|    \__,_|  \__|

                Welcome to the Firmware Analysis Toolkit - v0.3
    Offensive IoT Exploitation Training http://bit.do/offensiveiotexploitation
                  By Attify - https://attify.com  | @attifyme

[+] Firmware: WNAP320 Firmware Version 2.0.3.zip
[+] Extracting the firmware...
[!] Image extraction failed

It stuck for a few minutes and finally failed.

extremecoders-re commented 4 years ago

Thank you for the detailed steps. I was able to reproduce the issue.

The main reason is because several Python 2 related packages have been removed from Ubuntu 20.04. Unfortunately we cannot just switch to Python 3 yet because some of the dependencies of firmadyne specifically require Python 2. For example, while installing Binwalk manually, it immediately complained about the following missing packages.

python-pip
cramfsprogs
python-lzo
python-lzma

So as of now you have to stick to Ubuntu 18.04 or lower.

CaledoniaProject commented 4 years ago

This is still needed on Ubuntu 16.04, ./setup.sh does not install them:

apt install -y unzip python-pip
pip install pexpect
CaledoniaProject commented 4 years ago

Also, please consider add set -e to the script

extremecoders-re commented 4 years ago

Added set -e

unzip and python-pip are already specified. https://github.com/attify/firmware-analysis-toolkit/blob/946255df4e1460508794e1af772c4ab1b543f110/setup.sh#L5

We are using python3-pexpect installed by apt.

Just tested on a 16.04 LXC container and it's working as expected.

CaledoniaProject commented 4 years ago

There is a python error during installation, but seems harmless:

Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/7d/d4/e4c40c62cd8608ca09f0684e64139c56512e195f2351ac41a472d4dc8b38/matplotlib-3.3.0.tar.gz (38.8MB)
    100% |████████████████████████████████| 38.8MB 47kB/s
    Complete output from command python setup.py egg_info:

    Beginning with Matplotlib 3.1, Python 3.6 or above is required.
    You are using Python 3.5.2.

    This may be due to an out of date pip.

    Make sure you have pip >= 9.0.1.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-hzk7vw11/matplotlib/

Everything worked today. I was on a minimal Ubuntu Server 16.04 installation.

Thanks!

jollytrivedi2019 commented 1 year ago

I am getting the same error while I am trying to extract the Firmware.