2

Problem

Basically I've have working with a Python script that emulate a real terminal. So, I was trying some tools for Linux, and when I try to use some tools the STDOUT comes with:

stty: 'standard input': Inappropriate ioctl for device" message error

Question

Is possible to suppress this error message without the .replace()?

Script

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())

Error example

$ python3 script.py

Type: msfconsole

*wait a few seconds for load the banner

Type: banner

   =[ metasploit v6.0.15-dev                          ]
  • -- --=[ 2071 exploits - 1123 auxiliary - 352 post ]
  • -- --=[ 592 payloads - 45 encoders - 10 nops ]
  • -- --=[ 7 evasion ]

Metasploit tip: Use the edit command to open the currently active module in your editor

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

msf6>

Type:

Black Coral
  • 55
  • 2
  • 6

1 Answers1

-1

You can add other exceptions, like you did for cls :

    elif command == "stty" or command == "...":
        os.system(command)
Philippe
  • 20,025
  • 2
  • 23
  • 32