SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
www.SecurityXploded.com
Disclaimer
The Content, Demonstration, Source Code and Programs presented here is "AS IS"
without any warranty or conditions of any kind. Also the views/ideas/knowledge
expressed here are solely of the trainer’s only and nothing to do with the company or
the organization in which the trainer is currently working.
However in no circumstances neither the trainer nor SecurityXploded is responsible for
any damage or loss caused due to use or misuse of the information presented here.
www.SecurityXploded.com
Acknowledgement
 Special thanks to null & Garage4Hackers community for their extended support and
cooperation.
 Thanks to all the Trainers who have devoted their precious time and countless hours to
make it happen.
www.SecurityXploded.com
Reversing & Malware Analysis Training
This presentation is part of our Reverse Engineering & Malware Analysis Training
program. Currently it is delivered only during our local meet for FREE of cost.
For complete details of this course, visit our Security Training page.
www.SecurityXploded.com
Who am I #1
Amit Malik (sometimes DouBle_Zer0,DZZ)
 Member SecurityXploded
 Security Researcher @ McAfee Labs
 RE, Exploit Analysis/Development, Malware Analysis
 Email: m.amit30@gmail.com
www.SecurityXploded.com
Who am I #2
Swapnil Pathak
 Member SecurityXploded
 Security Researcher @ McAfee Labs
 RE, Malware Analysis, Network Security
 Email: swapnilpathak101@gmail.com
www.SecurityXploded.com
Course Q&A
 Keep yourself up to date with latest security news
 http://www.securityphresh.com
 For Q&A, join our mailing list.
 http://groups.google.com/group/securityxploded
www.SecurityXploded.com
Presentation Outline
 Intro to x86-32
 AssemblyLanguage
 Instructions
 Stack Operations
 Callingconventions
 Demo
www.SecurityXploded.com
x86-32
 32 bit instruction set architecturesbased on Intel 8086 CPU
 Addressa linear address spaceup to 4GB
 8, 32 bit General PurposeRegisters(GPR)
 6,16 bit Segment Registers
 EFLAGS and EIP register
 ControlRegisters(CR0-CR4)(16 bits)
 Memory ManagementRegistersDescriptorTableRegisters (GDTR, IDTR,
LDTR)
 Debug Registers ( DR0-DR7)
www.SecurityXploded.com
Registers Usage - RE
 Register
 StorageLocations.
 Much fasteraccess compareto memory locations.
 EAX: Accumulator, mostly storesreturn values fromfunctions(APIs)
 EBX: Base index (for use with arrays)
 ECX: Counter
 EDX: Data/general
 ESI: Sourceindex for string operations.
www.SecurityXploded.com
Registers Usage – RE Cont.
 EDI: Destination index forstring operations.
 ESP: Stack pointerfortop address of the stack.
 EBP: Stack base pointerforholding theaddress of the current stack frame.
 EIP: Instructionpointer.Holds the programcounter, thenext instruction address.
 Segment registers:
 Used to address particularsegments ofmemory ( code, data, stack )
!) CS: Code !!) SS: Stack
!!!) ES: Extra !V) DS: Data V) FS, GS
www.SecurityXploded.com
Registers – 32 bit (X86)
www.SecurityXploded.com
(R/E)Flags Register
 Bit field of states
 Status Flags
 Carrry (CF) : set when an arithmetic carry/borrow has been generated out of the
MSB.
 Zero (ZF) : set when an arithmetic operation result is zero and reset otherwise.
 Sign (SF) : set when an arithmetic operation set the MSB i.e. the result value was
negative.
 Trap (TF ) : when set permits operation of processor in single-step. Mostly used by
debuggers.
 Interrupt (IF) : determines whether the CPU should handle maskable hardware
interrupts.
 Direction (DF) : determines the direction (left-to-right or right-to-left) of string
processing.
 Overflow (OF) : indicates arithmetic overflow.
www.SecurityXploded.com
Assembly Language
 Low level programming language
 Symbolicrepresentationof machinecodes, constants.
 Assemblylanguageprogramconsist ofsequenceof process instructions and meta
statements
 Assemblertranslates themto executableinstructionsthat are loaded into memory and
executed.
 BasicStructure
[label]: opcode operand1,operand2
opcode – mnemonicthat symbolizeinstructions
 Example.
 MOV AL, 61h => 1011000001100001
www.SecurityXploded.com
Instructions
ADD dst, src
- Adds thevalues of src and dst and stores the result into dst.
- For exampleADD EAX, 1
SUB dst, src
- Subtractssrcvalue from dst and stores the result in dst.
- For exampleSUB EAX, 1
CMPdst, src
- Subtractssrcvalue from dst but does storethe result in dst
- Mostlyused to set/reset decisionmaking bits in EFLAGS registersuch as ZF
- For exampleCMP EAX, EBX
www.SecurityXploded.com
Instructions cont.
MOV dst, src
- Moves datafrom src (left operand)to destination(right operand)
- For examplemov EDI, ESI
Note:
- Both operands cannotbe memory locations.
- Both the operands must be of the same size
LEAdst, src
- Stands forLoad EffectiveAddress.
- Computestheeffectiveaddress of src operand and stores it in dst operand.
- For exampleLEA ECX,[EBX + 5]
Note:
- Generally bracketsdenotevalueat memory locations.
- In case of LEA it does simplearithmeticand stores it in dst
www.SecurityXploded.com
Instructions cont.
XOR dst, src
- Performs a bitwiseexclusiveORoperation on the dst and src and stores the
result in dst.
- Each bit of the result is 1 if the correspondingbits ofthe operands are different,
0 if the correspondingbit are same
Note:
- When used with same register clears the contents ofthe register
- Optimizedway to clear the register. Betterthan MOV EAX, 0
www.SecurityXploded.com
Instructions cont.
REP
- Used with string operations
- Repeats a string instructionuntil ECX (counterregister)valueis equal to zero.
- For exampleREPMOVS byte ptr DS:[EDI], DS:[ESI]
LOOP
- Similarto loops in high level languages
- Used to executesequenceof instructionsmultipletimes.
- For example
MOV ECX, 10
Test : INC EBX
INC EAX
LOOP Test
www.SecurityXploded.com
Instructions cont.
TEST dst, src
- Performs bitwiselogicaland between dst and src
- UpdatestheZero flag bit of the EFLAGS register
- Mostlyused to check if the return valueof the function is not zero
- For exampleTEST EAX, EAX
INT3h
- Breakpointinstruction
- Used by debuggersto stop execution ofthe programat particularinstruction
www.SecurityXploded.com
Instructions cont.
CALLaddress
- Performs two functions
- Push address of the next instructionon stack (return address)
- Jump to the address specifiedby the instruction
- For exampleCALL dword ptr [EAX+4]
RET
- Transfers thecontrol to the address previously pushedon the stack by CALL
instruction
- Mostlydenotestheend of the function
www.SecurityXploded.com
Instructions cont.
Jump instructions
- Categorized as conditional and unconditional
- Unconditionaljump instructions
- JMP(Far Jump) – E9 – (Cross segments)
- JMP( Short Jump ) – EB – (-127 to 128 bytes)
- JMP( Near Jump ) – E9 – (in a segment)
- For exampleJMPEAX
- Conditional jump instructions
- Jumps according to bit flags set in the EFLAGS register
- JC, JNC, JZ, JNZ, JS, JNS, JO, JNO
- UnsignedcomparisonsJA, JAE, JB, JBE
- Signed comparisonsJG, JGE, JL, JLE
- Usually followedby CMP instruction
www.SecurityXploded.com
Instructions cont.
PUSH operand
- Pushes operandon the stack
- Decrementsthestack pointerregisterby operand size
- For examplePUSH EAX
POP operand
- Stores thevalue pointedby the stack pointerin operand
- Incrementsthestack pointerregisterby operand size
- For examplePOPEAX
Note: POP/PUSHEIPis an invalid instruction
PUSHF, POPF
www.SecurityXploded.com
Calling Conventions
 Describeshow thearguments are passed and values returned by functions.
 Steps performed when a functionis called
 Arguments are passed to the called function
 Program execution is transferred to the address of the called function
 Called function starts with lines of code that prepare stack and registers for use within the function.Also
known as function prologue.
○ For e.g.
push ebp
mov ebp, esp
or with enter instruction
 Called function ends with lines of code that restore stack and registers set initially. Also known as function
epilogue.
○ For e.g.
mov esp, ebp
pop ebp
ret
or with leave instruction
 Passed arguments are removed from the stack, known as stack cleanup. Can be performed by both calling
function or called function depending on the calling convention used.
www.SecurityXploded.com
Calling conventions cont.
 __cdecl (C calling convention)
 Arguments are passed from right to left and placed on the stack
 Stack cleanup is performed by the caller
 Return values are stored in EAX register
 Standard calling convention used by C compilers
 __stdcall(Standardcallingconvention)
 Arguments are passed from right to left and placed on the stack
 Stack cleanup is performed by the called function
 Return values are stored in EAX register
 Standard calling convention for Microsoft Win32 API
 __fastcall(Fast calling convention)
 Arguments passed are stored in registers for faster access
 Thiscall
 Arguments are passed from right to left and placed on the stack. this pointer placed in ECX
- Standard calling convention for calling member functions of C++ classeswww.SecurityXploded.com
Stack operations
 Stack is a LIFO (Last In First Out) typedata structure
 Stacks grows downward in memory, from highermemory address to lower
memory address
 PUSH decrement the stack pointer i.eESP
 POPIncrement thestack pointer i.e ESP
 Eachfunction has its own stack frame
 Function prologuesetup thestack frame for each function
 Local variableof a functionare storedinto its stack frame
www.SecurityXploded.com
Stack #1
www.SecurityXploded.com
Stack #2
www.SecurityXploded.com
 Each function creates its own stack.
 Callerfunctionstack: knownas parent stack.
 Called function stack:known as child stack.
For e.g.
main(){ ASMPseudo:
sum(); _main:
} 123: push ebp
124: mov ebp,esp
125: sub esp,val
126: call _sum
127: mov esp,ebp
128: pop ebp
129: ret
* The parentand child notation is theinstructor notation, technically it shouldbecaller and callee stack frames.
Stack #3
www.SecurityXploded.com
Stack #4
www.SecurityXploded.com
Stack #5
www.SecurityXploded.com
Stack #6
www.SecurityXploded.com
DEMO (Source Code)
 #include <stdio.h>
 /*
 Author:Amit Malik
 http://www.securityxploded.com - Compile in Dev C++
 */
 int mysum(int,int);
 int main()
 {
 int a,b,s;
 a = 5;
 b = 6;
 s = mysum(a,b); // call mysum function
 printf("sum is: %d",s);
 getchar();
 }
 int mysum(int l, int m) // mysum function
 {
 int c;
 c = l + m;
 return c;
 }
www.SecurityXploded.com
DEMO (Video)
www.SecurityXploded.com
http://vimeo.com/36198403
x86-64 Intro.
 64 bit instruction set architecturesbased on Intel 8086 CPU
 Addressa linear address spaceup to 16TB
 16, 64 bit General PurposeRegisters(GPR)
 6, 16 bit Segment Registers
 RFLAGS and RIP register
 ControlRegisters(CR0-CR4) and CR8 (16 bits)
 Memory ManagementRegisters DescriptorTableRegisters(GDTR, IDTR,
LDTR)size expanded to 10 bytes
 Debug Registers ( DR0-DR7)
www.SecurityXploded.com
Reference
 Complete Reference Guide for Reversing & Malware Analysis Training
www.SecurityXploded.com
Thank You !
www.SecurityXploded.com

Weitere ähnliche Inhalte

Was ist angesagt?

Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Simon Ritter
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to phpAnjan Banda
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterJAXLondon2014
 
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...frank2
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesKris Mok
 
Java Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey KovalenkoJava Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey KovalenkoValeriia Maliarenko
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichWillem van Ketwich
 
T01520010220104023 t0152 pert 10
T01520010220104023 t0152 pert 10T01520010220104023 t0152 pert 10
T01520010220104023 t0152 pert 10Fenroy D-Messiah
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...jaxLondonConference
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and ParallelizationDmitri Nesteruk
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7Damien Seguy
 

Was ist angesagt? (20)

Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
[ASM]Lab8
[ASM]Lab8[ASM]Lab8
[ASM]Lab8
 
The Java Carputer
The Java CarputerThe Java Carputer
The Java Carputer
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
 
Using PHP 5.3 Namespaces for Fame and Fortune
Using PHP 5.3 Namespaces for Fame and FortuneUsing PHP 5.3 Namespaces for Fame and Fortune
Using PHP 5.3 Namespaces for Fame and Fortune
 
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple Languages
 
Java Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey KovalenkoJava Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey Kovalenko
 
Perl Modules
Perl ModulesPerl Modules
Perl Modules
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Lecture6
Lecture6Lecture6
Lecture6
 
T01520010220104023 t0152 pert 10
T01520010220104023 t0152 pert 10T01520010220104023 t0152 pert 10
T01520010220104023 t0152 pert 10
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and Parallelization
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 

Ähnlich wie Reversing & malware analysis training part 4 assembly programming basics

Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsAjin Abraham
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptMuhammad Sikandar Mustafa
 
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Elvin Gentiles
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick reviewCe.Se.N.A. Security
 
02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stackAlexandre Moneger
 
Introduction to Assembly Language
Introduction to Assembly Language Introduction to Assembly Language
Introduction to Assembly Language ApekshaShinde6
 
Reversing & malware analysis training part 11 exploit development advanced
Reversing & malware analysis training part 11   exploit development advancedReversing & malware analysis training part 11   exploit development advanced
Reversing & malware analysis training part 11 exploit development advancedAbdulrahman Bassam
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1  Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1 securityxploded
 
[ENG] Hacktivity 2013 - Alice in eXploitland
[ENG] Hacktivity 2013 - Alice in eXploitland[ENG] Hacktivity 2013 - Alice in eXploitland
[ENG] Hacktivity 2013 - Alice in eXploitlandZoltan Balazs
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit developmentPayampardaz
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploitshughpearse
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applicationscommiebstrd
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHackito Ergo Sum
 
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]securityxploded
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 

Ähnlich wie Reversing & malware analysis training part 4 assembly programming basics (20)

Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter ppt
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
 
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick review
 
02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack
 
Introduction to Assembly Language
Introduction to Assembly Language Introduction to Assembly Language
Introduction to Assembly Language
 
Reversing & malware analysis training part 11 exploit development advanced
Reversing & malware analysis training part 11   exploit development advancedReversing & malware analysis training part 11   exploit development advanced
Reversing & malware analysis training part 11 exploit development advanced
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1  Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
 
[ENG] Hacktivity 2013 - Alice in eXploitland
[ENG] Hacktivity 2013 - Alice in eXploitland[ENG] Hacktivity 2013 - Alice in eXploitland
[ENG] Hacktivity 2013 - Alice in eXploitland
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
 
x86
x86x86
x86
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
 
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 

Mehr von Abdulrahman Bassam

Reversing & malware analysis training part 12 rootkit analysis
Reversing & malware analysis training part 12   rootkit analysisReversing & malware analysis training part 12   rootkit analysis
Reversing & malware analysis training part 12 rootkit analysisAbdulrahman Bassam
 
Reversing & malware analysis training part 10 exploit development basics
Reversing & malware analysis training part 10   exploit development basicsReversing & malware analysis training part 10   exploit development basics
Reversing & malware analysis training part 10 exploit development basicsAbdulrahman Bassam
 
Reversing & malware analysis training part 9 advanced malware analysis
Reversing & malware analysis training part 9   advanced malware analysisReversing & malware analysis training part 9   advanced malware analysis
Reversing & malware analysis training part 9 advanced malware analysisAbdulrahman Bassam
 
Reversing & malware analysis training part 8 malware memory forensics
Reversing & malware analysis training part 8   malware memory forensicsReversing & malware analysis training part 8   malware memory forensics
Reversing & malware analysis training part 8 malware memory forensicsAbdulrahman Bassam
 
Reversing & malware analysis training part 7 unpacking upx
Reversing & malware analysis training part 7   unpacking upxReversing & malware analysis training part 7   unpacking upx
Reversing & malware analysis training part 7 unpacking upxAbdulrahman Bassam
 
Reversing & malware analysis training part 6 practical reversing (i)
Reversing & malware analysis training part 6   practical reversing (i)Reversing & malware analysis training part 6   practical reversing (i)
Reversing & malware analysis training part 6 practical reversing (i)Abdulrahman Bassam
 
Reversing & malware analysis training part 5 reverse engineering tools basics
Reversing & malware analysis training part 5   reverse engineering tools basics Reversing & malware analysis training part 5   reverse engineering tools basics
Reversing & malware analysis training part 5 reverse engineering tools basics Abdulrahman Bassam
 
Reversing & malware analysis training part 3 windows pe file format basics
Reversing & malware analysis training part 3   windows pe file format basicsReversing & malware analysis training part 3   windows pe file format basics
Reversing & malware analysis training part 3 windows pe file format basicsAbdulrahman Bassam
 
Reversing & malware analysis training part 2 introduction to windows internals
Reversing & malware analysis training part 2   introduction to windows internalsReversing & malware analysis training part 2   introduction to windows internals
Reversing & malware analysis training part 2 introduction to windows internalsAbdulrahman Bassam
 
Reversing & malware analysis training part 1 lab setup guide
Reversing & malware analysis training part 1   lab setup guideReversing & malware analysis training part 1   lab setup guide
Reversing & malware analysis training part 1 lab setup guideAbdulrahman Bassam
 
The apache software foundation
The apache software foundationThe apache software foundation
The apache software foundationAbdulrahman Bassam
 

Mehr von Abdulrahman Bassam (11)

Reversing & malware analysis training part 12 rootkit analysis
Reversing & malware analysis training part 12   rootkit analysisReversing & malware analysis training part 12   rootkit analysis
Reversing & malware analysis training part 12 rootkit analysis
 
Reversing & malware analysis training part 10 exploit development basics
Reversing & malware analysis training part 10   exploit development basicsReversing & malware analysis training part 10   exploit development basics
Reversing & malware analysis training part 10 exploit development basics
 
Reversing & malware analysis training part 9 advanced malware analysis
Reversing & malware analysis training part 9   advanced malware analysisReversing & malware analysis training part 9   advanced malware analysis
Reversing & malware analysis training part 9 advanced malware analysis
 
Reversing & malware analysis training part 8 malware memory forensics
Reversing & malware analysis training part 8   malware memory forensicsReversing & malware analysis training part 8   malware memory forensics
Reversing & malware analysis training part 8 malware memory forensics
 
Reversing & malware analysis training part 7 unpacking upx
Reversing & malware analysis training part 7   unpacking upxReversing & malware analysis training part 7   unpacking upx
Reversing & malware analysis training part 7 unpacking upx
 
Reversing & malware analysis training part 6 practical reversing (i)
Reversing & malware analysis training part 6   practical reversing (i)Reversing & malware analysis training part 6   practical reversing (i)
Reversing & malware analysis training part 6 practical reversing (i)
 
Reversing & malware analysis training part 5 reverse engineering tools basics
Reversing & malware analysis training part 5   reverse engineering tools basics Reversing & malware analysis training part 5   reverse engineering tools basics
Reversing & malware analysis training part 5 reverse engineering tools basics
 
Reversing & malware analysis training part 3 windows pe file format basics
Reversing & malware analysis training part 3   windows pe file format basicsReversing & malware analysis training part 3   windows pe file format basics
Reversing & malware analysis training part 3 windows pe file format basics
 
Reversing & malware analysis training part 2 introduction to windows internals
Reversing & malware analysis training part 2   introduction to windows internalsReversing & malware analysis training part 2   introduction to windows internals
Reversing & malware analysis training part 2 introduction to windows internals
 
Reversing & malware analysis training part 1 lab setup guide
Reversing & malware analysis training part 1   lab setup guideReversing & malware analysis training part 1   lab setup guide
Reversing & malware analysis training part 1 lab setup guide
 
The apache software foundation
The apache software foundationThe apache software foundation
The apache software foundation
 

Kürzlich hochgeladen

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Kürzlich hochgeladen (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

Reversing & malware analysis training part 4 assembly programming basics

  • 2. Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions of any kind. Also the views/ideas/knowledge expressed here are solely of the trainer’s only and nothing to do with the company or the organization in which the trainer is currently working. However in no circumstances neither the trainer nor SecurityXploded is responsible for any damage or loss caused due to use or misuse of the information presented here. www.SecurityXploded.com
  • 3. Acknowledgement  Special thanks to null & Garage4Hackers community for their extended support and cooperation.  Thanks to all the Trainers who have devoted their precious time and countless hours to make it happen. www.SecurityXploded.com
  • 4. Reversing & Malware Analysis Training This presentation is part of our Reverse Engineering & Malware Analysis Training program. Currently it is delivered only during our local meet for FREE of cost. For complete details of this course, visit our Security Training page. www.SecurityXploded.com
  • 5. Who am I #1 Amit Malik (sometimes DouBle_Zer0,DZZ)  Member SecurityXploded  Security Researcher @ McAfee Labs  RE, Exploit Analysis/Development, Malware Analysis  Email: m.amit30@gmail.com www.SecurityXploded.com
  • 6. Who am I #2 Swapnil Pathak  Member SecurityXploded  Security Researcher @ McAfee Labs  RE, Malware Analysis, Network Security  Email: swapnilpathak101@gmail.com www.SecurityXploded.com
  • 7. Course Q&A  Keep yourself up to date with latest security news  http://www.securityphresh.com  For Q&A, join our mailing list.  http://groups.google.com/group/securityxploded www.SecurityXploded.com
  • 8. Presentation Outline  Intro to x86-32  AssemblyLanguage  Instructions  Stack Operations  Callingconventions  Demo www.SecurityXploded.com
  • 9. x86-32  32 bit instruction set architecturesbased on Intel 8086 CPU  Addressa linear address spaceup to 4GB  8, 32 bit General PurposeRegisters(GPR)  6,16 bit Segment Registers  EFLAGS and EIP register  ControlRegisters(CR0-CR4)(16 bits)  Memory ManagementRegistersDescriptorTableRegisters (GDTR, IDTR, LDTR)  Debug Registers ( DR0-DR7) www.SecurityXploded.com
  • 10. Registers Usage - RE  Register  StorageLocations.  Much fasteraccess compareto memory locations.  EAX: Accumulator, mostly storesreturn values fromfunctions(APIs)  EBX: Base index (for use with arrays)  ECX: Counter  EDX: Data/general  ESI: Sourceindex for string operations. www.SecurityXploded.com
  • 11. Registers Usage – RE Cont.  EDI: Destination index forstring operations.  ESP: Stack pointerfortop address of the stack.  EBP: Stack base pointerforholding theaddress of the current stack frame.  EIP: Instructionpointer.Holds the programcounter, thenext instruction address.  Segment registers:  Used to address particularsegments ofmemory ( code, data, stack ) !) CS: Code !!) SS: Stack !!!) ES: Extra !V) DS: Data V) FS, GS www.SecurityXploded.com
  • 12. Registers – 32 bit (X86) www.SecurityXploded.com
  • 13. (R/E)Flags Register  Bit field of states  Status Flags  Carrry (CF) : set when an arithmetic carry/borrow has been generated out of the MSB.  Zero (ZF) : set when an arithmetic operation result is zero and reset otherwise.  Sign (SF) : set when an arithmetic operation set the MSB i.e. the result value was negative.  Trap (TF ) : when set permits operation of processor in single-step. Mostly used by debuggers.  Interrupt (IF) : determines whether the CPU should handle maskable hardware interrupts.  Direction (DF) : determines the direction (left-to-right or right-to-left) of string processing.  Overflow (OF) : indicates arithmetic overflow. www.SecurityXploded.com
  • 14. Assembly Language  Low level programming language  Symbolicrepresentationof machinecodes, constants.  Assemblylanguageprogramconsist ofsequenceof process instructions and meta statements  Assemblertranslates themto executableinstructionsthat are loaded into memory and executed.  BasicStructure [label]: opcode operand1,operand2 opcode – mnemonicthat symbolizeinstructions  Example.  MOV AL, 61h => 1011000001100001 www.SecurityXploded.com
  • 15. Instructions ADD dst, src - Adds thevalues of src and dst and stores the result into dst. - For exampleADD EAX, 1 SUB dst, src - Subtractssrcvalue from dst and stores the result in dst. - For exampleSUB EAX, 1 CMPdst, src - Subtractssrcvalue from dst but does storethe result in dst - Mostlyused to set/reset decisionmaking bits in EFLAGS registersuch as ZF - For exampleCMP EAX, EBX www.SecurityXploded.com
  • 16. Instructions cont. MOV dst, src - Moves datafrom src (left operand)to destination(right operand) - For examplemov EDI, ESI Note: - Both operands cannotbe memory locations. - Both the operands must be of the same size LEAdst, src - Stands forLoad EffectiveAddress. - Computestheeffectiveaddress of src operand and stores it in dst operand. - For exampleLEA ECX,[EBX + 5] Note: - Generally bracketsdenotevalueat memory locations. - In case of LEA it does simplearithmeticand stores it in dst www.SecurityXploded.com
  • 17. Instructions cont. XOR dst, src - Performs a bitwiseexclusiveORoperation on the dst and src and stores the result in dst. - Each bit of the result is 1 if the correspondingbits ofthe operands are different, 0 if the correspondingbit are same Note: - When used with same register clears the contents ofthe register - Optimizedway to clear the register. Betterthan MOV EAX, 0 www.SecurityXploded.com
  • 18. Instructions cont. REP - Used with string operations - Repeats a string instructionuntil ECX (counterregister)valueis equal to zero. - For exampleREPMOVS byte ptr DS:[EDI], DS:[ESI] LOOP - Similarto loops in high level languages - Used to executesequenceof instructionsmultipletimes. - For example MOV ECX, 10 Test : INC EBX INC EAX LOOP Test www.SecurityXploded.com
  • 19. Instructions cont. TEST dst, src - Performs bitwiselogicaland between dst and src - UpdatestheZero flag bit of the EFLAGS register - Mostlyused to check if the return valueof the function is not zero - For exampleTEST EAX, EAX INT3h - Breakpointinstruction - Used by debuggersto stop execution ofthe programat particularinstruction www.SecurityXploded.com
  • 20. Instructions cont. CALLaddress - Performs two functions - Push address of the next instructionon stack (return address) - Jump to the address specifiedby the instruction - For exampleCALL dword ptr [EAX+4] RET - Transfers thecontrol to the address previously pushedon the stack by CALL instruction - Mostlydenotestheend of the function www.SecurityXploded.com
  • 21. Instructions cont. Jump instructions - Categorized as conditional and unconditional - Unconditionaljump instructions - JMP(Far Jump) – E9 – (Cross segments) - JMP( Short Jump ) – EB – (-127 to 128 bytes) - JMP( Near Jump ) – E9 – (in a segment) - For exampleJMPEAX - Conditional jump instructions - Jumps according to bit flags set in the EFLAGS register - JC, JNC, JZ, JNZ, JS, JNS, JO, JNO - UnsignedcomparisonsJA, JAE, JB, JBE - Signed comparisonsJG, JGE, JL, JLE - Usually followedby CMP instruction www.SecurityXploded.com
  • 22. Instructions cont. PUSH operand - Pushes operandon the stack - Decrementsthestack pointerregisterby operand size - For examplePUSH EAX POP operand - Stores thevalue pointedby the stack pointerin operand - Incrementsthestack pointerregisterby operand size - For examplePOPEAX Note: POP/PUSHEIPis an invalid instruction PUSHF, POPF www.SecurityXploded.com
  • 23. Calling Conventions  Describeshow thearguments are passed and values returned by functions.  Steps performed when a functionis called  Arguments are passed to the called function  Program execution is transferred to the address of the called function  Called function starts with lines of code that prepare stack and registers for use within the function.Also known as function prologue. ○ For e.g. push ebp mov ebp, esp or with enter instruction  Called function ends with lines of code that restore stack and registers set initially. Also known as function epilogue. ○ For e.g. mov esp, ebp pop ebp ret or with leave instruction  Passed arguments are removed from the stack, known as stack cleanup. Can be performed by both calling function or called function depending on the calling convention used. www.SecurityXploded.com
  • 24. Calling conventions cont.  __cdecl (C calling convention)  Arguments are passed from right to left and placed on the stack  Stack cleanup is performed by the caller  Return values are stored in EAX register  Standard calling convention used by C compilers  __stdcall(Standardcallingconvention)  Arguments are passed from right to left and placed on the stack  Stack cleanup is performed by the called function  Return values are stored in EAX register  Standard calling convention for Microsoft Win32 API  __fastcall(Fast calling convention)  Arguments passed are stored in registers for faster access  Thiscall  Arguments are passed from right to left and placed on the stack. this pointer placed in ECX - Standard calling convention for calling member functions of C++ classeswww.SecurityXploded.com
  • 25. Stack operations  Stack is a LIFO (Last In First Out) typedata structure  Stacks grows downward in memory, from highermemory address to lower memory address  PUSH decrement the stack pointer i.eESP  POPIncrement thestack pointer i.e ESP  Eachfunction has its own stack frame  Function prologuesetup thestack frame for each function  Local variableof a functionare storedinto its stack frame www.SecurityXploded.com
  • 28.  Each function creates its own stack.  Callerfunctionstack: knownas parent stack.  Called function stack:known as child stack. For e.g. main(){ ASMPseudo: sum(); _main: } 123: push ebp 124: mov ebp,esp 125: sub esp,val 126: call _sum 127: mov esp,ebp 128: pop ebp 129: ret * The parentand child notation is theinstructor notation, technically it shouldbecaller and callee stack frames. Stack #3 www.SecurityXploded.com
  • 32. DEMO (Source Code)  #include <stdio.h>  /*  Author:Amit Malik  http://www.securityxploded.com - Compile in Dev C++  */  int mysum(int,int);  int main()  {  int a,b,s;  a = 5;  b = 6;  s = mysum(a,b); // call mysum function  printf("sum is: %d",s);  getchar();  }  int mysum(int l, int m) // mysum function  {  int c;  c = l + m;  return c;  } www.SecurityXploded.com
  • 34. x86-64 Intro.  64 bit instruction set architecturesbased on Intel 8086 CPU  Addressa linear address spaceup to 16TB  16, 64 bit General PurposeRegisters(GPR)  6, 16 bit Segment Registers  RFLAGS and RIP register  ControlRegisters(CR0-CR4) and CR8 (16 bits)  Memory ManagementRegisters DescriptorTableRegisters(GDTR, IDTR, LDTR)size expanded to 10 bytes  Debug Registers ( DR0-DR7) www.SecurityXploded.com
  • 35. Reference  Complete Reference Guide for Reversing & Malware Analysis Training www.SecurityXploded.com