$ cat t.pyx = '' nothing to see here';import os;os.system('echo pwnd')
$ python3 t.pypwnd
it appears that after splitting the source into lines, the individual lines are treated as c strings and so the null terminator is misinterpreted, jamming the string contents together and it executes similar to this:
x='';importos;os.system('echo pwnd')
note that if you want to write out a file like this here's a simple bit of code you can paste into an interactive prompt:
open('t.py', 'w').write("x = '\0' nothing to see here\n';import os;os.system('echo pwnd')\n")
asottile commentedSep 8, 2022
Bug report
the parser mishandles lines containing null bytes when parsing source -- this allows the code to be misleadingly different from what it looks like.
I've been told by security@ that it is ok to post this publicly.
in the below example,
<NUL>
is an actual null byte:and the execution and appearance in the terminal:
it appears that after splitting the source into lines, the individual lines are treated as c strings and so the null terminator is misinterpreted, jamming the string contents together and it executes similar to this:
note that if you want to write out a file like this here's a simple bit of code you can paste into an interactive prompt:
here is perhaps a shorter example:
I originally found this due to a bug report where the
ast
parser rejects code containing null bytes:ideally I would want the interpreter to reject files containing null bytes as a
SyntaxError
(and update theast.parse
error to aSyntaxError
as well) -- though it appears there are some of these files in the wild -- such as https://github.com/univention/univention-corporate-server/blob/5.0-2/services/univention-ldb-modules/buildtools/bin/waf-svnYour environment
The text was updated successfully, but these errors were encountered: