nerdexam
CompTIA

PT0-001 · Question #167

A web server is running PHP, and a penetration tester is using LFI to execute commands by passing parameters through the URL. This is possible because server logs were poisoned to execute the PHP…

The correct answer is A. ''&CMD_cat /etc/passwd--&id-34''. LFI with log poisoning allows arbitrary PHP execution by injecting code into server logs and including those logs, then passing OS commands via GET parameters.

Attacks and exploits

Question

A web server is running PHP, and a penetration tester is using LFI to execute commands by passing parameters through the URL. This is possible because server logs were poisoned to execute the PHP system ( ) function. Which of the following would retrieve the contents of the passwd file?

Options

  • A''&CMD_cat /etc/passwd--&id-34''
  • B''&CMD=cat / etc/passwd%&id= 34''
  • C''&CMD=cat ../../../../etc/passwd7id=34'
  • D''&system(CMD) ''cat /etc/passed&id=34''

How the community answered

(54 responses)
  • A
    59% (32)
  • B
    13% (7)
  • C
    22% (12)
  • D
    6% (3)

Why each option

LFI with log poisoning allows arbitrary PHP execution by injecting code into server logs and including those logs, then passing OS commands via GET parameters.

A''&CMD_cat /etc/passwd--&id-34''Correct

After poisoning server logs with injected PHP such as <?php system($_GET['CMD']); ?>, the LFI vulnerability includes the poisoned log and executes the PHP code. Passing a CMD parameter containing the cat /etc/passwd command causes the system() function to execute and return the passwd file contents. This is the only option with a properly formed absolute path and no syntax errors that would prevent command execution.

B''&CMD=cat / etc/passwd%&id= 34''

The space in '/ etc/passwd' between the slash and 'etc' is invalid path syntax and would cause the shell command to fail.

C''&CMD=cat ../../../../etc/passwd7id=34'

Path traversal sequences like '../../../../' are unnecessary when calling an absolute path via system(), and '7id=34' is a malformed parameter separator that breaks the query string.

D''&system(CMD) ''cat /etc/passed&id=34''

The word 'passed' is a typo for 'passwd', meaning the command targets a non-existent file, and the syntax does not correctly pass a GET parameter to the PHP system() function.

Concept tested: LFI log poisoning with PHP system() command execution

Source: https://owasp.org/www-project-web-security-testing-guide/v42/4-Web_Application_Security_Testing/07-Input_Validation_Testing/11.1-Testing_for_Local_File_Inclusion

Topics

#LFI#log poisoning#PHP#web exploitation

Community Discussion

No community discussion yet for this question.

Full PT0-001 Practice