0

问题

基本上我一直在使用模拟真实终端的 Python 脚本。所以,我尝试了一些 Linux 工具,当我尝试使用一些工具时,STDOUT 附带:

stty:“标准输入”:设备的 ioctl 不合适”消息错误

问题

是否可以在没有.replace()的情况下抑制此错误消息?

脚本

import subprocess
import os

f = open('output.txt', 'w')
proc = subprocess.Popen('/bin/bash', stderr=subprocess.STDOUT, stdin=subprocess.PIPE, stdout=f, shell=True)
while True:
    command = input('Type:')
    if command == "cls":
        open('output.txt', 'w').close()
        os.system('cls' if os.name == 'nt' else 'clear')
    else:
        command = command.encode('utf-8') + b'\n'
        proc.stdin.write(command)
        proc.stdin.flush()
        with open('output.txt', 'r+') as ff:
            print(ff.read())

错误示例

$ python3脚本.py

类型:msfconsole

*等待几秒钟以加载横幅

类型:横幅

   =[ metasploit v6.0.15-dev                          ]
  • -- --=[ 2071 漏洞利用 - 1123 辅助 - 352 帖子]
  • -- --=[ 592 个有效载荷 - 45 个编码器 - 10 个 nops ]
  • -- --=[7闪避]

Metasploit 提示:使用 edit 命令在编辑器中打开当前活动的模块

stty:“标准输入”:设备的 ioctl 不合适

stty:“标准输入”:设备的 ioctl 不合适

stty:“标准输入”:设备的 ioctl 不合适

stty:“标准输入”:设备的 ioctl 不合适

stty:“标准输入”:设备的 ioctl 不合适

stty:“标准输入”:设备的 ioctl 不合适

stty:“标准输入”:设备的 ioctl 不合适

msf6>

类型:

4

1 回答 1

-1

您可以添加其他例外,就像您为cls

    elif command == "stty" or command == "...":
        os.system(command)
于 2021-02-07T18:44:09.437 回答