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.
Question
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)- A77% (20)
- B4% (1)
- C8% (2)
- D12% (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.
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.
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.
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.
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
Community Discussion
No community discussion yet for this question.
