Exploit database

GH-7bd325ad03e3f3122b2aecb63733a70c

danielw98/zero-click-exploit-analysis

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-55177

4 sources

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

Repository files3

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

web/static/js/pages/heap-lab.js

JavaScript · 16,361 bytes
// Heap lab — authentic gdb `x/24gx` memory view with narrative walkthrough.

// ─────────────────────────────────────────────────────────────────────
// Memory model (64-bit glibc, simplified).
//
// Byte offsets from BASE, total MEM_LEN bytes:
//
//   [ 0..15 ]  chunk A metadata (prev_size=0, size=0x31 | PREV_INUSE)
//   [16..47 ]  auth->name[32]
//   [48..51 ]  auth->auth (int)
//   [52..55 ]  4 bytes alignment padding
//   [56..71 ]  chunk B metadata (prev_size=0, size=0x21 | PREV_INUSE)
//   [72..95 ]  service (strdup payload, initially "owner\0...")
// ─────────────────────────────────────────────────────────────────────

const BASE = 0x555555559290n;
const OFF_META_A = 0;
const OFF_NAME   = 16;
const OFF_AUTH   = 48;
const OFF_META_B = 56;
const OFF_SVC    = 72;
const MEM_LEN    = 96;

function freshMem() {
  const m = new Uint8Array(MEM_LEN);
  m[OFF_META_A + 8] = 0x31;       // chunk A size field
  m[OFF_META_B + 8] = 0x21;       // chunk B size field
  const svc = "owner";
  for (let i = 0; i < svc.length; i++) m[OFF_SVC + i] = svc.charCodeAt(i);
  return m;
}

function classify(off) {
  if (off < OFF_NAME)   return "meta";
  if (off < OFF_AUTH)   return "name";
  if (off < OFF_META_B) return "auth";
  if (off < OFF_SVC)    return "meta";
  return "service";
}

// ─────────────────────────────────────────────────────────────────────
// State
// ─────────────────────────────────────────────────────────────────────
let mem = freshMem();
let baseline = freshMem();
let overflowMarks = new Uint8Array(MEM_LEN);
let currentStep = 0;

const STEPS = [
  { len: 16, title: "Benign input",     execute: true,  login: false, text: '16 bytes fit in <code>name[32]</code> — nothing outside the buffer is touched.' },
  { len: 32, title: "Boundary",         execute: true,  login: false, text: 'Exactly 32 bytes. The name buffer is full; the <code>auth</code> flag is untouched, still zero.' },
  { len: 36, title: "Overflow the flag", execute: true, login: false, text: '36 bytes — the last 4 spill into <code>auth-&gt;auth</code>. The authentication flag is now non-zero.' },
  { len: 36, title: "Unauth login()",   execute: false, login: true,  text: '<code>login()</code> reads <code>auth-&gt;auth</code>, sees a non-zero flag, and reports the user as authenticated.' },
  { len: 64, title: "Cross into chunk B", execute: true, login: false, text: '64 bytes crosses into chunk B\'s metadata and overwrites the service payload.' }
];

// ─────────────────────────────────────────────────────────────────────
// DOM
// ─────────────────────────────────────────────────────────────────────
const memEl      = document.getElementById("lab-mem");
const gdbEl      = document.getElementById("lab-gdb-out");
const loginBtn   = document.getElementById("lab-login");
const resetBtn   = document.getElementById("lab-reset");
const prevBtn    = document.getElementById("lab-prev");
const nextBtn    = document.getElementById("lab-next");
const walkPos    = document.getElementById("lab-walk-pos");
const stepTitle  = document.getElementById("lab-step-title");
const stepText   = document.getElementById("lab-step-text");
const badge      = document.getElementById("lab-badge");
const stateText  = document.getElementById("lab-state-text");
let isRunning    = false;

const fillName  = document.getElementById("fill-name");
const fillAuth  = document.getElementById("fill-auth");
const fillMeta  = document.getElementById("fill-meta");
const fillSvc   = document.getElementById("fill-svc");

// ─────────────────────────────────────────────────────────────────────
// Formatting helpers
// ─────────────────────────────────────────────────────────────────────
function hex16(n) {
  const v = (typeof n === "bigint" ? n : BigInt(n));
  return "0x" + v.toString(16).padStart(12, "0");
}
function word64(off) {
  let v = 0n;
  for (let i = 7; i >= 0; i--) v = (v << 8n) | BigInt(mem[off + i] ?? 0);
  return "0x" + v.toString(16).padStart(16, "0");
}
function wasChanged(off) {
  for (let i = 0; i < 8; i++) {
    if (mem[off + i] !== baseline[off + i]) return true;
  }
  return false;
}
function rowHasOverflow(off) {
  for (let i = 0; i < 16; i++) if (overflowMarks[off + i]) return true;
  return false;
}

// gdb `x/gx` prints two 8-byte words per 16-byte row.
// Authentic format:  0x555555559290: 0x0000000000000000  0x0000000000000031
function renderMem() {
  const rows = [];
  for (let off = 0; off < MEM_LEN; off += 16) {
    const addr = hex16(BASE + BigInt(off));
    const w1 = word64(off);
    const w2 = word64(off + 8);
    const c1 = wasChanged(off)     ? "changed" : "";
    const c2 = wasChanged(off + 8) ? "changed" : "";
    const ov = rowHasOverflow(off) ? "overflow" : "";
    const label = rowLabel(off);
    const cls1 = overflowByteIn(off, 8)     ? "overflow" : c1;
    const cls2 = overflowByteIn(off + 8, 8) ? "overflow" : c2;
    rows.push(
      `<span class="mem-row ${ov}">` +
        `<span class="mem-addr">${addr}:</span>  ` +
        `<span class="mem-word ${cls1}">${w1}</span>  ` +
        `<span class="mem-word ${cls2}">${w2}</span>` +
        (label ? `<span class="mem-section-label ${label.cls}"># ${label.text}</span>` : "") +
      `</span>`
    );
  }
  memEl.innerHTML = rows.join("");
}

function overflowByteIn(off, len) {
  for (let i = 0; i < len; i++) if (overflowMarks[off + i]) return true;
  return false;
}

function rowLabel(off) {
  if (off === OFF_META_A)   return { text: "chunk A metadata", cls: "is-meta" };
  if (off === OFF_NAME)     return { text: "auth->name[0..15]", cls: "is-name" };
  if (off === OFF_NAME+16)  return { text: "auth->name[16..31]", cls: "is-name" };
  if (off === OFF_AUTH)     return { text: "auth->auth + chunk B meta", cls: "is-auth" };
  if (off === 80)           return { text: "service strdup(\"owner\")", cls: "is-service" };
  return null;
}

// Horizontal strip: 5 regions metaA(16) | name(32) | auth(8) | metaB(16) | svc(24).
// strcpy writes starting at name — so writeLen fills: name 0..32, auth 0..8, metaB 0..16, svc 0..24.
function renderDiagram(writeLen) {
  const nameLen  = Math.min(writeLen, 32);
  const authLen  = Math.max(0, Math.min(writeLen - 32, 8));
  const metaLen  = Math.max(0, Math.min(writeLen - 40, 16));
  const svcLen   = Math.max(0, Math.min(writeLen - 56, 24));

  fillName.style.width = (nameLen / 32 * 100) + "%";
  fillAuth.style.width = (authLen / 8  * 100) + "%";
  fillMeta.style.width = (metaLen / 16 * 100) + "%";
  fillSvc.style.width  = (svcLen / 24  * 100) + "%";

  fillAuth.parentElement.classList.toggle("is-overflowed", authLen > 0);
  fillMeta.parentElement.classList.toggle("is-overflowed", metaLen > 0);
  fillSvc.parentElement.classList.toggle("is-overflowed", svcLen > 0);
}

// ─────────────────────────────────────────────────────────────────────
// State readout
// ─────────────────────────────────────────────────────────────────────
function authInt32() {
  return (mem[OFF_AUTH] | (mem[OFF_AUTH+1] << 8) | (mem[OFF_AUTH+2] << 16) | (mem[OFF_AUTH+3] << 24)) >>> 0;
}
function updateState() {
  const v = authInt32();
  const hijacked = v !== 0;
  badge.textContent = hijacked ? "HIJACKED" : "SAFE";
  badge.className = "lab-badge " + (hijacked ? "lab-badge-danger" : "lab-badge-safe");
  const hex = "0x" + v.toString(16).padStart(8, "0");
  stateText.innerHTML = hijacked
    ? `<code>auth-&gt;auth</code> = <code>${hex}</code> · <strong>login() will succeed</strong> — auth flag overwritten by overflow`
    : `<code>auth-&gt;auth</code> = <code>${hex}</code> · login would fail (flag not set)`;
}

// ─────────────────────────────────────────────────────────────────────
// GDB transcript
// ─────────────────────────────────────────────────────────────────────
function gdbLine(prompt, body, cls = "") {
  const p = prompt ? `<span class="gdb-prompt">${prompt}</span> ` : "";
  return `<div class="gdb-line ${cls}">${p}<span class="gdb-body">${body}</span></div>`;
}
function append(...lines) {
  gdbEl.insertAdjacentHTML("beforeend", lines.join(""));
  const scroller = gdbEl.closest(".lab-pane-body") || gdbEl;
  scroller.scrollTop = scroller.scrollHeight;
}
function initialTranscript() {
  gdbEl.innerHTML = "";
  append(
    gdbLine("", "GNU gdb (Ubuntu 12.1) — Reading symbols from ./heap-two...", "gdb-dim"),
    gdbLine("(gdb)", `<span class="gdb-cmd">break main</span>`),
    gdbLine("", "Breakpoint 1 at 0x11a9: file heap-two.c, line 14.", "gdb-dim"),
    gdbLine("(gdb)", `<span class="gdb-cmd">run</span>`),
    gdbLine("", "Starting program: /home/user/phoenix/heap-two", "gdb-dim"),
    gdbLine("(gdb)", `<span class="gdb-cmd">x/24gx 0x555555559290</span>`),
    gdbLine("", "→ memory view on the right panel", "gdb-dim"),
  );
}

// ─────────────────────────────────────────────────────────────────────
// Actions
// ─────────────────────────────────────────────────────────────────────
function buildPayload(len) {
  // A's up to 32, then 01 00 00 00 for the auth flag, then 00 pad, then B's.
  const out = new Uint8Array(len);
  for (let i = 0; i < len; i++) {
    if (i < 32) out[i] = 0x41;
    else if (i === 32) out[i] = 0x01;
    else if (i < 36) out[i] = 0x00;
    else if (i < 48) out[i] = 0x00;
    else out[i] = 0x42;
  }
  return out;
}
function payloadRepr(len) {
  if (len === 0) return '""';
  const parts = [];
  const aLen    = Math.min(len, 32);
  const flag    = len > 32 ? 1 : 0;
  const padLen  = Math.max(0, Math.min(len - 36, 12));
  const bLen    = Math.max(0, len - 48);
  if (aLen > 0)   parts.push(`"A"*${aLen}`);
  if (flag)       parts.push(`"\\x01\\x00\\x00\\x00"`);
  if (padLen > 0) parts.push(`"\\x00"*${padLen}`);
  if (bLen > 0)   parts.push(`"B"*${bLen}`);
  return parts.join(" + ");
}

async function executeWrite(len) {
  overflowMarks = new Uint8Array(MEM_LEN);
  // Reset mem to baseline (fresh malloc) before writing.
  mem = freshMem();

  append(
    gdbLine("(gdb)", `<span class="gdb-cmd">call strcpy(auth-&gt;name, ${payloadRepr(len)})</span>`),
  );

  const payload = buildPayload(len);

  const stride = Math.max(1, Math.ceil(len / 48));
  for (let i = 0; i < len; i += stride) {
    for (let k = 0; k < stride && i + k < len; k++) {
      const p = OFF_NAME + i + k;
      if (p >= MEM_LEN) break;
      mem[p] = payload[i + k];
      if (p >= OFF_AUTH) overflowMarks[p] = 1;
    }
    renderMem();
    renderDiagram(i + stride);
    await sleep(35);
  }
  renderDiagram(len);
  updateState();

  const v = authInt32();
  append(
    gdbLine("(gdb)", `<span class="gdb-cmd">p/x auth-&gt;auth</span>`),
    gdbLine("", v !== 0
      ? `$1 = <span class="gdb-danger">0x${v.toString(16).padStart(8,"0")}</span>  <span class="gdb-comment"># flag overwritten</span>`
      : `$1 = 0x00000000  <span class="gdb-comment"># flag still zero</span>`)
  );
}

function doLogin() {
  const ok = authInt32() !== 0;
  append(
    gdbLine("(gdb)", `<span class="gdb-cmd">continue</span>`),
    gdbLine("", "> <span class='gdb-cmd'>login</span>", "gdb-dim"),
    gdbLine("", ok
      ? `<span class="gdb-danger">you have logged in already!</span>   <span class="gdb-comment"># exploit successful</span>`
      : "please enter your password")
  );
}

function doReset() {
  mem = freshMem();
  overflowMarks = new Uint8Array(MEM_LEN);
  renderMem();
  renderDiagram(0);
  updateState();
  initialTranscript();
}

function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }

// ─────────────────────────────────────────────────────────────────────
// Narrative walkthrough
// ─────────────────────────────────────────────────────────────────────
const ALL_BTNS = [loginBtn, resetBtn, prevBtn, nextBtn];
function setBusy(busy) {
  isRunning = busy;
  ALL_BTNS.forEach(b => b && (b.disabled = busy));
  if (!busy) updateNavButtons();
}
function updateNavButtons() {
  prevBtn.disabled = currentStep === 0;
  nextBtn.disabled = currentStep === STEPS.length - 1;
}
function paintStep() {
  const s = STEPS[currentStep];
  walkPos.textContent = `Step ${currentStep + 1} of ${STEPS.length}`;
  stepTitle.textContent = s.title;
  if (stepText) stepText.innerHTML = s.text;
  loginBtn.style.display = s.login ? "" : "none";
  updateNavButtons();
}

async function runStep(i) {
  if (isRunning) return;
  if (i < 0 || i >= STEPS.length) return;
  currentStep = i;
  paintStep();
  setBusy(true);
  try {
    const s = STEPS[i];
    if (s.execute) await executeWrite(s.len);
    else           renderDiagram(s.len);
    if (s.login)   doLogin();
  } finally {
    setBusy(false);
  }
}

// Wire-up
loginBtn.addEventListener("click", () => { if (!isRunning) doLogin(); });
resetBtn.addEventListener("click", () => { if (isRunning) return; currentStep = 0; doReset(); paintStep(); });
prevBtn.addEventListener("click", () => runStep(currentStep - 1));
nextBtn.addEventListener("click", () => runStep(currentStep + 1));

// Init
initialTranscript();
renderMem();
renderDiagram(0);
updateState();
paintStep();

// Lock the gdb pane to the height of its INITIAL transcript, snapped up to
// a whole multiple of the gdb line-height so: (1) the default view fits all
// initial lines, (2) later overflow scrolls internally, and (3) each snap
// position shows whole lines, not a half-line at top or bottom. The memory
// pane keeps its own intrinsic height.
(function lockGdbHeight() {
  const panes = document.querySelectorAll(".lab-terminals .lab-pane");
  if (panes.length < 2) return;
  const gdbPane = panes[1];
  const gdbBody = gdbPane.querySelector(".lab-pane-body");
  const gdbTerm = gdbPane.querySelector(".lab-term-body") || gdbBody;
  const gdbHead = gdbPane.querySelector(".lab-pane-head");
  const apply = () => {
    const cs = getComputedStyle(gdbTerm);
    const lh = parseFloat(cs.lineHeight) || 22;
    const bodyCs = getComputedStyle(gdbBody);
    const bodyChrome = parseFloat(bodyCs.paddingTop) + parseFloat(bodyCs.paddingBottom);
    const headH = gdbHead ? gdbHead.offsetHeight : 0;
    const contentH = gdbTerm.scrollHeight;
    const snapped = Math.ceil(contentH / lh) * lh;
    gdbPane.style.height = (headH + bodyChrome + snapped + 7) + "px";
  };
  apply();
  window.addEventListener("resize", apply);
})();