26 lines
4.9 KiB
PHP
26 lines
4.9 KiB
PHP
<?php
|
|
// Scoped incident audit only; never impersonate a human, rotate again, or alter profiles/sessions.
|
|
ini_set('zend.exception_ignore_args','1');set_exception_handler(function(Throwable $e){fwrite(STDERR,json_encode(['error_type'=>$e::class,'SQLSTATE'=>$e->getCode(),'line'=>$e->getLine(),'secret_values_recorded'=>false]));exit(1);});
|
|
$root=dirname(__DIR__,2);require $root.'/vendor/autoload.php';$app=require $root.'/bootstrap/app.php';(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);
|
|
$out=__DIR__;$load=fn($p)=>json_decode(ltrim(file_get_contents($p),"\xEF\xBB\xBF"),true,512,JSON_THROW_ON_ERROR);
|
|
$before=$load($out.'/C132-preflight.json');if(hash_file('sha256',$root.'/config/inertia.php')!=='80c68e12bf6cb64e39931e2467b43909893cea3eb6d04c3c1e68bdcb1236dfb7'||hash_file('sha256',$root.'/app/Services/OpportunityContacts.php')!==$before['C131_active_hash'])throw new RuntimeException('Incident scope differs');
|
|
$backup=$load($out.'/C132-backup-restoration.json');$private=$load($out.'/C132-private-location.json');$b=$load($private['private_directory'].'/recovery/backup-proof-private.json');
|
|
if(!$backup['restore_verified']||hash_file('sha256',$b['dump'])!==$backup['dump_sha256'])throw new RuntimeException('Verified recovery unavailable');
|
|
$c=config('database.connections.'.config('database.default'));if($c['database']!=='investemoz'||(int)$c['port']!==5432||!empty($c['url']))throw new RuntimeException('Target differs');
|
|
$db=new PDO('pgsql:host='.$c['host'].';port='.$c['port'].';dbname='.$c['database'],$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$db->exec('BEGIN');
|
|
try{$target=$db->query('SELECT current_database() AS database,inet_server_port() AS port')->fetch(PDO::FETCH_ASSOC);if($target['database']!=='investemoz'||(int)$target['port']!==5432)throw new RuntimeException('Actual target differs');
|
|
$usersBefore=$db->query('SELECT row_to_json(u)::text FROM users u ORDER BY id')->fetchAll(PDO::FETCH_COLUMN);$sessionsBefore=$db->query('SELECT row_to_json(s)::text FROM sessions s ORDER BY id')->fetchAll(PDO::FETCH_COLUMN);
|
|
$correlation='ead504de-19c1-4d84-9eca-d5649b8a456a';$events=[];$inserted=0;
|
|
foreach([14,15,16,17]as$id){$r=$load($out.'/C132-account'.$id.'-email-receipt.json');if(!$r['SMTP_accepted']||!$r['TLS_required_and_certificate_verified']||$r['recipient_count']!==1||$r['CC_BCC']!==0)throw new RuntimeException('Receipt differs');
|
|
$events[]=['id'=>$id,'action'=>'C132_individual_MFA_handoff_SMTP_accepted','data'=>['case'=>'C132','account_id'=>$id,'SMTP_accepted_at'=>$r['at'],'single_recipient'=>true,'TLS_protocol'=>$r['negotiated_TLS_protocol'],'mailbox_or_holder_confirmation_inferred'=>false,'authorization'=>'Explicit owner instructed individual email delivery','secret_values_recorded'=>false]];
|
|
}
|
|
$manual=$load($out.'/C132-account17-manual-recovery.json');if(!$manual['dashboard_access_confirmed']||!$manual['mailbox_receipt_confirmed'])throw new RuntimeException('Manual confirmation differs');
|
|
$events[]=['id'=>17,'action'=>'C132_holder_access_recovered_manual_confirmation','data'=>['case'=>'C132','account_id'=>17,'source'=>'Owner relayed individual account confirmation','received'=>true,'MFA_configured'=>true,'dashboard_accessible'=>true,'automated_browser_proof'=>false,'secret_values_recorded'=>false]];
|
|
$exists=$db->prepare("SELECT COUNT(*) FROM audit_events WHERE source_system=:source AND correlation_id=:correlation AND action=:action AND after_data->>'account_id'=:account");
|
|
$insert=$db->prepare("INSERT INTO audit_events(source_system,correlation_id,entity_type,action,actor_user_id,data_classification,after_data) VALUES(:source,:correlation,'security_incident_account',:action,NULL,'restricted',CAST(:data AS jsonb))");
|
|
foreach($events as$event){$params=['source'=>'C132-incident-response','correlation'=>$correlation,'action'=>$event['action']];$exists->execute([...$params,'account'=>(string)$event['id']]);if((int)$exists->fetchColumn()===0){$insert->execute([...$params,'data'=>json_encode($event['data'],JSON_THROW_ON_ERROR)]);$inserted++;}}
|
|
if($usersBefore!==$db->query('SELECT row_to_json(u)::text FROM users u ORDER BY id')->fetchAll(PDO::FETCH_COLUMN)||$sessionsBefore!==$db->query('SELECT row_to_json(s)::text FROM sessions s ORDER BY id')->fetchAll(PDO::FETCH_COLUMN))throw new RuntimeException('Unrelated data changed');
|
|
$db->exec('COMMIT');
|
|
}catch(Throwable $e){$db->exec('ROLLBACK');throw$e;}
|
|
$proof=['at'=>gmdate('c'),'target'=>$target,'audit_events_appended'=>$inserted,'audit_correlation_id'=>$correlation,'only_incident_audit_written'=>true,'human_actor_impersonated'=>false,'new_secret_values_recorded'=>false,'users_and_sessions_unchanged'=>true,'C131_included'=>false,'pending_holder_confirmation_ids'=>[14,15,16],'incident_closed'=>false];file_put_contents($out.'/C132-followup-audit.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($proof);
|