Skip to content

Instantly share code, notes, and snippets.

@code-boxx
Created June 27, 2023 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save code-boxx/a4b41058af347665acaef1bdeb3d4632 to your computer and use it in GitHub Desktop.
Save code-boxx/a4b41058af347665acaef1bdeb3d4632 to your computer and use it in GitHub Desktop.
Javascript Injection Examples

JAVASCRIPT INJECTION EXAMPLES

https://code-boxx.com/javascript-injection-beginners/

LICENSE

Copyright by Code Boxx

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

STEP 0
======
Click on the test button > It should show "Hello World"
STEP 1
======
Right click on test button > Inspect
Go to the "Events Listener" tab (at bottom-right side in Chrome/Opera/Edge)
Expand on "click" > There should only be 1 click event attached to the input button
Remove it
STEP 2
======
Back to "Elements" Tab > Double click on verbose() > Change it to hijack()
STEP 3
======
Go to the console tab
Input "function hijack(){ alert("HIJACKED"); }" > Hit return
Done > Clicking on the test button now will show "HIJACKED"
<!DOCTYPE html>
<html>
<head>
<script>
function verbose () { alert("Hello World!"); }
</script>
</head>
<body>
<input type="button" value="Test" onclick="verbose()">
</body>
</html>
<!DOCTYPE html>
<html>
<head></head>
<body>
<input type="text" id="txt-field" value="uvuwewewe onyetenyevwe uvwewenum osas">
</body>
</html>
STEP 1:
For testing, enter -
javascript:alert("Hi!");
into the address bar.
STEP 2:
Then try this -
javascript:alert(document.getElementById("txt-field").value);
This should give you "uvuwewewe onyetenyevwe uvwewenum osas" or whatever is in the text box.
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>LE NOOB WEBPAGE</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<h3>COMMENTS</h3>
<div>
Well done! <script>alert("HAHA!");</script>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment