SY0-501 · Question #414
An attacker exploited a vulnerability on a mail server using the code below. <HTML><body onload=document.location.replace "URL:" +"document.location) ; /> </body> </HTML> Which of the following BEST…
The correct answer is C. The attacker is replacing a document. The attacker is using the JavaScript document.location.replace() method to change the current URL, which causes the browser to replace the currently loaded document with another.
Question
An attacker exploited a vulnerability on a mail server using the code below. <HTML><body onload=document.location.replace "URL:" +"document.location) ; /> </body> </HTML> Which of the following BEST explains what the attacker is doing?
Options
- AThe attacker is replacing a cookie.
- BThe attacker is stealing a document.
- CThe attacker is replacing a document.
- DThe attacker is deleting a cookie.
How the community answered
(51 responses)- A6% (3)
- B2% (1)
- C80% (41)
- D12% (6)
Why each option
The attacker is using the JavaScript `document.location.replace()` method to change the current URL, which causes the browser to replace the currently loaded document with another.
The code snippet does not interact with `document.cookie` or any other cookie-specific functions; it targets the `location` object to change the page URL.
Stealing a document would typically involve extracting its content (e.g., via `document.body.innerHTML`) or sensitive data and sending it to an attacker-controlled server, not using `document.location.replace()` for redirection.
The JavaScript `document.location.replace()` method is used to navigate to a new URL, effectively replacing the currently loaded document in the browser window and removing the current URL from the browser's session history. This action directly corresponds to 'replacing a document'.
Deleting a cookie involves manipulating the `document.cookie` property with an expired date or an empty string, actions not present in the provided code.
Concept tested: Cross-Site Scripting (XSS) document redirection
Source: https://learn.microsoft.com/en-us/javascript/api/dom/html-dhtml/location
Topics
Community Discussion
No community discussion yet for this question.