Why I want to know
We need to write XSS worms for an university project in which those worms fight against each other. The goal is to gain as much points as possible which are generated by a post request with our team id to a server. Each worm must not send more than exactly one of those post requests and replicates itself once.
To win, we are allowed to attack other worms. We are also allowed to defend our own worms from others. So we want our worms to make more successful post requests than the others.
I thought about blocking or rewriting the send()
method of XMLHttpRequest
, so that post requests from other worms/teams would send our team id or wouldn't be send at all. But I'm unfamiliar with JavaScript and I don't know if something like that would be possible...
Question
Attack
Is it possible to override a class/object (or a function of that class/object) - more especially XMLHttpRequest
- in JavaScript? And if so, is the overridden class still valid in the global context (valid from another <script>
tag)?
Let's say we have a first <script>
tag with the following content: (not sure if correct JavaScript)
XMLHttpRequest = function () { // or class () ?
const originalXMLHttpRequest = XMLHttpRequest;
function send () {
alert('successful attack');
originalXMLHttpRequest.send(our_team_id);
}
};
And a second <script>
tag which calls the send()
method with their_team_id
:
const request = new XMLHttpRequest();
// ... configure request here
request.send(their_team_id);
Does a call from the second <script>
tag now trigger the alert and send our_team_id
to the server instead?
Defend
Is it possible to detect a overridden class/object? And if so, can I somehow reverse the change or access the original function?
Assuming we could only write code inside the second <script>
tag and the first already overrode the send()
method of XMLHttpRequest
, would the original method still be accessible somehow?
If someone can think about another (and better) attack or defend vector, I would like to hear about it.