Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all:
./factory.sh $(asm)
@./factory.sh $(asm)

clean:
rm -f *.bin *.o *.out
28 changes: 6 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,17 @@ saved as examples/shellcode.asm.

make asm=examples/shellcode.asm
```
::: x86 Shellcode Factory :::


::: Your piece of art :::

examples/shellcode.out: file format elf32-i386


Disassembly of section .text:

08048060 <_start>:
8048060: 31 db xor ebx,ebx
8048062: 31 c0 xor eax,eax
8048064: 40 inc eax
8048065: cd 80 int 0x80

::: shellcode buffer generator :::
::: x86(-64) Shellcode Factory :::

::: Your shellcode ready to go :::
\x31\xdb\x31\xc0\x40\xcd\x80

::: done, look at examples/shellcode.bin :::
::: length: 7
::: Your shellcode size : 7 :::
```

examples/shellcode.bin contains our precious shellcode :)
examples/shellcode.asm.bin contains our precious shellcode :)

## Requirements
* nasm
* ld (gcc-multilib on x86_64)
* objdump
* xxd (usually bundled with your Linux distribution)
* awk (usually bundled with your Linux distribution)
52 changes: 36 additions & 16 deletions factory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,39 @@ fi
asm=$1
name=${asm%%.*}

echo -e "\n::: x86 Shellcode Factory :::\n"

nasm -felf32 $asm
ld -melf_i386 -o $name.out $name.o

echo -e "\n::: Your piece of art :::"
objdump -d -Mintel $name.out

echo -e "\n::: shellcode buffer generator :::\n"
objdump -d $name.out | grep '[0-9a-f]:' | grep -v 'file' | cut -f2 -d: | cut -f1-6 -d' ' | tr -s ' ' | tr '\t' ' ' | sed 's/ $//g' | sed 's/ /\\x/g' | paste -d '' -s | tee $name.bin
echo -ne `cat $name.bin` > $name.bin

echo -e "\n::: done, look at $name.bin :::"
echo -n "::: length: "
wc -c $name.bin | cut -f1 -d' '

# Why /bin/echo rather than just 'echo' ?

# '/bin/echo' is the GNU echo binary, 'echo' usually refers to the shell
# built-in function, and some popular shells don't handle the '-e' option
# When GNU echo does.
# By "popular shells" I mean default /bin/sh in Debian/Ubuntu based
# distribution is now dash which echo built-in doesn't handle '-e'

/bin/echo -e "::: x86(-64) Shellcode Factory :::"

# Checks if arch is specified, if not 32 bits is the default
header=$(head -n 1 $asm)
if ! echo $header | grep -E 'BITS ?(32|64)';then
tmpfile="/tmp/tmp_asm"
echo "BITS 32" > $tmpfile
cat $asm >> $tmpfile
nasm -f bin $tmpfile -o $asm.bin
else
nasm -f bin $asm -o $asm.bin
fi

code=$(xxd -p $asm.bin | tr -d '\n')
code_sz=${#code}
i=0

/bin/echo -e '\n::: Your shellcode ready to go :::'

awk "BEGIN {binstr=\"$code\"
for(i=1;i<$code_sz;i=i+2)
{
printf \"\\\\x%s\", substr(binstr, i, 2)
}}"

# Setting code_sz to the real size rather than the hexdump size
code_sz=$((code_sz/2))
/bin/echo -e "\n\n::: Your shellcode size : $code_sz :::"