Files
Investidor-V2/outputs/investmoz-audit-current-20261012/B-MFA-diagnostic-readonly-20261015.php
T
nala c13f250b87
tests / ci (push) Canceled after 0s
versao compilada
2026-10-15 17:37:00 +02:00

21 lines
2.8 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');
set_exception_handler(function(Throwable $e){fwrite(STDERR,'MFA read-only diagnostic stopped: '.$e::class.' line '.$e->getLine());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);
$c=config('database.connections.'.config('database.default'));
if($c['driver']!=='pgsql'||$c['database']!=='investemoz'||(int)$c['port']!==5432||!in_array($c['host'],['127.0.0.1','localhost']))throw new RuntimeException('Destination guard');
$pdo=new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$pdo->exec('BEGIN READ ONLY');
try{
$key=config('app.key');if(str_starts_with($key,'base64:'))$key=base64_decode(substr($key,7),true);
$cipher=new Illuminate\Encryption\Encrypter($key,config('app.cipher'));$cipher->previousKeys(array_map(fn($v)=>str_starts_with($v,'base64:')?base64_decode(substr($v,7),true):$v,config('app.previous_keys',[])));
$rows=[];foreach($pdo->query('SELECT id,name,email,email_verified_at,two_factor_secret,two_factor_confirmed_at FROM users ORDER BY id')->fetchAll(PDO::FETCH_ASSOC)as$u){
$manager=in_array(strtolower($u['email']),config('portal.managers',[]),true);
$row=['account_id'=>$u['id'],'manager_designated'=>$manager,'email_verified'=>$u['email_verified_at']!==null,'MFA_enrolled'=>$u['two_factor_secret']!==null,'MFA_confirmed'=>$u['two_factor_confirmed_at']!==null];
if($u['two_factor_secret']!==null){try{$raw=$cipher->decrypt($u['two_factor_secret'],false);$row['decrypts_current_runtime_key']=true;$row['raw_is_Base32']=preg_match('/^[A-Z2-7]{16,}$/D',$raw)===1;$row['raw_has_serialized_string_prefix']=str_starts_with($raw,'s:');unset($raw);}catch(Throwable $e){$row['decrypts_current_runtime_key']=false;$row['exception_type']=$e::class;}}
$rows[]=$row;
}
$p=['at'=>gmdate('c'),'target'=>'investemoz:5432','SQL_read_only'=>true,'accounts'=>$rows,'current_key_matches_pre_window_backup'=>hash_file('sha256',$root.'/.env')===hash_file('sha256',json_decode(file_get_contents(__DIR__.'/B-activation-fresh-backup-20261015.json'),true)['private_directory'].'/files/.env'),'previous_key_count'=>count(config('app.previous_keys',[])),'LOG_LEVEL'=>config('logging.channels.single.level'),'no_plaintext_seeds_codes_or_recovery_values_in_receipt'=>true,'credentials_changed'=>false,'active_changes'=>0];
file_put_contents(__DIR__.'/B-MFA-diagnostic-readonly-20261015.json',json_encode($p,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo json_encode($p,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR);
}finally{$pdo->exec('ROLLBACK');}