ucsb-seclab / karonte

Karonte is a static analysis tool to detect multi-binary vulnerabilities in embedded firmware
BSD 2-Clause "Simplified" License
391 stars 60 forks source link

ZeroDivisionError when running parse_all_results.py #4

Closed phros closed 4 years ago

phros commented 4 years ago

Hi ,

I'm using the docker image. I ran the run.py from the eval/karonte_stats/ directory successfully on all vendors. When collecting the results with the parse_all_results.py, the script crashes with a ZeroDivisionError:

(karonte) karonte@516f08516846:~/karonte/eval/karonte_stats$ python parse_all_results.py 
No info to show :(.
Did you set 'stats: 'True' in the configuration file?
Vendor: huawei
# binaries: 0
Firmware samples: 1
Single binaries: 0
Multi binaries: 0
# Alerts: 0
Min analysis time: None
Traceback (most recent call last):
  File "parse_all_results.py", line 148, in <module>
    print "Avg analysis time: " + str(sum([x for x in avg_time]) / len(avg_time))
ZeroDivisionError: integer division or modulo by zero

I did set 'stats' to True. When running karonte on the only firmware image i got:

(karonte) karonte@516f08516846:~/karonte/tool$ python karonte.py ../config/huawei/ondevice_boot.json
/home/karonte/.virtualenvs/karonte/local/lib/python2.7/site-packages/cffi/cparser.py:164: UserWarning: Global variable 'r' in cdef(): for consistency with C it should have a storage class specifier (usually 'extern')
  "(usually 'extern')" % (decl.name,))
INFO      | 2020-02-12 16:36 | Karonte  |  Logging at: /tmp/Karonte.txt_56
INFO      | 2020-02-12 16:36 | Karonte  |  Firmware directory: 
Traceback (most recent call last):
  File "karonte.py", line 96, in <module>
    so.run()
  File "karonte.py", line 64, in run
    self._klog.save_parser_stats(bbf)
  File "/home/karonte/karonte/tool/file_logger/file_logger.py", line 182, in save_parser_stats
    ana_time = bbf.analysis_time()
  File "/home/karonte/karonte/tool/border_binaries_finder/border_binaries_finder.py", line 572, in analysis_time
    return self._end_time - self._start_time
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
(karonte) karonte@516f08516846:~/karonte/tool$ 

Is there something wrong with the config file or the image? I saw that the fw_path was missing and set it to the same as the "bin" path, but nothing changed.

Cheers

EDIT: Happens with more config files, e.g. config/lk/lk_unpatched.config.json

badnack commented 4 years ago

I tried to run the analysis on the firmware image you mentioned, but everything seems to work for me. Can you try to enter a new clean container, go to /home/karonte/karonte, and then run python tool/karonte.py ./config/huawei/ondevice_boot.json ? Does this work for you?

On Wed, 12 Feb 2020 at 08:43, phros notifications@github.com wrote:

Hi ,

I'm using the docker image. I ran the run.py from the eval/karonte_stats/ directory successfully on all vendors. When collecting the results with the parse_all_results.py, the script crashes with a ZeroDivisionError:

(karonte) karonte@516f08516846:~/karonte/eval/karonte_stats$ python parse_all_results.py No info to show :(. Did you set 'stats: 'True' in the configuration file? Vendor: huawei

binaries: 0

Firmware samples: 1 Single binaries: 0 Multi binaries: 0

Alerts: 0

Min analysis time: None Traceback (most recent call last): File "parse_all_results.py", line 148, in print "Avg analysis time: " + str(sum([x for x in avg_time]) / len(avg_time)) ZeroDivisionError: integer division or modulo by zero

I did set 'stats' to True. When running karonte on the only firmware image i got:

(karonte) karonte@516f08516846:~/karonte/tool$ python karonte.py ../config/huawei/ondevice_boot.json /home/karonte/.virtualenvs/karonte/local/lib/python2.7/site-packages/cffi/cparser.py:164: UserWarning: Global variable 'r' in cdef(): for consistency with C it should have a storage class specifier (usually 'extern') "(usually 'extern')" % (decl.name,)) INFO | 2020-02-12 16:36 | Karonte | Logging at: /tmp/Karonte.txt_56 INFO | 2020-02-12 16:36 | Karonte | Firmware directory: Traceback (most recent call last): File "karonte.py", line 96, in so.run() File "karonte.py", line 64, in run self._klog.save_parser_stats(bbf) File "/home/karonte/karonte/tool/file_logger/file_logger.py", line 182, in save_parser_stats ana_time = bbf.analysis_time() File "/home/karonte/karonte/tool/border_binaries_finder/border_binaries_finder.py", line 572, in analysis_time return self._end_time - self._start_time TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType' (karonte) karonte@516f08516846:~/karonte/tool$

Is there something wrong with the config file or the image? I saw that the fw_path was missing and set it to the same as the "bin" path, but nothing changed.

Cheers

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ucsb-seclab/karonte/issues/4?email_source=notifications&email_token=AAH5GZFBXYMCAR3BMQBX3NLRCQRKJA5CNFSM4KT5JO22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IM74D4Q, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH5GZG7DOPSS4ULSURND2TRCQRKJANCNFSM4KT5JO2Q .

-- Nilo Redini

Site: www.badnack.it Twitter: badnack Skype: badnack PGP key: http://www.badnack.it/Keys/PbKey

phros commented 4 years ago

This does work! Maybe some results or temporary files from older older executions disrupted the eval script... I'm sorry.

phros commented 4 years ago

I just realized that it happens when settings stats to True in the config file for the huawei config. Is this a known issue?

badnack commented 4 years ago

I fixed it, let me know if it works for you now.

On Tue, 18 Feb 2020 at 02:44, phros notifications@github.com wrote:

Reopened #4 https://github.com/ucsb-seclab/karonte/issues/4.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ucsb-seclab/karonte/issues/4?email_source=notifications&email_token=AAH5GZHWUEDRRTYV3TZVE33RDO3YNA5CNFSM4KT5JO22YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOWWLZLPA#event-3046610364, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH5GZHKPJCM7PFSNBEGHYDRDO3YNANCNFSM4KT5JO2Q .

-- Nilo Redini

Site: www.badnack.it Twitter: badnack Skype: badnack PGP key: http://www.badnack.it/Keys/PbKey

phros commented 4 years ago

I pulled the latest docker image and started the analysis. It runs!