Last active
July 5, 2023 20:16
-
-
Save Cdaprod/c96457acdc615c9d15c58af49e6ba7af to your computer and use it in GitHub Desktop.
For testing template injection on a page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Builder, By, Key, until } = require('selenium-webdriver'); | |
const chrome = require('selenium-webdriver/chrome'); | |
const templateInjectionPayloads = [ | |
'{{7*7}}', // Basic expression evaluation. Should return 49 if template injection is possible | |
'${7*7}', // This is for template engines that use $ like in AngularJS | |
'<%= 7 * 7 %>', // This is for EJS style templates | |
// Add more payloads to test different template engines | |
]; | |
const url = 'http://your-website.com'; | |
const inputField = 'input#your-input-field-id'; | |
async function testTemplateInjection() { | |
let driver = await new Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); | |
try { | |
await driver.get(url); | |
for (let payload of templateInjectionPayloads) { | |
await driver.findElement(By.css(inputField)).clear(); | |
await driver.findElement(By.css(inputField)).sendKeys(payload, Key.RETURN); | |
// You will need to implement the code to check if the payload was successful | |
} | |
} finally { | |
await driver.quit(); | |
} | |
} | |
testTemplateInjection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment