summaryrefslogtreecommitdiff
path: root/other/shell/shellcode.c
blob: 1fc68cf1edc62ba943457b4d3db929e4afabac29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* shellcode extraction utility,
 * by type / teso, small mods by scut.
 */


#include <stdio.h>
#include <stdlib.h>

extern void	cbegin ();
extern void	cend ();


int
main (int argc, char *argv[])
{
	int		i;
	unsigned char *	buf = (unsigned char *) cbegin;
	unsigned char	ex_buf[1024];


	printf ("/* %d byte shellcode */\n", cend - cbegin);
	printf ("\"");
	for (i = 0 ; buf < (unsigned char *) cend; ++buf) {

		printf ("\\x%02x", *buf & 0xff);

		if (++i >= 12) {
			i = 0;
			printf ("\"\n\"");
		}
	}
	printf ("\";\n");

	printf("\n");

	if (argc > 1) {
		printf ("%02x\n", ((unsigned char *) cbegin)[0]);
		printf ("%02x\n", ex_buf[0]);
		memcpy (ex_buf, cbegin, cend - cbegin);
		printf ("%02x\n", ex_buf[0]);
		((void (*)()) &ex_buf)();
	}

	exit (EXIT_SUCCESS);
}