【问题标题】:Why I can't execute this Pytho subprocess command on my Windows 10 machine?为什么我不能在我的 Windows 10 机器上执行这个 Pytho 子进程命令?
【发布时间】:2020-07-25 08:31:24
【问题描述】:

我对 Python 还不是很了解,但我遇到了以下问题(我正在学习一门 Python 应用于安全的课程)。

在我的 Windows 10 机器上安装了 Python 2.7.17 版本。

然后我有这个非常简单的脚本:

#!/usr/env/bin python

import subprocess

command = "msg you have been hacked !!!"

# Popen() continue the program and doesn't wait that the command is completly finished to terminate the script execution:
subprocess.Popen(command, shell=True)

问题是当我尝试执行它时,我得到了这个错误:

C:\Users\myuser\Desktop\python_evil>python execute_command.py

C:\Users\myuser\Desktop\python_evil>you inesistente o disconnesso

这个错误对我来说似乎很奇怪(一半是英语(你),一半是意大利语)。基本上它说:你不存在或断开连接

为什么?怎么了?我错过了什么?如何解决此问题并正确执行此命令?

【问题讨论】:

  • 这不是一个关于 Python 的问题,而是一个关于 msg 程序的问题。

标签: python python-2.7 subprocess


【解决方案1】:

这个错误对我来说似乎很奇怪(一半是英语(你),一半是意大利语)。基本上它说:你不存在或断开连接

you 来自命令,这就是它以英文出现的原因。其余部分来自 Windows,这就是它以意大利语(您的本地化语言)显示的原因。

如果您在命令窗口中单独尝试msg,您将获得使用信息,这可以解释问题:

Send a message to a user.
MSG {username | sessionname | sessionid | @filename | *}
    [/SERVER:servername] [/TIME:seconds] [/V] [/W] [message]

  username            Identifies the specified username.
  sessionname         The name of the session.
  sessionid           The ID of the session.
  @filename           Identifies a file containing a list of usernames,
                      sessionnames, and sessionids to send the message to.
  *                   Send message to all sessions on specified server.
  /SERVER:servername  server to contact (default is current).
  /TIME:seconds       Time delay to wait for receiver to acknowledge msg.
  /V                  Display information about actions being performed.
  /W                  Wait for response from user, useful with /V.
  message             Message to send.  If none specified, prompts for it
                      or reads from stdin.

发生的情况是 msg you have been hacked !!! 被 shell 解释为 msg 命令,其中 you 是(用户名或会话名称或会话 ID),have been hacked !!! 是消息。但是您的系统上没有名为 you 的用户,并且没有使用该名称或 ID 的登录会话,因此 msg 程序会产生错误 - 它无法确定谁应该看到该消息。

顺便说一句:尤其是作为学习安全的人,你真的,真的应该更新你的 Python 安装。 2.x 分支是no longer maintained, even for security reasons,最终版本(自 1 月 1 日起冻结的代码)正在筹备中。 most recent version on the website is 3.8.2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2014-05-15
    • 2017-10-03
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    相关资源
    最近更新 更多