Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.

Slides:



Advertisements
Similar presentations
Fred P. Baker CCIE, CCIP(security), CCSA, MCSE+I, MCSE(2000)
Advertisements

Operating Systems (CSCI2413) Lecture 2 Overview phones off (please)
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Operating System Security : David Phillips A Study of Windows Rootkits.
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
Countermeasures 0x610~0x Seokmyung Hong.
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
COSC 120 Computer Programming
UNIX Chapter 01 Overview of Operating Systems Mr. Mohammad A. Smirat.
16/13/2015 3:30 AM6/13/2015 3:30 AM6/13/2015 3:30 AMIntroduction to Software Development What is a computer? A computer system contains: Central Processing.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
1 DOS with Windows 3.1 and 3.11 Operating Environments n Designed to allow applications to have a graphical interface DOS runs in the background as the.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
Dennis  Application Security Specialist  WhiteHat Security  Full-Time Student  University of Houston – Main Campus ▪ Computer.
Chapter Introduction to Computers and Programming 1.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
UNIX SVR4 COSC513 Zhaohui Chen Jiefei Huang. UNIX SVR4 UNIX system V release 4 is a major new release of the UNIX operating system, developed by AT&T.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Port Scanning 0x470~0x480 Presenter SangDuk Seo 1.
CIS 450 – Network Security Chapter 16 – Covering the Tracks.
CS 444 Introduction to Operating Systems
Fundamental Programming: Fundamental Programming K.Chinnasarn, Ph.D.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
CS162B: Pipes Jacob T. Chan. Pipes  These allow output of one process to be the input of another process  One of the oldest and most basic forms of.
Exploitation Of Windows Buffer Overflows. What is a Buffer Overflow A buffer overflow is when memory is copied to a location that is outside of its allocated.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Shellcode Development -Femi Oloyede -Pallavi Murudkar.
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
OS Labs 2/25/08 Frans Kaashoek MIT
JMU GenCyber Boot Camp Summer, “Canned” Exploits For many known vulnerabilities attackers do not have to write their own exploit code Many repositories.
Introduction to InfoSec – Recitation 3 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (infosec15 at modprobe.net)
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
ROP Exploit. ROP Return Oriented Programming (ROP): is a hacking exploit technique where you exploit buffer overflow to inject a chain of gadgets. Each.
Radare Easing binary analysis for fun and profit.
CHAPTER 4 Methodology.
Penetration Testing Armitage: Metasploit GUI and Machine-Gun Style Attack CIS 6395, Incident Response Technologies Fall 2016, Dr. Cliff Zou
Protection of System Resources
CASE STUDY 1: Linux and Android
Operating System Structure
Metasploit Project For this exploit I will be using the following strategy Create backdoor exe file Upload file to website Have victim computer download.
Chapter 2: The Linux System Part 2
Chapter 2: System Structures
Web Application Penetration Testing ‘17
Metasploit Analysis Report Overview
System Calls David Ferry CSCI 3500 – Operating Systems
Chapter 2: Operating-System Structures
Operating Systems Lecture 3.
Week 2: Buffer Overflow Part 2.
Outline Chapter 2 (cont) OS Design OS structure
Cyber Operation and Penetration Testing Armitage: Metasploit GUI and Machine-Gun Style Attack Cliff Zou University of Central Florida.
System calls….. C-program->POSIX call
System Calls System calls are the user API to the OS
Chapter-1 Computer is an advanced electronic device that takes raw data as an input from the user and processes it under the control of a set of instructions.
Following Malware Execution in IDA
Chapter 2: Operating-System Structures
Penetration Testing & Network Defense
Penetration Testing & Network Defense
Reverse Shell.
SHELLSHOCK ATTACK.
Presentation transcript:

Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail

All materials is licensed under a Creative Commons “Share Alike” license. 2

# whoami Ali Al-Shemery Ph.D., MS.c., and BS.c., Jordan More than 14 years of Technical Background (mainly Linux/Unix and Infosec) Technical Instructor for more than 10 years (Infosec, and Linux Courses) Hold more than 15 well known Technical Certificates Infosec & Linux are my main Interests 3

Software Exploitation

Shellcode /* the Aleph One shellcode */ "\x31\xc0\x31\xdb\xb0\x17\xcd\x80\xeb\x1f\x5e\x89" "\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb" "\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh";

Outline – Part 3 Introduction System Calls Shellcode Basics Shellcode Types Considerations Useful Shellcode Tools 6

Shellcode? AKA bytecode Small piece of code used as the payload in the exploitation of a software vulnerability. Problems of writing shellcodes: – Not easy to write – Architecture and OS dependent – Must remove all string-delimiting characters 7

System Calls Kernel trap calls used by user-space programs to access kernel-space functions. Linux: – INT \x80, Sysenter, etc Windows – INT 0x2e, Sysenter, DLL(s), API(s), etc System Call # stored in EAX. 1st ARG in EBX, 2 nd in ECX, and so on. 8

Shellcode Basics Spawning the process – Linux/Unix:execve – Windows:CreateProcess How child process deals with input and output is very important File descriptors (regardless of OS): – 0 for Standard Input (stdin) – 1 for Standard Output (stdout) – 2 for Standard Error (stderr) 9

Shellcode Types Port Binding Reverse Find Socket Command Execution Code File Transfer Multistage System Call Proxy Process Injection Kernel Space 10

Port Binding Shellcode AKA “bind shell” Why/When to use this type of SC? What it does: – Create TCP socket – Bind socket to port (hardcoded and specified by the attacker) – Make socket Listen – Dup listening socket onto stdin, stdout, and stderr – Spawn command shell (bash, cmd.exe, etc) Attacker connects to that port to get control Problems: – Firewalls – Not Invisible – Can’t distinguish between connections made to it 11

Port Binding Shellcode 12

Reverse Shellcode AKA ‘callback shellcode”, solves bind shell problems Why connect to the target, were we can make the target connect to us? What it does: – Create TCP socket – Make socket connect back to the attacker on IP+Port (hardcoded and specified by the attacker) – Connect to the IP and port – Dup the socket onto stdin, stdout, and stderr – Spawn command shell (bash, cmd.exe, etc) Problems – Outbound Filtering – Attacker must be listening on the specified port – Attacker behind NAT – Target behind some proxy – Not invisible too 13

Reverse Shellcode 14

Find Socket Shellcode Search for the file descriptor that represents attackers connection. – POSIX (file descriptors) – Windows (File Handlers) Query each descriptor to find which is remotely connected to the attackers computer. Hardcode the outbound port into the shellcode, makes find much easier on target. No new network connection (hard to detect)! 15

Find Socket Shellcode - 2 Steps: – Find file descriptor for the network connection. – Duplicate the socket onto stdin, stdout, and stderr. – Spawn a new command shell process (will use original socket for I/O). Problem: – Attacker behind NAT device, can’t control the outbound port from which his connection originated (P.S. won’t know what file descriptor is used for his connection!) 16

Command Execution Shellcode Why create a network session when all needed to do is run a command? – ssh-copy-id to target – Adding/modifying a user account – Modify configuration file Steps: – Assemble command name – Assemble arguments required (if any!) – Invoke system call to execute the command Often very small 17

File Transfer Shellcode Very simple, all needed is to upload a file to the target Steps: – Open new file on target – Read data from the network connection, and write it to the opened file (Note: connection obtained using previous discussed network shellcodes) – Repeat RW until file successfully transferred. – Close the open file Can be combined with a CE Shellcode 18

Multistage Shellcode Vulnerability contains un-sufficient space for injecting shellcode Consist of 2 or more shellcode stages Steps: – Stage1: read more shellcode, pass control to Stage2 shellcode – Stage2: accomplish the functionality required 19

System Call Proxy Shellcode AKA Syscall Proxy Technique first introduced by Maximiliano Caceres (CORE Impact creators) which can provide a real remote interface to the target's kernel Local process running has no idea it is running remotely! Syscall proxy payload can continue to run in the context of the exploited process. 20

System Call Proxy – Cont. Use many tools without installing anything on the target machine Memory resident Kernel Interface Request Local, Execute Remote Remote Debugging Others? use your own imagination! Means What? 21

Process Injection Shellcode Loading libraries of code running under a separate thread of execution within the context of an existing process on the target. Host process can be: – Process exploited. – Migrate to a complete different process. Injected library might never get written to the hard drive and harness in memory (hard even for forensics to discover)! Ex: Metasploit’s Meterpreter (next week). 22

Important Stuff Disassemble – Maybe running a backdoor ! Encoding – Bad char(s) is chasing you! Others? – Please add … 23

Assignments – Choose 2 What is a Kernel Space Shellcode? Can we categories Metasploit’s Meterpreter as a Multi-Stage Shellcode? How can we debug a shellcode? 24

Debugging a Shellcode char shellcode[] = “Insert shellcode/bytecode here"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); } 25

Useful Tools GCC: gcc -c shellcode.s Objdump: objdump -d shellcode.o LD: ld binary.o -o binary NASM: nasm -f elf64 shellcode.asm strace: trace system calls and signals Corelan’s pveWritebin.pl and pveReadbin.pl BETA3 --decode Ndisasm Immunity Debugger GDB 26

Summary What Shellcodes are, and problems that face shellcode developers, Types of Shellcodes, Why it’s important to disassemble a shellcode you didn’t write, Why sometimes you need to encode your shellcode, List of useful tools related to shellcode development. 27

References (1) Papers/Presentations/Links: – ShellCode, – Introduction to win32 shellcoding, Corelan, part-9-introduction-to-win32-shellcodeing/ part-9-introduction-to-win32-shellcodeing/ – Hacking/Shellcode/Alphanumeric/x64 printable opcodes, 64_printable_opcodes 64_printable_opcodes – Learning Assembly Through Writing Shellcode, through-writing-shellcode/ through-writing-shellcode/ – Shellcoding for Linux and Windows Tutorial, – Unix Assembly Codes Development, – Win32 Assembly Components,

References (2) Papers/Presentations/Links: – 64-bit Linux Shellcode, linux-shellcode/ linux-shellcode/ – Writing shellcode for Linux and *BSD, panic.it/security/shellcode/index.htmlhttp:// panic.it/security/shellcode/index.html – Understanding Windows’s Shellcode (Matt Miller’s, aka skape) – Metasploit’s Meterpreter (Matt Miller, aka skape) – Syscall Proxying fun and applications, uberwall.org – X86 Opcode and Instruction Reference, – Shellcode: the assembly cocktail, by Samy Bahra,

References (3) Books: – Grayhat Hacking: The Ethical Hacker’s Handbook, 3 rd Edition – The Shellcoders Handbook, – The Art of Exploitation, 2 nd Edition, Shellcode Repositories: – Exploit-DB: – Shell Storm: Tools: – BETA3 - Multi-format shellcode encoding tool, – X86 Opcode and Instruction Reference, – bin2shell, content/uploads/2012/06/bin2shell.tar.gz 30