forked from mtusi2026/mtusi2026lab7
lab7: исправления по независимому ревью
This commit is contained in:
@@ -666,10 +666,10 @@ def s3_plaintext_probe(cfg):
|
||||
raise ProbeFailure('network_timeout') from None
|
||||
except ConnectionRefusedError:
|
||||
raise ProbeFailure('connection_refused') from None
|
||||
if data.startswith(b'HTTP/') and b'x-amz-request-id' in data.lower():
|
||||
return {'classification': 'accepted', 'detail': 's3_http_response'}
|
||||
if data.startswith(b'HTTP/'):
|
||||
return {'classification': 'rejected', 'detail': 'https_listener_rejected_http'}
|
||||
if b'Client sent an HTTP request to an HTTPS server' in data:
|
||||
return {'classification': 'rejected', 'detail': 'https_listener_rejected_http'}
|
||||
return {'classification': 'accepted', 'detail': 'plaintext_http_response'}
|
||||
return {'classification': 'rejected', 'detail': 'no_http_response'}
|
||||
|
||||
|
||||
@@ -680,22 +680,24 @@ def loki_scan_probe(cfg):
|
||||
now = dt.datetime.now(dt.timezone.utc)
|
||||
start = (now - dt.timedelta(hours=24)).strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
end = now.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
query = cfg.get('selector', '{service_name=~".+"}')
|
||||
path = ('/loki/api/v1/query_range?query=' + urllib.parse.quote(query) +
|
||||
'&start=' + start + '&end=' + end + '&limit=2000&direction=backward')
|
||||
result = http('loki', 3100, 'GET', path, role='grafana')
|
||||
require(result['status'] == 200, 'loki_query_failed', str(result['status']))
|
||||
payload = json.loads(result['body'])
|
||||
require(payload.get('status') == 'success', 'loki_query_failed', str(payload.get('status')))
|
||||
selectors = cfg.get('selectors') or ['{service_name=~".+"}', '{job=~".+"}']
|
||||
lines = 0
|
||||
leaked = False
|
||||
for stream in payload.get('data', {}).get('result', []):
|
||||
for _, value in stream.get('values', []):
|
||||
lines += 1
|
||||
if any(secret in value for secret in sensitive):
|
||||
leaked = True
|
||||
for selector in selectors:
|
||||
path = ('/loki/api/v1/query_range?query=' + urllib.parse.quote(selector) +
|
||||
'&start=' + start + '&end=' + end + '&limit=2000&direction=backward')
|
||||
result = http('loki', 3100, 'GET', path, role='grafana')
|
||||
require(result['status'] == 200, 'loki_query_failed', str(result['status']))
|
||||
payload = json.loads(result['body'])
|
||||
require(payload.get('status') == 'success', 'loki_query_failed', str(payload.get('status')))
|
||||
for stream in payload.get('data', {}).get('result', []):
|
||||
for _, value in stream.get('values', []):
|
||||
lines += 1
|
||||
if any(secret in value for secret in sensitive):
|
||||
leaked = True
|
||||
require(lines > 0, 'loki_scan_empty')
|
||||
return {'classification': 'leak' if leaked else 'passed', 'lines': lines,
|
||||
'sensitive_values': len(sensitive)}
|
||||
'sensitive_values': len(sensitive), 'window_hours': 24, 'selectors': len(selectors)}
|
||||
|
||||
|
||||
def internal_main():
|
||||
|
||||
Reference in New Issue
Block a user