-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add server module #1067
Add server module #1067
Conversation
pwnlib/tubes/server.py
Outdated
h.success('Got connection from %s on port %d' % (rhost, rport)) | ||
|
||
self._accepter = context.Thread(target = accepter) | ||
self._accepter.daemon = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be set to True
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this is set to True
, a program which only initializes a server with a callback function exits immediately rather than listen for connections. Do you know a good way to wait on the server when it is initialized as a daemon?
pwnlib/tubes/server.py
Outdated
s = remote.readline() | ||
remote.send(s) | ||
|
||
if not callback: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the default argument to be a echo
and move echo
to the module level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, if the callback
is None
, then we should just queue the sockets and pop them out of the queue wait_for_connection()
a la listen.py
.
pwnlib/tubes/server.py
Outdated
|
||
r = remote(rhost, rport, sock = sock) | ||
t = context.Thread(target = callback, args = (r,)) | ||
t.daemon = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set daemon = True
Thanks for this! Overall it looks good, with only some minor tweaks necessary. Because this is ~50% copy-pasted from |
continue | ||
|
||
h.status("Trying %s" % self.sockaddr[0]) | ||
listen_sock = socket.socket(self.family, self.type, self.proto) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never set self.sock
, which makes inheritance from sock
behave oddly. Consider setting self.sock = listen_sock
once we have the listener.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also ended up setting self.rhost
and self.rport
on each new connection so that closing wouldn't crash.
pwnlib/tubes/server.py
Outdated
r"""Creates an TCP or UDP-server to listen for connections. It supports | ||
both IPv4 and IPv6. | ||
|
||
The callback function should take a :class:`pwnlib.tubes.remote` as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit of documentation should go on the callback
argument documentation below
pwnlib/tubes/server.py
Outdated
return | ||
|
||
r = remote(rhost, rport, sock = sock) | ||
t = context.Thread(target = callback, args = (r,)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be useful to support non-threaded (i.e. blocking) callbacks via an optional argument to __init__
.
I'd like to keep the two modules separate until the server is ready, then see if combining the two is still feasible. |
Any update on the review? |
On vacation until Nov 28
…On Tue, Nov 21, 2017 at 9:11 AM Devin Neal ***@***.***> wrote:
Any update on the review?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#1067 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAG0GPvd8TYC0mFbQKHYOFx1Ty4xB4rxks5s4vY6gaJpZM4Qcaad>
.
|
Any update on this? |
You need to add a |
pwnlib/tubes/server.py
Outdated
self.connections_waiting.set() | ||
|
||
self._accepter = context.Thread(target = accepter) | ||
self._accepter.daemon = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be set to True
.
I've added a |
It looks like we actually just put them all in https://github.com/Gallopsled/pwntools/blob/dev/docs/source/tubes/sockets.rst Thanks! |
server
Adds a class
pwnlib.tubes.server.server
, similar topwnlib.tubes.listen.listen
, but able to accept multiple connections.A few things worth mentioning that I'm unsure how to fix:
pkill
python -m doctest server.py
hangs upon creation of the serverspawn_process
forpwnlib.tubes.listen.listen
, but I'm not sure how to best go about implementing this