-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Hi, I think pwntools tubes could use some sort of "middleware" solution, that would process the data between
the underlying communication layer and the recvX
functions.
I tried to look if the pwntools already has such a thing, but did not find one, if I just missed it, please let me know and close this ticket. The system that connects tubes together looked somewhat promising, but I don't think it does what I'm envisioning.
It is also very possible something like this cannot be implemented.
For a very simple example, say a service communicates with a rot13. Currently I can do:
p = Remote(IP, PORT)
p.recvuntil(b'fryrpgvba >')
p.sendline(b'ybtva')
...
but it gets a little bit tedious to do the cipher by hand for each line. And if the service uses some actual encryption scheme, then it just gets worse.
What if you could do:
def rot13(input):
...
p = Remote(IP, PORT)
p.addmiddleware(rot13, rot13)
p.recvuntil(b'selection >')
p.sendline(b'login')
...
I'm not sure about the syntax (mainly should the middleware be a class with in and out methods, or just separate functions), but I hope this gets the idea across.
Things that I've thought this should be able to do is
- decrypt / encrypt data without state
- decrypt / encrypt data with state (know the last message, use running block/stream cipher for subsequent messages)
- I think this can be done by user if the middleware is a class, or with capturing lambdas if not
- keep track of message count to add running sequence numbers to messages
- add / check signatures/checksums on messages.
- either silently skip, warn or fail if some message fails these
- maybe it would be nice to be able to disable/enable the middleware for some messages?
- might be useful to layer multiple middlewares together,
- one to add / strip sequence number closest to the user code, and one to encrypt/decrypt above that.
Of course the things mentioned would be actually done by the middlewares themselves, but the tubes
layer would need to provide API to connect them.
I looked into creating this, but when I found the unrecv
function and realized sometimes the data needs to flow back, I wasn't sure I knew how to to implement any of this. Or if it would be possible.