summaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2022-12-24 08:02:29 -0500
committerMalfurious <m@lfurio.us>2023-01-15 10:12:48 -0500
commit806f9029d160c5f47f0b49db288f469718424f7b (patch)
treec210a990ff46afb4d73ad592eae11973baa2d190 /templates
parentc41649b5077eb3e0d66043658df8bccbdfef0f1a (diff)
downloadlib-des-gnux-806f9029d160c5f47f0b49db288f469718424f7b.tar.gz
lib-des-gnux-806f9029d160c5f47f0b49db288f469718424f7b.zip
shellcode: Update Makefile
This patch brings various improvements to the shellcoding experience: - There is no longer a hardcoded assembly sample that gets built Although the default was pretty sane, it will be more convenient to experiment, or build more complex shellcodes using a new untracked filename as the main build target: code.asm If code.asm is missing, then as before, it will be created from shell64.asm (the old hard default). The Makefile targets will compile code.* files. - Hex string generation and bad char detection are improved grep is used to highlight detected bad chars right in place. This entire feature is now implemented directly in the Makefile using a couple command lines, making shelltool deprecated. - Builtin disassembly Just run 'make disas' instead of manually invoking objdump. The output is also filtered through grep for bad char detection. - ELF executable is optional Rather than linking an executable all the time, just run 'make elf' when you need it. Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'templates')
-rw-r--r--templates/shellcode/Makefile38
1 files changed, 26 insertions, 12 deletions
diff --git a/templates/shellcode/Makefile b/templates/shellcode/Makefile
index 2e67adc..757878f 100644
--- a/templates/shellcode/Makefile
+++ b/templates/shellcode/Makefile
@@ -1,17 +1,31 @@
-.PHONY: all
+LDFLAGS?=
+FORMAT?=elf64
+CODE?=examples/shell64.asm
+GREP=00|0a
-all: shell32.elf shell64.elf
- @objdump -d shell32.elf | ./shelltool.py
- @objdump -d shell64.elf | ./shelltool.py
+.PHONY: all elf disas
-shell32.o: shell32.asm
- nasm -f elf shell32.asm -o shell32.o
+# Format bytecode as an escaped string, highlight bad bytes
+all: code.bin
+ @xxd -i -c 16 <code.bin \
+ | sed 's/,//g;s/ 0/\\/g;s/^ */"/g;s/$$/"/g' \
+ | grep --color=always -E '$(GREP)|$$'
-shell32.elf: shell32.o
- ld -melf_i386 shell32.o -o shell32.elf
+elf: code.o
+ ld $(LDFLAGS) code.o -o code.elf
-shell64.o: shell64.asm
- nasm -f elf64 shell64.asm -o shell64.o
+disas: code.o
+ @objdump -d code.o \
+ | grep --color=always -E '$(GREP)|$$'
-shell64.elf: shell64.o
- ld shell64.o -o shell64.elf
+code.bin: code.o
+ objcopy -O binary code.o code.bin
+
+code.o: code.asm
+ nasm -f '$(FORMAT)' code.asm -o code.o
+
+code.asm:
+ cp '$(CODE)' code.asm
+
+
+# -melf_i386