Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSexec.py doesn't return stderr nor does it return certain ouputs like running python of any kind in windows. #25

Open
GoogleCodeExporter opened this issue Mar 24, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1.run psexec.py on a machine with python installed
2.attempt to run pyhton or a python script or some program that will ouput to 
stderr
3.Nothing is put out to the console

What is the expected output? What do you see instead?
you should be getting all output from the console indipendent of what is ran or 
how it is ran.

What version of the product are you using? On what operating system?
0.9.9.9

Please provide any additional information below.


Original issue reported on code.google.com by rustysto...@gmail.com on 16 May 2013 at 12:41

@GoogleCodeExporter
Copy link
Author

Hey there:

If you have an example I can reproduce this bug with that'd be great.

I create a python file with:

import sys

sys.stdout.write("stdout\n")
sys.stderr.write("stderr\n")

run psexec against the machine that script was under.. Ran it with python and 
it outputed both strings.

Keep in mind some applications won't work under psexec due to weird ways used 
to output results back to the console. You will have a similar problem with 
Microsoft's psexec as well. 

The Python IDLE is one example of that. 

Still.. running the Python scripts should work actually.

beto

Original comment by bet...@gmail.com on 16 May 2013 at 2:07

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

If you run C:\Python26\python.exe to access the python console, it won't
return what it should..  Running %compspec% won't return stderr of a
program you are running.  But you say that psexec suffers from the same
problem...  What is the root cause of the problem?

Original comment by rustysto...@gmail.com on 23 May 2013 at 5:22

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

OK.. I think I have this problem figured out.. on windows, because python
always assumes that you are using a bufferd command window will not start
in interactive mode and rely on the cmd window to flush the output to the
user.. when you are running from a windowless application that spawns a
process with the CREATE_NO_WINDOW, there is no cmd window to flush the
output for you.  In python you can start the interpreter in interactive
mode by using the -i parameter.
example....
impacket-0.9.10\examples>C:\Python27\python.exe psexec.py
myhost/Administrator:mypassword@myhost C:\Windows\System32\cmd.exe /c
python -i
This stems from the psexec's reliance of the remcomsvc.exe to be able to
run it's remote execution
<<RemComSvc.cpp >>
if ( CreateProcess(
         NULL,
         szCommand,
         NULL,
         NULL,
         TRUE,
         pMsg->dwPriority | CREATE_NO_WINDOW,
         NULL,
         pMsg->szWorkingDir[0] != _T('\0') ? pMsg->szWorkingDir : NULL,
         &si,
         &pi ) )
   I wonder if there is a fix that we can implement in remcom that would
tell the pipes to continuously flush themselves at regular intervals like a
normal command window will do.
consider the following...

 psi->hStdInput = CreateNamedPipe(
            szStdInPipe,
            PIPE_ACCESS_INBOUND,
            PIPE_TYPE_MESSAGE | PIPE_WAIT,
            PIPE_UNLIMITED_INSTANCES,
            0,
            0,
            (DWORD)-1,
            &SecAttrib);
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365150%28v=vs.85%29.as
px
What if remcom used *PIPE_READMODE_BYTE or **PIPE_READMODE_MESSAGE?*


On Thu, May 23, 2013 at 11:22 AM, Russell Weber <
rustystotallyfakeemailaddress@gmail.com> wrote:

Original comment by rustysto...@gmail.com on 7 Jun 2013 at 3:52

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Hey there:

Great analysis!.. A couple of things that can be done here:

1) Contact the rem com guys to ask these questions. They are located 
https://github.com/kavika13/RemCom
2) Try to change those arguments, recompile RemCom and pass it to psexec.py 
with the -file parameter

I don't know if you are handy with Visual Studio.. if so.. you could give it a 
try!

I'm on vacations right now.. if you can't I'll give it a try once I come back 
home.

cheers!
beto

Original comment by bet...@gmail.com on 11 Jun 2013 at 2:05

  • Added labels: ****
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant