introduction to cyber security - tau · o disassemble x86 binary code into human readable format o...

20
Introduction to Information Security מרצים: Dr. Eran Tromer: [email protected] מתרגלים: Itamar Gilad ([email protected]) Nir Krakowski ([email protected])

Upload: others

Post on 07-Jul-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Introduction to Information

Security :מרצים

Dr. Eran Tromer: [email protected] :מתרגלים

Itamar Gilad ([email protected])

Nir Krakowski ([email protected])

Page 2: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Today • Reverse Engineering 101

• IDA (!)

• Binary patching 101

• More tools

Page 3: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Reverse Engineering • What does the following code do:

o LEA EDX, [address to “Hello, world!”]

oMOV ECX, 12

MYLOOP:

o PUSH EDX

oCALL printf

oADD ESP, 4

o LOOP MYLOOP

Page 4: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Reverse Engineering • What is it?

o Using the binary to recreate any knowledge

needed

• Why?

o Recreating lost platforms (ReactOS)

o ‘Secret’ algorithms (Encryption, trade secrets,

etc.)

o Hidden features (and hidden backdoors)

o Internal structures & implementation details

o Bugs / Vulnerabilities that only exist in the binary

o you name it!

Page 5: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

So, what’s the problem? o Compiling is like a one-way function.

o Information is lost, and we *often* loose access

to –

• Variable and function names

• Comments

o What do we still have -

• Import and export names (relations between

modules)

• Structure of parameters to functions.

• Starting point

• Hard-coded strings

• Constants

Page 6: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

RE Process • Our objectives –

o Find the most interesting piece of code in the least amount

of time

o Understand what it does and how

o Find weaknesses and figure out how to exploit them

• Use leads –

o Strings, UI

o Dynamic debugging, breakpoints.

o Library and system functions

• Interpret the assembled code by using intelligent guesses –

o Context-based

o Code is written by people using regular code conventions

o Code is written in an upper level language, and compilers

are usually pretty predictable

Page 7: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

IDA • The Interactive Dis-Assembler (IDA) is the most popular

reverse engineering tool o Version 5.0 is free-ware and that is what we’ll use.

• IDA does several things automatically: o Disassemble x86 binary code into human readable format

o Identifies ELF headers (executable file formats)

o Signature based recognition for library functions and compiler tricks

o Creates code graph by basic blocks

o Code and data xrefs (references to memory addresses, functions)

• Provides a good environment for research: o Adding comments (‘;’)

o Renaming labels: code blocks, variables, function names, structures. (‘n’)

o Change interpretation of binary data (code->data, data->code, data type change, etc.)

https://www.hex-rays.com/products/ida/support/freefiles/IDA_Pro_Shortcuts.pdf

Page 8: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

IDA Options

Page 9: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

IDA Demo • [Hello World]

Page 10: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

IDA Demo • [re2]

Page 11: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Binary patching • What?

o Changing instructions/data/metadata in the “production”

binary

• Why? o You lost the source code

o You never had the source code

o Small changes that would be easier to test on their own

o Hot patching

o And many more

Page 12: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Binary patching example int verify_login(char * username, char * password)

{

if ((0 == strcmp(username, “root”)) &&

(0 == strcmp(password, “my_pass”)) {

return 0;

}

else {

return 1;

}

}

Page 13: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Patch Layout

Patch area (NOPs)

Function body

Function prolog

Function Epilog

Page 14: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Execution Layout

Patch area (CODE)

Function body

Function prolog

Function Epilog

Page 15: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Patch Layout

Patch area (NOPs)

Function body

Function prolog

Function Epilog

Divert execution around patch area

Page 16: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Patch Layout

Patch area (NOPs)

Function body

Function prolog

Function Epilog

Jump into patch area

Page 17: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Patch Layout

Patch area (NOPs)

Function body

Function prolog

Function Epilog

Jump back into original code

Page 18: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

Patch Layout

Patch area (CODE)

Function body

Function prolog

Function Epilog

Page 19: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

New tools! va_to_offset.py – A tool to map a virtual address (as

you see in IDA) to a file offset

patch_util_gcc.py – A script that lets you patch a

binary by using simple text files with (bare) assembly

instructions

Page 20: Introduction to Cyber Security - TAU · o Disassemble x86 binary code into human readable format o Identifies ELF headers (executable file formats) o Signature based recognition for

This week’s exercise • First reverse engineering task

• First binary patching task

• It isn’t hard – but please start early and

contact us if you have any trouble with the

setup