diff options
author | toni <matzeton@googlemail.com> | 2014-11-19 23:32:18 +0100 |
---|---|---|
committer | toni <matzeton@googlemail.com> | 2014-11-19 23:32:18 +0100 |
commit | 0ce0a24f199558dbe7afb4b045647e259608254c (patch) | |
tree | e8bdffbc49005ad287eb1d239dc5b9ecedd19732 | |
parent | 5c26ae8af99016bcbb6fae633367ab7100521c6d (diff) |
- added crypter stuff
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | crypter/.gitignore | 1 | ||||
-rw-r--r-- | crypter/Makefile | 34 | ||||
-rw-r--r-- | crypter/simple_decoder.asm | 16 | ||||
-rw-r--r-- | crypter/simple_encoder.c | 64 |
5 files changed, 124 insertions, 3 deletions
@@ -8,11 +8,16 @@ X64_FLAGS = -m64 -mpreferred-stack-boundary=4 SOURCES = $(wildcard *.c) TARGETS = $(patsubst %.c,%.o,$(SOURCES)) -all: $(SOURCES) $(TARGETS) shellcode post-build +all: $(SOURCES) $(TARGETS) shellcode crypter post-build + +main: $(SOURCES) $(TARGETS) shellcode: make -f shellcode/Makefile SUBDIR=shellcode +crypter: + make -f crypter/Makefile SUBDIR=crypter SCDIR=. + post-build: @read -p "disable protection stuff? (y/N) " answ; \ if [ "x$$answ" != "xy" ]; then \ @@ -35,8 +40,9 @@ disable-prot: ln -s $< $@ clean: - $(RM) -f $(patsubst %.o,%,$(TARGETS)) + $(RM) -f $(patsubst %.o,%,$(TARGETS)) $(patsubst %.c,%_x64,$(wildcard *.c)) $(RM) -f $(TARGETS) make -f shellcode/Makefile SUBDIR=shellcode clean + make -f crypter/Makefile SUBDIR=crypter clean -.PHONY: shellcode clean +.PHONY: shellcode crypter clean diff --git a/crypter/.gitignore b/crypter/.gitignore new file mode 100644 index 0000000..424c745 --- /dev/null +++ b/crypter/.gitignore @@ -0,0 +1 @@ +*.h diff --git a/crypter/Makefile b/crypter/Makefile new file mode 100644 index 0000000..c009e2b --- /dev/null +++ b/crypter/Makefile @@ -0,0 +1,34 @@ +RM := rm +ASM := nasm +CC := gcc +LD := ld +XXD := xxd +CFLAGS = -c -Wall -fpic -Os +LDFLAGS = +SUBDIR ?= . +TARGETS = $(patsubst %.asm,%.o,$(wildcard $(SUBDIR)/*.asm)) $(patsubst %.c,%.o,$(wildcard $(SUBDIR)/*.c)) +SCDIR ?= .. +SCC := $(shell if [ -x $(SCDIR)/sc-test ]; then echo "yes"; else echo "no"; fi) + + +all: $(TARGETS) + +%.o : %.asm + $(ASM) -o $@ $< + +%.o : %.c +ifneq ($(SCC),yes) + $(error Please run 'make' in the main directory) +endif +ifneq ($(shell if [ -r "$<" ]; then echo "yes"; else echo "no"; fi),yes) + $(error Necessary file '$<' not found) +endif + -$(shell ../sc-test -p `cat "$<" | sed -n 's/.*#DECODER=//p'` > $(patsubst %.o,%.h,$@)) + -$(shell ../sc-test -p `cat "$<" | sed -n 's/.*#DECODER=//p'` > $(patsubst %.o,%.h,$@)) + $(CC) $(CFLAGS) -D_USE_CFG -o $@ $< + $(LD) $(LDFLAGS) $@ -o $(patsubst %.o,%,$@) + +clean: + $(RM) -f $(patsubst %.o,%,$(TARGETS)) $(TARGETS) $(patsubst %.o,%.h,$(TARGETS)) + +.PHONY: all clean diff --git a/crypter/simple_decoder.asm b/crypter/simple_decoder.asm new file mode 100644 index 0000000..7d2670c --- /dev/null +++ b/crypter/simple_decoder.asm @@ -0,0 +1,16 @@ +BITS 32 + + +jmp short go +next: +pop esi +xor ecx,ecx +mov cl,0 +change: +sub byte [esi + ecx - 1],0 +dec cl +jnz change +jmp short ok +go: +call next +ok: diff --git a/crypter/simple_encoder.c b/crypter/simple_encoder.c new file mode 100644 index 0000000..791a20f --- /dev/null +++ b/crypter/simple_encoder.c @@ -0,0 +1,64 @@ +// #DECODER=./simple_decoder.o +// #SHELLCODE=../hello.o +#include <stdio.h> +#include <string.h> +#include <sys/time.h> +#include <stdlib.h> +#include <unistd.h> + +#ifdef _USE_CFG +#include "simple_encoder.h" +#else +#error "simple_encode.h config file missing including decoder && shellcode" +#endif + +#ifndef _CRYPTVAL +#define _CRYPTVAL 200 +#endif + + +int +getnumber(int n) +{ + int seed; + struct timeval tm; + + gettimeofday(&tm, NULL); + seed = tm.tv_sec + tm.tv_usec; + srandom(seed); + return (random() % n); +} + +void +print_code(char *data) +{ + int i,l = 15; + + printf("\n\nunsigned long int lshellcode = %lu;\nchar shellcode[] = \n", (unsigned long int) strlen(data)); + for (i = 0; i < strlen(data); i++) { + if (l >= 15) { + if (i) { + printf("\"\n"); + } + printf("\t\""); + l = 0; + } + ++l; + printf("\\x%02x", ((unsigned char *)data)[i]); + } + printf("\";\n\n\n"); +} + +int +main(int argc, char **argv) +{ +// char decoder[] = _DECODER; + int count, number = getnumber(_CRYPTVAL), nullbyte = 0, ldecoder = strlen(decoder), lshellcode = strlen(shellcode); + char *result; + + printf("Using value %d to encode the shellcode.\n", number); + printf("*** PRINT SHELLCODE\n"); + print_code(shellcode); + printf("*** PRINT DECODER\n"); + print_code(decoder); +} |