Skip to content
Home · Sonraki hedefe 100 XP
Son hareketler
Henüz bir öğrenme hareketi yok. İlk derse başlayın.

Web Application Security

Command injection: Separating data from command syntax

Appending user text to an operating system command may cause the data to be processed as code by the command interpreter. First compare input validation with the design that does not use the command at all.

Bu derste neler var?

SIBERSALDIRI.COM · FOCUSED LESSON

What you will learn

  • Explain the relationship between user data and the Embedded API.
  • “What is the strongest first design choice?” To give a reasoned answer to the question.
  • Changing the example and comparing expected and observed behavior.

How it works and where the trust boundary lies

Instead of calling a shell for work like file size, use the language's built-in API. If the command is really necessary, the executable file and arguments should be transferred with a separate contract, and the allowed operations and values ​​should be restricted. The escape technique depends on the operating system and interpreter; It is not a general purpose cleaning guarantee. The service account must run with minimal permissions.

Command injection: Flow of extracting data from command syntax: User data → Embedded API → Limited result
User data → Embedded API → Limited results. The diagram shows the relationship; It does not replace the entire application.

Worked example

The following passage makes the concept visible. Evaluate samples containing commands or code in your own separate testing environment, not in the production system. Architectural diagrams and policy examples are not executable programs.

<?php
$path = __DIR__ . '/sample.txt';
if (!is_file($path)) { throw new RuntimeException('Dosya yok'); }
echo filesize($path);

Expected result and interpretation

The size of the local hard file is obtained without running the shell command.

Compare the scenarios

StatusRecommended approachWhy?
Built-in API is sufficientUsing a shellInterpreter limit is removed
command requiredConstant executable and argumentFree codes are not accepted
Input is claimed to be sanitisedVerify contextEscape rules are not the same

Practice task

Write how to replace a shell-using file listing job with the built-in file API.

  1. Write down the expected outcome and acceptance condition before the action.
  2. Change a single variable; Record the observation and the medium you used.
  3. Evaluate the result with the comparison table above. Explain which assumption might be wrong if it does not fit.

Common mistake and how to correct it

Do not accept commands or executable filenames from the client.

Test your understanding

What is the strongest first design choice?

Answer explained: Doing the job with the secure built-in API without the shell interpreter removes the associated interpreter limit.

Continue with related lessons

Technical reference

The explanation and examples of this course have been re-prepared for the academy. The link below is a technical reference to verify details of the technology or security approach used.

Bir adım daha ilerlediniz.

Dersi bitirdiyseniz tamamlandı olarak işaretleyin. İlerlemeniz bu cihazda saklanır.

Academy menu

Akademide ara

En az 2 karakter yazın.