comparison target-utils/tf-breakin/mkembed.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 #include <sys/types.h>
2 #include <sys/file.h>
3 #include <sys/stat.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7
8 #define PAYLOAD_SIZE 116
9 u_char payload_buf[PAYLOAD_SIZE];
10
11 read_binary(filename)
12 char *filename;
13 {
14 int fd;
15 struct stat st;
16
17 fd = open(filename, O_RDONLY);
18 if (fd < 0) {
19 perror(filename);
20 exit(1);
21 }
22 fstat(fd, &st);
23 if (!S_ISREG(st.st_mode)) {
24 fprintf(stderr, "error: %s is not a regular file\n", filename);
25 exit(1);
26 }
27 if (st.st_size != PAYLOAD_SIZE) {
28 fprintf(stderr, "error: %s size mismatch\n", filename);
29 exit(1);
30 }
31 if (read(fd, payload_buf, PAYLOAD_SIZE) != PAYLOAD_SIZE) {
32 perror("read error");
33 exit(1);
34 }
35 close(fd);
36 }
37
38 write_output(filename)
39 char *filename;
40 {
41 FILE *of;
42 int i, j, idx;
43
44 of = fopen(filename, "w");
45 if (!of) {
46 perror(filename);
47 exit(1);
48 }
49 fprintf(of, "u_char shellcode[%d] = {\n", PAYLOAD_SIZE);
50 idx = 0;
51 for (i = 0; i < 15; i++) {
52 for (j = 0; j < 8; j++) {
53 if (j)
54 putc(' ', of);
55 else
56 putc('\t', of);
57 fprintf(of, "0x%02X,", payload_buf[idx++]);
58 if (idx >= PAYLOAD_SIZE)
59 break;
60 }
61 putc('\n', of);
62 }
63 fputs("};\n", of);
64 fclose(of);
65 }
66
67 main(argc, argv)
68 char **argv;
69 {
70 if (argc != 3) {
71 fprintf(stderr, "usage: %s payload.bin output.c\n", argv[0]);
72 exit(1);
73 }
74 read_binary(argv[1]);
75 write_output(argv[2]);
76 exit(0);
77 }