nerdexam
EC-Council

312-50V12 · Question #47

Judy created a forum. One day, she discovers that a user is posting strange images without writing comments. She immediately calls a security expert, who discovers that the following code is hidden…

The correct answer is A. This php file silently executes the code and grabs the user's session cookie and session ID. This question describes a Cross-Site Scripting (XSS) attack where malicious PHP/JavaScript code is embedded behind images in a forum to steal session data from users who click on them.

Submitted by paula_co· Mar 4, 2026Web Application Hacking

Question

Judy created a forum. One day, she discovers that a user is posting strange images without writing comments. She immediately calls a security expert, who discovers that the following code is hidden behind those images: What issue occurred for the users who clicked on the image?

Exhibit

312-50V12 question #47 exhibit

Options

  • AThis php file silently executes the code and grabs the user's session cookie and session ID.
  • BThe code redirects the user to another site.
  • CThe code injects a new cookie to the browser.
  • DThe code is a virus that is attempting to gather the user's username and password.

How the community answered

(26 responses)
  • A
    77% (20)
  • B
    4% (1)
  • C
    8% (2)
  • D
    12% (3)

Why each option

This question describes a Cross-Site Scripting (XSS) attack where malicious PHP/JavaScript code is embedded behind images in a forum to steal session data from users who click on them.

AThis php file silently executes the code and grabs the user's session cookie and session ID.Correct

The hidden code behind the image is a classic XSS-based session hijacking payload. When a user clicks the image, the malicious script silently executes in the browser context, accessing document.cookie or session identifiers and exfiltrating them to an attacker-controlled server without the victim's knowledge, allowing the attacker to impersonate the user.

BThe code redirects the user to another site.

While some XSS payloads can redirect users, the scenario specifically describes code hidden behind images designed to steal session data, not perform a redirect, and no window.location or redirect logic is indicated.

CThe code injects a new cookie to the browser.

The attack is focused on reading and stealing existing session cookies rather than injecting new cookies into the browser; cookie injection is a different attack vector not described here.

DThe code is a virus that is attempting to gather the user's username and password.

This is not a virus targeting usernames and passwords directly; it is a session hijacking attack that steals active session tokens, which is technically distinct from credential harvesting malware or keyloggers.

Concept tested: XSS session hijacking via malicious forum image code

Source: https://owasp.org/www-community/attacks/xss/

Topics

#Web application security#Cross-site scripting (XSS)#Session hijacking#Cookie theft

Community Discussion

No community discussion yet for this question.

Full 312-50V12 Practice