wootski / impacket

Automatically exported from code.google.com/p/impacket
Other
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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