SlideShare una empresa de 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

Más contenido relacionado

Destacado

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
 

Destacado (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

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 

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