CSC 497/583 Advanced Topics in Computer Security

Slides:



Advertisements
Similar presentations
Calling sequence ESP.
Advertisements

COMP 2003: Assembly Language and Digital Logic
Procedures in more detail. CMPE12cGabriel Hugh Elkaim 2 Why use procedures? –Code reuse –More readable code –Less code Microprocessors (and assembly languages)
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Advanced topics in X86 assembly by Istvan Haller.
Review: Software Security David Brumley Carnegie Mellon University.
Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
Procedures in more detail. CMPE12cCyrus Bazeghi 2 Procedures Why use procedures? Reuse of code More readable Less code Microprocessors (and assembly languages)
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Accessing parameters from the stack and calling functions.
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
28/06/2015CMPUT Functions (2)  Function calling convention  Various conventions available  One is specified by CMPUT229  Recursive functions.
CS2422 Assembly Language & System Programming November 7, 2006.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Fall 2008CS 334: Computer SecuritySlide #1 Smashing The Stack A detailed look at buffer overflows as described in Smashing the Stack for Fun and Profit.
Linked Lists in MIPS Let’s see how singly linked lists are implemented in MIPS on MP2, we have a special type of doubly linked list Each node consists.
Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Procedures – Generating the Code Lecture 21 Mon, Apr 4, 2005.
CSC 221 Computer Organization and Assembly Language
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Functions/Methods in Assembly
Compiler Construction Code Generation Activation Records
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
1 Assembly Language: Function Calls Jennifer Rexford.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
Overview of Back-end for CComp Zhaopeng Li Software Security Lab. June 8, 2009.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Programming Model CS 333 Sam Houston State University Dr. Tim McGuire.
B1101 Call of Duty ENGR xD52 Eric VanWyk Fall 2013.
NASM ASSEMBLER & COMPILE WITH GCC 어셈러브 refered to ‘PC Assembly Language’ by Paul A. Carter
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Section 5: Procedures & Stacks
Programs – Calling Conventions
Assembly function call convention
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Computer Science 210 Computer Organization
C function call conventions and the stack
Segment Definition The CPU has several segment registers:
CS-401 Computer Architecture & Assembly Language Programming
Computer Architecture and Assembly Language
143A: Principles of Operating Systems Lecture 4: Calling conventions
Introduction to Compilers Tim Teitelbaum
Von Neumann model - Memory
Discussion Section – 11/3/2012
Machine-Level Programming 4 Procedures
Application Binary Interface (ABI)
Stack Frames and Advanced Procedures
Stack Frame Linkage.
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
Machine-Level Programming III: Procedures Sept 18, 2001
MIPS Procedure Calls CSE 378 – Section 3.
Understanding Program Address Space
EECE.3170 Microprocessor Systems Design I
Practical Session 4.
Von Neumann model - Memory
Multi-modules programming
Lecture 2 SCOPE – Local and Global variables
EECE.3170 Microprocessor Systems Design I
Miscellaneous Topics.
CSC 497/583 Advanced Topics in Computer Security
Computer Architecture and System Programming Laboratory
Runtime Stack Activation record for hanoi;
Presentation transcript:

CSC 497/583 Advanced Topics in Computer Security Class10 CSC 497/583 Advanced Topics in Computer Security Modern Malware Analysis Stack Frame (Review), Calling Convention, Dynamic Analysis Si Chen (schen@wcupa.edu)

Stack Frame

https://www.slideshare.net/saumilshah/how-functions-work-7776073

https://www.slideshare.net/saumilshah/how-functions-work-7776073

https://www.slideshare.net/saumilshah/how-functions-work-7776073

https://www.slideshare.net/saumilshah/how-functions-work-7776073

https://www.slideshare.net/saumilshah/how-functions-work-7776073

Stack Frame

StackFrame.exe

StackFrame.exe

StackFrame.exe

StackFrame.exe EBP 12FFC0 ESP 12FF7C

StackFrame.exe EBP ESP 12FF78

StackFrame.exe

StackFrame.exe Create space for ‘a’ and ‘b’  long  4 byte EBP ESP 12FF78 Create space for ‘a’ and ‘b’  long  4 byte

StackFrame.exe Create space for ‘a’ and ‘b’  long  4 byte EBP ESP 12FF78 Create space for ‘a’ and ‘b’  long  4 byte

StackFrame.exe 4 Byte memory space at address [EBP-4] Assembly C Type Conversion DWORD PTR SS:[EBP-4] *(DWORD*)(EBP-4) DWORD (4 byte) WORD PTR SS:[EBP-4] *(WORD*)(EBP-4) WORD (2 byte) BYTE PTR SS:[EBP-4] *(BYTE*)(EBP-4) 1 byte 4 Byte memory space at address [EBP-4]

StackFrame.exe

StackFrame.exe

StackFrame.exe

StackFrame.exe

StackFrame.exe

StackFrame.exe Clean Stack

StackFrame.exe Clean Stack

StackFrame.exe

StackFrame.exe Set EAX –> 0 Faster than MOV EAX,0

Save the return address Save local variable Stack Pass arguments Save the return address Save local variable

Local Variable Limited Register(s)  Store Local Variable in stack Use esp and ebp to define a stack frame for current function Use relative position of esp or ebp for retrieving and storing data e.g. mov eax, [esp+124] Very easy to do recursive call

Calling Convention

Two Questions Q: When a function finished, how to handle the parameter left in the stack. Q: When a function finished, how change the ESP value? A: We don’t care… A: ESP should be restored to the previous value

Standard C Calling Conventions Calling conventions are a standardized method for functions to be implemented and called by the machine. A calling convention specifies the method that a compiler sets up to access a subroutine. There are three major calling conventions that are used with the C language on 32-bit x86 processors: CDECL STDCALL, FASTCALL.

CDECL The C language, by default, uses the CDECL calling convention In the CDECL calling convention the following holds: Arguments are passed on the stack in Right-to-Left order, and return values are passed in eax. The calling function cleans the stack. This allows CDECL functions to have variable-length argument lists.

STDCALL The C language, by default, uses the CDECL calling convention In the CDECL calling convention the following holds: Arguments are passed on the stack in Right-to-Left order, and return values are passed in eax. The calling function cleans the stack. This allows CDECL functions to have variable-length argument lists.

STDCALL STDCALL, also known as "WINAPI" (and a few other names, depending on where you are reading it) is used almost exclusively by Microsoft as the standard calling convention for the Win32 API.  STDCALL passes arguments right-to-left, and returns the value in eax. The called function cleans the stack, unlike CDECL. This means that STDCALL doesn't allow variable-length argument lists.

STDCALL STDCALL, also known as "WINAPI" (and a few other names, depending on where you are reading it) is used almost exclusively by Microsoft as the standard calling convention for the Win32 API.  STDCALL passes arguments right-to-left, and returns the value in eax. The called function cleans the stack, unlike CDECL. This means that STDCALL doesn't allow variable-length argument lists. RET 8  RET + POP 8 Byte

FASTCALL The FASTCALL calling convention is not completely standard across all compilers, so it should be used with caution.  The calling function most frequently is responsible for cleaning the stack, if needed.

Dynamic Analysis: Let’s reverse helloword.exe

Dynamic Analysis: Let’s reverse myhack.dll

Q & A