Skip to content

Commit c447e0d

Browse files
authored
Merge pull request #2000 from OWASP/macos-test-fix
Fix for M1(+) binary executions outside of docker
2 parents 5319e6f + b72ec2b commit c447e0d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/main/java/org/owasp/wrongsecrets/challenges/docker/binaryexecution/BinaryExecutionHelper.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,44 @@ private File createTempExecutable(String fileName) throws IOException {
229229
log.info("setting the file {} executable failed... rest can be ignored", execFile.getPath());
230230
}
231231
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+
}
232239
return execFile;
233240
}
234241

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+
235270
private void deleteFile(File execFile) {
236271
if (!execFile.delete()) {
237272
log.info("Deleting the file {} failed...", execFile.getPath());

0 commit comments

Comments
 (0)