Can someone explain how this “Shellshock” code works in shell [duplicate]

你离开我真会死。 提交于 2019-12-02 04:58:00
nu11p01n73R

env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

What does env do?

From the documentation, env runs programs in a modified environment.

env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

It is clear that x is a name/variable and () { :;}; echo vulnerable' is the value for the variable.

Now, what is () { :;};?

When a function is exported, Bash stores its defenition as a value in the environment variable:

$ x() {echo hello world;}
$ export x
$ env | grep x
x=() {echo hello world};

Now, when x='() {:;}' means similar as writing

$ x() {:;}
$ export x
$ env | grep x

That is, we indirectly made export x onto the new environmnet created by the env. Here : is a null statement in Bash.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!