aboutsummaryrefslogtreecommitdiff
path: root/crypter/simple_encoder.c
diff options
context:
space:
mode:
authortoni <matzeton@googlemail.com>2014-11-23 13:03:43 +0100
committertoni <matzeton@googlemail.com>2014-11-23 13:03:43 +0100
commita10d4f3aa6d62cf225a3771f421ad5fc54813502 (patch)
treebfc833ba6d58687e32debf7f42001d2a52086e88 /crypter/simple_encoder.c
parent6b20dd49d40aabd06d1b836c7dc1eaf7c6022563 (diff)
- the most simplest crypter works ;)
Diffstat (limited to 'crypter/simple_encoder.c')
-rw-r--r--crypter/simple_encoder.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/crypter/simple_encoder.c b/crypter/simple_encoder.c
index 5ab4f66..abcd7d1 100644
--- a/crypter/simple_encoder.c
+++ b/crypter/simple_encoder.c
@@ -1,5 +1,7 @@
// #DECODER=./simple_decoder.o
// #SHELLCODE=../shellcode/hello.o
+#define _GNU_SOURCE 1
+
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
@@ -16,6 +18,10 @@
#define _CRYPTVAL 200
#endif
+#ifndef _OUTFILE
+#define _OUTFILE "simple_encoded.o"
+#endif
+
int
getnumber(int n)
@@ -49,6 +55,22 @@ print_code(const char *name, char *data, int len)
printf("\";\n\n");
}
+void
+err_n_xit(const char *exit_msg, const char *arg)
+{
+ char *tmp;
+ if (arg != NULL) {
+ asprintf(&tmp, "%s('%s')", exit_msg, arg);
+ } else {
+ tmp = (char *) exit_msg;
+ }
+ perror(tmp);
+ if (arg != NULL) {
+ free(tmp);
+ }
+ exit(1);
+}
+
int
main(int argc, char **argv)
{
@@ -57,6 +79,7 @@ main(int argc, char **argv)
int lshellcode = sizeof(shellcode)-1; /* same as above */
int first_arg = 1;
char *result;
+ FILE *outfile;
printf("/* Using value %d to encode the shellcode. */\n", number);
printf("/* PRINT SHELLCODE */\n");
@@ -100,6 +123,13 @@ main(int argc, char **argv)
*(result + ldecoder + lshellcode) = '\0';
print_code("result", result, ldecoder + lshellcode);
+ /* write2file */
+ outfile = fopen(_OUTFILE, "w+b");
+ if (outfile == NULL) err_n_xit("fopen", _OUTFILE);
+ if (fwrite((void *) result, sizeof(char), strlen(result), outfile) != strlen(result)) err_n_xit("fwrite", _OUTFILE);
+ if (fclose(outfile) != 0) err_n_xit("fclose", _OUTFILE);
+ fprintf(stderr, "outfile: %s\n", _OUTFILE);
+
free(result);
return (0);
}