@@ -11,39 +11,46 @@ 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
23
27
end
24
28
25
29
unless datastore [ 'COMPILE' ] == 'Auto'
26
- fail_with Module ::Failure ::BadConfig , 'gcc is not installed. Set COMPILE False to upload a pre-compiled executable.'
30
+ fail_with Module ::Failure ::BadConfig , " #{ datastore [ 'COMPILER' ] } is not installed. Set COMPILE False to upload a pre-compiled executable."
27
31
end
32
+
33
+ false
28
34
end
29
35
30
- def upload_and_compile ( path , data , gcc_args = '' )
36
+ def upload_and_compile ( path , data , compiler_args = '' )
31
37
write_file "#{ path } .c" , strip_comments ( data )
32
38
33
- gcc_cmd = "gcc -o '#{ path } ' '#{ path } .c'"
39
+ compiler_cmd = "#{ datastore [ 'COMPILER' ] } -o '#{ path } ' '#{ path } .c'"
34
40
if session . type == 'shell'
35
- gcc_cmd = "PATH=\" $PATH:/usr/bin/\" #{ gcc_cmd } "
41
+ compiler_cmd = "PATH=\" $PATH:/usr/bin/\" #{ compiler_cmd } "
36
42
end
37
43
38
- unless gcc_args . to_s . blank?
39
- gcc_cmd << " #{ gcc_args } "
44
+ unless compiler_args . to_s . blank?
45
+ compiler_cmd << " #{ compiler_args } "
40
46
end
41
47
42
- output = cmd_exec gcc_cmd
48
+ verification_token = Rex ::Text . rand_text_alphanumeric ( 8 )
49
+ success = cmd_exec ( "#{ compiler_cmd } && echo #{ verification_token } " ) &.include? ( verification_token )
50
+
43
51
rm_f "#{ path } .c"
44
52
45
- unless output . blank?
46
- print_error output
53
+ unless success
47
54
message = "#{ path } .c failed to compile."
48
55
# don't mention the COMPILE option if it was deregistered
49
56
message << ' Set COMPILE to False to upload a pre-compiled executable.' if options . include? ( 'COMPILE' )
0 commit comments