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

Do not evaluate arithmetic expressions from environment variables at startup, validation #205

Closed
hyenias opened this issue Mar 3, 2021 · 4 comments
Labels
invalid This does not seem right

Comments

@hyenias
Copy link

hyenias commented Mar 3, 2021

I was reading over the wiki and tried the following referenced check for CVE-2019-14868 as it relates to command execution via startup environment variables. To my surprise, it seemed to work when my shell was ksh93 but not when my shell was bash or zsh. Is this because my current ksh parent process is evaluating the contents of SHLVL before passing it along to the new ksh invocation?

$ echo $KSH_VERSION
Version AJMv 93u+m/1.0.0-alpha+37c9ac27 2021-03-01
$ SHLVL='2#11+x[$(/bin/echo DANGER WILL ROBINSON >&2)0]' ksh
DANGER WILL ROBINSON
$
@hyenias hyenias changed the title Do not evaluate arithmetic expressions from environment variables at startup, validation #2 Do not evaluate arithmetic expressions from environment variables at startup, validation Mar 3, 2021
@McDutchie
Copy link

McDutchie commented Mar 3, 2021

The CVE vulnerability you're referencing should have been fixed in 593a5a8.

Is this because my current ksh parent process is evaluating the contents of SHLVL before passing it along to the new ksh invocation?

I believe so, though arguably it should not be doing that because of the single quotes. But it's easy to test:

$ export SHLVL='2#11+x[$(/bin/echo DANGER WILL ROBINSON >&2)0]'
DANGER WILL ROBINSON

That happens in the current shell, no other shell is even launched.

What actually gets passed to the child shell is the value '3'. This can be tested as follows:

$ SHLVL='2#11+x[$(/bin/echo DANGER WILL ROBINSON >&2)0]' env | grep ^SHLVL=
DANGER WILL ROBINSON
SHLVL=3

@McDutchie McDutchie added the invalid This does not seem right label Mar 3, 2021
@McDutchie
Copy link

I think this is caused by the fact that SHLVL is pre-declared as an integer variable, so any assignment will automatically be evaluated as an arithmetic expression

And in arithmetic expressions, command substitutions in array indices are evaluated as well, even if they were passed as literal and quoted strings. I think that is pretty bogus. It might warrant an issue of its own.

@hyenias
Copy link
Author

hyenias commented Mar 3, 2021

Thank you for triple checking this. I do appreciate it.

I believe #152 covers this then.

@McDutchie
Copy link

Another check, to be extra sure:

$ env SHLVL='2#11+x[$(/bin/echo DANGER WILL ROBINSON >&2)0]' ksh
$

Nothing untoward happens if we stop the current shell from evaluating the expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This does not seem right
Projects
None yet
Development

No branches or pull requests

2 participants