pypsexec icon indicating copy to clipboard operation
pypsexec copied to clipboard

[Feature Request/Community Contribution] Interactive Shell and Ansible Connection Plugin Functionality

Open aesrentai opened this issue 2 years ago • 2 comments

In the blog introducing pypsexec there were a number of TODOs at the bottom, including:

  • An interactive shell for pypsexec that takes input from stdin and outputs the responses to stdout and stderr
  • Move beyond a simple Ansible module and turn it into a connection plugin so it can be used to run all the existing Windows modules instead of just commands

As far as I can tell, these features have never been added (if they have and I just can't figure out how they work please let me know). There is an interactive parameter, but it doesn't give a shell, only run allow an interactive program to be run in an interactive_session.

I would be willing to contribute the code to add these features, specifically the shell first and the ansible later, if you would be open to upstreaming these changes and if you think they're feasible without any major awful hacks. If you already have unreleased code working on this I would also be interested in seeing that.

aesrentai avatar Oct 16 '22 22:10 aesrentai

It was never implemented, the biggest problem is figuring out how to avoid the echoing of characters. For example if you typed in testing123 and pressed enter, the stdout will contain the characters you typed then the output. If you do end making a PR I will definitely have a look but keep in mind the codebase is a bit old and not the most efficiently designed.

jborean93 avatar Nov 04 '22 00:11 jborean93

Interesting, thank you for the response, I was wondering why we couldn't just

while True:
    input = read()
    if input == "exit": exit_shell()
    client.run_executable(input)

the input repeating problem is something I've hit using the ansible frontend to pypsexec although I'm going to see if we can just hack around the problem by ignoring the first line of the output. I haven't actually started writing the code yet as you can see.

Also, I'm curious why you say the code is not the most efficiently designed. While it is old and I'm admittedly very inexperienced with windows and network protocols in general, the pypsexec library itself is small given the complexity of the underlying protocol. I can't speak to the smbprotocol library however.

aesrentai avatar Nov 07 '22 23:11 aesrentai