
A blockchain oracle node deserializes data from a smart contract event using Python’s pickle, allowing an attacker to execute arbitrary commands.
Severity: Critical (Full Node Compromise)
#!/usr/bin/env python3
"""
vulnerable_oracle.py - Oracle node that listens to events and deserializes data unsafely.
"""
import pickle, socketserver, threading, time, base64
# Simulated blockchain event: attacker can emit a log with a pickled payload.
# The oracle fetches the log data and processes it.
class Oracle:
def process_event(self, log_data_b64):
data = base64.b64decode(log_data_b64)
# VULNERABILITY: deserializing untrusted pickle
obj = pickle.loads(data)
# The object could be anything; we expect a dict with 'price'
print(f"Price update: {obj.get('price', 'N/A')}")
return obj
# Simulate an event listener (HTTP server) where attacker pushes events
class EventHandler(socketserver.BaseRequestHandler):
def handle(self):
data = self.request.recv(4096).strip()
# data is base64 pickled payload
oracle.process_event(data.decode())
self.request.sendall(b"OK\n")
def run_server():
server = socketserver.TCPServer(("0.0.0.0", 9999), EventHandler)
server.serve_forever()
if __name__ == '__main__':
threading.Thread(target=run_server, daemon=True).start()
# Keep oracle running
time.sleep(1)
print("Oracle listening on :9999")
while True: time.sleep(10)
A decentralized oracle node processes off‑chain data by deserializing Python pickled objects from untrusted smart contract events. An attacker can inject a malicious pickle that executes arbitrary system commands, compromising the entire node.
pickle.loads() on data obtained from an external, attacker‑controlled source without any validation.python vulnerable_oracle.py
python oracle_exploit.py