Hello ASM World: A Painless and Contextual Introduction to x86 Assembly rogueclown DerbyCon 3.0 September 28, 2013.

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

COMP 2003: Assembly Language and Digital Logic
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Introduction to X86 assembly by Istvan Haller
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Practical Session 8 Computer Architecture and Assembly Language.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
6.828: PC hardware and x86 Frans Kaashoek
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
CET 3510 Microcomputer Systems Tech. Lecture 2 Professor: Dr. José M. Reyes Álamo.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
1 ICS 51 Introductory Computer Organization Fall 2009.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
CNIT 127: Exploit Development Ch 1: Before you begin.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Functions/Methods in Assembly
Compiler Construction Code Generation Activation Records
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
Practical Session 8. Position Independent Code- self sufficiency of combining program Position Independent Code (PIC) program has everything it needs.
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.
Precept 7: Introduction to IA-32 Assembly Language Programming
CSC 221 Computer Organization and Assembly Language
Instruction Set Architecture
Assembly language.
Credits and Disclaimers
Assembly Lab 3.
Data Transfers, Addressing, and Arithmetic
Homework Reading Labs PAL, pp
Exploiting & Defense Day 2 Recap
Aaron Miller David Cohen Spring 2011
Introduction to Compilers Tim Teitelbaum
Assembly IA-32.
Assembly Language Programming Part 2
High-Level Language Interface
Computer Architecture and Assembly Language
Summary by - Bo Zhang and Shuang Guo [Date: 03/31/2014]
BIC 10503: COMPUTER ARCHITECTURE
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Fundamentals of Computer Organisation & Architecture
MIPS Procedure Calls CSE 378 – Section 3.
Practical Session 4.
Homework Reading Machine Projects Labs PAL, pp
Multi-modules programming
Week 2: Buffer Overflow Part 1.
Computer Architecture CST 250
X86 Assembly Review.
CSC 497/583 Advanced Topics in Computer Security
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

Hello ASM World: A Painless and Contextual Introduction to x86 Assembly rogueclown DerbyCon 3.0 September 28, 2013

who? security consultant by vocation mess around with computers, code, CTFs by avocation frustrated when things feel like a black box

what is assembly language? not exactly machine language…but close – instructions: mnemonics for machine operations – normally a one-to-one correlation between ASM instruction and machine instruction varies by processor – today, we will be discussing 32-bit x86

why learn assembly language? some infosec disciplines require it curious about lower-level details of memory or interfacing with an operating system it’s fun and challenging!

how does assembly language work?

hello memory what parts of computer memory does assembly language commonly access? how does assembly language access those parts of computer memory?

where is this memory? what one “normally” thinks of as memory – RAM – virtual memory CPU – registers

computer memory layout heap – global variables, usually allocated at compile-time – envision a bookshelf…that won’t let you push books together when you take one out stack – local, contextual variables – envision a card game discard pile – you will use this when coding ASM. a lot.

registers memory located on the CPU registers are awesome because they are fast. registers are a pain because they are tiny.

registers general purpose registers – alphabet soup eax, ebx, ecx, edx can address in parts: ax, ah, al – stack and base pointers esp ebp – index registers esi, edi

registers instruction pointer – eip – records the next instruction for the program to follow other registers – eflags – segment registers

instructions mov – moves a value to a register – can either specify a value, or specify a register where a value resides syntax in assembly – Intel syntax: mov ebx, 0xfee1dead – AT&T syntax: mov $0xfee1dead, %eax

instructions interrupt – int 0x80 – int 0x3 system calls – how a program interacts with the kernel of the OS

instructions mathematical instructions – add, sub, mul, div mov eax, 10 cdq; edx is now 0 div 3; eax is now 3, edx is now 1 – dec, inc – useful for looping mov ecx, 3 dec ecx; ecx is now 2

jumps jge, jg, jle, jl – work with a compare (cmp) instruction jz, jnz, js, jns – check zero flag or sign flag for jump

instructions stack operations: push and pop mov eax, 10 push eax; 10 on top of stack inc eax; eax is now 11 push eax; 11 on top of stack pop ebx; ebx is now 11 pop ecx; ecx is now 10

instructions function access instructions – call places the address of the next instruction on top of the stack moves execution to identified function – ret returns to the memory address on top of the stack designed to work in tandem with the “call” instruction…but we’re hackers, yes?

sections of ASM code.data – constant variables initialized at compile time.bss – declaration of variables that may are set of changed during runtime.text – executable instructions

instructions: how do they work?

putting it together time to take a bit of C code, and reimplement it in assembly language!

where does shellcode come in?

what is shellcode? instructions injected into a running process lacks some of the luxuries of writing a stand-alone program – no laying out nice memory segments in a.bss or.data section – basically, just one big.text section

a first stab at shellcode… this is going to look mostly familiar, except for how data is handled.

why did it fail? bad characters – shellcode is often passed to an application as a string. – if a character makes a string act funny, you may not want it in your shellcode 0x00, 0x0a, 0x0d, etc. – use an encoder, or do it yourself

try that shellcode again…

where can i learn more about assembly language?

suggested resources dead trees – “Hacking: The Art of Exploitation” by Jon Erickson – “Practical Malware Analysis” by Michael Sikorski and Andrew Honig – “Gray Hat Python” by Justin Seitz

suggested resources the series of tubes – – quick and dirty opcode reference – – Netwide Assembler documentation system calls – Linux: /usr/include/asm/unistd.h man 2 $syscall – Windows: %28vs.85%29 – Windows API reference

how to find me IRC: #derbycon, #misec, or #burbsec on Freenode or, just wave me down at the con