Custom Penetration Testing



Similar documents
Bypassing Memory Protections: The Future of Exploitation

ASL IT SECURITY XTREME XPLOIT DEVELOPMENT

Format string exploitation on windows Using Immunity Debugger / Python. By Abysssec Inc

Bypassing Browser Memory Protections in Windows Vista

SECURITY B-SIDES: ATLANTA STRATEGIC PENETRATION TESTING. Presented by: Dave Kennedy Eric Smith

Vulnerability Assessment and Penetration Testing

Automated Penetration Testing with the Metasploit Framework. NEO Information Security Forum March 19, 2008

Penetration Testing with Kali Linux

Hotpatching and the Rise of Third-Party Patches

Hacking your perimeter. Social-Engineering. Not everyone needs to use zero. David Kennedy (ReL1K) Twitter: Dave_ReL1K

風 水. Heap Feng Shui in JavaScript. Alexander Sotirov.

Reverse Engineering and Computer Security

The Advantages of Block-Based Protocol Analysis for Security Testing

Learn Ethical Hacking, Become a Pentester

Bug hunting. Vulnerability finding methods in Windows 32 environments compared. FX of Phenoelit

Defense in Depth: Protecting Against Zero-Day Attacks

WHITEPAPER. Nessus Exploit Integration

Penetration Testing. What Is a Penetration Testing?

Aiming at Higher Network Security Levels Through Extensive PENETRATION TESTING. Anestis Bechtsoudis. abechtsoudis (at) ieee.

PTSv2 in pills: The Best First for Beginners who want to become Penetration Testers. Self-paced, online, flexible access

Make a folder named Lab3. We will be using Unix redirection commands to create several output files in that folder.

Linux exploit development part 2 (rev 2) - Real app demo (part 2)

Peach Fuzzer Platform

90% of data breaches are caused by software vulnerabilities.

Integrating Tools Into the SDLC

Using fuzzing to detect security vulnerabilities

Attacking Host Intrusion Prevention Systems. Eugene Tsyrklevich

Modern Binary Exploitation Course Syllabus

ASL IT Security Advanced Web Exploitation Kung Fu V2.0

SY system so that an unauthorized individual can take over an authorized session, or to disrupt service to authorized users.

Ivan Medvedev Principal Security Development Lead Microsoft Corporation

0days: How hacking really works. V 1.0 Jan 29, 2005 Dave Aitel dave@immunitysec.com

ERNW Newsletter 51 / September 2015

Web Application Security

MWR InfoSecurity Advisory. Interwoven Worksite ActiveX Control Remote Code Execution. 10 th March Contents

Turn the Page: Why now is the time to migrate off Windows Server 2003

Stop that Big Hack Attack Protecting Your Network from Hackers.

Exploiting nginx chunked overflow bug, the undisclosed attack vector

Web Application Threats and Vulnerabilities Web Server Hacking and Web Application Vulnerability

Penetration Testing Using The Kill Chain Methodology

FIREWALLS & NETWORK SECURITY with Intrusion Detection and VPNs, 2 nd ed. Chapter 4 Finding Network Vulnerabilities

Tools and Techniques to automate the discovery of Zero Day Vulnerabilities. A.K.A Fuzzing 101

North Dakota 2013 IT Security Audit Vulnerability Assessment & Penetration Test Project Briefing

Sample Report. Security Test Plan. Prepared by Security Innovation

Network Penetration Testing and Ethical Hacking Scanning/Penetration Testing. SANS Security Sans Mentor: Daryl Fallin

Eugene Tsyrklevich. Ozone HIPS: Unbreakable Windows

Testing for Security

Advanced IBM AIX Heap Exploitation. Tim Shelton V.P. Research & Development HAWK Network Defense, Inc. tshelton@hawkdefense.com

Intrusion Detection Systems (IDS)

INTRODUCTION: PENETRATION TEST A BUSINESS PERSPECTIVE:

The Nexpose Expert System

Web Application Security

Networks and Security Lab. Network Forensics

Implementing and testing tftp

Firewalls and Software Updates

Computer Security: Principles and Practice

HackSim: An Automation of Penetration Testing for Remote Buffer Overflow Vulnerabilities

Integrated Network Vulnerability Scanning & Penetration Testing SAINTcorporation.com

SAST, DAST and Vulnerability Assessments, = 4

Network Working Group Request for Comments: 840 April Official Protocols

Thick Client Application Security

Professional Penetration Testing Techniques and Vulnerability Assessment ...

Certified Ethical Hacker (CEH) Ethical Hacking & Counter Measures Course 9962; 5 Days, Instructor-Led

Exploiting Transparent User Identification Systems

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

Developing ASP.NET MVC 4 Web Applications MOC 20486

Security & Exploitation

Writing Exploits III

Ethical Hacking and Attack Tools

Software Vulnerabilities

Google Apps Engine. G-Jacking AppEngine-based applications. Presented 30/05/2014. For HITB 2014 By Nicolas Collignon and Samir Megueddem

Metasploit Beginners

Database's Security Paradise. Joxean Koret

Unix Security Technologies. Pete Markowsky <peterm[at] ccs.neu.edu>

What is Web Security? Motivation

NEXPOSE ENTERPRISE METASPLOIT PRO. Effective Vulnerability Management and validation. March 2015

Threat Advisory: Trivial File Transfer Protocol (TFTP) Reflection DDoS

The purpose of this report is to educate our prospective clients about capabilities of Hackers Locked.

Bypassing Windows Hardware-enforced Data Execution Prevention

Telecom Testing and Security Certification. A.K.MITTAL DDG (TTSC) Department of Telecommunication Ministry of Communication & IT

HoneyBOT User Guide A Windows based honeypot solution

Jonathan Worthington Scarborough Linux User Group

telnetd exploit FreeBSD Telnetd Remote Exploit Für Compass Security AG Öffentliche Version 1.0 Januar 2012

FRONT FLYLEAF PAGE. This page has been intentionally left blank

Project 4: IP over DNS Due: 11:59 PM, Dec 14, 2015

Source Code Review Using Static Analysis Tools

Port Scanning. Objectives. Introduction: Port Scanning. 1. Introduce the techniques of port scanning. 2. Use port scanning audit tools such as Nmap.

Chapter 3.2 C++, Java, and Scripting Languages. The major programming languages used in game development.

Why should I care about PDF application security?

Computer Forensics Training - Digital Forensics and Electronic Discovery (Mile2)

Software Vulnerability Exploitation Trends. Exploring the impact of software mitigations on patterns of vulnerability exploitation

Secure Web Application Coding Team Introductory Meeting December 1, :00 2:00PM Bits & Pieces Room, Sansom West Room 306 Agenda

Security-as-a-Service (Sec-aaS) Framework. Service Introduction

Transcription:

Custom Penetration Testing Compromising a Vulnerability through Discovery and Custom Exploitation Stephen Sims Advanced Penetration Testing - 2009 SANS 1

Objectives Penetration Testing Precompiled Tools Targeting TFTP Testing a TFTP Server for Bugs Discovering the Bug Exploiting the TFTP Server Advanced Concepts Advanced Penetration Testing - 2009 SANS 2

What is Penetration Testing? Process of testing a target environment for weaknesses More thorough than vulnerability scanning alone Validates findings by exploiting flaws Allows you to think like an attacker Various levels of interaction/depth Advanced Penetration Testing - 2009 SANS 3

Types of Penetration Testing Black-Box Penetration Testing No access to source code No access provided to OS, architecture, etc More like an outsider attack scenario More time consuming Crystal-Box Penetration Testing Tester given source code, system & network architecture and/or privileged system access More thorough than black-box testing Cost effective Advanced Penetration Testing - 2009 SANS 4

Precompiled Tools Pros Can quickly be used Customer support Broad user community Often allow custom scripts or modules Cons Limited in scope Only discover and test known vulnerabilities Skilled attackers are not relying solely on them Precompiled tools offer a sense of complacency Do not perform code coverage or do deep fuzzing Advanced Penetration Testing - 2009 SANS 5

Targeting General Steps 1. Determine Target Application and Operating System 2. Obtain a Copy of the Application 3. Analyze RFC and Communications Protocols 4. Discover and Record a Crash Condition 5. Analyze Crash Condition for Exploitation Opportunities Advanced Penetration Testing - 2009 SANS 6

1) Determine Target Application and Operating System What application/service are you analyzing? What OS is it available for? Which one(s) are you interested in? What services does the application start up? There may be several Scanning may help Analyze documentation and code if possible Are the services proprietary or standards-based? Proprietary often offer a lot of new opportunities Advanced Penetration Testing - 2009 SANS 7

2) Obtain a Copy of the Application Create a lab environment and install the application Use the OS you are targeting Utilize Virtual Machines Create snapshots prior to installation Install monitoring tools Attempt to obtain the source code Code analysis is often more complex than behavioral analysis, but valuable Advanced Penetration Testing - 2009 SANS 8

3) Analyze RFC and Communications Protocols Is documentation available? Programmers should follow RFC s Search RFC for potential options and fields that may contain opportunities to cause a fault Understand each aspect of the protocols used by the application and relative behavior Is architectural documentation available? Advanced Penetration Testing - 2009 SANS 9

4) Discover and Record a Crash Condition Are you properly monitoring? Sniffers to record packets sent to the application Wireshark/Tshark, tcpdump, etc Packets can be recorded and replayed Debuggers to record application behavior while receiving/handling data OllyDbg, Immunity Debugger, WinDbg OS monitoring tools to monitor health ProcMon, RegMon, FileMon, RegShot, etc The condition must be repeatable Advanced Penetration Testing - 2009 SANS 10

5) Analyze Crash Condition for Exploitation Opportunities What is happening during the crash? Analyze the status of each register Are registers holding or pointing to strange values? e.g. 0x41414141 if inputting A s Is the Return Pointer or SEH chain being overwritten? Analyze the stack segment and monitor ESP/EBP Are heap pointers being overwritten? Analyze dynamic memory allocations and behavior There s way more to analyze, but this is a start! Advanced Penetration Testing - 2009 SANS 11

Targeting (2) Our goal is to discover and exploit a Windows Program vulnerability! The techniques we ll cover is applicable with any target or service We re targeting a TFTP service Must understand how the protocol works Developers should follow RFC s We can leverage the RFC as well Could use fuzzing to automate bug discovery Advanced Penetration Testing - 2009 SANS 12

Our TFTP Target Quick TFTP Server Pro Version 2.1 Vulnerable to a stack-based buffer overflow Can exploit by overwriting the Structured Exception Handling (SEH) chain Allows for DoS or code execution as System TFTP Server Published by TallSoft Vulnerability discovered in 2008 by Mati Aharoni of Offensive Security Advanced Penetration Testing - 2009 SANS 13

TFTP Trivial File Transfer Protocol (TFTP) Simple protocol for transferring files over a network Clear-text protocol using UDP port 69 Used for transferring files by network devices, VOIP phones and other client-server programs Advanced Penetration Testing - 2009 SANS 14

TFTP Behavior Connection request is combined with either a read or write request Blocks of data are sent in a fixed 512 byte size Each block must be acknowledged for error control A block less than 512 bytes indicates the end of the stream Advanced Penetration Testing - 2009 SANS 15

TFTP Behavior (2) The first two bytes of a TFTP header indicates the request type and format \x00\x01 indicates a read request \x00\x02 indicates a write request \x00\x03 indicates the data block \x00\x04 is an acknowledgement \x00\x05 indicates an error \x00\x06 is an optional acknowledgement Advanced Penetration Testing - 2009 SANS 16

TFTP Behavior (3) Read and Write request format: \x00\x01 for read \x00\x02 for write File Name Null byte - \x00 Mode Binary, ASCII or Mail Null byte - \x00 Example Request Type File Name Null Mode Null Read \x00\x01 file1.txt 0 Octet 0 Advanced Penetration Testing - 2009 SANS 17

Hacking Quick TFTP Server Quick TFTP Server Version 2.1 Install tftpserver_setup.exe onto a Windows XP Virtual Machine Use the TFTP information just covered to help with the investigation Attempt to crash the TFTP server while running in a debugger Create a custom script to start the testing Validate findings Attempt code execution Advanced Penetration Testing - 2009 SANS 18

Tools We Need Programming/Scripting Language Python, Perl, Ruby, C Debugger and Disassembler OllyDbg, Immunity Debugger, IDAPro Shellcode Metasploit, Milw0rm, Custom An open mind! Knowledge of OS controls, Opcodes, Tricks Advanced Penetration Testing - 2009 SANS 19

Python Object-oriented, High-level Programming Language Very Intuitive Very Modular No Manual Compilation Plays well with other languages C, C++, Jython, IronPython (.NET) Good Debugging Advanced Penetration Testing - 2009 SANS 20

Tool: OllyDbg Software Debugger for Windows Author: Oleh Yuschuk Shareware! Binary Code Analysis Register Contents, Procedures, API Calls, Patching, memory searching and more! Advanced Penetration Testing - 2009 SANS 21

Hacking TFTP Hint #1 Consider the format of TFTP requests for your script We covered the order a few slides ago Read & Write requests are often the easiest to attack as they have variable fields They start with \x00\x01 & \x00\x02 The header format must be correct to trigger a valid response Command line scripting not always the best option You may want to write a script Advanced Penetration Testing - 2009 SANS 22

Hacking TFTP Hint #2 Where could a buffer overflow condition exist? Try the request type field, file name and/or the mode Don t forget the nulls to terminate! Make sure you re watching the right thread in OllyDbg Processes have multiple threads on Windows Advanced Penetration Testing - 2009 SANS 23

Hacking TFTP Hint #3 The easiest way is to use Python or Perl to open a socket and send your script import socket import sys target = IP ADDRESS #Enter the right IP here port = 69 #Port for TFTP s = socket.socket(socket.af_inet, socket.sock_dgram) cmd = "A"*10 #Enter the number of A's to send data = "\x00\x01"+ cmd #Modify this line to format your packet s.sendto(data, (target, port)) Advanced Penetration Testing - 2009 SANS 24

Quick TFTP Walk-Through Start Quick TFTP Server with Olly Ignore entry point messages Press F9 once loaded Click OK on the demo pop-up Advanced Penetration Testing - 2009 SANS 25

Quick TFTP Walk-Through (2) This may be possible via command line, but We need a script! Don t forget the formatting of TFTP read and write requests: Request Type File Name Null Mode Null Read \x00\x01 file1.txt 0 Octet 0 The overflow is in the mode section! Advanced Penetration Testing - 2009 SANS 26

Quick TFTP Walk-Through (3) Write a python script that connects to the TFTP server with 1000 A s No Crash in Olly Advanced Penetration Testing - 2009 SANS 27

Quick TFTP Walk-Through (4) 1060 A s EIP is 41414141 Success! Olly has paused Advanced Penetration Testing - 2009 SANS 28

Quick TFTP Walk-Through (5) What are we overwriting? We overwrote the SEH Chain! Lets do some math to see where the overflow is occurring Advanced Penetration Testing - 2009 SANS 29

Quick TFTP Walk-Through (6) Subtracting 41 A s should take us to the SEH handler Lets give it a try by setting: cmd = "A"*1023+"\xde\xc0\xad\xde" We control EIP at 1023 bytes! Advanced Penetration Testing - 2009 SANS 30

Quick TFTP Walk-Through (7) We now need to find a valid pop/pop/ret instruction Use the findjmp tool and experiment 0x77ec9cac is one I chose from kernel32.dll for XP SP1 Remember that you must compensate for SafeSEH if hacking XP SP2/SP3 Also remember that not every pop/pop/ret address will work. You gotta dig Advanced Penetration Testing - 2009 SANS 31

Quick TFTP Walk-Through (8) Finalizing our script cmd = "A"*1019+"\xeb\x06\x90\x90"+"\xac\x9c\xec\x77"+"\x90"*4+sc data = "\x00\x01" + "blah" + "\x00"+cmd+"\x00 Our jmp and pointer Our NOP s and shellcode Advanced Penetration Testing - 2009 SANS 32

Advanced Concepts Depending on the OS Version, a number of controls have been added SafeSEH Protects SEH pointers against overwrites ASLR Randomizes locations of libraries and memory segments DEP Prevents code execution on the stack and heap Security Cookies Pushes unique values onto the stack and heap during allocations which are checked upon exit or free Every byte in memory is a potential full or partial opcode As long as the segment is executable Advanced Penetration Testing - 2009 SANS 33

More Information Defeating the Stack Based Buffer Overflow Prevention Mechanism of Microsoft Windows 2003 Server by David Litchfield http://www.nextgenss.com/papers/defeating-w2k3-stackprotection.pdf Preventing the Exploitation of SEH Overwrites by Skape Matt Miller http://www.uninformed.org/?v=5&a=2&t=pdf SEH Overwrites Simplified v1.01 by Aelphaeis Mangaraehttp://www.milw0rm.com/papers/187 Defeating Microsoft Windows XP SP2 Heap protection and DEP bypass by Alexander Anisimov http://www.maxpatrol.com/defeating-xpsp2-heap-protection.pdf Reliable Windows Heap Exploits by Matt Conover & Oded Horovitz http://www.slideshare.net/amiable_indian/reliable-windows-heap-exploits Third Generation Exploitation by Halvar Flake www.blackhat.com/presentations/win-usa- 02/halvarflake-winsec02.ppt Defeating the Stack Based Buffer Overflow Prevention Mechanism of Microsoft Windows 2003 Server by David Litchfield http://www.ngssoftware.com/papers/defeating-w2k3-stackprotection.pdf Heap Feng Shui in JavaScript by Alexander Sotirov http://www.blackhat.com/presentations/bh-europe-07/sotirov/presentation/bh-eu-07- sotirov-apr19.pdf Understanding Windows Shellcode by Skape http://www.hick.org/code/skape/papers/win32- shellcode.pdf Advanced Penetration Testing - 2009 SANS 34

End Questions? SANS SEC709 Developing Exploits for Penetration Testers and Security Researchers stephen@deadlisting.com Advanced Penetration Testing - 2009 SANS 35