@@ -11,39 +11,47 @@ def initialize(info = {})
11
11
super
12
12
register_options ( [
13
13
OptEnum . new ( 'COMPILE' , [ true , 'Compile on target' , 'Auto' , [ 'Auto' , 'True' , 'False' ] ] ) ,
14
+ OptEnum . new ( 'COMPILER' , [ true , 'Compiler to use on target' , 'gcc' , [ 'gcc' , 'clang' ] ] ) ,
14
15
] , self . class )
15
16
end
16
17
17
18
def live_compile?
18
19
return false unless %w{ Auto True } . include? ( datastore [ 'COMPILE' ] )
19
20
20
- if has_gcc?
21
+ if datastore [ 'COMPILER' ] == 'gcc' && has_gcc?
21
22
vprint_good 'gcc is installed'
22
23
return true
24
+ elsif datastore [ 'COMPILER' ] == 'clang' && has_clang?
25
+ vprint_good 'clang is installed'
26
+ return true
27
+ end
23
28
end
24
29
25
30
unless datastore [ 'COMPILE' ] == 'Auto'
26
- fail_with Module ::Failure ::BadConfig , 'gcc is not installed. Set COMPILE False to upload a pre-compiled executable.'
31
+ fail_with Module ::Failure ::BadConfig , " #{ datastore [ 'COMPILER' ] } is not installed. Set COMPILE False to upload a pre-compiled executable."
27
32
end
33
+
34
+ false
28
35
end
29
36
30
- def upload_and_compile ( path , data , gcc_args = '' )
37
+ def upload_and_compile ( path , data , compiler_args = '' )
31
38
write_file "#{ path } .c" , strip_comments ( data )
32
39
33
- gcc_cmd = "gcc -o '#{ path } ' '#{ path } .c'"
40
+ compiler_cmd = "#{ datastore [ 'COMPILER' ] } -o '#{ path } ' '#{ path } .c'"
34
41
if session . type == 'shell'
35
- gcc_cmd = "PATH=\" $PATH:/usr/bin/\" #{ gcc_cmd } "
42
+ compiler_cmd = "PATH=\" $PATH:/usr/bin/\" #{ compiler_cmd } "
36
43
end
37
44
38
- unless gcc_args . to_s . blank?
39
- gcc_cmd << " #{ gcc_args } "
45
+ unless compiler_args . to_s . blank?
46
+ compiler_cmd << " #{ compiler_args } "
40
47
end
41
48
42
- output = cmd_exec gcc_cmd
49
+ verification_token = Rex ::Text . rand_text_alphanumeric ( 8 )
50
+ success = cmd_exec ( "#{ compiler_cmd } && echo #{ verification_token } " ) &.include? ( verification_token )
51
+
43
52
rm_f "#{ path } .c"
44
53
45
- unless output . blank?
46
- print_error output
54
+ unless success
47
55
message = "#{ path } .c failed to compile."
48
56
# don't mention the COMPILE option if it was deregistered
49
57
message << ' Set COMPILE to False to upload a pre-compiled executable.' if options . include? ( 'COMPILE' )
0 commit comments