summaryrefslogtreecommitdiff
path: root/other/tsig/shellcode/shellcode.c
blob: 0239f121644ab7b751c7a19d043b5d7502dccded (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
47
48
/* shellcode extraction utility,
 * by typo / teso, small mods by scut.
 */


#include <stdio.h>
#include <stdlib.h>
#include <ctype.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);
}