PHP code example of salvatorecervone / laravel-pentest

1. Go to this page and download the library: Download salvatorecervone/laravel-pentest library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

salvatorecervone / laravel-pentest example snippets


'suppressions' => [
    'UNPROTECTED_SENSITIVE_ROUTE:/api/public-report',
],

use LaravelPentest\Support\DatabaseSandbox;

DatabaseSandbox::executeInTransaction(function () {
    // Probing or test mutation runs here
    // Automatically rolled back in a finally block — zero persistence!
});

// config/pentest.php
'authorization' => [
    'forbidden_routes' => [
        '/cancellatutto',
        '/admin/*',
        'App\Http\Controllers\Admin\*',
    ],
],

namespace Tests\Feature;

use App\Models\Customer;
use App\Models\User;
use LaravelPentest\Testing\InteractsWithPentest;
use Tests\TestCase;

class SecurityRegressionTest extends TestCase
{
    use InteractsWithPentest;

    public function test_sensitive_routes_are_protected_from_guests(): void
    {
        $this->assertRouteProtectedFromGuest('/admin/dashboard');
        $this->assertRouteProtectedFromGuest('/billing/invoices');
    }

    public function test_auth_routes_have_rate_limiting(): void
    {
        $this->assertRouteHasRateLimiting('/login');
        $this->assertRouteHasRateLimiting('/password/reset');
    }

    public function test_models_have_encryption_and_hidden_attributes(): void
    {
        $this->assertModelIsGuarded(User::class);
        $this->assertModelHidesAttributes(User::class, ['password', 'two_factor_secret']);
        $this->assertModelEncryptsAttributes(Customer::class, ['ssn', 'credit_card']);
    }

    public function test_no_critical_pentest_vulnerabilities_exist(): void
    {
        $this->assertNoPentestVulnerabilities();
    }
}

return [
    // Patterns of routes to skip (dev debuggers, health checks, or session-altering endpoints)
    'ignore_routes' => [
        '_ignition/*',
        '_debugbar/*',
        'telescope/*',
        'horizon/*',
        'pulse/*',
        'up',
        'sanctum/csrf-cookie',
        // User session & profile mutating routes (Jetstream, Fortify, Breeze)
        'user/profile-photo',
        'user/other-browser-sessions',
        'user/password',
        'user/two-factor-*',
        'user/confirmed-password-status',
        'user/confirm-password',
        'current-user/*',
        // Add custom session-altering or logout routes here:
        // 'logout',
        // 'session/terminate-all',
        // 'App\Http\Controllers\Auth\*SessionController*',
    ],

    // Additional directories where Eloquent models should be discovered
    'models_paths' => [
        // app_path('Domain/Billing/Models'),
    ],

    // Minimum severity to fail CI command ('CRITICAL', 'HIGH', 'MEDIUM', 'LOW')
    'fail_on_severity' => env('PENTEST_FAIL_SEVERITY', 'HIGH'),

    // Database Hardening & Security Audit
    'database' => [
        // Connections to audit. Null defaults to config('database.default')
        'connections' => env('PENTEST_DB_CONNECTIONS', null),

        // Fallback/override credentials when not stored in .env
        // Useful for CI runners, Docker secrets, or AWS Secrets Manager
        'credentials' => [
            'mysql' => [
                'username' => env('PENTEST_DB_USERNAME'),
                'password' => env('PENTEST_DB_PASSWORD'),
            ],
        ],

        // Allow blank passwords if database uses socket or IAM authentication
        'allow_empty_password' => env('PENTEST_DB_ALLOW_EMPTY_PASSWORD', false),

        // Custom weak password dictionary
        'weak_passwords' => [
            '', 'root', 'admin', 'password', '123456', 'secret',
        ],
    ],

    // Sensitive Data & PII Audit
    'sensitive_data' => [
        // Columns that should have 'encrypted' casts in Eloquent
        'sensitive_attributes' => [
            'ssn', 'tax_number', 'fiscal_code', 'credit_card', 'iban', 'bank_account', 'passport',
        ],

        // Attributes that must be hidden from API JSON responses
        'critical_hidden_attributes' => [
            'password', 'remember_token', 'two_factor_secret', 'api_token',
        ],
    ],

    // Cryptographic & Environment Audit
    'crypto' => [
        // Minimum bcrypt rounds (OWASP recommends >= 10, default 10)
        'min_bcrypt_rounds' => 10,

        // Check if .env has world-readable filesystem permissions
        'check_env_permissions' => true,
    ],
];
bash
php artisan vendor:publish --tag="pentest-config"
bash
php artisan pentest:run
bash
php artisan pentest:run --fail-on-vuln
bash
php artisan pentest:run --fail-on-vuln