Module: Msf::Post::Linux::Compile
- Includes:
- Common, File, Unix
- Defined in:
- lib/msf/core/post/linux/compile.rb
Instance Method Summary
collapse
Methods included from Unix
#enum_user_directories, #get_groups, #get_session_pid, #get_users, #is_root?, #whoami
Methods included from File
#_append_file_powershell, #_append_file_unix_shell, #_can_echo?, #_read_file_meterpreter, #_read_file_powershell, #_read_file_powershell_fragment, #_shell_command_with_success_code, #_unix_max_line_length, #_win_ansi_append_file, #_win_ansi_write_file, #_win_bin_append_file, #_win_bin_write_file, #_write_file_meterpreter, #_write_file_powershell, #_write_file_powershell_fragment, #_write_file_unix_shell, #append_file, #attributes, #cd, #chmod, #copy_file, #dir, #directory?, #executable?, #exist?, #expand_path, #exploit_data, #exploit_source, #file?, #file_local_write, #file_remote_digestmd5, #file_remote_digestsha1, #file_remote_digestsha2, #immutable?, #mkdir, #pwd, #read_file, #readable?, #rename_file, #rm_f, #rm_rf, #setuid?, #stat, #upload_and_chmodx, #upload_file, #writable?, #write_file
Methods included from Common
#clear_screen, #cmd_exec, #cmd_exec_get_pid, #cmd_exec_with_result, #command_exists?, #get_env, #get_envs, #peer, #report_virtualization, #rhost, #rport
Instance Method Details
#initialize(info = {}) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/msf/core/post/linux/compile.rb', line 10
def initialize(info = {})
super
register_options( [
OptEnum.new('COMPILE', [true, 'Compile on target', 'Auto', ['Auto', 'True', 'False']]),
], self.class)
end
|
#live_compile? ⇒ Boolean
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/msf/core/post/linux/compile.rb', line 17
def live_compile?
return false unless %w{ Auto True }.include?(datastore['COMPILE'])
if has_gcc?
vprint_good 'gcc is installed'
return true
end
unless datastore['COMPILE'] == 'Auto'
fail_with Module::Failure::BadConfig, 'gcc is not installed. Set COMPILE False to upload a pre-compiled executable.'
end
end
|
56
57
58
|
# File 'lib/msf/core/post/linux/compile.rb', line 56
def (c_code)
c_code.gsub(%r{/\*.*?\*/}m, '').gsub(%r{^\s*//.*$}, '')
end
|
#upload_and_compile(path, data, gcc_args = '') ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/msf/core/post/linux/compile.rb', line 30
def upload_and_compile(path, data, gcc_args='')
write_file "#{path}.c", (data)
gcc_cmd = "gcc -o '#{path}' '#{path}.c'"
if session.type == 'shell'
gcc_cmd = "PATH=\"$PATH:/usr/bin/\" #{gcc_cmd}"
end
unless gcc_args.to_s.blank?
gcc_cmd << " #{gcc_args}"
end
output = cmd_exec gcc_cmd
rm_f "#{path}.c"
unless output.blank?
print_error output
message = "#{path}.c failed to compile."
message << ' Set COMPILE to False to upload a pre-compiled executable.' if options.include?('COMPILE')
fail_with Module::Failure::BadConfig, message
end
chmod path
end
|