micropython/tools
Michael Buesch 60cf2c0959 tools/pyboard.py: Replace eval() of received data with alternative.
Prior to this commit, pyboard.py used eval() to "parse" file data received
from the board.  Using eval() on received data from a device is dangerous,
because a malicious device may inject arbitrary code execution on the PC
that is doing the operation.

Consider the following scenario:

Eve may write a malicious script to Bob's board in his absence.  On return
Bob notices that something is wrong with the board, because it doesn't work
as expected anymore.  He wants to read out boot.py (or any other file) to
see what is wrong.  What he gets is a remote code execution on his PC.

Proof of concept:

Eve:

  $ cat boot.py
  _print = print
  print = lambda *x, **y: _print("os.system('ls /; echo Pwned!')", end="\r\n\x04")
  $ ./pyboard.py -f cp boot.py :
  cp boot.py :boot.py

Bob:

  $ ./pyboard.py -f cp :boot.py /tmp/foo
  cp :boot.py /tmp/foo
  bin   chroot  dev  home  lib32  media  opt   root  sbin  sys  usr
  boot  config  etc  lib   lib64  mnt    proc  run   srv   tmp  var
  Pwned!

There's also the possibility that the device is malfunctioning and sends
random and possibly dangerous data back to the PC, to be eval'd.

Fix this problem by using ast.literal_eval() to parse the received bytes,
instead of eval().

Signed-off-by: Michael Buesch <m@bues.ch>
2020-08-21 16:08:03 +10:00
..
.gitattributes micropython-upip: Mark as binary file and re-commit. 2015-06-06 23:09:23 +03:00
.gitignore tools: check-in errordeveloper/tinytest@eb2dbc858f 2014-05-08 01:41:21 +03:00
bootstrap_upip.sh tools/upip: Upgrade upip to 1.2.4. 2018-04-23 16:11:27 +10:00
build-stm-latest.sh tools: Add STM32F4DISC and ESPRUINO_PICO to stmhal build script. 2015-04-21 13:16:41 +00:00
cc1 tools: Add C middle-processor to make builtin tables proper hash tables. 2015-12-31 00:24:33 +00:00
codeformat.py lib/mbedtls_errors: Add code to patch mbedtls for shortened error strs. 2020-07-20 23:53:27 +10:00
codestats.sh all: Update Makefiles and others to build with new ports/ dir layout. 2017-09-06 14:09:13 +10:00
dfu.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
file2h.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
gen-changelog.sh Rename "Micro Python" to "MicroPython" in REPL, help, readme's and misc. 2015-10-12 00:06:25 +01:00
gen-cpydiff.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
gendoc.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
insert-usb-ids.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
make-frozen.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
makemanifest.py tools/makemanifest.py: Print nicely formatted errors from mpy-cross. 2020-08-08 14:46:05 +10:00
metrics.py tools/metrics.py: Use OrderedDict when reading build log. 2020-04-22 14:03:26 +10:00
mpy_bin2res.py tools/mpy_bin2res: Tools to convert binary resources to Python module. 2017-07-27 14:41:27 +03:00
mpy_cross_all.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpy_ld.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpy-tool.py all: Fix implicit conversion from double to float. 2020-04-18 22:42:24 +10:00
pyboard.py tools/pyboard.py: Replace eval() of received data with alternative. 2020-08-21 16:08:03 +10:00
pydfu.py Revert "tools/pydfu.py: Respect longer timeouts requested by DFU dev..." 2020-07-01 16:54:03 +10:00
tinytest-codegen.py py/objexcept: Allow compression of exception message text. 2020-04-05 15:02:06 +10:00
uf2conv.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
uncrustify.cfg tools/uncrustify: Enable more opts to remove space between func and '('. 2020-06-19 22:07:32 +10:00
upip_utarfile.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
upip.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00