[Defcon24] Introduction to the Witchcraft Compiler Collection

Moabi.com
Moabi.comHacker at Moabi.com
Introduction to the
Witchcraft Compiler Collection
Jonathan Brossard
5th of August 2016 DEFCON 24, Las Vegas, USA
• The Witchcraft Compiler Collection is free software
(MIT/BSD License).
• I would love you to extend it and contribute to WCC on
https://github.com/endrazine/wcc
• You can write in Lua, Punk-C or C.
• No assembly skills required.
TL ; DR
Who am I ?
Image courtesy of Pixabay (https://pixabay.com/en/museum-mask-africa-african-cult-953595/)
License : CC0 Public Domain
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
https://www.defcon.org/images/defcon-20/dc-20-presentations/Brossard/DEFCON-20-
Brossard-Hardware-Backdooring-is-Practical.pdf
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
https://media.blackhat.com/bh-us-11/Brossard/BH_US_11_Brossard_Post_Memory_WP.pdf
https://github.com/toucan-system/pmcma
[Defcon24] Introduction to the Witchcraft Compiler Collection
+ Nullcon Goa, which is awesome :)
+ add your own preferred conferences around the globe here :) #NonExhaustiveList
DISCLAIMERS
• My employers are not associated with this talk in any way.
• This is my personal research.
DISCLAIMER
• This talk received help from the EFF.
• Warmest thank you to Nate Cardozo, Andrew Crocker and
Mitch Stoltz
Free legal advising to security researchers :
https://www.eff.org/
https://www.eff.org/issues/coders/reverse-engineering-faq
LEGAL HELP
Fcrnx gb bhe fravbe frphevgl UE:
Wnzrf Fnyr
wfnyr@fnyrfsbepr.pbz
uggc://jjj.yvaxrqva.pbz/va/wnzrftfnyr
Tbbq yhpx !
WE’RE RECRUITING
• Motivation
• WCC components
• “Libifying” a binary
• Unlinking binaries
• Crossing a Fish and a Rabbit
• Introduction to Witchcraft
• Binary “reflection” without a VM
• Towards binary self awareness
• Future work
AGENDA
Prerequisites: A binary you have the right to reverse engineer. No source code.
Case studies:
1) You would like to verify the results of a static analysis
2) You know a way to crash an application but don’t want to work on the
entire binary (eg: remote fuzzing).
Let’s work on the ELF 64b version of smbserver-1.5.32.
MOTIVATION
CASE STUDY : STATIC ANALYSIS
STATIC ANALYSIS
STATIC ANALYSIS
STATIC ANALYSIS
STATIC ANALYSIS
We have only a partial symbolic stack trace.
How to verify if this vulnerability exists ?
Wouldn’t it be nice if we could call reply_close() with arbitrary
arguments directly ?
STATIC ANALYSIS
You are fuzzing a complex server (smbd) over the network.
CASE STUDY : FUZZING
We have only a partial symbolic stack trace.
This could be a worker thread (note: smbd is linked with libpthread).
I don’t want to resend new packets or restart threads when analyzing !
Bonus points if you triggered it via instrumentation/concolic execution and
don’t actually have a trigger either.
Can we verify if this vulnerability is exploitable ?
Wouldn’t it be nice to call rpc_clnt_record_build_header() or any
function in client.so with arbitrary arguments directly ?
CASE STUDY : FUZZING
You can do the later with some work (exported functions from shared
libraries) but in theory, not the former ever ever (function directly within a
binary).
Let’s make both possible with 0 code nor reverse engineering.
PROBLEM STATEMENT
[Defcon24] Introduction to the Witchcraft Compiler Collection
Binaries (C):
wld : witchcraft linker
wcc : witchcraft core compiler
wsh : witchcraft shell : dynamic interpreter + scripting engine
Scripts (lua, …):
wcch : witchcraft header generator
wldd : witchcraft compiler flags generator
...
Host machine : GNU/Linux x86_64 (mostly portable to POSIX systems).
WCC COMPONENTS
Transforming an ELF executable binary into an ELF shared library.
WLD : “LIBIFICATION”
A word on decompiling
DEMOS
typedef struct
{
unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
Elf64_Half e_type; /* Object file type */
Elf64_Half e_machine; /* Architecture */
Elf64_Word e_version; /* Object file version */
Elf64_Addr e_entry; /* Entry point virtual address */
Elf64_Off e_phoff; /* Program header table file offset */
Elf64_Off e_shoff; /* Section header table file offset */
Elf64_Word e_flags; /* Processor-specific flags */
Elf64_Half e_ehsize; /* ELF header size in bytes */
Elf64_Half e_phentsize; /* Program header table entry size */
Elf64_Half e_phnum; /* Program header table entry count */
Elf64_Half e_shentsize; /* Section header table entry size */
Elf64_Half e_shnum; /* Section header table entry count */
Elf64_Half e_shstrndx; /* Section header string table index */
} Elf64_Ehdr;
LIBIFICATION
Libification of proftpd
DEMOS
LIBIFICATION OF PROFTPD
WE REALLY PATCHED 1 BYTE
ONLY
USING OUR NEW SHARED
LIBRARY
We’re really creating a “non relocatable” shared library.
ET_DYN and ET_EXEC ELF files are both executable (ASLR support in the
kernel)
This is equivalent to creating a shared library with a non NULL base address
(equivalent to prelinking)
Note: Amazingly, this shared library is still a valid executable too.
HOW COMES THIS WORKS ?
Linking against apache2
DEMOS
APACHE2 AS A SHARED LIBRARY
APACHE2 AS A SHARED LIBRARY
The typical approach to reverse engineering is to transform binaries or shared
libraries back to source code.
Instead, we aim at transforming final binaries or shared libraries back to ELF
relocatable objects, that can later be relinked normally (using gcc/ld) into
executables or shared objects.
This binary refactoring is enough to “reuse” (steal) binary functions without
any disassembly. This is no longuer true : some relocations require some
disassembly. We used the capstone disassembly library to perform this.
WCC : “UNLINKING”
Source code
WCC : “UNLINKING”
Relocatable objects
(*.o)
Binaries
(executables,
shared libs…)
Compiler
L
i
n
k
e
r
Source code
WCC : “UNLINKING”
Relocatable objects
(*.o)
Binaries
(executables,
shared libs…)
Compiler
L
i
n
k
e
r
Decompiler
Source code
WCC : “UNLINKING”
Relocatable objects
(*.o)
Binaries
(executables,
shared libs…)
Compiler
L
i
n
k
e
r
Decompiler
Source code
UNLINKING
Relocatable objects
(*.o)
Binaries
(executables,
shared libs…)
Compiler
L
i
n
k
e
r
Decompiler
w
c
c
The command line is made to resemble the syntax of gcc :
WCC : COMMAND LINE
The front end is build around libbfd. The backend is trivial C to copy each
mapped section of the binary, handle symbols and relocations.
Benefit of using libbfd : the input binary doesn’t need to be an ELF !
=> We can for instance transform a Win64 executable into ELF 64b
relocatable objects…
WCC : INTERNALS
(Binary to object file to relocatable to
unstripped library)
DEMO
WCC : DEMO
(Crossing a Fish and a Rabbit)
DEMO
PE + ELF = PELF
WCC : PE32 TO ELF64
Native OpenBSD on linux
DEMO
(Punk-C/Punxie)
WITCHCRAFT
Lua Interpreter
+
“Reflected” C API
=
Punk-C
PUNK-C LANGUAGE (WSH)
INTRODUCTION TO
WITCHCRAFT
Now that we know how to transform arbitrary binaries into shared libraries,
we can load them into our address space via dlopen().
Let’s implement the same features as traditional virtual machines, but for raw
binaries !
Whish list :
- Load arbitrary applications into memory
- Execute arbitrary functions with any arguments (and get results)
- Monitor/Trace execution
- Automated functions prototyping/annotation
- Learn new behavior
- Examine/Modify arbitrary memory
BINARY “REFLECTION”
WITHOUT A VM
Loading is done via dlopen().
The core engine/shell is built around lua.
Can be compiled with luajit to get JIT compilation.
Tracing/Memory analysis doesn’t rely on ptrace() : we share the address space.
Lightweight : ~5k lines of C.
No disassembler (as of writing. Subject to change).
No need for /proc support !
Function names mapped in each library is dumped from the link_map cache.
WSH : ARCHITECTURE
Distinctive features:
- We fully share the address space with analyzed applications (no ptrace() nor context
switches).
- Requires no privileges/capabilities (no root, no ptrace(), no CAP_PTRACE, no /proc…)
- No disassembly : fully portable (POSIX)
- Implements “reflection” for binaries
- Full featured programming language
- Interactive and/or fully scriptable, autonomous programs
- Has no types
- Has no fixed API : any function you load in memory becomes available in WSH
- Functions have no prototypes
=> Can call arbitrary functions without knowing their prototypes
=> Allows for extended function annotations (to be fully automated)
=> Steal/Reuse any code. Add scripting to any application.
NONE OF THIS IS SUPPOSED TO WORK
WSH : THE WICHCRAFT
INTERPRETER
Advanced features:
- Loads any code via dlopen() : this solves relocations, symbols resolution,
dependencies for us.
- Secondary loader bfd based (could load invalid binaries, anything in
memory).
- Dumping of dynamic linker cash internals (undocumented) : linkmap
- Breakpoints without int 0x03 (use SIGINVALID + invalid opcode)
- Bruteforcing of mapped memory pages via msync() (0day, no /proc needed)
- Wsh can be compiled to do JIT compilation on the fly at runtime.
- Automated fuzzing/extended prototyping/functional testing
NONE OF THIS IS SUPPOSED TO WORK
WSH : THE WICHCRAFT
INTERPRETER
DEMO
WITCHCRAFT
Consciousness 1.0
TOWARDS BINARY SELF
AWARENESS
“Self-awareness is the capacity for introspection and the ability to recognize
oneself as an individual separate from the environment and other individuals.”
https://en.wikipedia.org/wiki/Self-awareness
“Consciousness is the state or quality of awareness, or, of being aware of an
external object or something within oneself. It has been defined as: sentience,
awareness, subjectivity, the ability to experience or to feel, wakefulness, having
a sense of selfhood, and the executive control system of the mind.”
https://en.wikipedia.org/wiki/Consciousness
SELF AWARENESS
Numerical solutions
WITCHCRAFT
FUTURE WORK
WITCHCRAFT
- Hyde our own presence better in memory (second heap)
- Remote debugging, running process injection
- Shadow mapping, internal libraries tracing (recursive ltrace)
- ltrace/strace to valid scripts
- system call tracing
FUTURE WORK
Questions ?
TO BE CONTINUED
1 of 67

Recommended

[Defcon] Hardware backdooring is practical by
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practicalMoabi.com
130.2K views70 slides
Hardware backdooring is practical : slides by
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slidesMoabi.com
1.3K views49 slides
[CCC-28c3] Post Memory Corruption Memory Analysis by
[CCC-28c3] Post Memory Corruption Memory Analysis[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory AnalysisMoabi.com
2.5K views94 slides
[Ruxcon 2011] Post Memory Corruption Memory Analysis by
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory AnalysisMoabi.com
793 views92 slides
[Hackito2012] Hardware backdooring is practical by
[Hackito2012] Hardware backdooring is practical[Hackito2012] Hardware backdooring is practical
[Hackito2012] Hardware backdooring is practicalMoabi.com
1.4K views37 slides
FreeBSD and Drivers by
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and DriversKernel TLV
1.3K views34 slides

More Related Content

What's hot

Kernelvm 201312-dlmopen by
Kernelvm 201312-dlmopenKernelvm 201312-dlmopen
Kernelvm 201312-dlmopenHajime Tazaki
2.3K views16 slides
Direct Code Execution @ CoNEXT 2013 by
Direct Code Execution @ CoNEXT 2013Direct Code Execution @ CoNEXT 2013
Direct Code Execution @ CoNEXT 2013Hajime Tazaki
2.3K views29 slides
LibOS as a regression test framework for Linux networking #netdev1.1 by
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1Hajime Tazaki
1.6K views44 slides
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation by
Semtex.c [CVE-2013-2094] - A Linux Privelege EscalationSemtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege EscalationKernel TLV
1.4K views30 slides
Network Stack in Userspace (NUSE) by
Network Stack in Userspace (NUSE)Network Stack in Userspace (NUSE)
Network Stack in Userspace (NUSE)Hajime Tazaki
6.7K views27 slides
Essentials of Multithreaded System Programming in C++ by
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Shuo Chen
6.5K views31 slides

What's hot(20)

Kernelvm 201312-dlmopen by Hajime Tazaki
Kernelvm 201312-dlmopenKernelvm 201312-dlmopen
Kernelvm 201312-dlmopen
Hajime Tazaki2.3K views
Direct Code Execution @ CoNEXT 2013 by Hajime Tazaki
Direct Code Execution @ CoNEXT 2013Direct Code Execution @ CoNEXT 2013
Direct Code Execution @ CoNEXT 2013
Hajime Tazaki2.3K views
LibOS as a regression test framework for Linux networking #netdev1.1 by Hajime Tazaki
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1
Hajime Tazaki1.6K views
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation by Kernel TLV
Semtex.c [CVE-2013-2094] - A Linux Privelege EscalationSemtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Kernel TLV1.4K views
Network Stack in Userspace (NUSE) by Hajime Tazaki
Network Stack in Userspace (NUSE)Network Stack in Userspace (NUSE)
Network Stack in Userspace (NUSE)
Hajime Tazaki6.7K views
Essentials of Multithreaded System Programming in C++ by Shuo Chen
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++
Shuo Chen6.5K views
I/O, You Own: Regaining Control of Your Disk in the Presence of Bootkits by CrowdStrike
I/O, You Own: Regaining Control of Your Disk in the Presence of BootkitsI/O, You Own: Regaining Control of Your Disk in the Presence of Bootkits
I/O, You Own: Regaining Control of Your Disk in the Presence of Bootkits
CrowdStrike5.3K views
Talk 160920 @ Cat System Workshop by Quey-Liang Kao
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System Workshop
Quey-Liang Kao297 views
Docker Introduction + what is new in 0.9 by Jérôme Petazzoni
Docker Introduction + what is new in 0.9 Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9
Jérôme Petazzoni3.7K views
Make container without_docker_7 by Sam Kim
Make container without_docker_7Make container without_docker_7
Make container without_docker_7
Sam Kim184 views
NUSE (Network Stack in Userspace) at #osio by Hajime Tazaki
NUSE (Network Stack in Userspace) at #osioNUSE (Network Stack in Userspace) at #osio
NUSE (Network Stack in Userspace) at #osio
Hajime Tazaki6.7K views
Kernel Recipes 2015: Anatomy of an atomic KMS driver by Anne Nicolas
Kernel Recipes 2015: Anatomy of an atomic KMS driverKernel Recipes 2015: Anatomy of an atomic KMS driver
Kernel Recipes 2015: Anatomy of an atomic KMS driver
Anne Nicolas2.4K views
Ищем уязвимости нулевого дня в ядре Linux by Positive Hack Days
Ищем уязвимости нулевого дня в ядре LinuxИщем уязвимости нулевого дня в ядре Linux
Ищем уязвимости нулевого дня в ядре Linux
Positive Hack Days768 views
Make container without_docker_6-overlay-network_1 by Sam Kim
Make container without_docker_6-overlay-network_1 Make container without_docker_6-overlay-network_1
Make container without_docker_6-overlay-network_1
Sam Kim238 views
Fun with FUSE by Kernel TLV
Fun with FUSEFun with FUSE
Fun with FUSE
Kernel TLV1.9K views
Kernel Recipes 2015 - So you want to write a Linux driver framework by Anne Nicolas
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
Anne Nicolas2.1K views
Introduction to Docker and deployment and Azure by Jérôme Petazzoni
Introduction to Docker and deployment and AzureIntroduction to Docker and deployment and Azure
Introduction to Docker and deployment and Azure
Jérôme Petazzoni2.1K views
Advanced Evasion Techniques by Win32/Gapz by Alex Matrosov
Advanced Evasion Techniques by Win32/GapzAdvanced Evasion Techniques by Win32/Gapz
Advanced Evasion Techniques by Win32/Gapz
Alex Matrosov4.4K views
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale by Jérôme Petazzoni
Introduction to Docker (and a bit more) at LSPE meetup SunnyvaleIntroduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Jérôme Petazzoni4.4K views

Viewers also liked

Hardware backdooring is practical by
Hardware backdooring is practicalHardware backdooring is practical
Hardware backdooring is practicalMoabi.com
1.2K views13 slides
[HackInTheBox] Breaking virtualization by any means by
[HackInTheBox] Breaking virtualization by any means[HackInTheBox] Breaking virtualization by any means
[HackInTheBox] Breaking virtualization by any meansMoabi.com
2.1K views35 slides
[DEFCON 16] Bypassing pre-boot authentication passwords by instrumenting the... by
[DEFCON 16] Bypassing pre-boot authentication passwords  by instrumenting the...[DEFCON 16] Bypassing pre-boot authentication passwords  by instrumenting the...
[DEFCON 16] Bypassing pre-boot authentication passwords by instrumenting the...Moabi.com
10.5K views53 slides
DNS Exfiltration Using sqlmap by
DNS Exfiltration Using sqlmapDNS Exfiltration Using sqlmap
DNS Exfiltration Using sqlmapPositive Hack Days
1.9K views26 slides
Hacking XPATH 2.0 by
Hacking XPATH 2.0Hacking XPATH 2.0
Hacking XPATH 2.0michelemanzotti
2.1K views65 slides
Automated and unified opensource web application testing by
Automated and unified opensource web application testingAutomated and unified opensource web application testing
Automated and unified opensource web application testingnavajanegra
974 views28 slides

Viewers also liked(20)

Hardware backdooring is practical by Moabi.com
Hardware backdooring is practicalHardware backdooring is practical
Hardware backdooring is practical
Moabi.com1.2K views
[HackInTheBox] Breaking virtualization by any means by Moabi.com
[HackInTheBox] Breaking virtualization by any means[HackInTheBox] Breaking virtualization by any means
[HackInTheBox] Breaking virtualization by any means
Moabi.com2.1K views
[DEFCON 16] Bypassing pre-boot authentication passwords by instrumenting the... by Moabi.com
[DEFCON 16] Bypassing pre-boot authentication passwords  by instrumenting the...[DEFCON 16] Bypassing pre-boot authentication passwords  by instrumenting the...
[DEFCON 16] Bypassing pre-boot authentication passwords by instrumenting the...
Moabi.com10.5K views
Automated and unified opensource web application testing by navajanegra
Automated and unified opensource web application testingAutomated and unified opensource web application testing
Automated and unified opensource web application testing
navajanegra974 views
[1.4] «Ой, не шмогла». Обзор ограничений современных технологий в области ... by OWASP Russia
[1.4] «Ой, не шмогла». Обзор ограничений современных технологий в области ...[1.4] «Ой, не шмогла». Обзор ограничений современных технологий в области ...
[1.4] «Ой, не шмогла». Обзор ограничений современных технологий в области ...
OWASP Russia930 views
[3.3] Detection & exploitation of Xpath/Xquery Injections - Boris Savkov by OWASP Russia
[3.3] Detection & exploitation of Xpath/Xquery Injections - Boris Savkov[3.3] Detection & exploitation of Xpath/Xquery Injections - Boris Savkov
[3.3] Detection & exploitation of Xpath/Xquery Injections - Boris Savkov
OWASP Russia1.6K views
[HITB Malaysia 2011] Exploit Automation by Moabi.com
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation
Moabi.com1.2K views
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper by Moabi.com
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper
Moabi.com3.1K views
[Blackhat2015] FileCry attack against Internet Explorer by Moabi.com
[Blackhat2015] FileCry attack against Internet Explorer[Blackhat2015] FileCry attack against Internet Explorer
[Blackhat2015] FileCry attack against Internet Explorer
Moabi.com1.4K views
Web Application Firewalls: Advanced analysis of detection logic mechanisms, V... by OWASP Russia
Web Application Firewalls: Advanced analysis of detection logic mechanisms, V...Web Application Firewalls: Advanced analysis of detection logic mechanisms, V...
Web Application Firewalls: Advanced analysis of detection logic mechanisms, V...
OWASP Russia550 views
[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS... by Moabi.com
[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS...[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS...
[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS...
Moabi.com2.2K views
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... by Moabi.com
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...
Moabi.com2K views
XML & XPath Injections by AMol NAik
XML & XPath InjectionsXML & XPath Injections
XML & XPath Injections
AMol NAik4.9K views
Grade 7 Science Learner's Module 3rd and 4th QTR Modules by Jan Cecilio
Grade 7 Science Learner's Module 3rd and 4th QTR ModulesGrade 7 Science Learner's Module 3rd and 4th QTR Modules
Grade 7 Science Learner's Module 3rd and 4th QTR Modules
Jan Cecilio36.9K views
[Blackhat2015] FileCry attack against Java by Moabi.com
[Blackhat2015] FileCry attack against Java[Blackhat2015] FileCry attack against Java
[Blackhat2015] FileCry attack against Java
Moabi.com1.8K views
Lie to Me: Bypassing Modern Web Application Firewalls by Ivan Novikov
Lie to Me: Bypassing Modern Web Application FirewallsLie to Me: Bypassing Modern Web Application Firewalls
Lie to Me: Bypassing Modern Web Application Firewalls
Ivan Novikov33.8K views
Wireless charging of smartphones by Jeffrey Funk
Wireless charging of smartphonesWireless charging of smartphones
Wireless charging of smartphones
Jeffrey Funk12.7K views

Similar to [Defcon24] Introduction to the Witchcraft Compiler Collection

Post exploitation techniques on OSX and Iphone, EuSecWest 2009 by
Post exploitation techniques on OSX and Iphone, EuSecWest 2009Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009Vincenzo Iozzo
735 views58 slides
Настройка окружения для кросскомпиляции проектов на основе docker'a by
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'acorehard_by
174 views25 slides
maXbox Starter87 by
maXbox Starter87maXbox Starter87
maXbox Starter87Max Kleiner
91 views22 slides
Automate drupal deployments with linux containers, docker and vagrant by
Automate drupal deployments with linux containers, docker and vagrant Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant Ricardo Amaro
9.8K views43 slides
Agile Brown Bag - Vagrant & Docker: Introduction by
Agile Brown Bag - Vagrant & Docker: IntroductionAgile Brown Bag - Vagrant & Docker: Introduction
Agile Brown Bag - Vagrant & Docker: IntroductionAgile Partner S.A.
1.2K views50 slides
Build your own discovery index of scholary e-resources by
Build your own discovery index of scholary e-resourcesBuild your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resourcesMartin Czygan
10.7K views58 slides

Similar to [Defcon24] Introduction to the Witchcraft Compiler Collection(20)

Post exploitation techniques on OSX and Iphone, EuSecWest 2009 by Vincenzo Iozzo
Post exploitation techniques on OSX and Iphone, EuSecWest 2009Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Vincenzo Iozzo735 views
Настройка окружения для кросскомпиляции проектов на основе docker'a by corehard_by
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
corehard_by174 views
Automate drupal deployments with linux containers, docker and vagrant by Ricardo Amaro
Automate drupal deployments with linux containers, docker and vagrant Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant
Ricardo Amaro9.8K views
Agile Brown Bag - Vagrant & Docker: Introduction by Agile Partner S.A.
Agile Brown Bag - Vagrant & Docker: IntroductionAgile Brown Bag - Vagrant & Docker: Introduction
Agile Brown Bag - Vagrant & Docker: Introduction
Agile Partner S.A.1.2K views
Build your own discovery index of scholary e-resources by Martin Czygan
Build your own discovery index of scholary e-resourcesBuild your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resources
Martin Czygan10.7K views
Red Teaming macOS Environments with Hermes the Swift Messenger by Justin Bui
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift Messenger
Justin Bui735 views
Extending DevOps to Big Data Applications with Kubernetes by Nicola Ferraro
Extending DevOps to Big Data Applications with KubernetesExtending DevOps to Big Data Applications with Kubernetes
Extending DevOps to Big Data Applications with Kubernetes
Nicola Ferraro3.4K views
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic... by Codemotion
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Codemotion765 views
Docker and-containers-for-development-and-deployment-scale12x by rkr10
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
rkr10112 views
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of... by Jérôme Petazzoni
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Jérôme Petazzoni5.3K views
Drupalcamp es 2013 drupal with lxc docker and vagrant by Ricardo Amaro
Drupalcamp es 2013  drupal with lxc docker and vagrant Drupalcamp es 2013  drupal with lxc docker and vagrant
Drupalcamp es 2013 drupal with lxc docker and vagrant
Ricardo Amaro3.8K views
Come costruire una Platform As A Service con Docker, Kubernetes Go e Java by Codemotion
Come costruire una Platform As A Service con Docker, Kubernetes Go e JavaCome costruire una Platform As A Service con Docker, Kubernetes Go e Java
Come costruire una Platform As A Service con Docker, Kubernetes Go e Java
Codemotion538 views
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition by Jérôme Petazzoni
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionIntroduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Jérôme Petazzoni6.5K views
Intel Briefing Notes by Graham Lee
Intel Briefing NotesIntel Briefing Notes
Intel Briefing Notes
Graham Lee379 views

Recently uploaded

2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx by
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptxlwang78
109 views19 slides
DESIGN OF SPRINGS-UNIT4.pptx by
DESIGN OF SPRINGS-UNIT4.pptxDESIGN OF SPRINGS-UNIT4.pptx
DESIGN OF SPRINGS-UNIT4.pptxgopinathcreddy
19 views47 slides
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf by
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdfASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdfAlhamduKure
6 views11 slides
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) by
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Tsuyoshi Horigome
38 views16 slides
SPICE PARK DEC2023 (6,625 SPICE Models) by
SPICE PARK DEC2023 (6,625 SPICE Models) SPICE PARK DEC2023 (6,625 SPICE Models)
SPICE PARK DEC2023 (6,625 SPICE Models) Tsuyoshi Horigome
33 views218 slides
SUMIT SQL PROJECT SUPERSTORE 1.pptx by
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptxSumit Jadhav
18 views26 slides

Recently uploaded(20)

2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx by lwang78
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
lwang78109 views
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf by AlhamduKure
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdfASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
AlhamduKure6 views
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) by Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
SUMIT SQL PROJECT SUPERSTORE 1.pptx by Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 18 views
Design of machine elements-UNIT 3.pptx by gopinathcreddy
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptx
gopinathcreddy33 views
REACTJS.pdf by ArthyR3
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
ArthyR334 views
Ansari: Practical experiences with an LLM-based Islamic Assistant by M Waleed Kadous
Ansari: Practical experiences with an LLM-based Islamic AssistantAnsari: Practical experiences with an LLM-based Islamic Assistant
Ansari: Practical experiences with an LLM-based Islamic Assistant
M Waleed Kadous5 views
fakenews_DBDA_Mar23.pptx by deepmitra8
fakenews_DBDA_Mar23.pptxfakenews_DBDA_Mar23.pptx
fakenews_DBDA_Mar23.pptx
deepmitra816 views
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth by Innomantra
BCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for GrowthBCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for Growth
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth
Innomantra 6 views
Web Dev Session 1.pptx by VedVekhande
Web Dev Session 1.pptxWeb Dev Session 1.pptx
Web Dev Session 1.pptx
VedVekhande11 views
GDSC Mikroskil Members Onboarding 2023.pdf by gdscmikroskil
GDSC Mikroskil Members Onboarding 2023.pdfGDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdf
gdscmikroskil58 views
_MAKRIADI-FOTEINI_diploma thesis.pptx by fotinimakriadi
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptx
fotinimakriadi8 views
Design_Discover_Develop_Campaign.pptx by ShivanshSeth6
Design_Discover_Develop_Campaign.pptxDesign_Discover_Develop_Campaign.pptx
Design_Discover_Develop_Campaign.pptx
ShivanshSeth637 views

[Defcon24] Introduction to the Witchcraft Compiler Collection

  • 1. Introduction to the Witchcraft Compiler Collection Jonathan Brossard 5th of August 2016 DEFCON 24, Las Vegas, USA
  • 2. • The Witchcraft Compiler Collection is free software (MIT/BSD License). • I would love you to extend it and contribute to WCC on https://github.com/endrazine/wcc • You can write in Lua, Punk-C or C. • No assembly skills required. TL ; DR
  • 3. Who am I ? Image courtesy of Pixabay (https://pixabay.com/en/museum-mask-africa-african-cult-953595/) License : CC0 Public Domain
  • 11. + Nullcon Goa, which is awesome :)
  • 12. + add your own preferred conferences around the globe here :) #NonExhaustiveList
  • 14. • My employers are not associated with this talk in any way. • This is my personal research. DISCLAIMER
  • 15. • This talk received help from the EFF. • Warmest thank you to Nate Cardozo, Andrew Crocker and Mitch Stoltz Free legal advising to security researchers : https://www.eff.org/ https://www.eff.org/issues/coders/reverse-engineering-faq LEGAL HELP
  • 16. Fcrnx gb bhe fravbe frphevgl UE: Wnzrf Fnyr wfnyr@fnyrfsbepr.pbz uggc://jjj.yvaxrqva.pbz/va/wnzrftfnyr Tbbq yhpx ! WE’RE RECRUITING
  • 17. • Motivation • WCC components • “Libifying” a binary • Unlinking binaries • Crossing a Fish and a Rabbit • Introduction to Witchcraft • Binary “reflection” without a VM • Towards binary self awareness • Future work AGENDA
  • 18. Prerequisites: A binary you have the right to reverse engineer. No source code. Case studies: 1) You would like to verify the results of a static analysis 2) You know a way to crash an application but don’t want to work on the entire binary (eg: remote fuzzing). Let’s work on the ELF 64b version of smbserver-1.5.32. MOTIVATION
  • 19. CASE STUDY : STATIC ANALYSIS
  • 24. We have only a partial symbolic stack trace. How to verify if this vulnerability exists ? Wouldn’t it be nice if we could call reply_close() with arbitrary arguments directly ? STATIC ANALYSIS
  • 25. You are fuzzing a complex server (smbd) over the network. CASE STUDY : FUZZING
  • 26. We have only a partial symbolic stack trace. This could be a worker thread (note: smbd is linked with libpthread). I don’t want to resend new packets or restart threads when analyzing ! Bonus points if you triggered it via instrumentation/concolic execution and don’t actually have a trigger either. Can we verify if this vulnerability is exploitable ? Wouldn’t it be nice to call rpc_clnt_record_build_header() or any function in client.so with arbitrary arguments directly ? CASE STUDY : FUZZING
  • 27. You can do the later with some work (exported functions from shared libraries) but in theory, not the former ever ever (function directly within a binary). Let’s make both possible with 0 code nor reverse engineering. PROBLEM STATEMENT
  • 29. Binaries (C): wld : witchcraft linker wcc : witchcraft core compiler wsh : witchcraft shell : dynamic interpreter + scripting engine Scripts (lua, …): wcch : witchcraft header generator wldd : witchcraft compiler flags generator ... Host machine : GNU/Linux x86_64 (mostly portable to POSIX systems). WCC COMPONENTS
  • 30. Transforming an ELF executable binary into an ELF shared library. WLD : “LIBIFICATION”
  • 31. A word on decompiling DEMOS
  • 32. typedef struct { unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ Elf64_Half e_type; /* Object file type */ Elf64_Half e_machine; /* Architecture */ Elf64_Word e_version; /* Object file version */ Elf64_Addr e_entry; /* Entry point virtual address */ Elf64_Off e_phoff; /* Program header table file offset */ Elf64_Off e_shoff; /* Section header table file offset */ Elf64_Word e_flags; /* Processor-specific flags */ Elf64_Half e_ehsize; /* ELF header size in bytes */ Elf64_Half e_phentsize; /* Program header table entry size */ Elf64_Half e_phnum; /* Program header table entry count */ Elf64_Half e_shentsize; /* Section header table entry size */ Elf64_Half e_shnum; /* Section header table entry count */ Elf64_Half e_shstrndx; /* Section header string table index */ } Elf64_Ehdr; LIBIFICATION
  • 35. WE REALLY PATCHED 1 BYTE ONLY
  • 36. USING OUR NEW SHARED LIBRARY
  • 37. We’re really creating a “non relocatable” shared library. ET_DYN and ET_EXEC ELF files are both executable (ASLR support in the kernel) This is equivalent to creating a shared library with a non NULL base address (equivalent to prelinking) Note: Amazingly, this shared library is still a valid executable too. HOW COMES THIS WORKS ?
  • 39. APACHE2 AS A SHARED LIBRARY
  • 40. APACHE2 AS A SHARED LIBRARY
  • 41. The typical approach to reverse engineering is to transform binaries or shared libraries back to source code. Instead, we aim at transforming final binaries or shared libraries back to ELF relocatable objects, that can later be relinked normally (using gcc/ld) into executables or shared objects. This binary refactoring is enough to “reuse” (steal) binary functions without any disassembly. This is no longuer true : some relocations require some disassembly. We used the capstone disassembly library to perform this. WCC : “UNLINKING”
  • 42. Source code WCC : “UNLINKING” Relocatable objects (*.o) Binaries (executables, shared libs…) Compiler L i n k e r
  • 43. Source code WCC : “UNLINKING” Relocatable objects (*.o) Binaries (executables, shared libs…) Compiler L i n k e r Decompiler
  • 44. Source code WCC : “UNLINKING” Relocatable objects (*.o) Binaries (executables, shared libs…) Compiler L i n k e r Decompiler
  • 46. The command line is made to resemble the syntax of gcc : WCC : COMMAND LINE
  • 47. The front end is build around libbfd. The backend is trivial C to copy each mapped section of the binary, handle symbols and relocations. Benefit of using libbfd : the input binary doesn’t need to be an ELF ! => We can for instance transform a Win64 executable into ELF 64b relocatable objects… WCC : INTERNALS
  • 48. (Binary to object file to relocatable to unstripped library) DEMO
  • 50. (Crossing a Fish and a Rabbit) DEMO
  • 51. PE + ELF = PELF
  • 52. WCC : PE32 TO ELF64
  • 53. Native OpenBSD on linux DEMO
  • 55. Lua Interpreter + “Reflected” C API = Punk-C PUNK-C LANGUAGE (WSH)
  • 57. Now that we know how to transform arbitrary binaries into shared libraries, we can load them into our address space via dlopen(). Let’s implement the same features as traditional virtual machines, but for raw binaries ! Whish list : - Load arbitrary applications into memory - Execute arbitrary functions with any arguments (and get results) - Monitor/Trace execution - Automated functions prototyping/annotation - Learn new behavior - Examine/Modify arbitrary memory BINARY “REFLECTION” WITHOUT A VM
  • 58. Loading is done via dlopen(). The core engine/shell is built around lua. Can be compiled with luajit to get JIT compilation. Tracing/Memory analysis doesn’t rely on ptrace() : we share the address space. Lightweight : ~5k lines of C. No disassembler (as of writing. Subject to change). No need for /proc support ! Function names mapped in each library is dumped from the link_map cache. WSH : ARCHITECTURE
  • 59. Distinctive features: - We fully share the address space with analyzed applications (no ptrace() nor context switches). - Requires no privileges/capabilities (no root, no ptrace(), no CAP_PTRACE, no /proc…) - No disassembly : fully portable (POSIX) - Implements “reflection” for binaries - Full featured programming language - Interactive and/or fully scriptable, autonomous programs - Has no types - Has no fixed API : any function you load in memory becomes available in WSH - Functions have no prototypes => Can call arbitrary functions without knowing their prototypes => Allows for extended function annotations (to be fully automated) => Steal/Reuse any code. Add scripting to any application. NONE OF THIS IS SUPPOSED TO WORK WSH : THE WICHCRAFT INTERPRETER
  • 60. Advanced features: - Loads any code via dlopen() : this solves relocations, symbols resolution, dependencies for us. - Secondary loader bfd based (could load invalid binaries, anything in memory). - Dumping of dynamic linker cash internals (undocumented) : linkmap - Breakpoints without int 0x03 (use SIGINVALID + invalid opcode) - Bruteforcing of mapped memory pages via msync() (0day, no /proc needed) - Wsh can be compiled to do JIT compilation on the fly at runtime. - Automated fuzzing/extended prototyping/functional testing NONE OF THIS IS SUPPOSED TO WORK WSH : THE WICHCRAFT INTERPRETER
  • 63. “Self-awareness is the capacity for introspection and the ability to recognize oneself as an individual separate from the environment and other individuals.” https://en.wikipedia.org/wiki/Self-awareness “Consciousness is the state or quality of awareness, or, of being aware of an external object or something within oneself. It has been defined as: sentience, awareness, subjectivity, the ability to experience or to feel, wakefulness, having a sense of selfhood, and the executive control system of the mind.” https://en.wikipedia.org/wiki/Consciousness SELF AWARENESS
  • 66. - Hyde our own presence better in memory (second heap) - Remote debugging, running process injection - Shadow mapping, internal libraries tracing (recursive ltrace) - ltrace/strace to valid scripts - system call tracing FUTURE WORK
  • 67. Questions ? TO BE CONTINUED