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

AI PRP: Pickle deserialization on recv_pyobj method of pyZMQ pacakge #586

Open
mr-mosi opened this issue Jan 23, 2025 · 2 comments
Open
Assignees

Comments

@mr-mosi
Copy link
Contributor

mr-mosi commented Jan 23, 2025

Hello,
This is related to this recent blog post that we can expend the vulnerable instances to all kind of application which are using the recv_pyobj method on an open TCP socket.

TLDR: the recv_pyobj sends the received TCP message to a pickle deserialize method which is unsafe and leads to code injection.

references:
https://pyzmq.readthedocs.io/en/latest/howto/morethanbindings.html#builtin-serialization
https://pyzmq.readthedocs.io/en/latest/api/zmq.html#zmq.Socket.recv_pyobj

a simple example can be this:
a pyZMQ server:

import zmq

# Create a ZeroMQ context
context = zmq.Context()

# Create a REP (Reply) socket
socket = context.socket(zmq.REP)

# Bind the socket to a TCP address
socket.bind("tcp://*:5555")  # Listen on port 5555

print("Server is listening on tcp://*:5555...")

while True:
    try:
        # Receive a Python object
        received_obj = socket.recv_pyobj()
        print(f"Received object: {received_obj}")

        # Send a response back to the client
        response = f"Server received: {received_obj}"
        socket.send_pyobj(response)

    except KeyboardInterrupt:
        print("Server shutting down...")
        break

# Clean up
socket.close()
context.term()

a client simply pickle the exploit object and send it through the TCP socket.
I'm not sure, but for writing a python tsunami plugin we maybe need to add a pypi package too. i don't know if this is possible or not.

@tooryx
Copy link
Member

tooryx commented Jan 30, 2025

Hi @mr-mosi,

Could you provide a bit more details on how you would identify a vulnerable service? Would you just send the pickle exploit to every TCP service? Which for us, would be considered a bit too aggressive/prone to denial of service.

~tooryx

@mr-mosi
Copy link
Contributor Author

mr-mosi commented Feb 6, 2025

@tooryx Hii

fortunately, nmap can detect the zmq protocol.

Image

i tested it on the example server above in the issue description and nmap detect the open port as zeromq.

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

No branches or pull requests

2 participants