aboutsummaryrefslogtreecommitdiff
path: root/crypter
diff options
context:
space:
mode:
Diffstat (limited to 'crypter')
-rw-r--r--crypter/.gitignore1
-rw-r--r--crypter/Makefile12
-rw-r--r--crypter/simple_encoder.c56
3 files changed, 49 insertions, 20 deletions
diff --git a/crypter/.gitignore b/crypter/.gitignore
index 424c745..f69e226 100644
--- a/crypter/.gitignore
+++ b/crypter/.gitignore
@@ -1 +1,2 @@
*.h
+simple_encoder
diff --git a/crypter/Makefile b/crypter/Makefile
index c009e2b..57409a9 100644
--- a/crypter/Makefile
+++ b/crypter/Makefile
@@ -3,7 +3,7 @@ ASM := nasm
CC := gcc
LD := ld
XXD := xxd
-CFLAGS = -c -Wall -fpic -Os
+CFLAGS = -Wall -fpic -Os
LDFLAGS =
SUBDIR ?= .
TARGETS = $(patsubst %.asm,%.o,$(wildcard $(SUBDIR)/*.asm)) $(patsubst %.c,%.o,$(wildcard $(SUBDIR)/*.c))
@@ -20,13 +20,9 @@ all: $(TARGETS)
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,%,$@)
+ -$(shell $(SCDIR)/sc-test -p $(SUBDIR)/`cat "$<" | sed -n 's/.*#DECODER=//p'` | sed 's/shellcode/decoder/' > $(patsubst %.o,%.h,$@))
+ -$(shell $(SCDIR)/sc-test -p $(SUBDIR)/`cat "$<" | sed -n 's/.*#SHELLCODE=//p'` >> $(patsubst %.o,%.h,$@))
+ $(CC) $(CFLAGS) -D_USE_CFG -o $(patsubst %.c,%,$<) $<
clean:
$(RM) -f $(patsubst %.o,%,$(TARGETS)) $(TARGETS) $(patsubst %.o,%.h,$(TARGETS))
diff --git a/crypter/simple_encoder.c b/crypter/simple_encoder.c
index 791a20f..bbedaf3 100644
--- a/crypter/simple_encoder.c
+++ b/crypter/simple_encoder.c
@@ -1,5 +1,5 @@
// #DECODER=./simple_decoder.o
-// #SHELLCODE=../hello.o
+// #SHELLCODE=../shellcode/hello.o
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
@@ -30,12 +30,12 @@ getnumber(int n)
}
void
-print_code(char *data)
+print_code(const char *name, char *data, int len)
{
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++) {
+ printf("unsigned long int l%s = %lu;\nchar %s[] = \n", name, (unsigned long int) strlen(data), name);
+ for (i = 0; i < len; i++) {
if (l >= 15) {
if (i) {
printf("\"\n");
@@ -46,19 +46,51 @@ print_code(char *data)
++l;
printf("\\x%02x", ((unsigned char *)data)[i]);
}
- printf("\";\n\n\n");
+ printf("\";\n\n");
}
int
main(int argc, char **argv)
{
-// char decoder[] = _DECODER;
- int count, number = getnumber(_CRYPTVAL), nullbyte = 0, ldecoder = strlen(decoder), lshellcode = strlen(shellcode);
+ int i, npos = 0, number = getnumber(_CRYPTVAL), nullbyte = 0;
+ int ldecoder = sizeof(decoder)-1; /* last byte is '\x00' */
+ int lshellcode = sizeof(shellcode)-1; /* same as above */
+ int first_arg = 1;
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);
+ printf("/* Using value %d to encode the shellcode. */\n", number);
+ printf("/* PRINT SHELLCODE */\n");
+ print_code("shellcode", shellcode, lshellcode);
+ printf("/* PRINT DECODER */\n");
+ print_code("decoder", decoder, ldecoder);
+
+ for (i = 0; i < ldecoder; i++) {
+ if (decoder[i] == '\x00') {
+ if (first_arg) {
+ decoder[i] = lshellcode;
+ first_arg = 0;
+ } else {
+ decoder[i] = (unsigned char) number;
+ npos = i;
+ }
+ printf("// decoder[%d] = %u (%02x)\n", i, (unsigned char) decoder[i], (unsigned char) decoder[i]);
+ }
+ }
+
+ do {
+ if (nullbyte == 1) {
+ number = getnumber(10);
+ decoder[npos] += number;
+ nullbyte = 0;
+ }
+
+ for (i = 0; i < lshellcode; i++) {
+ shellcode[i] += number;
+ if (shellcode[i] == '\x00') {
+ nullbyte = 1;
+ }
+ }
+ } while (nullbyte == 1);
+
+ return (0);
}