Module: Msf::Exploit::Local::Linux

Includes:
CompileC
Defined in:
lib/msf/core/exploit/local/linux.rb

Instance Attribute Summary

Attributes included from CompileC

#cparser, #cpu

Instance Method Summary collapse

Methods included from CompileC

#init_metasm, #setup

Instance Method Details

#linux_x86_syscall_wrappers(metasm_exe) ⇒ Object


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
# File 'lib/msf/core/exploit/local/linux.rb', line 7

def linux_x86_syscall_wrappers(metasm_exe)
  cparser.parse "#ifndef size_t\n#define size_t int\n#endif\n#ifndef off_t\n#define off_t unsigned long\n#endif\n\n#define O_CREAT 64\n#define O_RDWR 2\n\n#define MAP_PRIVATE   0x02\n#define MAP_FIXED     0x10\n#define MAP_ANONYMOUS 0x20\n#define MAP_ANON MAP_ANONYMOUS\n#define MAP_FAILED ((void *)-1)\n\n#define PROT_READ  0x1\n#define PROT_WRITE 0x2\n#define PROT_EXEC  0x4\n\nvoid exit(int status);\nint read(int fd, void *buf, size_t count);\nint write(int fd, void *buf, size_t count);\nint open(const char *pathname, int flags, int mode);\nint unlink(const char *pathname);\nint ftruncate(int fd, off_t length);\nint socket(int, int, int);\nint sendfile(int in_fd, int out_fd, void *, int count);\nvoid *__mmap2(void *addr, size_t length, int prot, int flags, int fd, off_t offset);\n\n#ifdef DEBUGGING\nvoid sigtrap();\n#else\n#define sigtrap()\n#endif\nvoid *__get_tls();\n\n"
  metasm_exe.parse "sigtrap:\nint    3\nret\nexit:\nmov    eax, 1         ; sys_exit\nmov    ebx, [esp+4]\nint    0x80\nret\nread:\nmov    eax, 3         ; sys_write\nmov    edx,[esp+12]   ; length\nmov    ecx,[esp+8]    ; string\nmov    ebx,[esp+4]    ; file descriptor\nint    0x80\nret\nwrite:\nmov    eax, 4         ; sys_write\nmov    edx,[esp+12]   ; length\nmov    ecx,[esp+8]    ; string\nmov    ebx,[esp+4]    ; file descriptor\nint    0x80\nret\nopen:\nmov    eax, 5         ; sys_open\nmov    edx,[esp+12]   ; mode\nmov    ecx,[esp+8]    ; flags\nmov    ebx,[esp+4]    ; file name\nint    0x80\ncmp    eax, -129\njb     1f\nneg    eax\npush   eax\ncall   __set_errno\nadd    esp, 4\nor     eax, -1\n1:\nret\nftruncate:\npush   ebx\npush   ecx\nmov    eax, 93        ; sys_ftruncate\nmov    ecx,[esp+16]   ; file descriptor\nmov    ebx,[esp+12]   ; size\nint    0x80\ncmp    eax, -129\njb     1f\nneg    eax\npush   eax\ncall   __set_errno\nadd    esp, 4\nor     eax, -1\n1:\npop    ecx\npop    ebx\nret\nsocket:\npush   ebx\npush   ecx\nmov    eax, 102       ; sys_socketcall\nmov    ebx, 1\nmov    ecx, esp\nadd    ecx, 12\nint    0x80\ncmp    eax, -129\njb     1f\nneg    eax\npush   eax\ncall   __set_errno\nadd    esp, 4\nor     eax, -1\n1:\npop    ecx\npop    ebx\nret\nsendfile:\npush   ebx\npush   ecx\npush   edx\npush   esi\n\nmov    eax, 187       ; sys_sendfile\nmov    esi,[esp+32]   ; size\nmov    edx,[esp+28]   ; offset\nmov    ecx,[esp+24]    ; out_fd\nmov    ebx,[esp+20]    ; in_fd\nint    0x80\ncmp    eax, -129\njb     1f\nneg    eax\npush   eax\ncall   __set_errno\nadd    esp, 4\nor     eax, -1\n1:\npop    esi\npop    edx\npop    ecx\npop    ebx\nret\n\nunlink:\nmov    eax, 10        ; sys_unlink\nmov    ebx,[esp+4]    ; filename\nint    0x80\nret\n\n; stolen from bionic\n__mmap2:\npush   ebx\npush   ecx\npush   edx\npush   esi\npush   edi\npush   ebp\n\nmov    eax, 192\nmov    ebx, [esp+28]\nmov    ecx, [esp+32]\nmov    edx, [esp+36]\nmov    esi, [esp+40]\nmov    edi, [esp+44]\nmov    ebp, [esp+48]\nint    0x80\ncmp    eax, -129\njb     1f\nneg    eax\npush   eax\ncall   __set_errno\nadd    esp, 4\nor     eax, -1\n1:\npop    ebp\npop    edi\npop    esi\npop    edx\npop    ecx\npop    ebx\nret\n\n; Thread Local Storage, used by errno\n__get_tls:\nmov    eax, gs:[0]\nret\n"

end