-
Notifications
You must be signed in to change notification settings - Fork 16
/
shellcode-retty-linux-ia32.S
244 lines (213 loc) · 6.45 KB
/
shellcode-retty-linux-ia32.S
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#if defined(__linux__) && defined(__i386)
/** injcode/shellcode-retty-linux-ia32.S
*
* Copyright(c) Thomas Habets 2009
*/
#include "asm-constants.h"
/* data map */
.equ teststr, 0 /* 10 */
.equ socketstruct, 12 /* 12 */
.equ connectstruct, 24 /* 12 + 110 */
.equ recvstruct, 144 /* 12 */
.equ msghdr, 160 /* 28 */
.equ iovec, 188 /* 8 */
.equ cmsg, 196 /* 24 */
.equ scratchdata, 220 /* 4 */
.equ childfunc, 224 /* 4 */
.equ childpid, 228 /* 4 */
.equ oldtio, 232 /* 60 */
/* variables (can be inside structs) */
.equ socketfd, 24 /* permanent location of fd */
.equ fd0, 208 /* 4 */
.equ fd1, 212 /* 4 */
.equ fd2, 216 /* 4 */
.text
.globl shellcodeRetty
shellcodeRetty:
# Debug print
#movl $SYS_write, %eax
#movl $2, %ebx # stderr
#leal teststr(%ebp), %ecx
#movl $10, %edx # len
#int $0x80
#movl $10, %ebx # step 10 - debug print
#cmpl $0, %eax
#jl errout
# ioctl(0, TCGETS, &oldtio)
movl $SYS_ioctl, %eax
movl $0, %ebx
movl $TCGETS, %ecx
leal oldtio(%ebp), %edx
int $0x80
movl $12, %ebx # step 12
cmpl $0, %eax
jl errout
# fork()
movl $SYS_fork, %eax
int $0x80
cmpl $0, %eax
jne parent
jl errout
movl childfunc(%ebp), %eax
jmp *%eax
parent:
movl %eax, childpid(%ebp)
# setpgid()
setpgid:
movl %eax, %ecx
movl $SYS_setpgid, %eax
movl $0, %ebx
int $0x80
movl $15, %ebx # step 15
cmpl $0, %eax
jl setpgid
# setsid()
movl $SYS_setsid, %eax
int $0x80
movl $73, %ebx # step 73
cmpl $0, %eax
jl erroutclose
# kill()
movl $SYS_kill, %eax
movl childpid(%ebp), %ebx
movl $SIGKILL, %ecx
int $0x80
# waitpid()
movl $SYS_waitpid, %eax
movl childpid(%ebp), %ebx
movl $0, %ecx
movl $0, %edx
int $0x80
# FIXME: do three open(/dev/null)s, just in case
# socket()
movl $SYS_socketcall, %eax
movl $SC_socket, %ebx
leal socketstruct(%ebp), %ecx # socket struct
int $0x80
movl %eax, socketfd(%ebp)
movl $20, %ebx # step 20 - socket
cmpl $0, %eax
jl errout
# FIXME: error handling
# connect()
movl $SYS_socketcall, %eax
movl $SC_connect, %ebx
leal connectstruct(%ebp), %ecx
int $0x80
movl $30, %ebx # step 30 - connect
cmpl $0, %eax
jl erroutclose
# recvmsg()
movl socketfd(%ebp), %eax
movl %eax, recvstruct(%ebp)
movl $SYS_socketcall, %eax
movl $SC_recvmsg, %ebx
leal recvstruct(%ebp), %ecx
int $0x80
movl $40, %ebx # step 40 - recvmsg
cmpl $1, %eax
jne errout
# ioctl(fd, TIOCNOTTY, .) -- not needed. setsid() does it for us
#movl $SYS_ioctl, %eax
#movl $0, %ebx # fd
#movl $TIOCNOTTY, %ecx
#movl $0, %edx
#int $0x80
#movl $45, %ebx # step 45
#cmpl $0, %eax
#jl erroutclose
# dup2(n, 0)
movl $SYS_dup2, %eax
movl fd0(%ebp), %ebx
movl $0, %ecx
int $0x80
movl $50, %ebx # step 50 - dup2(n, 0)
cmpl $0, %eax
jl erroutclose
# dup2(n, 1)
movl $SYS_dup2, %eax
movl fd1(%ebp), %ebx
movl $1, %ecx
int $0x80
movl $60, %ebx # step 60 - dup2(n, 1)
cmpl $0, %eax
jl erroutclose
# dup2(n, 2)
movl $SYS_dup2, %eax
movl fd2(%ebp), %ebx
movl $2, %ecx
int $0x80
movl $70, %ebx # step 70 - dup2(n, 2)
cmpl $0, %eax
jl erroutclose
# ioctl(fd, TIOCTTY, 1)
movl $SYS_ioctl, %eax
movl $0, %ebx # fd
movl $TIOCSCTTY, %ecx
movl $1, %edx
int $0x80
movl $75, %ebx # step 75
cmpl $0, %eax
jne erroutclose
# ioctl(0, TCSETS, &oldtio)
movl $SYS_ioctl, %eax
movl $0, %ebx
movl $TCSETS, %ecx
leal oldtio(%ebp), %edx
int $0x80
movl $77, %ebx # step 77
cmpl $0, %eax
jl errout
# kill()
movl $SYS_kill, %eax
movl $0, %ebx
movl $SIGWINCH, %ecx
int $0x80
# close(socket)
movl $SYS_close, %eax
movl socketfd(%ebp), %ebx
int $0x80
movl $80, %ebx # step 80
cmpl $0, %eax
jl erroutclose
# close(fd0)
movl $SYS_close, %eax
movl fd0(%ebp), %ebx
int $0x80
movl $90, %ebx # step 90
cmpl $0, %eax
jl erroutclose
# close(fd1)
movl $SYS_close, %eax
movl fd1(%ebp), %ebx
int $0x80
movl $100, %ebx # step 100
cmpl $0, %eax
jl erroutclose
# close(fd2)
movl $SYS_close, %eax
movl fd2(%ebp), %ebx
int $0x80
movl $110, %ebx # step 110
cmpl $0, %eax
jl erroutclose
movl $255, %ebx
# all done
jmp okout
.globl shellcodeRettyChild
shellcodeRettyChild:
# setpgid()
movl $SYS_setpgid, %eax
movl $0, %ebx
movl $0, %ecx
int $0x80
# FIXME sleep(10)
jmp shellcodeRettyChild
# exit(0)
erroutclose:
#FIXME: close socket
errout:
okout:
.globl shellcodeRettyEnd
shellcodeRettyEnd: nop
#endif