From 9bf5abe10b26354189046d5e8f7425686be14263 Mon Sep 17 00:00:00 2001 From: Translator Date: Tue, 7 Jan 2025 18:15:53 +0000 Subject: [PATCH] Translated ['src/network-services-pentesting/pentesting-web/electron-des --- .gitignore | 1 + hacktricks-preprocessor.py | 53 ++++--- .../electron-desktop-apps/README.md | 131 +++++++++++++++--- 3 files changed, 148 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 365859fbc..77edd91a0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ scripts/* book book/* hacktricks-preprocessor.log +hacktricks-preprocessor-error.log diff --git a/hacktricks-preprocessor.py b/hacktricks-preprocessor.py index 969d5333e..af5949449 100644 --- a/hacktricks-preprocessor.py +++ b/hacktricks-preprocessor.py @@ -7,7 +7,14 @@ from os import path from urllib.request import urlopen, Request logger = logging.getLogger(__name__) -logging.basicConfig(filename='hacktricks-preprocessor.log', filemode='w', encoding='utf-8', level=logging.DEBUG) +logger.setLevel(logging.DEBUG) +handler = logging.FileHandler(filename='hacktricks-preprocessor.log', mode='w', encoding='utf-8') +handler.setLevel(logging.DEBUG) +logger.addHandler(handler) + +handler2 = logging.FileHandler(filename='hacktricks-preprocessor-error.log', mode='w', encoding='utf-8') +handler2.setLevel(logging.ERROR) +logger.addHandler(handler2) def findtitle(search ,obj, key, path=(),): @@ -27,7 +34,7 @@ def findtitle(search ,obj, key, path=(),): def ref(matchobj): - logger.debug(f'Match: {matchobj.groups(0)[0].strip()}') + logger.debug(f'Ref match: {matchobj.groups(0)[0].strip()}') href = matchobj.groups(0)[0].strip() title = href if href.startswith("http://") or href.startswith("https://"): @@ -45,19 +52,29 @@ def ref(matchobj): try: if href.endswith("/"): href = href+"README.md" # Fix if ref points to a folder - chapter, _path = findtitle(href, book, "source_path") - logger.debug(f'Recursive title search result: {chapter["name"]}') - title = chapter['name'] + if "#" in href: + chapter, _path = findtitle(href.split("#")[0], book, "source_path") + title = " ".join(href.split("#")[1].split("-")).title() + logger.debug(f'Ref has # using title: {title}') + else: + chapter, _path = findtitle(href, book, "source_path") + logger.debug(f'Recursive title search result: {chapter["name"]}') + title = chapter['name'] except Exception as e: try: dir = path.dirname(current_chapter['source_path']) logger.debug(f'Error getting chapter title: {href} trying with relative path {path.normpath(path.join(dir,href))}') - chapter, _path = findtitle(path.normpath(path.join(dir,href)), book, "source_path") - logger.debug(f'Recursive title search result: {chapter["name"]}') - title = chapter['name'] + if "#" in href: + chapter, _path = findtitle(path.normpath(path.join(dir,href.split('#')[0])), book, "source_path") + title = " ".join(href.split("#")[1].split("-")).title() + logger.debug(f'Ref has # using title: {title}') + else: + chapter, _path = findtitle(path.normpath(path.join(dir,href.split('#')[0])), book, "source_path") + title = chapter["name"] + logger.debug(f'Recursive title search result: {chapter["name"]}') except Exception as e: - logger.debug(f'Error getting chapter title: {path.normpath(path.join(dir,href))}') - print(f'Error getting chapter title: {path.normpath(path.join(dir,href))}') + logger.debug(e) + logger.error(f'Error getting chapter title: {path.normpath(path.join(dir,href))}') sys.exit(1) @@ -69,6 +86,7 @@ def ref(matchobj): return result + def files(matchobj): logger.debug(f'Files match: {matchobj.groups(0)[0].strip()}') href = matchobj.groups(0)[0].strip() @@ -76,19 +94,19 @@ def files(matchobj): try: for root, dirs, files in os.walk(os.getcwd()+'/src/files'): + logger.debug(root) + logger.debug(files) if href in files: title = href logger.debug(f'File search result: {os.path.join(root, href)}') except Exception as e: logger.debug(e) - logger.debug(f'Error searching file: {href}') - print(f'Error searching file: {href}') + logger.error(f'Error searching file: {href}') sys.exit(1) if title=="": - logger.debug(f'Error searching file: {href}') - print(f'Error searching file: {href}') + logger.error(f'Error searching file: {href}') sys.exit(1) template = f"""{title}""" @@ -97,6 +115,7 @@ def files(matchobj): return result + def add_read_time(content): regex = r'(<\/style>\n# .*(?=\n))' new_content = re.sub(regex, lambda x: x.group(0) + "\n\nReading time: {{ #reading_time }}", content) @@ -126,15 +145,15 @@ if __name__ == '__main__': context, book = json.load(sys.stdin) logger.debug(f"Context: {context}") - logger.debug(f"Env: {context['config']['preprocessor']['hacktricks']['env']}") for chapter in iterate_chapters(book['sections']): logger.debug(f"Chapter: {chapter['path']}") current_chapter = chapter - regex = r'{{[\s]*#ref[\s]*}}(?:\n)?([^\\\n]*)(?:\n)?{{[\s]*#endref[\s]*}}' + # regex = r'{{[\s]*#ref[\s]*}}(?:\n)?([^\\\n]*)(?:\n)?{{[\s]*#endref[\s]*}}' + regex = r'{{[\s]*#ref[\s]*}}(?:\n)?([^\\\n#]*(?:#(.*))?)(?:\n)?{{[\s]*#endref[\s]*}}' new_content = re.sub(regex, ref, chapter['content']) regex = r'{{[\s]*#file[\s]*}}(?:\n)?([^\\\n]*)(?:\n)?{{[\s]*#endfile[\s]*}}' - new_content = re.sub(regex, files, chapter['content']) + new_content = re.sub(regex, files, new_content) new_content = add_read_time(new_content) chapter['content'] = new_content diff --git a/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md b/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md index b3b8c8517..c1b432812 100644 --- a/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md +++ b/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md @@ -4,14 +4,14 @@ ## Introduction -Electron एक स्थानीय बैकएंड (जिसमें **NodeJS**) और एक फ्रंटएंड (**Chromium**) को मिलाता है, हालांकि इसमें आधुनिक ब्राउज़रों के कुछ सुरक्षा तंत्रों की कमी है। +Electron एक स्थानीय बैकएंड (जिसमें **NodeJS**) और एक फ्रंटेंड (**Chromium**) को मिलाता है, हालांकि इसमें आधुनिक ब्राउज़रों के कुछ सुरक्षा तंत्रों की कमी है। आमतौर पर आप इलेक्ट्रॉन ऐप कोड को एक `.asar` एप्लिकेशन के अंदर पाएंगे, कोड प्राप्त करने के लिए आपको इसे निकालना होगा: ```bash npx asar extract app.asar destfolder #Extract everything npx asar extract-file app.asar main.js #Extract just a file ``` -Electron ऐप के स्रोत कोड में, `packet.json` के अंदर, आप `main.js` फ़ाइल पा सकते हैं जहाँ सुरक्षा कॉन्फ़िग्स सेट किए गए हैं। +Electron ऐप के स्रोत कोड में, `packet.json` के अंदर, आप `main.js` फ़ाइल को पा सकते हैं जहाँ सुरक्षा कॉन्फ़िग्स सेट किए गए हैं। ```json { "name": "standard-notes", @@ -20,7 +20,7 @@ Electron ऐप के स्रोत कोड में, `packet.json` के Electron के 2 प्रक्रिया प्रकार हैं: - मुख्य प्रक्रिया (NodeJS तक पूर्ण पहुंच है) -- रेंडरर प्रक्रिया (सुरक्षा कारणों से NodeJS की पहुंच सीमित होनी चाहिए) +- रेंडरर प्रक्रिया (सुरक्षा कारणों से NodeJS की सीमित पहुंच होनी चाहिए) ![](<../../../images/image (182).png>) @@ -71,7 +71,7 @@ spellcheck: true, }, } ``` -कुछ **RCE payloads** [यहाँ](https://7as.es/electron/nodeIntegration_rce.txt) से: +कुछ **RCE पेलोड** [यहाँ](https://7as.es/electron/nodeIntegration_rce.txt) से: ```html Example Payloads (Windows): { ``` ## RCE via shell.openExternal -इस उदाहरणों के बारे में अधिक जानकारी के लिए देखें [https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8](https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8) और [https://benjamin-altpeter.de/shell-openexternal-dangers/](https://benjamin-altpeter.de/shell-openexternal-dangers/) +For more info about this examples check [https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8](https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8) and [https://benjamin-altpeter.de/shell-openexternal-dangers/](https://benjamin-altpeter.de/shell-openexternal-dangers/) जब एक Electron डेस्कटॉप एप्लिकेशन को तैनात किया जाता है, तो `nodeIntegration` और `contextIsolation` के लिए सही सेटिंग्स सुनिश्चित करना महत्वपूर्ण है। यह स्थापित किया गया है कि **क्लाइंट-साइड रिमोट कोड निष्पादन (RCE)** जो प्रीलोड स्क्रिप्ट या मुख्य प्रक्रिया से Electron के मूल कोड को लक्षित करता है, इन सेटिंग्स के साथ प्रभावी रूप से रोका जाता है। -जब एक उपयोगकर्ता लिंक के साथ इंटरैक्ट करता है या नई विंडो खोलता है, तो विशिष्ट इवेंट लिस्नर्स ट्रिगर होते हैं, जो एप्लिकेशन की सुरक्षा और कार्यक्षमता के लिए महत्वपूर्ण होते हैं: +जब एक उपयोगकर्ता लिंक के साथ इंटरैक्ट करता है या नए विंडो खोलता है, तो विशिष्ट इवेंट लिसनर्स ट्रिगर होते हैं, जो एप्लिकेशन की सुरक्षा और कार्यक्षमता के लिए महत्वपूर्ण होते हैं: ```javascript webContents.on("new-window", function (event, url, disposition, options) {} webContents.on("will-navigate", function (event, url) {} @@ -200,7 +200,9 @@ webContents.on("will-navigate", function (event, url) {} ![https://miro.medium.com/max/1400/1*ZfgVwT3X1V_UfjcKaAccag.png](<../../../images/image (963).png>) -Electron JS सुरक्षा सर्वोत्तम प्रथाओं की सलाह देती है कि `openExternal` फ़ंक्शन के साथ अविश्वसनीय सामग्री को स्वीकार न करें, क्योंकि यह विभिन्न प्रोटोकॉल के माध्यम से RCE की ओर ले जा सकता है। ऑपरेटिंग सिस्टम विभिन्न प्रोटोकॉल का समर्थन करते हैं जो RCE को ट्रिगर कर सकते हैं। इस विषय पर विस्तृत उदाहरणों और आगे की व्याख्या के लिए, कोई [इस संसाधन](https://positive.security/blog/url-open-rce#windows-10-19042) का संदर्भ ले सकता है, जिसमें इस कमजोरियों का शोषण करने में सक्षम Windows प्रोटोकॉल के उदाहरण शामिल हैं। +Electron JS सुरक्षा सर्वोत्तम प्रथाओं की सलाह देती है कि `openExternal` फ़ंक्शन के साथ अविश्वसनीय सामग्री को स्वीकार न करें, क्योंकि यह विभिन्न प्रोटोकॉल के माध्यम से RCE का कारण बन सकता है। ऑपरेटिंग सिस्टम विभिन्न प्रोटोकॉल का समर्थन करते हैं जो RCE को ट्रिगर कर सकते हैं। इस विषय पर विस्तृत उदाहरणों और आगे की व्याख्या के लिए, कोई [इस संसाधन](https://positive.security/blog/url-open-rce#windows-10-19042) का संदर्भ ले सकता है, जिसमें इस भेद्यता का शोषण करने में सक्षम Windows प्रोटोकॉल के उदाहरण शामिल हैं। + +macos में, `openExternal` फ़ंक्शन का उपयोग मनमाने कमांड को निष्पादित करने के लिए किया जा सकता है जैसे कि `shell.openExternal('file:///System/Applications/Calculator.app')`। **Windows प्रोटोकॉल शोषण के उदाहरणों में शामिल हैं:** ```html @@ -222,13 +224,13 @@ window.open( ) ``` -## आंतरिक फ़ाइलें पढ़ना: XSS + contextIsolation +## Reading Internal Files: XSS + contextIsolation -**`contextIsolation` को अक्षम करना `` टैग के उपयोग की अनुमति देता है**, जो `