pr0v3rbs / FirmAE

Towards Large-Scale Emulation of IoT Firmware for Dynamic Analysis
MIT License
610 stars 117 forks source link

Why a KeyboardInterrupt is raised when simulating a linksys firmware? #20

Closed cloud0606 closed 3 years ago

cloud0606 commented 3 years ago

I didn't do anything, but I got KeyboardInterrupt

$ sudo ./run.sh -c linksys ./FW_WRT32X_1.0.180404.58.img
[*] FirmAE_dataset/linksys_latest/FW_WRT32X_1.0.180404.58.img emulation start!!!
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/binwalk/core/module.py", line 548, in main
    self.init()
  File "/usr/lib/python3/dist-packages/binwalk/modules/signature.py", line 98, in init
    self.magic.load(f)
  File "/usr/lib/python3/dist-packages/binwalk/core/magic.py", line 795, in load
    self.parse(lines)
  File "/usr/lib/python3/dist-packages/binwalk/core/magic.py", line 842, in parse
    self.signatures.sort(key=lambda x: x.confidence, reverse=True)
  File "/usr/lib/python3/dist-packages/binwalk/core/magic.py", line 842, in <lambda>
    self.signatures.sort(key=lambda x: x.confidence, reverse=True)
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./sources/extractor/extractor.py", line 778, in <module>
    main()
  File "./sources/extractor/extractor.py", line 775, in main
    extract.extract()
  File "./sources/extractor/extractor.py", line 203, in extract
    self._extract_item(item)
  File "./sources/extractor/extractor.py", line 211, in _extract_item
    ExtractionItem(self, path, 0, None, self.debug).extract()
  File "./sources/extractor/extractor.py", line 474, in extract
    self._check_recursive(module, entry)
  File "./sources/extractor/extractor.py", line 728, in _check_recursive
    if new_item.extract():
  File "./sources/extractor/extractor.py", line 474, in extract
    self._check_recursive(module, entry)
  File "./sources/extractor/extractor.py", line 728, in _check_recursive
    if new_item.extract():
  File "./sources/extractor/extractor.py", line 474, in extract
    self._check_recursive(module, entry)
  File "./sources/extractor/extractor.py", line 728, in _check_recursive
    if new_item.extract():
  File "./sources/extractor/extractor.py", line 446, in extract
    signature=True, quiet=True):
  File "/usr/lib/python3/dist-packages/binwalk/__init__.py", line 8, in scan
    objs = m.execute()
  File "/usr/lib/python3/dist-packages/binwalk/core/module.py", line 729, in execute
    obj = self.run(module)
  File "/usr/lib/python3/dist-packages/binwalk/core/module.py", line 767, in run
    raise e
  File "/usr/lib/python3/dist-packages/binwalk/core/module.py", line 749, in run
    obj.main()
  File "/usr/lib/python3/dist-packages/binwalk/core/module.py", line 548, in main
    self.init()
KeyboardInterrupt

I can use binwalk alone to extract firmware

$ binwalk -e  ./FW_WRT32X_1.0.180404.58.img

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             POSIX tar archive (GNU), owner user name: "de-armada-385-linksys-venom/"

~/FirmAE/_FW_WRT32X_1.0.180404.58.img.extracted/sysupgrade-armada-385-linksys-venom$ ll
total 10496
drwxr-xr-x 2 cuc cuc    4096 11月  5  2017 ./
drwxrwxr-x 3 cuc cuc    4096 5月   6 14:39 ../
-rw-r--r-- 1 cuc cuc      31 11月  5  2017 CONTROL
-rwxr-xr-x 1 cuc cuc 2076997 11月  5  2017 kernel*
-rw-r--r-- 1 cuc cuc 8650756 11月  5  2017 root

I don't know which step went wrong, Is it my problem with binwalk installation?

pr0v3rbs commented 3 years ago

Thank you for your issue!

The old version binwalk cannot correctly extract files in FW_WRT32X_1.0.180404.58.img firmware.

I missed pulling the latest binwalk when executing install.sh.

Now, install.sh script will install latest binwalk (53701af3615d0caa015e41ed2d5804edee7ff3c7), and extractor.py will extract filesystem correctly from FW_WRT32X_1.0.180404.58.img firmware.

Thank you!

cloud0606 commented 3 years ago

After following your help, the problem was solved, thank you for the quick reply and making such a handy tool!😀