For a 64-bit system. I - Presentation Of The Shellcode



Similar documents
Off-by-One exploitation tutorial

64-Bit NASM Notes. Invoking 64-Bit NASM

CS61: Systems Programing and Machine Organization

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

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

Practical taint analysis for protecting buggy binaries

Software Vulnerabilities

Buffer Overflows. Security 2011

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Stack Overflows. Mitchell Adair

TitanMist: Your First Step to Reversing Nirvana TitanMist. mist.reversinglabs.com

Assembly Language Tutorial

Abysssec Research. 1) Advisory information. 2) Vulnerable version

Attacking Host Intrusion Prevention Systems. Eugene Tsyrklevich

Software security. Buffer overflow attacks SQL injections. Lecture 11 EIT060 Computer Security

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

Machine Programming II: Instruc8ons

Syscall Proxying - Simulating remote execution Maximiliano Caceres <maximiliano.caceres@corest.com> Copyright 2002 CORE SECURITY TECHNOLOGIES

Simple C Programs. Goals for this Lecture. Help you learn about:

Return-oriented programming without returns

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

Test Driven Development in Assembler a little story about growing software from nothing

Assembly Language: Function Calls" Jennifer Rexford!

Unix Security Technologies: Host Security Tools. Peter Markowsky <peterm[at]ccs.neu.edu>

Virtualization Technologies

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

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

Lecture 27 C and Assembly

esrever gnireenigne tfosorcim seiranib

CS 161 Computer Security

Machine-Level Programming II: Arithmetic & Control

Using the RDTSC Instruction for Performance Monitoring

Attacking x86 Windows Binaries by Jump Oriented Programming

Leak Check Version 2.1 for Linux TM

An introduction to the Return Oriented Programming. Why and How

Informatica e Sistemi in Tempo Reale

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

CS Computer Security Thirteenth topic: System attacks. defenses

The Plan Today... System Calls and API's Basics of OS design Virtual Machines

Introduction. Figure 1 Schema of DarunGrim2

Instruction Set Architecture

Caml Virtual Machine File & data formats Document version: 1.4

Korset: Code-based Intrusion Detection for Linux

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

OpenBSD Remote Exploit

Module 26. Penetration Testing

Practical Windows and Linux Shellcode design by Nomenumbra. 0x00) Intro

ELEG3924 Microprocessor Ch.7 Programming In C

W4118 Operating Systems. Junfeng Yang

How Compilers Work. by Walter Bright. Digital Mars

From SQL Injection to MIPS Overflows

Linux Kernel Rootkit : Virtual Terminal Key Logger

Betriebssysteme KU Security

Violating Database - Enforced Security Mechanisms

1. General function and functionality of the malware

Pemrograman Dasar. Basic Elements Of Java

Cryptography and Network Security Prof. D. Mukhopadhyay Department of Computer Science and Engineering

Chapter 4 Processor Architecture

Chapter 7D The Java Virtual Machine

Encryption Wrapper. on OSX

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

The programming language C. sws1 1

Hydra. Advanced x86 polymorphic engine. Incorporates existing techniques and introduces new ones in one package. All but one feature OS-independent

Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection

Systems Design & Programming Data Movement Instructions. Intel Assembly

Evaluating a ROP Defense Mechanism. Vasilis Pappas, Michalis Polychronakis, and Angelos D. Keromytis Columbia University

Hotpatching and the Rise of Third-Party Patches

The Beast is Resting in Your Memory On Return-Oriented Programming Attacks and Mitigation Techniques To appear at USENIX Security & BlackHat USA, 2014

Programmation Systèmes Cours 4 Runtime user management

Application-Specific Attacks: Leveraging the ActionScript Virtual Machine

CSC 2405: Computer Systems II

TODAY, FEW PROGRAMMERS USE ASSEMBLY LANGUAGE. Higher-level languages such

Software Fingerprinting for Automated Malicious Code Analysis

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

Andreas Herrmann. AMD Operating System Research Center

Heap-based Buffer Overflow Vulnerability in Adobe Flash Player

There s a kernel security researcher named Dan Rosenberg whose done a lot of linux kernel vulnerability research

Understanding a Simple Operating System

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

PC Assembly Language. Paul A. Carter

High-speed image processing algorithms using MMX hardware

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

CPU performance monitoring using the Time-Stamp Counter register

What Happens In Windows 7 Stays In Windows 7

Absolute Backdoor Revisited. Vitaliy Kamlyuk, Kaspersky Lab Sergey Belov, Kaspersky Lab Anibal Sacco, Cubica Labs

How To Protect Your Computer From Being Hacked By A Hacker (For A Fee)

Jorix kernel: real-time scheduling

Introduction to Information Security

Lecture 21: Buffer Overflow Attack. Lecture Notes on Computer and Network Security. by Avi Kak

System Calls and Standard I/O

Buffer Overflows. Code Security: Buffer Overflows. Buffer Overflows are everywhere. 13 Buffer Overflow 12 Nov 2015

Programming from the Ground Up. Jonathan Bartlett

Keil C51 Cross Compiler

Automating Mimicry Attacks Using Static Binary Analysis

Inside a killer IMBot. Wei Ming Khoo University of Cambridge 19 Nov 2010

Applying Clang Static Analyzer to Linux Kernel

Transcription:

#How To Create Your Own Shellcode On Arch Linux? #Author : N3td3v!l #Contact-mail : 4nonymouse@usa.com #Website : Nopotm.ir #Spcial tnx to : C0nn3ct0r And All Honest Hackerz and Security Managers I - Presentation Of The Shellcode A shellcode is a string that represents an executable binary code capable of launching any application on the machine. Most of the time shellcode opens a shell to have full access to the machine. Generally, the shellcode is injected into the memory of the machine via the exploitation of a buffer overflow flaw type (buffer overflow). II - Understanding the basics 1 - System calls A system call (in English, system call, syscall abbreviated) is a function provided by the kernel an operating system. According to our syscall Os will be called differently.example of commonly used system call: open, write, read, close, chmod, chown... On most operating systems, system calls can be used as simple functions written in C. For example for the chown system call: extern int chown ( const char * file, uid_t owner, gid_t group) Each system call to an address that is assigned by the operating system and which is own. For example Linux kernel 2.6.31 with the address of syscall chown is 0xb6. How do I know this address? A simple command like below allows for address the syscall. The addresses are in decimal unistd_x.h. For a 32-bit N3td3v!l@archlinux [ shellcode ]# cat /usr/include/asm/unistd_32.h grep chown #define NR_lchown 16 #define NR_fchown 95 #define NR_chown 182 #define NR_lchown32 198 #define NR_fchown32 207 #define NR_chown32 212 #define NR_fchownat 298 For a 64-bit system

N3td3v!l@archlinux [ shellcode ]# cat /usr/include/asm/unistd_64.h grep chown #define NR_chown 92 SYSCALL( NR_chown, sys_chown) #define NR_fchown 93 SYSCALL( NR_fchown, sys_fchown) #define NR_lchown 94 SYSCALL( NR_lchown, sys_lchown) #define NR_fchownat 260 SYSCALL( NR_fchownat, sys_fchownat) As you can see, if the bone is under 32 or 64 bits, the address of syscalls change. III - Write the first shellcode First we will create a simple shellcode, which will allow us to pause. Why we call the function whose address is _pause 29 resulting in hexadecimal 0x1d (in 32 bits). N3td3v!l@archlinux [ ~ ]$ cat /usr/include/asm/unistd_32.h grep pause #define NR_pause 29 Once you know the address of the syscall, it remains for us to know what to put on the books. For this refer to this page =>http://www.potomacparent.com/cache/syscalls.html We can see that to break we do not need to complete records, just a call away, which is going to be very short schedule. N3td3v!l@archlinux [ shellcode ]$ cat pause.s xor %eax,%eax mov $29,%al int $0x80 N3td3v!l@archlinux [ shellcode ]$ as -o pause.o pause.s N3td3v!l@archlinux [ shellcode ]$ ld -o pause pause.o ld: warning: cannot find entry symbol _start; defaulting to 08048054 N3td3v!l@archlinux [ shellcode ]$./pause ^C N3td3v!l@archlinux [ shellcode ]$

Explanation : #xor %eax,%eax <= We put the register eax to 0 to avoid segmentation faults #mov $29,%al <= Placed 29 (the address of the syscall) in the register al #int $0x80 <= executed Now we will write C For this we need to know the value of work in hexadecimal asm what will eventually be our shellcode. How have the hexadecimal equivalent? It's simple, we simply use the objdump tool, which gives: N3td3v!l@archlinux [ shellcode ]$ objdump -d./pause pause: file format elf32-i386 Disassembly of section.text: 08048054 <.text>: 8048054: 31 c0 xor %eax,%eax 8048056: b0 1d mov $0x1d,%al 8048058: cd 80 int $0x80 N3td3v!l@archlinux [ shellcode ]$ And now, so the code is in C: N3td3v!l@archlinux [ shellcode ]$ cat pause_c.c #include <stdio.h> void main(void) { char shellcode[] = "\x31\xc0\xb0\x1d\xcd\x80"; (*(void(*)()) shellcode)(); } N3td3v!l@archlinux [ shellcode ]$ gcc -o pause_c pause_c.c N3td3v!l@archlinux [ shellcode ]$./pause_c ^C N3td3v!l@archlinux [ shellcode ]$

Your first shellcode working properly. Now we will study the write function. We still refer to the site that I submitted earlier. Info Register: #%eax = 4 #%ebx = unsigned int #%ecx = const char * #%edx = size We will simply write N3td3v!l, look at what gives the sources: N3td3v!l@ArchLinux [shellcode]$ cat write.s ;_write xor %eax,%eax <= To avoid segmentation faults xor %ebx,%ebx <= // // xor %ecx,%ecx <= // // xor %edx,%edx <= // // movb $0x9,%dl <= placed the size of our word in dl (edx) so N3td3v! l + \ n = 1 8 9 pushl $0x0a <= we begin to stack our line feed (\ n) = 0x0a push $0x6e616874 <= seam push $0x616e6f6a <= // // movl %esp,%ecx <= % esp is sent to% ecx register that contains the constant tank _write movb $0x1,%bl <= here for 1% ebx, movb $0x4,%al <= and by the syscall so _write 4 int $0x80 <= executed ;_exit xor %ebx,%ebx <= %ebx = 0 movb $0x1,%al <= %eax = 1 (_exit syscall) int $0x80 <= executed Compile and run our program: N3td3v!l@ArchLinux [shellcode]$ as -o write.o write.s N3td3v!l@ArchLinux [shellcode]$ ld -o write write.o ld: warning: cannot find entry symbol _start; defaulting to 08048054 N3td3v!l@ArchLinux [shellcode]$./write N3td3v!l N3td3v!l@ArchLinux [shellcode]$

Let's write our shellcode in C for this, objdump will help a little. N3td3v!l@ArchLinux [shellcode]$ objdump -d write write: file format elf32-i386 Disassembly of section.text: 08048054 <.text>: 8048054: 31 c0 xor %eax,%eax 8048056: 31 db xor %ebx,%ebx 8048058: 31 c9 xor %ecx,%ecx 804805a: 31 d2 xor %edx,%edx 804805c: b2 09 mov $0x9,%dl 804805e: 6a 0a push $0xa 8048060: 68 74 68 61 6e push $0x6e616874 8048065: 68 6a 6f 6e 61 push $0x616e6f6a 804806a: 89 e1 mov %esp,%ecx 804806c: b3 01 mov $0x1,%bl 804806e: b0 04 mov $0x4,%al 8048070: cd 80 int $0x80 8048072: 31 db xor %ebx,%ebx 8048074: b0 01 mov $0x1,%al 8048076: cd 80 int $0x80 N3td3v!l@ArchLinux [shellcode]$

There are many sources right in our asm code and then the equivalence of instructions in hexadecimal. N3td3v!l@ArchLinux [shellcode]$ cat write_c.c #include <stdio.h> void main(void) { char shellcode[] = "\x31\xc0\x31\xdb\x31\xc9" "\x31\xd2\xb2\x09\x6a\x0a" "\x68\x74\x68\x61\x6e\x68" "\x6a\x6f\x6e\x61\x89\xe1" "\xb3\x01\xb0\x04\xcd\x80" "\x31\xdb\xb0\x01\xcd\x80"; fprintf(stdout,"lenght: %d\n",strlen(shellcode)); (*(void(*)()) shellcode)(); } Compile and execute our shellcode: N3td3v!l@ArchLinux [shellcode]$ gcc -o write_c write_c.c N3td3v!l@ArchLinux [shellcode]$./write_c Lenght: 36 N3td3v!l N3td3v!l@ArchLinux [shellcode]$ And here it works perfectly. Shellcode _write (1, "N3td3v!l S \ n", 9) + _exit (0) to a size of 36 bytes.

IV - References [x] - http://wikipedia.org/wiki/shellcode [1] - /usr/include/asm/unistd_32.h [2] and etc... ==================================== Signature ===================================