SlideShare uma empresa Scribd logo
1 de 8
A Code Injection Approach to
Add Feature on Service
houcheng@gmail.com
CCMA, ITRI
Introduction
• Initial idea
• we need to extend features onto some running service
without suspending it.
• we don’t want to upgrade program binary file; when need
new feature turn it on and when don’t need turn it off

– Benefits
• new service can be on demand turn on
• when off: the same binary file, so its stability still kept
• when on: loss some stability but increase functionality
Basic Idea
s4~5
s1~3
service_wrapper()
s1
s2
s3

s1()
s2()
s3()

service’s memory space
BEFORE

service_wrapper()
s1
s2
s3

service_wrapper2()

s1()
s2()

s4

s4()

s5

s5()

s3()

hooked service’s memory
space that support s4 and s5
AFTER

: hook function
Steps
1) Use GDB to attach running process
2) Place the hook function that onto service
wrapper function;
• for original service request, run original code
• for new service request, run new code

3) The hook function
•
•
•

Has the same parameters as selected function
Can call functions and access data of application
Return 1 to indicate not execute original selected
function
Flow of Code Injection

hooker.S
hooker.c

build
scripts

code inject
scripts

hook

hook.o

running service

gdb

s45.c

• compile
• link

•
•
•
•

load
build symbol table
resolve reference
hook

libraries (GLIBC)
Linux OS
Code Inject Script
• Load
• call mmap() in GDB to load binary onto process memory
space
• Build symbol table:
• add symbols of service by signature searching on .code
segment
• add symbols of injected code by reading its debug file
• add symbols of GLIBC by calling GDB
• Resolve reference
• For each un-resolve symbols in hook code, resolve by
looking up symbol table
• Hook
• Copy hooker onto address of service wrapper function
Signature Search DB to support Multiple
Versions of Service Application
signature
search
script

running
service

offset:0x800, “v1.1”
offset:0x800, “v1.2”
vstring table
service_func, “aa cc dd ....”
function_2, “aa bb cc ... “
service_func, “aa cc dd ....”
function_2, “aa bb cc ... “

1) check every entry of
vstring table to find
service version
2) use correct version’s
signatures to build
symbol table
Detail of Hooker Implementation
•

hooker: (in assembly, hooker.S)
–

placed at selected function to jump to hook-body, the sequence is:
•
•

•

hook-body: (in assembly, hooker.S)
–
–

Call hook function in C
preserve selected function’s parameters (overwrite by hook function) , RAX (overwrite during far
jump) and selected function’s header code (overwrite by hooker code), the sequence is
•
•
•
•
•
•

•

jump to hook-body
pop rax, nop, nop and nop

push parameters of selected function
call hook function
pop parameters of selected function
preserve selected function header’s execution binary
push RAX
jump to hooker’s

hook-function (in C, hooker.C)
a) reference selected function’s original parameters,
b) reference global functions and data of application
c) reference functions of GLIBC
d) reference global functions and global objects of injected object

Mais conteúdo relacionado

Destaque

Influència de la Bíblia
Influència de la BíbliaInfluència de la Bíblia
Influència de la BíbliaMallabres
 
Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016 Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016 The Reznik Group
 
2013 03-08 [開発中] node-sacloud
2013 03-08 [開発中] node-sacloud2013 03-08 [開発中] node-sacloud
2013 03-08 [開発中] node-sacloudYuki KAN
 
Slideshow 2
Slideshow 2Slideshow 2
Slideshow 2ccantlie
 
il portale Dati.gov.it e l’Infografica su open data in Italia
il portale Dati.gov.it e l’Infografica su open data in Italia il portale Dati.gov.it e l’Infografica su open data in Italia
il portale Dati.gov.it e l’Infografica su open data in Italia DatiGovIT
 
Life Insurance - 2013 Gold Monitor Award Winners
Life Insurance - 2013 Gold Monitor Award WinnersLife Insurance - 2013 Gold Monitor Award Winners
Life Insurance - 2013 Gold Monitor Award WinnersCorporate Insight
 
Rapport de Situation #3 Tempête Tropicale Sandy
Rapport de Situation #3 Tempête Tropicale SandyRapport de Situation #3 Tempête Tropicale Sandy
Rapport de Situation #3 Tempête Tropicale Sandylaurentlamothe
 
Presentation constructing an information panel
Presentation   constructing an information panelPresentation   constructing an information panel
Presentation constructing an information paneldoogstone
 
Walker omladnete
Walker omladneteWalker omladnete
Walker omladnetecostica12
 
15 enemies-of-success
15 enemies-of-success15 enemies-of-success
15 enemies-of-successSarwan Singh
 
Análisis de de textos revisados en la construcción de la historia del arte de...
Análisis de de textos revisados en la construcción de la historia del arte de...Análisis de de textos revisados en la construcción de la historia del arte de...
Análisis de de textos revisados en la construcción de la historia del arte de...cediel1952
 

Destaque (14)

Jsf intro
Jsf introJsf intro
Jsf intro
 
Influència de la Bíblia
Influència de la BíbliaInfluència de la Bíblia
Influència de la Bíblia
 
Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016 Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016
 
2013 03-08 [開発中] node-sacloud
2013 03-08 [開発中] node-sacloud2013 03-08 [開発中] node-sacloud
2013 03-08 [開発中] node-sacloud
 
Slideshow 2
Slideshow 2Slideshow 2
Slideshow 2
 
il portale Dati.gov.it e l’Infografica su open data in Italia
il portale Dati.gov.it e l’Infografica su open data in Italia il portale Dati.gov.it e l’Infografica su open data in Italia
il portale Dati.gov.it e l’Infografica su open data in Italia
 
La guitarra
La guitarraLa guitarra
La guitarra
 
Life Insurance - 2013 Gold Monitor Award Winners
Life Insurance - 2013 Gold Monitor Award WinnersLife Insurance - 2013 Gold Monitor Award Winners
Life Insurance - 2013 Gold Monitor Award Winners
 
Rapport de Situation #3 Tempête Tropicale Sandy
Rapport de Situation #3 Tempête Tropicale SandyRapport de Situation #3 Tempête Tropicale Sandy
Rapport de Situation #3 Tempête Tropicale Sandy
 
Presentation constructing an information panel
Presentation   constructing an information panelPresentation   constructing an information panel
Presentation constructing an information panel
 
Walker omladnete
Walker omladneteWalker omladnete
Walker omladnete
 
15 enemies-of-success
15 enemies-of-success15 enemies-of-success
15 enemies-of-success
 
Análisis de de textos revisados en la construcción de la historia del arte de...
Análisis de de textos revisados en la construcción de la historia del arte de...Análisis de de textos revisados en la construcción de la historia del arte de...
Análisis de de textos revisados en la construcción de la historia del arte de...
 
Bs ipa7 semester 1
Bs ipa7 semester 1Bs ipa7 semester 1
Bs ipa7 semester 1
 

Último

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Code injection approach to add feature on service

  • 1. A Code Injection Approach to Add Feature on Service houcheng@gmail.com CCMA, ITRI
  • 2. Introduction • Initial idea • we need to extend features onto some running service without suspending it. • we don’t want to upgrade program binary file; when need new feature turn it on and when don’t need turn it off – Benefits • new service can be on demand turn on • when off: the same binary file, so its stability still kept • when on: loss some stability but increase functionality
  • 3. Basic Idea s4~5 s1~3 service_wrapper() s1 s2 s3 s1() s2() s3() service’s memory space BEFORE service_wrapper() s1 s2 s3 service_wrapper2() s1() s2() s4 s4() s5 s5() s3() hooked service’s memory space that support s4 and s5 AFTER : hook function
  • 4. Steps 1) Use GDB to attach running process 2) Place the hook function that onto service wrapper function; • for original service request, run original code • for new service request, run new code 3) The hook function • • • Has the same parameters as selected function Can call functions and access data of application Return 1 to indicate not execute original selected function
  • 5. Flow of Code Injection hooker.S hooker.c build scripts code inject scripts hook hook.o running service gdb s45.c • compile • link • • • • load build symbol table resolve reference hook libraries (GLIBC) Linux OS
  • 6. Code Inject Script • Load • call mmap() in GDB to load binary onto process memory space • Build symbol table: • add symbols of service by signature searching on .code segment • add symbols of injected code by reading its debug file • add symbols of GLIBC by calling GDB • Resolve reference • For each un-resolve symbols in hook code, resolve by looking up symbol table • Hook • Copy hooker onto address of service wrapper function
  • 7. Signature Search DB to support Multiple Versions of Service Application signature search script running service offset:0x800, “v1.1” offset:0x800, “v1.2” vstring table service_func, “aa cc dd ....” function_2, “aa bb cc ... “ service_func, “aa cc dd ....” function_2, “aa bb cc ... “ 1) check every entry of vstring table to find service version 2) use correct version’s signatures to build symbol table
  • 8. Detail of Hooker Implementation • hooker: (in assembly, hooker.S) – placed at selected function to jump to hook-body, the sequence is: • • • hook-body: (in assembly, hooker.S) – – Call hook function in C preserve selected function’s parameters (overwrite by hook function) , RAX (overwrite during far jump) and selected function’s header code (overwrite by hooker code), the sequence is • • • • • • • jump to hook-body pop rax, nop, nop and nop push parameters of selected function call hook function pop parameters of selected function preserve selected function header’s execution binary push RAX jump to hooker’s hook-function (in C, hooker.C) a) reference selected function’s original parameters, b) reference global functions and data of application c) reference functions of GLIBC d) reference global functions and global objects of injected object