SlideShare a Scribd company logo
1 of 30
Download to read offline
CODE BLUE 2016.10.20
@st4g3r
Hiroki MATSUKUMA
(@st4g3r)
Newbie Pentester
 Cyber Defense Institute, Inc.
CTF Player
 TokyoWesterns
My interests include
 Exploitation
 Glibc malloc (currently)
$whoami
tl;dr
Heap Exploitation(x64 Linux/Glibc malloc)
What's "House of Einherjar" ?
 This is a new heap exploitation technique that forces
glibc malloc() to return a nearly-arbitrary address.
 User is ordinarily able to read/write to the address
returned by malloc().
 The concept is abusing consolidating chunks to
prevent from the fragmentation.
 Off-by-one Overflow on well-sized chunk leads both control
of prev_size and PREV_INUSE bit of the next chunk.
Proof of Concept
 http://ux.nu/6Rv6h
Overview
Glibc malloc
 Chunk
 Bin
 Consolidating Chunks
House of Einherjar
 Flaw / Flow
 Demo
 Evaluation
 Countermeasures
"struct malloc_chunk"
 A memory block joins free list after being free()'ed.
 free()'ed block is treated as "struct malloc_chunk".
 The size of a chunk is aligned on SIZE_SZ*2 bytes.
(prev_size)
size
fd
bk
(not used)
(prev_size)
size
data
+
pads
SIZE_SZ
=8byte
User's
space
(a) in-used (b) free
Fig. 1 struct malloc_chunk
Shared with
previous chunk
Glibc malloc Chunk
TYPE NAME DESCRIPTION
INTERNAL_SIZE_T prev_size Size of previously contigous chunk (shared)
INTERNAL_SIZE_T size Size of itself and its current status
struct malloc_chunk *fd Pointer to forwardly linked chunk (free list).
struct malloc_chunk *bk Pointer to backwardly linked chunk (free list).
Glibc malloc Chunk
Table 1: struct malloc_chunk
"struct malloc_chunk"
 A memory block joins free list after being free()'ed.
 It is ordinarily treated as "struct malloc_chunk".
 The size of a chunk is aligned on SIZE_SZ*2 bytes.
(prev_size)
size
fd
bk
(not used)
(prev_size)
size
data
+
pads
SIZE_SZ
=8byte
PMA
User's
space
(a) in-used (b) free
Fig. 1 struct malloc_chunk
Low 3 bits
mean chunk
status
Glibc malloc Chunk
Shared with
previous chunk
"struct malloc_chunk"
 A memory block joins free list after being free()'ed.
 It is ordinarily treated as "struct malloc_chunk".
 The size of a chunk is aligned on SIZE_SZ*2 bytes.
(prev_size)
size
fd
bk
(not used)
(prev_size)
size
data
+
pads
SIZE_SZ
=8byte
PMA
User's
space
(a) in-used (b) free
Fig. 1 struct malloc_chunk
Low 3 bits
mean chunk
status
 [P]REV_INUSE
 IS_[M]MAPPED
 NON_MAIN_[A]RENA
Glibc malloc Chunk
Shared with
previous chunk
Glibc malloc Bin
A free chunk belongs to free list(bin).
 Small bins
 MAX_FAST_SIZE < size < MIN_LARGE_SIZE
 MAX_FAST_SIZE: 0xa0
 MIN_LARGE_SIZE: 0x400
 Unsorted bins
 The chunk which has just free()'ed temporarily belongs to
this list.
 There is no size restriction.
(prev_size)
size
fd
bk
(not used)
bins[n-1]
bins[n]
bins[n+1]
FD
BK
Fig 2. Small bin free list
bins
c
struct malloc_chunk
PMA
Glibc malloc Bin
Glibc malloc Consolidating Chunks
It can easily cause fragmentation owing
to frequent allocations and vice versa.
 Let's consider consolidating the chunk being free()'ed
and already free()'ed contiguous chunk.
 Previous contiguous.
 Next contiguous.
PREV_INUSE bit
 The flag for distinguishing whether the previous
contiguous chunk is in used or not.
 This is the sole criterion for the consolidating.
Glibc malloc Consolidating Chunks
Where is the flow of chunk consolidating?
 Let's read glibc!
 free(p)
 __libc_free(p)
 _int_free(av, p, have_lock) <- THIS!
(a) Entry point
Fig. 3 _int_free()
(b) Consolidating point
Fig. 3 _int_free()
(c) End point
Fig. 3 _int_free()
Glibc malloc Consolidating Chunks
(prev_size)
size
(a) Test prev_inuse
Fig. 4 Consolidating
size = p->size
If not prev_inuse(p):
prevsize = p->prev_size
size += prevsize
p += -(long)(prevsize)
fd
bk
(not used)
(prev_size)
size 0
data
+
pads
p
prev
p
Glibc malloc Consolidating Chunks
(prev_size)
size
(b) Relocation
Fig. 4 Consolidating
size = p->size
If not prev_inuse(p):
prevsize = p->prev_size
size += prevsize
p += -(long)(prevsize)
p
p
fd
bk
(not used)
(prev_size)
size 0
data
+
pads
prev
p
Glibc malloc Consolidating Chunks
(prev_size)
size 1
p
(c) New chunk
Fig. 4 Consolidating
p
(prev_size)
size
fd
bk
(not used)
fd
bk
(not used)
(prev_size)
size 0
data
+
pads
p
prev
p
House of Einherjar Flaw / Flow
Our current knowledge
 "p->prev_size" can be shared with previous contiguous
chunk.
 PREV_INUSE bit of "p->size" decides whether the two
contiguous chunks will be consolidated or not.
 New location of p depends on "p->prev_size".
 "p = chunk_at_offset(p, -((long)prevsize))"
House of Einherjar Flaw / Flow
Our current knowledge
 "p->prev_size" can be shared with previous contiguous
chunk.
 PREV_INUSE bit of "p->size" decides whether the two
contiguous chunks will be consolidated or not.
 New location of p depends on "p->prev_size".
 "p = chunk_at_offset(p, -((long)prevsize))"
Assumptions for House of Einherjar
 Three chunks.
 p0: the well-sized chunk(includes p1->prev_size).
 p1: the small bin sized chunk.
 (p2: the chunk to prevent from calling malloc_consolidate()).
 p0 will be Off-by-one(OBO) poisoned by NUL byte('¥0').
House of Einherjar Flaw / Flow
(prev_size)
size
data
(prev_size)
size
data
+
pads
1
(a) Before overflowing
Fig. 5 The House of Einherjar
shared
p0 (used)
p1 (used)
well-sized
House of Einherjar Flaw / Flow
(prev_size)
size
data
(prev_size)
size
data
+
pads
1
(b) Overflowing
Fig. 5 The House of Einherjar
Overflown
House of Einherjar Flaw / Flow
(prev_size)
size
data
0xdeadbeef
size
data
+
pads
'¥0'
(c) After overflowing
Fig. 5 The House of Einherjar
well-sized p0 (free)
p1 (used)
shared
House of Einherjar Flaw / Flow
(prev_size)
size
data
0xdeadbeef
size
data
+
pads
'¥0'
(c) After overflowing
Fig. 5 The House of Einherjar
well-sized p0 (free)
p1 (used)
sharedsize = p1->size
If not prev_inuse(p1):
prevsize = p1->prev_size
size += prevsize
p1 += -(long)(prevsize)
House of Einherjar Flaw / Flow
(prev_size)
size
data
0xdeadbeef
size
data
+
pads
'¥0'
(c) After overflowing
Fig. 5 The House of Einherjar
well-sized p0 (free)
p1 (used)
sharedsize = p1->size
If not prev_inuse(p1):
prevsize = 0xdeadbeef
size += prevsize
p1 += -(long)(prevsize)
House of Einherjar Flaw / Flow
How to enter into House of Einherjar
 The well-sized chunk will occur OBO Overflow into the
next chunk.
 We can put a fake chunk near the target area.
 For easy, we should make fd and bk members of fake
chunk to point to the fake chunk's self.
 We have to be able to calculate the diff between the
target area and "p1".
 Leaking the two addresses is required.
 We have to be able to fix "p1->size" broken by
free()'ing.
 On the assumption that we can write to the fake chunk
anytime.
Demo
http://ux.nu/6Rv6h
House of Einherjar Evaluation
Merit
 It depends on application's memory layout but only
OBO Overflow is required
 Huge malloc() like "House of Force" is not required.
Demerit
 The target area will be limited on the location of the
fake chunk.
 The leaking the two addresses is necessary.
Evaluation: "Not so bad"
House of Einherjar Countermeasures
"struct malloc_chunk" is NOT good
 "chunk->prev_size" SHOULD NOT be overwritable by
normal writes to a chunk.
 It uses Boundary Tag Algorithm. (It is what it is!)
Countermeasures?
 Address checking
 Is the consolidated chunk address valid?
 Stack and heap address spaces are completely different.
 It is possible to save a return address.
 But that cannot be the solution for House of Einherjar to
heap address space.
Thank You For Your Attention!
Any Questions?

More Related Content

Viewers also liked

Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory OverflowsAnkur Tyagi
 
[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin Long
[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin Long[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin Long
[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin LongCODE BLUE
 
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...CODE BLUE
 
[CB16] About the cyber grand challenge: the world’s first all-machine hacking...
[CB16] About the cyber grand challenge: the world’s first all-machine hacking...[CB16] About the cyber grand challenge: the world’s first all-machine hacking...
[CB16] About the cyber grand challenge: the world’s first all-machine hacking...CODE BLUE
 
[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...
[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...
[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...CODE BLUE
 
How to-catch-a-chameleon-steven seeley-ruxcon-2012
How to-catch-a-chameleon-steven seeley-ruxcon-2012How to-catch-a-chameleon-steven seeley-ruxcon-2012
How to-catch-a-chameleon-steven seeley-ruxcon-2012_mr_me
 
Final lfh presentation (3)
Final lfh presentation (3)Final lfh presentation (3)
Final lfh presentation (3)__x86
 
[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’Antoine
[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’Antoine[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’Antoine
[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’AntoineCODE BLUE
 
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacDefcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacPriyanka Aash
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaionAngel Boy
 
ORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORMORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORMMikhail Egorov
 
CNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsCNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsSam Bowne
 
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesWindows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesPeter Hlavaty
 
Expanding the control over the operating system from the database
Expanding the control over the operating system from the databaseExpanding the control over the operating system from the database
Expanding the control over the operating system from the databaseBernardo Damele A. G.
 
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypassObject Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypassSam Thomas
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Daniel Bohannon
 
BlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
BlackHat USA 2011 - Stefan Esser - iOS Kernel ExploitationBlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
BlackHat USA 2011 - Stefan Esser - iOS Kernel ExploitationStefan Esser
 

Viewers also liked (18)

Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
 
[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin Long
[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin Long[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin Long
[CB16] マイクロソフトウィンドウズカーネルのデスノート by Peter Hlavaty & Jin Long
 
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
 
[CB16] About the cyber grand challenge: the world’s first all-machine hacking...
[CB16] About the cyber grand challenge: the world’s first all-machine hacking...[CB16] About the cyber grand challenge: the world’s first all-machine hacking...
[CB16] About the cyber grand challenge: the world’s first all-machine hacking...
 
[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...
[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...
[CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary ...
 
How to-catch-a-chameleon-steven seeley-ruxcon-2012
How to-catch-a-chameleon-steven seeley-ruxcon-2012How to-catch-a-chameleon-steven seeley-ruxcon-2012
How to-catch-a-chameleon-steven seeley-ruxcon-2012
 
Final lfh presentation (3)
Final lfh presentation (3)Final lfh presentation (3)
Final lfh presentation (3)
 
[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’Antoine
[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’Antoine[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’Antoine
[CB16] バイナリロックスターになる:Binary Ninjaによるプログラム解析入門 by Sophia D’Antoine
 
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacDefcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaion
 
ORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORMORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORM
 
CNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsCNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflows
 
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesWindows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
 
Expanding the control over the operating system from the database
Expanding the control over the operating system from the databaseExpanding the control over the operating system from the database
Expanding the control over the operating system from the database
 
ORM Injection
ORM InjectionORM Injection
ORM Injection
 
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypassObject Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypass
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017
 
BlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
BlackHat USA 2011 - Stefan Esser - iOS Kernel ExploitationBlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
BlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
 

More from CODE BLUE

[cb22] Hayabusa Threat Hunting and Fast Forensics in Windows environments fo...
[cb22] Hayabusa  Threat Hunting and Fast Forensics in Windows environments fo...[cb22] Hayabusa  Threat Hunting and Fast Forensics in Windows environments fo...
[cb22] Hayabusa Threat Hunting and Fast Forensics in Windows environments fo...CODE BLUE
 
[cb22] Tales of 5G hacking by Karsten Nohl
[cb22] Tales of 5G hacking by Karsten Nohl[cb22] Tales of 5G hacking by Karsten Nohl
[cb22] Tales of 5G hacking by Karsten NohlCODE BLUE
 
[cb22] Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...
[cb22]  Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...[cb22]  Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...
[cb22] Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...CODE BLUE
 
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...CODE BLUE
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之CODE BLUE
 
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...CODE BLUE
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo Pupillo
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo Pupillo[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo Pupillo
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo PupilloCODE BLUE
 
[cb22] ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...
[cb22]  ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...[cb22]  ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...
[cb22] ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...CODE BLUE
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman
[cb22]  「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman [cb22]  「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman CODE BLUE
 
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...CODE BLUE
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by 高橋 郁夫
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by  高橋 郁夫[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by  高橋 郁夫
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by 高橋 郁夫CODE BLUE
 
[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...
[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...
[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...CODE BLUE
 
[cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka
[cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka [cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka
[cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka CODE BLUE
 
[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...
[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...
[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...CODE BLUE
 
[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...
[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...
[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...CODE BLUE
 
[cb22] From Parroting to Echoing: The Evolution of China’s Bots-Driven Info...
[cb22]  From Parroting to Echoing:  The Evolution of China’s Bots-Driven Info...[cb22]  From Parroting to Echoing:  The Evolution of China’s Bots-Driven Info...
[cb22] From Parroting to Echoing: The Evolution of China’s Bots-Driven Info...CODE BLUE
 
[cb22] Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...
[cb22]  Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...[cb22]  Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...
[cb22] Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...CODE BLUE
 
[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也
[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也
[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也CODE BLUE
 
[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...
[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...
[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...CODE BLUE
 
[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...
[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...
[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...CODE BLUE
 

More from CODE BLUE (20)

[cb22] Hayabusa Threat Hunting and Fast Forensics in Windows environments fo...
[cb22] Hayabusa  Threat Hunting and Fast Forensics in Windows environments fo...[cb22] Hayabusa  Threat Hunting and Fast Forensics in Windows environments fo...
[cb22] Hayabusa Threat Hunting and Fast Forensics in Windows environments fo...
 
[cb22] Tales of 5G hacking by Karsten Nohl
[cb22] Tales of 5G hacking by Karsten Nohl[cb22] Tales of 5G hacking by Karsten Nohl
[cb22] Tales of 5G hacking by Karsten Nohl
 
[cb22] Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...
[cb22]  Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...[cb22]  Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...
[cb22] Your Printer is not your Printer ! - Hacking Printers at Pwn2Own by A...
 
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(4) by 板橋 博之
 
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo Pupillo
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo Pupillo[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo Pupillo
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(3) by Lorenzo Pupillo
 
[cb22] ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...
[cb22]  ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...[cb22]  ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...
[cb22] ”The Present and Future of Coordinated Vulnerability Disclosure” Inte...
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman
[cb22]  「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman [cb22]  「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション(2)by Allan Friedman
 
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
[cb22] "The Present and Future of Coordinated Vulnerability Disclosure" Inter...
 
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by 高橋 郁夫
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by  高橋 郁夫[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by  高橋 郁夫
[cb22] 「協調された脆弱性開示の現在と未来」国際的なパネルディスカッション (1)by 高橋 郁夫
 
[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...
[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...
[cb22] Are Embedded Devices Ready for ROP Attacks? -ROP verification for low-...
 
[cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka
[cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka [cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka
[cb22] Wslinkのマルチレイヤーな仮想環境について by Vladislav Hrčka
 
[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...
[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...
[cb22] Under the hood of Wslink’s multilayered virtual machine en by Vladisla...
 
[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...
[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...
[cb22] CloudDragon’s Credential Factory is Powering Up Its Espionage Activiti...
 
[cb22] From Parroting to Echoing: The Evolution of China’s Bots-Driven Info...
[cb22]  From Parroting to Echoing:  The Evolution of China’s Bots-Driven Info...[cb22]  From Parroting to Echoing:  The Evolution of China’s Bots-Driven Info...
[cb22] From Parroting to Echoing: The Evolution of China’s Bots-Driven Info...
 
[cb22] Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...
[cb22]  Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...[cb22]  Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...
[cb22] Who is the Mal-Gopher? - Implementation and Evaluation of “gimpfuzzy”...
 
[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也
[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也
[cb22] Mal-gopherとは?Go系マルウェアの分類のためのgimpfuzzy実装と評価 by 澤部 祐太, 甘粕 伸幸, 野村 和也
 
[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...
[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...
[cb22] Tracking the Entire Iceberg - Long-term APT Malware C2 Protocol Emulat...
 
[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...
[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...
[cb22] Fight Against Malware Development Life Cycle by Shusei Tomonaga and Yu...
 

Recently uploaded

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Recently uploaded (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 

[CB16] House of Einherjar — Yet Another Heap Exploitation Technique on GLIBC by Hiroki Matsukuma

  • 2. Hiroki MATSUKUMA (@st4g3r) Newbie Pentester  Cyber Defense Institute, Inc. CTF Player  TokyoWesterns My interests include  Exploitation  Glibc malloc (currently) $whoami
  • 3. tl;dr Heap Exploitation(x64 Linux/Glibc malloc) What's "House of Einherjar" ?  This is a new heap exploitation technique that forces glibc malloc() to return a nearly-arbitrary address.  User is ordinarily able to read/write to the address returned by malloc().  The concept is abusing consolidating chunks to prevent from the fragmentation.  Off-by-one Overflow on well-sized chunk leads both control of prev_size and PREV_INUSE bit of the next chunk. Proof of Concept  http://ux.nu/6Rv6h
  • 4. Overview Glibc malloc  Chunk  Bin  Consolidating Chunks House of Einherjar  Flaw / Flow  Demo  Evaluation  Countermeasures
  • 5. "struct malloc_chunk"  A memory block joins free list after being free()'ed.  free()'ed block is treated as "struct malloc_chunk".  The size of a chunk is aligned on SIZE_SZ*2 bytes. (prev_size) size fd bk (not used) (prev_size) size data + pads SIZE_SZ =8byte User's space (a) in-used (b) free Fig. 1 struct malloc_chunk Shared with previous chunk Glibc malloc Chunk
  • 6. TYPE NAME DESCRIPTION INTERNAL_SIZE_T prev_size Size of previously contigous chunk (shared) INTERNAL_SIZE_T size Size of itself and its current status struct malloc_chunk *fd Pointer to forwardly linked chunk (free list). struct malloc_chunk *bk Pointer to backwardly linked chunk (free list). Glibc malloc Chunk Table 1: struct malloc_chunk
  • 7. "struct malloc_chunk"  A memory block joins free list after being free()'ed.  It is ordinarily treated as "struct malloc_chunk".  The size of a chunk is aligned on SIZE_SZ*2 bytes. (prev_size) size fd bk (not used) (prev_size) size data + pads SIZE_SZ =8byte PMA User's space (a) in-used (b) free Fig. 1 struct malloc_chunk Low 3 bits mean chunk status Glibc malloc Chunk Shared with previous chunk
  • 8. "struct malloc_chunk"  A memory block joins free list after being free()'ed.  It is ordinarily treated as "struct malloc_chunk".  The size of a chunk is aligned on SIZE_SZ*2 bytes. (prev_size) size fd bk (not used) (prev_size) size data + pads SIZE_SZ =8byte PMA User's space (a) in-used (b) free Fig. 1 struct malloc_chunk Low 3 bits mean chunk status  [P]REV_INUSE  IS_[M]MAPPED  NON_MAIN_[A]RENA Glibc malloc Chunk Shared with previous chunk
  • 9. Glibc malloc Bin A free chunk belongs to free list(bin).  Small bins  MAX_FAST_SIZE < size < MIN_LARGE_SIZE  MAX_FAST_SIZE: 0xa0  MIN_LARGE_SIZE: 0x400  Unsorted bins  The chunk which has just free()'ed temporarily belongs to this list.  There is no size restriction.
  • 10. (prev_size) size fd bk (not used) bins[n-1] bins[n] bins[n+1] FD BK Fig 2. Small bin free list bins c struct malloc_chunk PMA Glibc malloc Bin
  • 11. Glibc malloc Consolidating Chunks It can easily cause fragmentation owing to frequent allocations and vice versa.  Let's consider consolidating the chunk being free()'ed and already free()'ed contiguous chunk.  Previous contiguous.  Next contiguous. PREV_INUSE bit  The flag for distinguishing whether the previous contiguous chunk is in used or not.  This is the sole criterion for the consolidating.
  • 12. Glibc malloc Consolidating Chunks Where is the flow of chunk consolidating?  Let's read glibc!  free(p)  __libc_free(p)  _int_free(av, p, have_lock) <- THIS!
  • 13. (a) Entry point Fig. 3 _int_free()
  • 15. (c) End point Fig. 3 _int_free()
  • 16. Glibc malloc Consolidating Chunks (prev_size) size (a) Test prev_inuse Fig. 4 Consolidating size = p->size If not prev_inuse(p): prevsize = p->prev_size size += prevsize p += -(long)(prevsize) fd bk (not used) (prev_size) size 0 data + pads p prev p
  • 17. Glibc malloc Consolidating Chunks (prev_size) size (b) Relocation Fig. 4 Consolidating size = p->size If not prev_inuse(p): prevsize = p->prev_size size += prevsize p += -(long)(prevsize) p p fd bk (not used) (prev_size) size 0 data + pads prev p
  • 18. Glibc malloc Consolidating Chunks (prev_size) size 1 p (c) New chunk Fig. 4 Consolidating p (prev_size) size fd bk (not used) fd bk (not used) (prev_size) size 0 data + pads p prev p
  • 19. House of Einherjar Flaw / Flow Our current knowledge  "p->prev_size" can be shared with previous contiguous chunk.  PREV_INUSE bit of "p->size" decides whether the two contiguous chunks will be consolidated or not.  New location of p depends on "p->prev_size".  "p = chunk_at_offset(p, -((long)prevsize))"
  • 20. House of Einherjar Flaw / Flow Our current knowledge  "p->prev_size" can be shared with previous contiguous chunk.  PREV_INUSE bit of "p->size" decides whether the two contiguous chunks will be consolidated or not.  New location of p depends on "p->prev_size".  "p = chunk_at_offset(p, -((long)prevsize))" Assumptions for House of Einherjar  Three chunks.  p0: the well-sized chunk(includes p1->prev_size).  p1: the small bin sized chunk.  (p2: the chunk to prevent from calling malloc_consolidate()).  p0 will be Off-by-one(OBO) poisoned by NUL byte('¥0').
  • 21. House of Einherjar Flaw / Flow (prev_size) size data (prev_size) size data + pads 1 (a) Before overflowing Fig. 5 The House of Einherjar shared p0 (used) p1 (used) well-sized
  • 22. House of Einherjar Flaw / Flow (prev_size) size data (prev_size) size data + pads 1 (b) Overflowing Fig. 5 The House of Einherjar Overflown
  • 23. House of Einherjar Flaw / Flow (prev_size) size data 0xdeadbeef size data + pads '¥0' (c) After overflowing Fig. 5 The House of Einherjar well-sized p0 (free) p1 (used) shared
  • 24. House of Einherjar Flaw / Flow (prev_size) size data 0xdeadbeef size data + pads '¥0' (c) After overflowing Fig. 5 The House of Einherjar well-sized p0 (free) p1 (used) sharedsize = p1->size If not prev_inuse(p1): prevsize = p1->prev_size size += prevsize p1 += -(long)(prevsize)
  • 25. House of Einherjar Flaw / Flow (prev_size) size data 0xdeadbeef size data + pads '¥0' (c) After overflowing Fig. 5 The House of Einherjar well-sized p0 (free) p1 (used) sharedsize = p1->size If not prev_inuse(p1): prevsize = 0xdeadbeef size += prevsize p1 += -(long)(prevsize)
  • 26. House of Einherjar Flaw / Flow How to enter into House of Einherjar  The well-sized chunk will occur OBO Overflow into the next chunk.  We can put a fake chunk near the target area.  For easy, we should make fd and bk members of fake chunk to point to the fake chunk's self.  We have to be able to calculate the diff between the target area and "p1".  Leaking the two addresses is required.  We have to be able to fix "p1->size" broken by free()'ing.  On the assumption that we can write to the fake chunk anytime.
  • 28. House of Einherjar Evaluation Merit  It depends on application's memory layout but only OBO Overflow is required  Huge malloc() like "House of Force" is not required. Demerit  The target area will be limited on the location of the fake chunk.  The leaking the two addresses is necessary. Evaluation: "Not so bad"
  • 29. House of Einherjar Countermeasures "struct malloc_chunk" is NOT good  "chunk->prev_size" SHOULD NOT be overwritable by normal writes to a chunk.  It uses Boundary Tag Algorithm. (It is what it is!) Countermeasures?  Address checking  Is the consolidated chunk address valid?  Stack and heap address spaces are completely different.  It is possible to save a return address.  But that cannot be the solution for House of Einherjar to heap address space.
  • 30. Thank You For Your Attention! Any Questions?