@@ -229,9 +229,44 @@ private File createTempExecutable(String fileName) throws IOException {
229
229
log .info ("setting the file {} executable failed... rest can be ignored" , execFile .getPath ());
230
230
}
231
231
FileUtils .copyFile (challengeFile , execFile );
232
+ if (useArm () && !useLinux () && !useWindows ()) {
233
+ // we have an aarch macos
234
+ log .info (
235
+ "We are on Mac os with ARM let's use xattr -d com.apple.quarantine on {}" ,
236
+ execFile .getPath ());
237
+ xattrMacOSExecFile (execFile );
238
+ }
232
239
return execFile ;
233
240
}
234
241
242
+ @ SuppressFBWarnings (
243
+ value = "COMMAND_INJECTION" ,
244
+ justification = "We check for various injection methods and counter those" )
245
+ private static void xattrMacOSExecFile (File execFile ) {
246
+ try {
247
+ if (!(execFile != null
248
+ && execFile .exists ()
249
+ && !Strings .isNullOrEmpty (execFile .getPath ())
250
+ && execFile .getPath ().contains ("wrongsecrets" ))) {
251
+ log .info ("The execfile is not properly setup, returning" );
252
+ return ;
253
+ }
254
+ ProcessBuilder ps =
255
+ new ProcessBuilder ("/usr/bin/xattr" , "-d" , "com.apple.quarantine" , execFile .getPath ());
256
+ ps .redirectErrorStream (true );
257
+ Process pr = ps .start ();
258
+ try (BufferedReader in =
259
+ new BufferedReader (new InputStreamReader (pr .getInputStream (), StandardCharsets .UTF_8 ))) {
260
+ String result = in .readLine ();
261
+ log .info ("result of xatr operation: " + result );
262
+ } catch (IOException e ) {
263
+ log .warn ("error while reading executable file" , e );
264
+ }
265
+ } catch (IOException e ) {
266
+ log .warn ("error while reading executable file" , e );
267
+ }
268
+ }
269
+
235
270
private void deleteFile (File execFile ) {
236
271
if (!execFile .delete ()) {
237
272
log .info ("Deleting the file {} failed..." , execFile .getPath ());
0 commit comments