@@ -11,39 +11,47 @@ 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
27+ end
2328 end
2429
2530 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."
2732 end
33+
34+ false
2835 end
2936
30- def upload_and_compile ( path , data , gcc_args = '' )
37+ def upload_and_compile ( path , data , compiler_args = '' )
3138 write_file "#{ path } .c" , strip_comments ( data )
3239
33- gcc_cmd = "gcc -o '#{ path } ' '#{ path } .c'"
40+ compiler_cmd = "#{ datastore [ 'COMPILER' ] } -o '#{ path } ' '#{ path } .c'"
3441 if session . type == 'shell'
35- gcc_cmd = "PATH=\" $PATH:/usr/bin/\" #{ gcc_cmd } "
42+ compiler_cmd = "PATH=\" $PATH:/usr/bin/\" #{ compiler_cmd } "
3643 end
3744
38- unless gcc_args . to_s . blank?
39- gcc_cmd << " #{ gcc_args } "
45+ unless compiler_args . to_s . blank?
46+ compiler_cmd << " #{ compiler_args } "
4047 end
4148
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+
4352 rm_f "#{ path } .c"
4453
45- unless output . blank?
46- print_error output
54+ unless success
4755 message = "#{ path } .c failed to compile."
4856 # don't mention the COMPILE option if it was deregistered
4957 message << ' Set COMPILE to False to upload a pre-compiled executable.' if options . include? ( 'COMPILE' )
0 commit comments