Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binwalk analysis fails because of ParseException during entropy graph drawing #1211

Open
ElDavoo opened this issue Apr 15, 2024 · 2 comments
Labels

Comments

@ElDavoo
Copy link

ElDavoo commented Apr 15, 2024

FACT version

latest commit

Environment

ubuntu 24 on Docker

Steps to reproduce

  1. Analyze 9307037151e8488069e0d4166333803dd5f708c1bcffde15dd1b784dfcb59c0c_67 with binwalk plugin

Observed Behavior

  1. Exception

Expeced Behavior

  1. No exception and graph

Installation logs

install.log
PASTE HERE

Backend logs

fact_main_backend.log
[ERROR]: Binwalk analysis on 9307037151e8488069e0d4166333803dd5f708c1bcffde15dd1b784dfcb59c0c_67 failed:

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
10            0xA             Unix path: /sys/class/net/wifi0 -o "${dirs#ath}" = "${dirs}" ];then


Entropy Exception: 
Unix path: /sys/class/net/wifi0 -o "${dirs#ath}" = "${dirs}" ];then
                                    ^
ParseException: Expected end of text, found '$'  (at char 36), (line:1, col:37)
----------------------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/binwalk/core/module.py", line 595, in main
    retval = self.run()
             ^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/binwalk/modules/entropy.py", line 136, in run
    self._run()
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/binwalk/modules/entropy.py", line 158, in _run
    self.calculate_file_entropy(fp)
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/binwalk/modules/entropy.py", line 232, in calculate_file_entropy
    self.plot_entropy(fp.name)
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/binwalk/modules/entropy.py", line 342, in plot_entropy
    fig.savefig(self.output_file, bbox_inches='tight')
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/figure.py", line 3378, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/backend_bases.py", line 2342, in print_figure
    self.figure.draw(renderer)
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/figure.py", line 3175, in draw
    mimage._draw_list_compositing_images(
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/axes/_base.py", line 3064, in draw
    mimage._draw_list_compositing_images(
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/legend.py", line 726, in draw
    bbox = self._legend_box.get_window_extent(renderer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 400, in get_window_extent
    bbox = self.get_bbox(renderer)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 367, in get_bbox
    bbox, offsets = self._get_bbox_and_child_offsets(renderer)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 485, in _get_bbox_and_child_offsets
    bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
              ^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 367, in get_bbox
    bbox, offsets = self._get_bbox_and_child_offsets(renderer)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 512, in _get_bbox_and_child_offsets
    bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
              ^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 367, in get_bbox
    bbox, offsets = self._get_bbox_and_child_offsets(renderer)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 485, in _get_bbox_and_child_offsets
    bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
              ^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 367, in get_bbox
    bbox, offsets = self._get_bbox_and_child_offsets(renderer)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 512, in _get_bbox_and_child_offsets
    bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
              ^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/offsetbox.py", line 801, in get_bbox
    bbox, info, yd = self._text._get_layout(renderer)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/text.py", line 386, in _get_layout
    w, h, d = _get_text_metrics_with_cache(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/text.py", line 97, in _get_text_metrics_with_cache
    return _get_text_metrics_with_cache_impl(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/text.py", line 105, in _get_text_metrics_with_cache_impl
    return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/backends/backend_agg.py", line 230, in get_text_width_height_descent
    self.mathtext_parser.parse(s, self.dpi, prop)
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/mathtext.py", line 226, in parse
    return self._parse_cached(s, dpi, prop)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/mathtext.py", line 247, in _parse_cached
    box = self._parser.parse(s, fontset, fontsize, dpi)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/FACT_core/venv/lib/python3.12/site-packages/matplotlib/_mathtext.py", line 1971, in parse
    raise ValueError("\n" + ParseException.explain(err, 0)) from None
ValueError: 
Unix path: /sys/class/net/wifi0 -o "${dirs#ath}" = "${dirs}" ];then
                                    ^
ParseException: Expected end of text, found '$'  (at char 36), (line:1, col:37)
----------------------------------------------------------------------------------------------------

Frontend logs

fact_main_frontend.log
PASTE HERE

Other information

File content:
if [ ! -d /sys/class/net/wifi0 -o "${dirs#ath}" = "${dirs}" ];then

@ElDavoo ElDavoo added the bug label Apr 15, 2024
@jstucke
Copy link
Collaborator

jstucke commented Apr 15, 2024

Hi, it seems to me binwalk erroneously thinks /sys/class/net/wifi0 -o "${dirs#ath}" = "${dirs}" ];then is a path (when it should have ended at /sys/class/net/wifi0) and tries to use this as a label in matplotlib when generating the entropy graph. Matplotlib then probably tries to interpret this as a latex math string (because of the $) which obviously doesn't work. This seems to be a bug in binwalk.

@ElDavoo
Copy link
Author

ElDavoo commented Apr 23, 2024

Fix hit fork's upstream, need to wait for release and #1209

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants