SlideShare a Scribd company logo
Introduction to IDAPython
Byoungyoung Lee
POSTECH
PLUS 038
override@postech.ac.kr
Overview
• Brief intro to IDAPython
• How to install
• Examples
– Searching disassembly patterns
– Searching system calls in the binary
– Deobfuscation
Automatic Reversing with IDA
• To do automatic reversing ?
– you need to write scripts

• IDA supports multiple interfaces
– Plugins (C++)
– IDC (C-like scripting)
– IDAPython (Python)
Brief intro to IDAPython
• Most things you can do w/ your hands
– can be done w/ IDAPython
How to install
• COPY ‘python’ directory
– to %IDA_DIR%

• PUT ‘python.plw’
– to %IDA_DIR%/plugins
• ex) C:Program FilesIDA52plugins
How to execute
1. Press ‘ALT+9’ in IDA
2. Choose Python file you’d like to execute
 Results would be printed in the log window
Simple example
– walking the functions
# walkFunctions.py
### Walk the functions
# Get the segment's starting address
ea = ScreenEA()
# Loop through all the functions
for function_ea in Functions(SegStart(ea), SegEnd(ea)):
# Print the address and the function name.
print hex(function_ea), GetFunctionName(function_ea)
Simple example
– walking the instructions
# walkInstructions.py
# For each of the segments
for seg_ea in Segments():
# For each of the defined elements
for head in Heads(seg_ea, SegEnd(seg_ea)):
# If it's an instruction
if isCode(GetFlags(head)):
# Get the Disasm and print it
disasm = GetDisasm(head)
print disasm
Application
- Find ‘CALL’ instructions
# searchSystemCalls.py
from idautils import *
seg_ea = SegByName(".text")
# For each instruction
for addr in Heads(seg_ea, SegEnd(seg_ea)):
# Get disassembly
disasmStr = GetDisasm(addr)
if disasmStr.startswith( "int ") == True:
# Print if it is a system call
print "0x%08x [%s]" % (addr, disasmStr)
Deobfuscation
• What is obfuscation?
– To transform binary into something
• which has the same executing behavior
• which has very different outer representation

– To disrupt disassemblers
Deobfuscation
• How to obfuscate the binary
– Simple obfuscation methods
JMP X

=

PUSH X
RET

JMP X

=

XOR
JZ

original

ECX, ECX
X

obfuscated
Deobfuscation
• What happens due to these obfuscation?
– IDA failed to analyze the binary properly
• which means ..
• YOU CANNOT USE CFG LAYOUT
• YOU CANNOT EASILY FOLLOW THE CONTROL
FLOW
Deobfuscation
• Let’s learn deobfuscation w/ an example
– 1.
– 2.
– 3.
– 4.

load reversing500 in IDA
move to 0x08049891, and see ‘PUSH/RET’
execute ‘deobfuscation_simple.py’
see the instructions of 0x08049891

– For full deobfuscation
• execute ‘deobfuscation_full.py’
Exercises (more applications)
• 1. To list all string copy functions?
– such as strcpy(), strncpy(), strcat(), and etc.
– YES ,this is for finding Stack Overflow vulns.

• 2. To examine all malloc() calls?
– whose arg. is determined dynamically
– YES ,this is for finding Heap Overflow vulns.

• 3. Memory/Register Computation Back Tracer
Reference
• “Introduction to IDAPython”
by Ero Carrera

More Related Content

What's hot (20)

PDF
Introduction to Python for Bioinformatics
José Héctor Gálvez
 
PPT
Perl Modules
stn_tkiller
 
PPTX
Anti-Virus Evasion Techniques and Countermeasures
n|u - The Open Security Community
 
PPTX
Reversing & malware analysis training part 2 introduction to windows internals
securityxploded
 
PPT
Os Vanrossum
oscon2007
 
PPTX
Buffer overflow attacks
Japneet Singh
 
PDF
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
enSilo
 
PDF
Dynamic Binary Instrumentation
Cysinfo Cyber Security Community
 
PPTX
Tranning-2
Ali Hussain
 
PPTX
Buffer Overflow Demo by Saurabh Sharma
n|u - The Open Security Community
 
PDF
Improving DroidBox
Kelwin Yang
 
PPT
Buffer Overflows
Sumit Kumar
 
PDF
Richard wartell malware is hard. let's go shopping!!
Shakacon
 
PDF
[2014 CodeEngn Conference 11] 김호빈 - Android Bootkit Analysis EN
Code Engn
 
PDF
Elixir
Robert Brown
 
PDF
PyPy's approach to construct domain-specific language runtime
National Cheng Kung University
 
PPT
Exploiting stack overflow 101
n|u - The Open Security Community
 
PPTX
Stack-Based Buffer Overflows
Daniel Tumser
 
PDF
Effective testing with pytest
Hector Canto
 
PPTX
Buffer overflow
قصي نسور
 
Introduction to Python for Bioinformatics
José Héctor Gálvez
 
Perl Modules
stn_tkiller
 
Anti-Virus Evasion Techniques and Countermeasures
n|u - The Open Security Community
 
Reversing & malware analysis training part 2 introduction to windows internals
securityxploded
 
Os Vanrossum
oscon2007
 
Buffer overflow attacks
Japneet Singh
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
enSilo
 
Dynamic Binary Instrumentation
Cysinfo Cyber Security Community
 
Tranning-2
Ali Hussain
 
Buffer Overflow Demo by Saurabh Sharma
n|u - The Open Security Community
 
Improving DroidBox
Kelwin Yang
 
Buffer Overflows
Sumit Kumar
 
Richard wartell malware is hard. let's go shopping!!
Shakacon
 
[2014 CodeEngn Conference 11] 김호빈 - Android Bootkit Analysis EN
Code Engn
 
Elixir
Robert Brown
 
PyPy's approach to construct domain-specific language runtime
National Cheng Kung University
 
Exploiting stack overflow 101
n|u - The Open Security Community
 
Stack-Based Buffer Overflows
Daniel Tumser
 
Effective testing with pytest
Hector Canto
 
Buffer overflow
قصي نسور
 

Viewers also liked (7)

PPTX
Advanced Malware Analysis Training Session 5 - Reversing Automation
securityxploded
 
PDF
Dytan: A Generic Dynamic Taint Analysis Framework (ISSTA 2007)
James Clause
 
PPT
Packer Genetics: The selfish code
jduart
 
PDF
Malware Detection With Multiple Features
Muhammad Najmi Ahmad Zabidi
 
PDF
H@dfex 2015 malware analysis
Charles Lim
 
PDF
Control Flow Analysis
Edgar Barbosa
 
PPTX
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Sam Bowne
 
Advanced Malware Analysis Training Session 5 - Reversing Automation
securityxploded
 
Dytan: A Generic Dynamic Taint Analysis Framework (ISSTA 2007)
James Clause
 
Packer Genetics: The selfish code
jduart
 
Malware Detection With Multiple Features
Muhammad Najmi Ahmad Zabidi
 
H@dfex 2015 malware analysis
Charles Lim
 
Control Flow Analysis
Edgar Barbosa
 
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Sam Bowne
 
Ad

Similar to Introduction to ida python (20)

PDF
Rails Tips and Best Practices
David Keener
 
PDF
Compiler2016 by abcdabcd987
乐群 陈
 
PDF
Tdd is not about testing
Gianluca Padovani
 
PPTX
x86
Wei-Bo Chen
 
PDF
Building Hermetic Systems (without Docker)
William Farrell
 
PPTX
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
PDF
Dive into PySpark
Mateusz Buśkiewicz
 
PPTX
Java - A broad introduction
Birol Efe
 
PDF
Speed geeking-lotusscript
Bill Buchan
 
PDF
Multiprocessing with python
Patrick Vergain
 
PPT
Chelberg ptcuser 2010
Clay Helberg
 
PDF
fg.workshop: Software vulnerability
fg.informatik Universität Basel
 
PDF
How to deploy node to production
Sean Hess
 
PPTX
CodeIgniter Ant Scripting
Albert Rosa
 
PDF
Linux Shell Scripting Craftsmanship
bokonen
 
PDF
Node azure
Emanuele DelBono
 
PPTX
Dapper: the microORM that will change your life
Davide Mauri
 
PDF
Django at Scale
bretthoerner
 
PDF
What we Learned Implementing Puppet at Backstop
Puppet
 
ODP
Joxean Koret - Database Security Paradise [Rooted CON 2011]
RootedCON
 
Rails Tips and Best Practices
David Keener
 
Compiler2016 by abcdabcd987
乐群 陈
 
Tdd is not about testing
Gianluca Padovani
 
Building Hermetic Systems (without Docker)
William Farrell
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
Dive into PySpark
Mateusz Buśkiewicz
 
Java - A broad introduction
Birol Efe
 
Speed geeking-lotusscript
Bill Buchan
 
Multiprocessing with python
Patrick Vergain
 
Chelberg ptcuser 2010
Clay Helberg
 
fg.workshop: Software vulnerability
fg.informatik Universität Basel
 
How to deploy node to production
Sean Hess
 
CodeIgniter Ant Scripting
Albert Rosa
 
Linux Shell Scripting Craftsmanship
bokonen
 
Node azure
Emanuele DelBono
 
Dapper: the microORM that will change your life
Davide Mauri
 
Django at Scale
bretthoerner
 
What we Learned Implementing Puppet at Backstop
Puppet
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
RootedCON
 
Ad

More from geeksec80 (19)

PDF
Sipoc diagram (1)
geeksec80
 
PDF
Sipoc diagram (1)
geeksec80
 
PDF
Sipoc diagram
geeksec80
 
PDF
Python arsenal for re (1)
geeksec80
 
PDF
Python arsenal for re
geeksec80
 
PDF
02 banking trojans-thomassiebert
geeksec80
 
PDF
44 con slides (1)
geeksec80
 
PDF
44 con slides
geeksec80
 
PDF
Fuzz nt
geeksec80
 
DOC
Rpc调试通用
geeksec80
 
PDF
Bh us 11_tsai_pan_weapons_targeted_attack_wp
geeksec80
 
PDF
Taking browsers fuzzing new
geeksec80
 
PDF
529 owasp top 10 2013 - rc1[1]
geeksec80
 
PDF
Deep sec 2012_rosario_valotta_-_taking_browsers_fuzzing_to_the_next_(dom)_level
geeksec80
 
PDF
2012 04-16-ultrasurf-analysis (2)
geeksec80
 
PDF
12058 woot13-kholia
geeksec80
 
PDF
Https interception proxies
geeksec80
 
PPTX
Taint scope
geeksec80
 
PDF
Automated antlr tree walker
geeksec80
 
Sipoc diagram (1)
geeksec80
 
Sipoc diagram (1)
geeksec80
 
Sipoc diagram
geeksec80
 
Python arsenal for re (1)
geeksec80
 
Python arsenal for re
geeksec80
 
02 banking trojans-thomassiebert
geeksec80
 
44 con slides (1)
geeksec80
 
44 con slides
geeksec80
 
Fuzz nt
geeksec80
 
Rpc调试通用
geeksec80
 
Bh us 11_tsai_pan_weapons_targeted_attack_wp
geeksec80
 
Taking browsers fuzzing new
geeksec80
 
529 owasp top 10 2013 - rc1[1]
geeksec80
 
Deep sec 2012_rosario_valotta_-_taking_browsers_fuzzing_to_the_next_(dom)_level
geeksec80
 
2012 04-16-ultrasurf-analysis (2)
geeksec80
 
12058 woot13-kholia
geeksec80
 
Https interception proxies
geeksec80
 
Taint scope
geeksec80
 
Automated antlr tree walker
geeksec80
 

Recently uploaded (20)

PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
community health nursing question paper 2.pdf
Prince kumar
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 

Introduction to ida python

  • 2. Overview • Brief intro to IDAPython • How to install • Examples – Searching disassembly patterns – Searching system calls in the binary – Deobfuscation
  • 3. Automatic Reversing with IDA • To do automatic reversing ? – you need to write scripts • IDA supports multiple interfaces – Plugins (C++) – IDC (C-like scripting) – IDAPython (Python)
  • 4. Brief intro to IDAPython • Most things you can do w/ your hands – can be done w/ IDAPython
  • 5. How to install • COPY ‘python’ directory – to %IDA_DIR% • PUT ‘python.plw’ – to %IDA_DIR%/plugins • ex) C:Program FilesIDA52plugins
  • 6. How to execute 1. Press ‘ALT+9’ in IDA 2. Choose Python file you’d like to execute  Results would be printed in the log window
  • 7. Simple example – walking the functions # walkFunctions.py ### Walk the functions # Get the segment's starting address ea = ScreenEA() # Loop through all the functions for function_ea in Functions(SegStart(ea), SegEnd(ea)): # Print the address and the function name. print hex(function_ea), GetFunctionName(function_ea)
  • 8. Simple example – walking the instructions # walkInstructions.py # For each of the segments for seg_ea in Segments(): # For each of the defined elements for head in Heads(seg_ea, SegEnd(seg_ea)): # If it's an instruction if isCode(GetFlags(head)): # Get the Disasm and print it disasm = GetDisasm(head) print disasm
  • 9. Application - Find ‘CALL’ instructions # searchSystemCalls.py from idautils import * seg_ea = SegByName(".text") # For each instruction for addr in Heads(seg_ea, SegEnd(seg_ea)): # Get disassembly disasmStr = GetDisasm(addr) if disasmStr.startswith( "int ") == True: # Print if it is a system call print "0x%08x [%s]" % (addr, disasmStr)
  • 10. Deobfuscation • What is obfuscation? – To transform binary into something • which has the same executing behavior • which has very different outer representation – To disrupt disassemblers
  • 11. Deobfuscation • How to obfuscate the binary – Simple obfuscation methods JMP X = PUSH X RET JMP X = XOR JZ original ECX, ECX X obfuscated
  • 12. Deobfuscation • What happens due to these obfuscation? – IDA failed to analyze the binary properly • which means .. • YOU CANNOT USE CFG LAYOUT • YOU CANNOT EASILY FOLLOW THE CONTROL FLOW
  • 13. Deobfuscation • Let’s learn deobfuscation w/ an example – 1. – 2. – 3. – 4. load reversing500 in IDA move to 0x08049891, and see ‘PUSH/RET’ execute ‘deobfuscation_simple.py’ see the instructions of 0x08049891 – For full deobfuscation • execute ‘deobfuscation_full.py’
  • 14. Exercises (more applications) • 1. To list all string copy functions? – such as strcpy(), strncpy(), strcat(), and etc. – YES ,this is for finding Stack Overflow vulns. • 2. To examine all malloc() calls? – whose arg. is determined dynamically – YES ,this is for finding Heap Overflow vulns. • 3. Memory/Register Computation Back Tracer
  • 15. Reference • “Introduction to IDAPython” by Ero Carrera