@@ -11,39 +11,46 @@ def initialize(info = {})
1111 super
1212 register_options ( [
1313 OptEnum . new ( 'COMPILE' , [ true , 'Compile on target' , 'Auto' , [ 'Auto' , 'True' , 'False' ] ] ) ,
14+ OptEnum . new ( 'COMPILER' , [ true , 'Compiler to use on target' , 'gcc' , [ 'gcc' , 'clang' ] ] ) ,
1415 ] , self . class )
1516 end
1617
1718 def live_compile?
1819 return false unless %w{ Auto True } . include? ( datastore [ 'COMPILE' ] )
1920
20- if has_gcc?
21+ if datastore [ 'COMPILER' ] == 'gcc' && has_gcc?
2122 vprint_good 'gcc is installed'
2223 return true
24+ elsif datastore [ 'COMPILER' ] == 'clang' && has_clang?
25+ vprint_good 'clang is installed'
26+ return true
2327 end
2428
2529 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."
2731 end
32+
33+ false
2834 end
2935
30- def upload_and_compile ( path , data , gcc_args = '' )
36+ def upload_and_compile ( path , data , compiler_args = '' )
3137 write_file "#{ path } .c" , strip_comments ( data )
3238
33- gcc_cmd = "gcc -o '#{ path } ' '#{ path } .c'"
39+ compiler_cmd = "#{ datastore [ 'COMPILER' ] } -o '#{ path } ' '#{ path } .c'"
3440 if session . type == 'shell'
35- gcc_cmd = "PATH=\" $PATH:/usr/bin/\" #{ gcc_cmd } "
41+ compiler_cmd = "PATH=\" $PATH:/usr/bin/\" #{ compiler_cmd } "
3642 end
3743
38- unless gcc_args . to_s . blank?
39- gcc_cmd << " #{ gcc_args } "
44+ unless compiler_args . to_s . blank?
45+ compiler_cmd << " #{ compiler_args } "
4046 end
4147
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+
4351 rm_f "#{ path } .c"
4452
45- unless output . blank?
46- print_error output
53+ unless success
4754 message = "#{ path } .c failed to compile."
4855 # don't mention the COMPILE option if it was deregistered
4956 message << ' Set COMPILE to False to upload a pre-compiled executable.' if options . include? ( 'COMPILE' )
0 commit comments