Files
Investidor-V2/outputs/investmoz-audit-current-20261012/C132-preserve-period.py
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

32 lines
3.1 KiB
Python

from pathlib import Path
from datetime import datetime,timezone
import json,hashlib,re,shutil,subprocess,collections
OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1]
incident=Path(json.loads((OUT/'C132-private-location.json').read_text(encoding='utf-8-sig'))['private_directory'])
safe=[]
logdir=Path('C:/laragon/bin/apache/httpd-2.4.54-win64-VS16/logs');dest=incident/('apache-logs-'+datetime.now(timezone.utc).strftime('%Y%m%d_%H%M%S'));dest.mkdir(exist_ok=False)
for source in sorted(logdir.glob('*.log')):
original=source.read_bytes();target=dest/source.name;target.write_bytes(original);assert hashlib.sha256(target.read_bytes()).digest()==hashlib.sha256(original).digest()
lines=original.decode('utf-8',errors='replace').splitlines();dates=[];endpoint=collections.Counter();requests=0
for line in lines:
match=re.search(r'\[(\d{2}/[A-Za-z]{3}/\d{4}:\d{2}:\d{2}:\d{2} [+-]\d{4})\]',line)
if match:
try:dates.append(datetime.strptime(match[1],'%d/%b/%Y:%H:%M:%S %z').astimezone(timezone.utc).isoformat())
except ValueError:pass
if '/_inertia/devtools/entries' in line:
status=re.search(r'"\s+(\d{3})\s',line);endpoint[status[1] if status else 'unknown']+=1
if re.search(r'"(?:GET|POST|HEAD) ',line):requests+=1
safe.append({'name':source.name,'sha256':hashlib.sha256(original).hexdigest(),'bytes':len(original),'last_write_UTC':datetime.fromtimestamp(source.stat().st_mtime,timezone.utc).isoformat(),'dated_first':min(dates) if dates else None,'dated_last':max(dates) if dates else None,'devtools_requests_by_status':dict(endpoint),'raw_lines_exported':False})
analysis=json.loads((OUT/'C132-local-analysis.json').read_text(encoding='utf-8'))
containment=json.loads((OUT/'C132-containment.json').read_text(encoding='utf-8-sig'))
before=json.loads((OUT/'C132-active-readonly.json').read_text(encoding='utf-8'))
period={'at':datetime.now(timezone.utc).isoformat(),'case':'C132','known_anonymous_HTTP_confirmed_at':before['at'],'disabled_at':containment['contained_file_at'],
'first_retained_diagnostic_at':analysis['retained_first_timestamp'],'last_retained_diagnostic_at':analysis['retained_last_timestamp'],
'minimum_inferred_collection_and_endpoint_enabled_start':analysis['retained_first_timestamp'],
'inference_basis':'Recorder and routes use the same DevTools.enabled gate; retained diagnostic timestamps imply enabled collection. Earliest retained entry is not installation/start of full exposure.',
'full_exposure_start':'undetermined; 24-hour pruning and absence of an enable/disable history prevent an exact earlier start. Available access logs were preserved and inspected.',
'retention_hours_from_installed_default':24,'all_historical_accesses_identified':False,'unauthorized_downloads_proven':False,
'absence_of_downloads_proven':False,'logs_preserved_privately':safe,'observed_endpoint_reach':'Local HTTPS hostname, anonymous client; external reach not tested.',
'endpoint_diagnostics_have_no_per_actor_filter':True,'secret_values_or_IPs_in_report':False}
(OUT/'C132-exposure-period.json').write_text(json.dumps(period,ensure_ascii=False,indent=2),encoding='utf-8');print(json.dumps(period,ensure_ascii=True))