@@ -159,9 +159,9 @@ public function ping($system, $ip, $return = "list")
159159 case 0 :
160160 // linux ping
161161 if ($ return == "true " ) {
162- exec ("ping -c 1 -w 1 " . escapeshellarg ($ ip ), $ list );
162+ exec ("ping -n - c 1 -w 1 " . escapeshellarg ($ ip ), $ list );
163163 } else {
164- exec ("ping -c 1 -w 1 " . escapeshellarg ($ ip ), $ list , $ error );
164+ exec ("ping -n - c 1 -w 1 " . escapeshellarg ($ ip ), $ list , $ error );
165165 }
166166 $ nb = count ($ list );
167167 if (isset ($ nb ) && $ return == "true " ) {
@@ -210,9 +210,9 @@ public function ping($system, $ip, $return = "list")
210210 case 3 :
211211 // BSD ping
212212 if ($ return == "true " ) {
213- exec ("ping -c 1 -W 1 " . escapeshellarg ($ ip ), $ list );
213+ exec ("ping -n - c 1 -W 1 " . escapeshellarg ($ ip ), $ list );
214214 } else {
215- exec ("ping -c 1 -W 1 " . escapeshellarg ($ ip ), $ list , $ error );
215+ exec ("ping -n - c 1 -W 1 " . escapeshellarg ($ ip ), $ list , $ error );
216216 }
217217 $ nb = count ($ list );
218218 if (isset ($ nb ) && $ return == "true " ) {
@@ -227,9 +227,9 @@ public function ping($system, $ip, $return = "list")
227227 case 4 :
228228 // MacOSX ping
229229 if ($ return == "true " ) {
230- exec ("ping -c 1 -t 1 " . escapeshellarg ($ ip ), $ list );
230+ exec ("ping -n - c 1 -t 1 " . escapeshellarg ($ ip ), $ list );
231231 } else {
232- exec ("ping -c 1 -t 1 " . escapeshellarg ($ ip ), $ list , $ error );
232+ exec ("ping -n - c 1 -t 1 " . escapeshellarg ($ ip ), $ list , $ error );
233233 }
234234 $ nb = count ($ list );
235235 if (isset ($ nb ) && $ return == "true " ) {
@@ -242,7 +242,14 @@ public function ping($system, $ip, $return = "list")
242242 break ;
243243 }
244244 if ($ return == "list " ) {
245- $ list_str = implode ('<br /> ' , $ list );
245+ // Ping output is external, attacker-influenced data (notably the reverse-DNS
246+ // PTR of the target IP on Unix). It is echoed as text/html by ajax/ping.php,
247+ // so escape every line before joining with the intended <br /> separators to
248+ // prevent reflected XSS; the <br /> tags stay as the only markup emitted.
249+ $ list_str = implode ('<br /> ' , array_map (
250+ static fn ($ line ): string => htmlspecialchars ((string ) $ line , ENT_QUOTES , 'UTF-8 ' ),
251+ $ list ,
252+ ));
246253
247254 return [$ list_str , $ error ];
248255 } else {
0 commit comments