Open GoogleCodeExporter opened 9 years ago
Hey mate...
Interesting finding.. honestly I never thought about using psexec as an object.
I know there's a way to set pipes in non blocking mode for SMB version 2/3, I
should figure out how to do it in SMB version 1. If so, we could change the
behavior in the way you described it.
beto
Original comment by bet...@gmail.com
on 14 Jun 2013 at 7:52
I am making a slave driver interface combined with python's paramiko to give me
universal access to any machine and run remote commands on them. :)
I the case where there is a non blocking read, the exact usage may not be the
same, but the end goal is achieved. Maybe None is returned if the pipe had
nothing to write after a given timeout. I don't know too much about smb, but
maybe the new usage could be like the following:
ans = self.server.readFile_nonblocked(self.tid,self.fid, 0, 1024,
read_timeout=5)
if ans is None:
continue
But I guess that would totally dedend on how the SMB parts are setup...
Original comment by rustysco...@gmail.com
on 15 Jun 2013 at 12:20
After inspecting impacket a little more on the nmb layer. it looks like there
could be a way to make a non blocking read of the socket on that level. Then
there would be no need to modify the SMB layer to be non blocking.
Original comment by rustysco...@gmail.com
on 18 Jun 2013 at 10:56
Good point.. the select_poll argument..
You can give it a try yourself.. change the select_poll to True in
NetBIOSTCPSession().__init__ and give it a try.. let me know how it goes.
I'm still trying to understand what's the benefit for you tho :-o
let me know!
beto
Original comment by bet...@gmail.com
on 18 Jun 2013 at 11:03
The benefit is that the pipes, which are subclasses of threads in psexec, will
eventually go back into motion after being stopped on an attempted read of a
remote named pipe; or at least not attempt a blocking read if it is going to
wait forever by checking to see if there is anything to read. Currently,
execution in the thread stops at
>ans = self.server.readFile(self.tid,self.fid, 0, 1024)
and will block indefinitely. At this point, not even using ctypes to kill the
thread will work. This is fine, if you are killing the process and don't
really care if you are leaking threads which will be collected by the OS.
However, let's say that I am not going to kill the process, because I want to
integrate psexec into a higher structure called a connection which can be
imported into other scripts and be instantiated as an object. In this case, I
can't really leak threads because I want to be able to run many commands one
after another like one might do with an ssh console.
in short
ans = self.server.readFile(self.tid,self.fid, 0, 1024)
makes a thread unjoinable which is never a good idea. Either you waste memory
and processes with a zombie thread or you deadlock attempting to join the
thread.
Original comment by rustysco...@gmail.com
on 19 Jun 2013 at 8:00
Excellent explanation mate.. thanks!
Did you try the sellect_poll option in nmb.py?
cheers
beto
Original comment by bet...@gmail.com
on 19 Jun 2013 at 8:05
Original issue reported on code.google.com by
rustysto...@gmail.com
on 7 Jun 2013 at 6:22