๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ Pentesting ๋ฐฉ๋ฒ๋ก
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
๊ธฐ๋ณธ ์ ๋ณด
๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ์ JavaScript๋ก ์์ฑ๋๋ฉฐ ๋ธ๋ผ์ฐ์ ์ ์ํด ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๋ก๋๋ฉ๋๋ค. ํ์ฅ ํ๋ก๊ทธ๋จ์ DOM์ ๊ฐ์ง์ง๋ง ๋ค๋ฅธ ์ฌ์ดํธ๋ค์ DOM๊ณผ ์ํธ์์ฉํ ์ ์์ต๋๋ค. ์ด๋ ๋ค๋ฅธ ์ฌ์ดํธ๋ค์ ๊ธฐ๋ฐ์ฑ(confidentiality), ๋ฌด๊ฒฐ์ฑ(integrity), ๊ฐ์ฉ์ฑ(availability) (CIA)์ ์นจํดํ ์ ์์์ ์๋ฏธํฉ๋๋ค.
์ฃผ์ ๊ตฌ์ฑ ์์
ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋ ์ด์์์ ์๊ฐํํ์ ๋ ๊ฐ์ฅ ์ ์ดํด๋๋ฉฐ ์ธ ๊ฐ์ง ๊ตฌ์ฑ ์์๋ก ์ด๋ฃจ์ด์ ธ ์์ต๋๋ค. ๊ฐ ๊ตฌ์ฑ ์์๋ฅผ ์์ธํ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
 (1) (1).png)
Content Scripts
๊ฐ content script๋ ๋จ์ผ ์น ํ์ด์ง์ DOM์ ์ง์ ์ ๊ทผํ ์ ์์ผ๋ฏ๋ก ์ ์ฌ์ ์ผ๋ก ์ ์์ ์ธ ์ ๋ ฅ์ ๋ ธ์ถ๋ฉ๋๋ค. ๊ทธ๋ฌ๋ content script๋ ํ์ฅ ํ๋ก๊ทธ๋จ ์ฝ์ด์ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ ์๋ ๊ธฐ๋ฅ ์ธ์๋ ๊ถํ์ ๊ฐ์ง์ง ์์ต๋๋ค.
Extension Core
extension core๋ ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋๋ถ๋ถ ๊ถํ/์ ๊ทผ์ ํฌํจํ์ง๋ง, extension core๋ ์น ์ปจํ ์ธ ์ ์ํธ์์ฉํ ๋ XMLHttpRequest์ content scripts๋ฅผ ํตํด์๋ง ๊ฐ๋ฅํฉ๋๋ค. ๋ํ extension core๋ ํธ์คํธ ์์คํ ์ ๋ํ ์ง์ ์ ์ธ ์ ๊ทผ ๊ถํ์ด ์์ต๋๋ค.
Native Binary
ํ์ฅ ํ๋ก๊ทธ๋จ์ ์ฌ์ฉ์์ ์ ์ฒด ๊ถํ์ผ๋ก ํธ์คํธ ์์คํ ์ ์ ๊ทผํ ์ ์๋ native binary๋ฅผ ํ์ฉํ ์ ์์ต๋๋ค. native binary๋ Flash ๋ฐ ๊ธฐํ ๋ธ๋ผ์ฐ์ ํ๋ฌ๊ทธ์ธ์์ ์ฌ์ฉ๋๋ ํ์ค Netscape Plugin Application Programming Interface (NPAPI)๋ฅผ ํตํด extension core์ ์ํธ์์ฉํฉ๋๋ค.
Boundaries
Caution
์ฌ์ฉ์์ ์ ์ฒด ๊ถํ์ ์ป๊ธฐ ์ํด, ๊ณต๊ฒฉ์๋ content script์์ extension์ core๋ก ์ ์ฑ ์ ๋ ฅ์ ์ ๋ฌํ๊ณ extension์ core์์ native binary๋ก ์ ๋ฌํ๋๋ก ํ์ฅ ํ๋ก๊ทธ๋จ์ ์์ฌ์ผ ํฉ๋๋ค.
ํ์ฅ ํ๋ก๊ทธ๋จ์ ๊ฐ ๊ตฌ์ฑ ์์๋ ์๋ก ๊ฐ๋ ฅํ ๋ณดํธ ๊ฒฝ๊ณ๋ก ๋ถ๋ฆฌ๋์ด ์์ต๋๋ค. ๊ฐ ๊ตฌ์ฑ ์์๋ ๋ณ๋์ ์ด์ ์ฒด์ ํ๋ก์ธ์ค์์ ์คํ๋ฉ๋๋ค. Content scripts์ extension cores๋ ๋๋ถ๋ถ์ ์ด์ ์ฒด์ ์๋น์ค์์ ์ ๊ทผํ ์ ์๋ sandbox ํ๋ก์ธ์ค์์ ์คํ๋ฉ๋๋ค.
๋ํ content scripts๋ ๋ณ๋์ JavaScript ํ์์ ์คํ๋จ์ผ๋ก์จ ๊ด๋ จ ์น ํ์ด์ง์ ๋ถ๋ฆฌ๋ฉ๋๋ค. content script์ ์น ํ์ด์ง๋ ๊ฐ์ ๊ธฐ๋ณธ DOM์ ์ ๊ทผํ ์ ์์ง๋ง, ๋ ๊ฐ์ฒด๋ JavaScript ํฌ์ธํฐ๋ฅผ ์ ๋ ๊ตํํ์ง ์์ผ๋ฏ๋ก JavaScript ๊ธฐ๋ฅ์ leak๋ฅผ ๋ฐฉ์งํฉ๋๋ค.
manifest.json
Chrome ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋จ์ง .crx file extension์ ๊ฐ์ง ZIP ํด๋์ผ ๋ฟ์
๋๋ค. ํ์ฅ ํ๋ก๊ทธ๋จ์ ํต์ฌ์ ํด๋ ๋ฃจํธ์ ์๋ manifest.json ํ์ผ๋ก, ๋ ์ด์์, ๊ถํ ๋ฐ ๊ธฐํ ๊ตฌ์ฑ ์ต์
์ ์ง์ ํฉ๋๋ค.
Example:
{
"manifest_version": 2,
"name": "My extension",
"version": "1.0",
"permissions": ["storage"],
"content_scripts": [
{
"js": ["script.js"],
"matches": ["https://example.com/*", "https://www.example.com/*"],
"exclude_matches": ["*://*/*business*"]
}
],
"background": {
"scripts": ["background.js"]
},
"options_ui": {
"page": "options.html"
}
}
content_scripts
Content scripts๋ ์ฌ์ฉ์๊ฐ ์ผ์นํ๋ ํ์ด์ง๋ก ์ด๋ํ ๋๋ง๋ค ๋ก๋๋ฉ๋๋ค, ์ด ๊ฒฝ์ฐ https://example.com/* ํํ์๊ณผ ์ผ์นํ๊ณ *://*/*/business* ์ ๊ท์๊ณผ๋ ์ผ์นํ์ง ์๋ ๋ชจ๋ ํ์ด์ง๊ฐ ํด๋นํฉ๋๋ค. ์ด๋ค์ ํ์ด์ง ์์ฒด์ ์คํฌ๋ฆฝํธ์ฒ๋ผ ์คํ๋๋ฉฐ ํ์ด์ง์ Document Object Model (DOM)์ ์์๋ก ์ ๊ทผํ ์ ์์ต๋๋ค.
"content_scripts": [
{
"js": [
"script.js"
],
"matches": [
"https://example.com/*",
"https://www.example.com/*"
],
"exclude_matches": ["*://*/*business*"],
}
],
๋ ๋ง์ URL์ ํฌํจํ๊ฑฐ๋ ์ ์ธํ๋ ค๋ฉด **include_globs**์ **exclude_globs**๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ค์์ the storage API๋ฅผ ์ฌ์ฉํด ํ์ฅ ํ๋ก๊ทธ๋จ์ ์ ์ฅ์์์ message ๊ฐ์ ๊ฐ์ ธ์ฌ ๋ ํ์ด์ง์ explain ๋ฒํผ์ ์ถ๊ฐํ๋ ์์ content script์
๋๋ค.
chrome.storage.local.get("message", (result) => {
let div = document.createElement("div")
div.innerHTML = result.message + " <button>Explain</button>"
div.querySelector("button").addEventListener("click", () => {
chrome.runtime.sendMessage("explain")
})
document.body.appendChild(div)
})
.png)
์ด ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ฝํ
์ธ ์คํฌ๋ฆฝํธ๊ฐ runtime.sendMessage() API๋ฅผ ์ฌ์ฉํด ํ์ฅ ํ๋ก๊ทธ๋จ ํ์ด์ง๋ก ๋ฉ์์ง๋ฅผ ๋ณด๋
๋๋ค. ์ด๋ ์ฝํ
์ธ ์คํฌ๋ฆฝํธ๊ฐ ๋๋ถ๋ถ์ API์ ์ง์ ์ ๊ทผํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ฉฐ, storage ๊ฐ์ ๋ช ๊ฐ์ง ์์ธ๋ง ์ง์ ์ ๊ทผํ ์ ์์ต๋๋ค. ์ด๋ฌํ ์์ธ๋ฅผ ๋ฒ์ด๋ ๊ธฐ๋ฅ์ ํ์ฅ ํ๋ก๊ทธ๋จ ํ์ด์ง๋ก ๋ฉ์์ง๋ฅผ ๋ณด๋ด๊ณ , ์ฝํ
์ธ ์คํฌ๋ฆฝํธ๊ฐ ํด๋น ํ์ด์ง์ ํต์ ํฉ๋๋ค.
Warning
๋ธ๋ผ์ฐ์ ์ ๋ฐ๋ผ ์ฝํ ์ธ ์คํฌ๋ฆฝํธ์ ๊ธฐ๋ฅ์ด ์ฝ๊ฐ ๋ค๋ฅผ ์ ์์ต๋๋ค. Chromium ๊ธฐ๋ฐ ๋ธ๋ผ์ฐ์ ์ ๊ธฐ๋ฅ ๋ชฉ๋ก์ Chrome Developers documentation์์ ํ์ธํ ์ ์๊ณ , Firefox์ ๊ฒฝ์ฐ ์ฃผ์ ์ถ์ฒ๋ MDN์ ๋๋ค.
๋ํ ์ฝํ ์ธ ์คํฌ๋ฆฝํธ๋ background ์คํฌ๋ฆฝํธ์ ํต์ ํ์ฌ ๋์์ ์ํํ๊ณ ์๋ต์ ์ ๋ฌํ ์ ์๋ค๋ ์ ๋ ์ฃผ๋ชฉํ ๋งํฉ๋๋ค.
Chrome์์ ์ฝํ ์ธ ์คํฌ๋ฆฝํธ๋ฅผ ๋ณด๊ณ ๋๋ฒ๊น ํ๋ ค๋ฉด Chrome ๊ฐ๋ฐ์ ๋๊ตฌ ๋ฉ๋ด๋ฅผ Options > More tools > Developer tools์์ ์ด๊ฑฐ๋ Ctrl + Shift + I๋ฅผ ๋๋ฅด์ธ์.
๊ฐ๋ฐ์ ๋๊ตฌ๊ฐ ํ์๋๋ฉด Source tab์ ํด๋ฆญํ ๋ค์ Content Scripts ํญ์ ์ ํํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ๋ค์ํ ํ์ฅ ํ๋ก๊ทธ๋จ์์ ์คํ ์ค์ธ ์ฝํ ์ธ ์คํฌ๋ฆฝํธ๋ฅผ ๊ด์ฐฐํ๊ณ ์คํ ํ๋ฆ์ ์ถ์ ํ๊ธฐ ์ํด ๋ธ๋ ์ดํฌํฌ์ธํธ๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค.
Injected content scripts
Tip
Note that Content Scripts arenโt mandatory โ ์น ํ์ด์ง์ ์คํฌ๋ฆฝํธ๋ฅผ ๋์ ์ผ๋ก(inject) ์ฃผ์ ํ๊ฑฐ๋ ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์์ผ๋ก ์ฃผ์ ํ๋ ๊ฒ๋ ๊ฐ๋ฅํ๋ฉฐ, **
tabs.executeScript**๋ฅผ ํตํด ์ํํ ์ ์์ต๋๋ค. ์ด๋ ๋ณด๋ค ์ธ๋ฐํ ์ ์ด๋ฅผ ์ ๊ณตํฉ๋๋ค.
์ฝํ ์ธ ์คํฌ๋ฆฝํธ๋ฅผ ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์์ผ๋ก ์ฃผ์ ํ๋ ค๋ฉด, ์คํฌ๋ฆฝํธ๋ฅผ ์ฃผ์ ํ ํ์ด์ง์ ๋ํ [host permissions]๊ฐ ํ์ฅ ํ๋ก๊ทธ๋จ์ ์์ด์ผ ํฉ๋๋ค. ์ด๋ฌํ ๊ถํ์ ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋งค๋ํ์คํธ์์ ์์ฒญ(requesting them) ํ๊ฑฐ๋ ์ผ์์ ์ผ๋ก activeTab๋ฅผ ํตํด ํ๋ณดํ ์ ์์ต๋๋ค.
activeTab ๊ธฐ๋ฐ ํ์ฅ ์์
{
"name": "My extension",
...
"permissions": [
"activeTab",
"scripting"
],
"background": {
"service_worker": "background.js"
},
"action": {
"default_title": "Action Button"
}
}
- ํด๋ฆญ ์ JS ํ์ผ์ ์ฃผ์ :
// content-script.js
document.body.style.backgroundColor = "orange"
//service-worker.js - Inject the JS file
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["content-script.js"],
})
})
- ํด๋ฆญ ์ ํจ์ ์ฃผ์ :
//service-worker.js - Inject a function
function injectedFunction() {
document.body.style.backgroundColor = "orange"
}
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: injectedFunction,
})
})
์คํฌ๋ฆฝํ ๊ถํ์ด ์๋ ์์
// service-workser.js
chrome.scripting.registerContentScripts([
{
id: "test",
matches: ["https://*.example.com/*"],
excludeMatches: ["*://*/*business*"],
js: ["contentScript.js"],
},
])
// Another example
chrome.tabs.executeScript(tabId, { file: "content_script.js" })
In order to include or exclude more URLs itโs also possible to use include_globs and exclude_globs.
์ฝํ
์ธ ์คํฌ๋ฆฝํธ run_at
The run_at field controls ์ธ์ JavaScript ํ์ผ์ด ์น ํ์ด์ง์ ์ฃผ์
๋๋์ง. The preferred and default value is "document_idle".
The possible values are:
document_idle: ๊ฐ๋ฅํ ๊ฒฝ์ฐ๋ง๋คdocument_start:css์ ํ์ผ๋ค์ด ์ ์ฉ๋ ํ์ด์ง๋ง ๋ค๋ฅธ DOM์ด ๊ตฌ์ฑ๋๊ฑฐ๋ ๋ค๋ฅธ ์คํฌ๋ฆฝํธ๊ฐ ์คํ๋๊ธฐ ์ ์.document_end: DOM์ด ์๋ฃ๋ ์งํ์ด์ง๋ง ์ด๋ฏธ์ง๋ ํ๋ ์ ๊ฐ์ ํ์ ๋ฆฌ์์ค๊ฐ ๋ก๋๋๊ธฐ ์ .
Via manifest.json
{
"name": "My extension",
...
"content_scripts": [
{
"matches": ["https://*.example.com/*"],
"run_at": "document_idle",
"js": ["contentScript.js"]
}
],
...
}
**service-worker.js**๋ฅผ ํตํด
chrome.scripting.registerContentScripts([
{
id: "test",
matches: ["https://*.example.com/*"],
runAt: "document_idle",
js: ["contentScript.js"],
},
])
background
content scripts๊ฐ ๋ณด๋ธ ๋ฉ์์ง๋ ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง์์ ์์ ๋๋ฉฐ, ์ด๋ ํ์ฅ(extension) ๊ตฌ์ฑ ์์๋ค์ ์กฐ์ ํ๋ ์ค์ ์ญํ ์ ํฉ๋๋ค. ํนํ ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง๋ ํ์ฅ ํ๋ก๊ทธ๋จ์ ์๋ช ๋์ ์ง์์ ์ผ๋ก ์กด์ฌํ๋ฉฐ, ์ฌ์ฉ์์ ์ง์ ์ ์ธ ์ํธ์์ฉ ์์ด ์๋ฐํ๊ฒ ๋์ํฉ๋๋ค. ์์ฒด Document Object Model (DOM)์ ๊ฐ์ง๊ณ ์์ด ๋ณต์กํ ์ํธ์์ฉ๊ณผ ์ํ ๊ด๋ฆฌ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค.
ํต์ฌ ํฌ์ธํธ:
- ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง ์ญํ : ํ์ฅ์ ์ ๊ฒฝ์ค์ถ๋ก์ ํ์ฅ์ ์ฌ๋ฌ ๋ถ๋ถ ๊ฐ ํต์ ๊ณผ ์กฐ์ ์ ๋ณด์ฅํฉ๋๋ค.
- ์ง์์ฑ: ์ฌ์ฉ์์๊ฒ๋ ๋ณด์ด์ง ์์ง๋ง ํ์ฅ์ ๊ธฐ๋ฅ์ ํ์์ ์ธ ํญ์ ์กด์ฌํ๋ ์ํฐํฐ์ ๋๋ค.
- ์๋ ์์ฑ: ๋ช ์์ ์ผ๋ก ์ ์๋์ง ์์ ๊ฒฝ์ฐ ๋ธ๋ผ์ฐ์ ๋ ์๋์ผ๋ก ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง๋ฅผ ์์ฑํฉ๋๋ค. ์ด ์๋ ์์ฑ๋ ํ์ด์ง์๋ ํ์ฅ manifest์ ๋ช ์๋ ๋ชจ๋ background scripts๊ฐ ํฌํจ๋์ด ๋ฐฑ๊ทธ๋ผ์ด๋ ์์ ์ด ์ํํ ์ํ๋๋๋ก ํฉ๋๋ค.
Tip
๋ธ๋ผ์ฐ์ ๊ฐ ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง๋ฅผ ์๋์ผ๋ก ์์ฑํด ์ฃผ๋ ํธ์์ฑ(๋ช ์์ ์ผ๋ก ์ ์ธํ์ง ์์ ๊ฒฝ์ฐ)์ ํ์ํ ๋ชจ๋ background scripts๊ฐ ํตํฉ๋์ด ๋์ํ๋๋ก ํ์ฌ ํ์ฅ ์ค์ ๊ณผ์ ์ ๊ฐ์ํํฉ๋๋ค.
์์ ๋ฐฑ๊ทธ๋ผ์ด๋ ์คํฌ๋ฆฝํธ:
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request == "explain") {
chrome.tabs.create({ url: "https://example.net/explanation" })
}
})
It uses runtime.onMessage API to listen to messages. When an โexplainโ message is received, it uses tabs API to open a page in a new tab.
๋ฐฑ๊ทธ๋ผ์ด๋ ์คํฌ๋ฆฝํธ๋ฅผ ๋๋ฒ๊ทธํ๋ ค๋ฉด extension details and inspect the service worker, ๋ก ์ด๋ํ๋ฉด ๊ฐ๋ฐ์ ๋๊ตฌ๊ฐ ๋ฐฑ๊ทธ๋ผ์ด๋ ์คํฌ๋ฆฝํธ์ ํจ๊ป ์ด๋ฆฝ๋๋ค:
Options pages and other
Browser extensions can contain various kinds of pages:
- Action pages are displayed in a drop-down when the extension icon is clicked.
- ํ์ฅ ํ๋ก๊ทธ๋จ์ด ์ ํญ์์ ๋ก๋ํ ํ์ด์ง.
- Option Pages: ์ด ํ์ด์ง๋ ํด๋ฆญํ๋ฉด ํ์ฅ ์์ ํ์๋ฉ๋๋ค. ์ด์ manifest์์ ์ ๊ฒฝ์ฐ ์ด ํ์ด์ง์
chrome://extensions/?options=fadlhnelkbeojnebcbkacjilhnbjfjca๋ก ์ ๊ทผํ ์ ์์์ต๋๋ค ๋๋ ํด๋ฆญํ๋ฉด:
.png)
์ด๋ฌํ ํ์ด์ง๋ค์ ํ์์ ๋ฐ๋ผ ๋์ ์ผ๋ก ์ฝํ ์ธ ๋ฅผ ๋ก๋ํ๊ธฐ ๋๋ฌธ์ ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง์ฒ๋ผ ํญ์ ์ง์๋์ง ์๋๋ค๋ ์ ์ ์ ์ํ์ธ์. ๊ทธ๋ผ์๋ ๋ถ๊ตฌํ๊ณ , ์ด๋ค์ ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง์ ๋ช ๊ฐ์ง ๊ธฐ๋ฅ์ ๊ณต์ ํฉ๋๋ค:
- Content Scripts์์ ํต์ : ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์ด์ง์ ์ ์ฌํ๊ฒ, ์ด๋ฌํ ํ์ด์ง๋ค์ content scripts๋ก๋ถํฐ ๋ฉ์์ง๋ฅผ ๋ฐ์ ์ ์์ด ํ์ฅ ๋ด ์ํธ์์ฉ์ ์ด์งํฉ๋๋ค.
- ํ์ฅ ์ ์ฉ API์ ๋ํ ์ ๊ทผ: ์ด๋ฌํ ํ์ด์ง๋ค์ ํ์ฅ์ ์ ์๋ ๊ถํ์ ๋ฐ๋ผ ํ์ฅ ์ ์ฉ API์ ๊ด๋ฒ์ํ๊ฒ ์ ๊ทผํ ์ ์์ต๋๋ค.
permissions & host_permissions
**permissions**์ **host_permissions**๋ manifest.json์ ํญ๋ชฉ์ผ๋ก, ๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ์ด (storage, locationโฆ) ์ด๋ค ๊ถํ์ ๊ฐ๊ณ ์๋์ง์ ์ด๋ค ์น ํ์ด์ง์์ ๋์ํ๋์ง๋ฅผ ๋ํ๋
๋๋ค.
๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋งค์ฐ ๊ถํ์ด ๊ฐ๋ ฅํ ์ ์๊ธฐ ๋๋ฌธ์, ์ ์ฑ ํ์ฅ์ด๋ ์นจํด๋ ํ์ฅ์ ๊ณต๊ฒฉ์์๊ฒ ์ฌ์ฉ์๋ก๋ถํฐ ๋ฏผ๊ฐํ ์ ๋ณด๋ฅผ ํ์น๊ณ ๊ฐ์ํ ์ ์๋ ๋ค์ํ ์๋จ์ ์ ๊ณตํ ์ ์์ต๋๋ค.
Check how these settings work and how they could get abused in:
BrowExt - permissions & host_permissions
content_security_policy
A content security policy can be declared also inside the manifest.json. If there is one defined, it could be vulnerable.
The default setting for browser extension pages is rather restrictive:
script-src 'self'; object-src 'self';
CSP์ ์ ์ฌ์ ์ฐํ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ ๋ค์์ ํ์ธํ์ธ์:
Content Security Policy (CSP) Bypass
web_accessible_resources
์นํ์ด์ง๊ฐ Browser Extension์ ํ์ด์ง(์: .html ํ์ด์ง)์ ์ ๊ทผํ๋ ค๋ฉด, ํด๋น ํ์ด์ง๋ manifest.json์ web_accessible_resources ํ๋์ ๋ช
์๋์ด ์์ด์ผ ํฉ๋๋ค.
์์:
{
...
"web_accessible_resources": [
{
"resources": [ "images/*.png" ],
"matches": [ "https://example.com/*" ]
},
{
"resources": [ "fonts/*.woff" ],
"matches": [ "https://example.com/*" ]
}
],
...
}
์ด ํ์ด์ง๋ค์ ๋ค์๊ณผ ๊ฐ์ URL์์ ์ ๊ทผํ ์ ์์ต๋๋ค:
chrome-extension://<extension-id>/message.html
In public extensions the extension-id is accesible:
.png)
Although, if the manifest.json parameter use_dynamic_url is used, this id can be dynamic.
Tip
Note that even if a page is mentioned here, it might be protected against ClickJacking thanks to the Content Security Policy. So you also need to check it (frame-ancestors section) before confirming a ClickJacking attack is possible.
Being allowed to access these pages make these pages potentially vulnerable ClickJacking:
Tip
Allowing these pages to be loaded only by the extension and not by random URLs could prevent ClickJacking attacks.
Caution
Note that the pages from
web_accessible_resourcesand other pages of the extension are also capable of contacting background scripts. So if one of these pages is vulnerable to XSS it could open a bigger vulnerability.Moreover, note that you can only open pages indicated in
web_accessible_resourcesinside iframes, but from a new tab itโs possible to access any page in the extension knowing the extension ID. Therefore, if an XSS is found abusing same parameters, it could be abused even if the page isnโt configured inweb_accessible_resources.
externally_connectable
A per the docs, The "externally_connectable" manifest property declares which extensions and web pages can connect to your extension via runtime.connect and runtime.sendMessage.
- If the
externally_connectablekey is not declared in your extensionโs manifest or itโs declared as"ids": ["*"], all extensions can connect, but no web pages can connect. - If specific IDs are specified, like in
"ids": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], only those applications can connect. - If matches are specified, those web apps will be able to connect:
"matches": [
"https://*.google.com/*",
"*://*.chromium.org/*",
- If itโs specified as empty:
"externally_connectable": {}, no app or web will be able to connect.
์ฌ๊ธฐ์์ ์ง์ ๋ extensions ๋ฐ URLs๊ฐ ์ ์์๋ก ๊ณต๊ฒฉ ํ๋ฉด(attack surface) ์ด ์์์ง๋๋ค.
Caution
If a web page vulnerable to XSS or takeover is indicated in
externally_connectable, an attacker will be able to send messages directly to the background script, completely bypassing the Content Script and its CSP.Therefore, this is a very powerful bypass.
Moreover, if the client installs a rouge extension, even if it isnโt allowed to communicate with the vulnerable extension, it could inject XSS data in an allowed web page or abuse
WebRequestorDeclarativeNetRequestAPIs to manipulate requests on a targeted domain altering a pageโs request for a JavaScript file. (Note that CSP on the targeted page could prevent these attacks). This idea comes from this writeup.
ํต์ ์์ฝ
Extension <โ> WebApp
content script์ ์น ํ์ด์ง ๊ฐ ํต์ ์๋ ๋ณดํต post messages๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. ๋ฐ๋ผ์ ์น ์ ํ๋ฆฌ์ผ์ด์
์์๋ ๋ณดํต window.postMessage ํธ์ถ์, content script ์ชฝ์์๋ window.addEventListener ๊ฐ์ ๋ฆฌ์ค๋๋ฅผ ๋ณผ ์ ์์ต๋๋ค. ๋ค๋ง extension์ด ์น ์ ํ๋ฆฌ์ผ์ด์
์ Post Message๋ฅผ ๋ณด๋ด ํต์ ํ ์๋(๋ฐ๋ผ์ ์น ์ชฝ์์ ์ด๋ฅผ ๋๋นํด์ผ ํจ) ์๊ณ , ๋จ์ํ ์น์ด ์๋ก์ด ์คํฌ๋ฆฝํธ๋ฅผ ๋ก๋ํ๊ฒ ๋ง๋ค ์๋ ์์ต๋๋ค.
ํ์ฅ ๋ด๋ถ
๋ณดํต ํ์ฅ ๋ด๋ถ์์ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๊ธฐ ์ํด chrome.runtime.sendMessage ํจ์๋ฅผ ์ฌ์ฉํ๋ฉฐ(๋๊ฐ background script์์ ์ฒ๋ฆฌ) ์ด๋ฅผ ์์ ํ๊ณ ์ฒ๋ฆฌํ๊ธฐ ์ํด **chrome.runtime.onMessage.addListener**๋ฅผ ํธ์ถํ๋ ๋ฆฌ์ค๋๋ฅผ ์ ์ธํฉ๋๋ค.
๋จ๋ฐ์ฑ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๋ ๋์ ์ง์์ ์ธ ์ฐ๊ฒฐ์ ์ํด **chrome.runtime.connect()**๋ฅผ ์ฌ์ฉํ ์๋ ์์ผ๋ฉฐ, ๋ค์ ์์ ๊ฐ์ด ์ด๋ฅผ ์ด์ฉํด messages๋ฅผ send ๋ฐ receive ํ ์ ์์ต๋๋ค:
chrome.runtime.connect() example
```javascript
var port = chrome.runtime.connect()
// Listen for messages from the web page window.addEventListener( โmessageโ, (event) => { // Only accept messages from the same window if (event.source !== window) { return }
// Check if the message type is โFROM_PAGEโ if (event.data.type && event.data.type === โFROM_PAGEโ) { console.log(โContent script received: โ + event.data.text) // Forward the message to the background script port.postMessage({ type: โFROM_PAGEโ, text: event.data.text }) } }, false )
// Listen for messages from the background script port.onMessage.addListener(function (msg) { console.log(โContent script received message from background script:โ, msg) // Handle the response message from the background script })
</details>
๋ํ background script์์ ํน์ ํญ์ ์์นํ content script๋ก ๋ฉ์์ง๋ฅผ ๋ณด๋ด๊ธฐ ์ํด **`chrome.tabs.sendMessage`**๋ฅผ ํธ์ถํ ์ ์์ผ๋ฉฐ, ์ด๋ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ **ํญ์ ID**๋ฅผ ์ง์ ํด์ผ ํฉ๋๋ค.
### ํ์ฉ๋ `externally_connectable`์์ ํ์ฅ ํ๋ก๊ทธ๋จ์ผ๋ก
**ํ์ฉ๋ Web apps ๋ฐ ์ธ๋ถ ๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ**๋ `externally_connectable` ๊ตฌ์ฑ์์ ๋ค์์ ์ฌ์ฉํ์ฌ ์์ฒญ์ ๋ณด๋ผ ์ ์์ต๋๋ค :
```javascript
chrome.runtime.sendMessage(extensionId, ...
ํ์ํ ๊ณณ์์๋ extension ID๋ฅผ ์ธ๊ธํ์ธ์.
Native Messaging
๋ฐฑ๊ทธ๋ผ์ด๋ ์คํฌ๋ฆฝํธ๊ฐ ์์คํ ๋ด๋ถ์ ๋ฐ์ด๋๋ฆฌ์ ํต์ ํ ์ ์์ผ๋ฉฐ, ์ด ํต์ ์ด ์ ์ ํ ๋ณดํธ๋์ง ์์ผ๋ฉด RCEs์ ๊ฐ์ ์น๋ช ์ ์ธ ์ทจ์ฝ์ ์ ์ทจ์ฝํ ์ ์์ต๋๋ค. More on this later.
chrome.runtime.sendNativeMessage(
"com.my_company.my_application",
{ text: "Hello" },
function (response) {
console.log("Received " + response)
}
)
์น โ๏ธ Content Script Communication
content scripts๊ฐ ๋์ํ๋ ํ๊ฒฝ๊ณผ ํธ์คํธ ํ์ด์ง๊ฐ ์กด์ฌํ๋ ํ๊ฒฝ์ ์๋ก ๋ถ๋ฆฌ๋์ด ์์ด ๊ฒฉ๋ฆฌ๊ฐ ๋ณด์ฅ๋ฉ๋๋ค. ์ด๋ฌํ ๊ฒฉ๋ฆฌ์๋ ๋ถ๊ตฌํ๊ณ , ์์ธก์ ๊ณต์ฉ ์์์ธ ํ์ด์ง์ **Document Object Model (DOM)**๊ณผ ์ํธ์์ฉํ ์ ์์ต๋๋ค. ํธ์คํธ ํ์ด์ง๊ฐ content script์ ํต์ ํ๊ฑฐ๋ content script๋ฅผ ํตํด extension๊ณผ ๊ฐ์ ์ ์ผ๋ก ํต์ ํ๋ ค๋ฉด, ์์ธก์์ ์ ๊ทผ ๊ฐ๋ฅํ DOM์ ํต์ ์ฑ๋๋ก ์ฌ์ฉํด์ผ ํฉ๋๋ค.
Post Messages
// This is like "chrome.runtime.sendMessage" but to maintain the connection
var port = chrome.runtime.connect()
window.addEventListener(
"message",
(event) => {
// We only accept messages from ourselves
if (event.source !== window) {
return
}
if (event.data.type && event.data.type === "FROM_PAGE") {
console.log("Content script received: " + event.data.text)
// Forward the message to the background script
port.postMessage(event.data.text)
}
},
false
)
document.getElementById("theButton").addEventListener(
"click",
() => {
window.postMessage(
{ type: "FROM_PAGE", text: "Hello from the webpage!" },
"*"
)
},
false
)
A secure Post Message communication should check the authenticity of the received message, this can be done checking:
event.isTrusted: ์ด ๊ฐ์ ์ด๋ฒคํธ๊ฐ ์ฌ์ฉ์์ ๋์์ ์ํด ํธ๋ฆฌ๊ฑฐ๋ ๊ฒฝ์ฐ์๋ง True์ ๋๋ค- Content Script๋ ์ฌ์ฉ์๊ฐ ํน์ ๋์์ ์ํํ ๋์๋ง ๋ฉ์์ง๋ฅผ ๊ธฐ๋ํ๋๋ก ์ค๊ณ๋ ์ ์์ต๋๋ค
- origin domain: ํน์ ๋๋ฉ์ธ๋ค์ allowlist(ํ์ฉ ๋ชฉ๋ก)์๋ง ๋ฉ์์ง๋ฅผ ํ์ฉํ๋๋ก ๊ธฐ๋ํ ์ ์์ต๋๋ค.
- If a regex is used, be very careful
- Source:
received_message.source !== window๋ฅผ ์ฌ์ฉํด์ ๋ฉ์์ง๊ฐ Content Script๊ฐ ๋ฆฌ์ค๋ ์ค์ธ ๋์ผํ ์ฐฝ์์ ์จ ๊ฒ์ธ์ง ํ์ธํ ์ ์์ต๋๋ค.
The previous checks, even if performed, could be vulnerable, so check in the following page potential Post Message bypasses:
Iframe
Another possible way of communication might be through Iframe URLs, you can find an example in:
DOM
This isnโt โexactlyโ a communication way, but the web and the content script will have access to the web DOM. So, if the content script is reading some information from it, trusting the web DOM, the web could modify this data (because the web shouldnโt be trusted, or because the web is vulnerable to XSS) and compromise the Content Script.
You can also find an example of a DOM based XSS to compromise a browser extension in:
Content Script โ๏ธ Background Script Communication
A Content Script can use the functions runtime.sendMessage() or tabs.sendMessage() to send a one-time JSON-serializable message.
To handle the response, use the returned Promise. Although, for backward compatibility, you can still pass a callback as the last argument.
Sending a request from a content script looks like this:
;(async () => {
const response = await chrome.runtime.sendMessage({ greeting: "hello" })
// do something with response here, not outside the function
console.log(response)
})()
extension (๋ณดํต background script)์์ ์์ฒญ์ ๋ณด๋ ๋๋ค. ์ ํ๋ ํญ์ content script๋ก ๋ฉ์์ง๋ฅผ ๋ณด๋ด๋ ์:
// From https://stackoverflow.com/questions/36153999/how-to-send-a-message-between-chrome-extension-popup-and-content-script
;(async () => {
const [tab] = await chrome.tabs.query({
active: true,
lastFocusedWindow: true,
})
const response = await chrome.tabs.sendMessage(tab.id, { greeting: "hello" })
// do something with response here, not outside the function
console.log(response)
})()
์์ ์ธก์์๋ ๋ฉ์์ง๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด runtime.onMessage ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ์ค์ ํด์ผ ํฉ๋๋ค. ์ด ๋์์ content script๋ extension page์์ ๋์ผํ๊ฒ ๋ณด์ ๋๋ค.
// From https://stackoverflow.com/questions/70406787/javascript-send-message-from-content-js-to-background-js
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
console.log(
sender.tab
? "from a content script:" + sender.tab.url
: "from the extension"
)
if (request.greeting === "hello") sendResponse({ farewell: "goodbye" })
})
์ ์์ ์์๋ **sendResponse()**๊ฐ ๋๊ธฐ ๋ฐฉ์์ผ๋ก ์คํ๋์์ต๋๋ค. sendResponse()๋ฅผ ๋น๋๊ธฐ์ ์ผ๋ก ์คํํ๋๋ก onMessage ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ฅผ ์์ ํ๋ ค๋ฉด return true;๋ฅผ ๋ฐ๋์ ํฌํจํด์ผ ํฉ๋๋ค.
์ฌ๋ฌ ํ์ด์ง๊ฐ onMessage ์ด๋ฒคํธ๋ฅผ ๋ฐ๋๋ก ์ค์ ๋ ์ํฉ์์๋, ํน์ ์ด๋ฒคํธ์ ๋ํด ๊ฐ์ฅ ๋จผ์ sendResponse()๋ฅผ ์คํํ ํ์ด์ง๋ง ์๋ต์ ์ ๋ฌํ ์ ์๋ค๋ ์ ์ ์ ์ํด์ผ ํฉ๋๋ค. ๊ฐ์ ์ด๋ฒคํธ์ ๋ํ ์ดํ์ ์๋ต์ ๋ฌด์๋ฉ๋๋ค.
์ ํ์ฅ ๊ธฐ๋ฅ์ ์์ฑํ ๋๋ promises๋ณด๋ค callbacks๋ณด๋ค promises๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ฐ๋์งํฉ๋๋ค. callbacks๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ sendResponse()๋ ๋๊ธฐ ์ปจํ
์คํธ ๋ด์์ ์ง์ ์คํ๋์๊ฑฐ๋ ์ด๋ฒคํธ ํธ๋ค๋ฌ๊ฐ return true;๋ก ๋น๋๊ธฐ ์์
์์ ํ์ํ ๊ฒฝ์ฐ์๋ง ์ ํจํฉ๋๋ค. ์ด๋ค ํธ๋ค๋ฌ๋ true๋ฅผ ๋ฐํํ์ง ์๊ฑฐ๋ sendResponse()๊ฐ ๋ฉ๋ชจ๋ฆฌ์์ ํด์ (garbage-collected)๋๋ฉด, sendMessage()์ ์ ๋ฌ๋ ์ฝ๋ฐฑ์ ๊ธฐ๋ณธ์ ์ผ๋ก ํธ์ถ๋ฉ๋๋ค.
Native Messaging
Browser extensions also allow to communicate with binaries in the system via stdin. The application must install a json indicating so in a json like:
{
"name": "com.my_company.my_application",
"description": "My Application",
"path": "C:\\Program Files\\My Application\\chrome_native_messaging_host.exe",
"type": "stdio",
"allowed_origins": ["chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"]
}
Where the name is the string passed to runtime.connectNative() or runtime.sendNativeMessage() to communicate with the application from the background scripts of the browser extension. The path is the path to the binary, there is only 1 valid type which is stdio (use stdin and stdout) and the allowed_origins indicate the extensions that can access it (and canโt have wildcard).
Chrome/Chromium will search for this json in some windows registry and some paths in macOS and Linux (more info in the docs).
Tip
The browser extension also needs the
nativeMessaingpermission declared in order to be able to use this communication.
This is how it looks like some background script code sending messages to a native application:
chrome.runtime.sendNativeMessage(
"com.my_company.my_application",
{ text: "Hello" },
function (response) {
console.log("Received " + response)
}
)
In this blog post, native messages๋ฅผ ์ ์ฉํ๋ ์ทจ์ฝํ ํจํด์ด ์ ์๋ฉ๋๋ค:
- Browser extension has a wildcard pattern for content script.
- Content script passes
postMessagemessages to the background script usingsendMessage. - Background script passes the message to native application using
sendNativeMessage. - Native application handles the message dangerously, leading to code execution.
๊ทธ๋ฆฌ๊ณ ์ด ๊ธ์๋ ์ด๋ค ํ์ด์ง์์๋ browser extension์ ์ ์ฉํด RCE๋ก ์ด์ด์ง๋ ์์ ๊ฐ ์ค๋ช ๋์ด ์์ต๋๋ค.
Sensitive Information in Memory/Code/Clipboard
Browser Extension์ด ๋ฉ๋ชจ๋ฆฌ์ ๋ฏผ๊ฐํ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ๊ฒฝ์ฐ, ํนํ Windows ํ๊ฒฝ์์๋ ํด๋น ๋ฉ๋ชจ๋ฆฌ๊ฐ **๋คํ(dump)**๋์ด ๊ทธ ์ ๋ณด๋ฅผ ๊ฒ์ํ ์ ์์ต๋๋ค.
๋ฐ๋ผ์ Browser Extension์ ๋ฉ๋ชจ๋ฆฌ๋ ์์ ํ๋ค๊ณ ๊ฐ์ฃผํด์๋ ์ ๋๋ฉฐ, ์๊ฒฉ ์ฆ๋ช ์ด๋ ๋๋ชจ๋ ๋ฌธ๊ตฌ ๊ฐ์ ๋ฏผ๊ฐํ ์ ๋ณด๋ ์ ์ฅํด์๋ ์ ๋ฉ๋๋ค.
๋ฌผ๋ก , not put sensitive information in the code, ์ด๋ **๊ณต๊ฐ(public)**๋ ์ ์์ต๋๋ค.
๋ธ๋ผ์ฐ์ ์์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋คํํ๋ ค๋ฉด ํ๋ก์ธ์ค ๋ฉ๋ชจ๋ฆฌ๋ฅผ dump the process memoryํ๊ฑฐ๋ browser extension์ settings๋ก ๊ฐ์ **Inspect pop-up**์ ํด๋ฆญํ ๋ค Memory ์น์
์์ **Take a snaphost**๋ฅผ ์ํํ๊ณ **CTRL+F**๋ก ์ค๋
์ท ๋ด๋ถ๋ฅผ ๊ฒ์ํ์ฌ ๋ฏผ๊ฐํ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.
๋ํ, ๋๋ชจ๋ ํค๋ ๋น๋ฐ๋ฒํธ์ฒ๋ผ ๋งค์ฐ ๋ฏผ๊ฐํ ์ ๋ณด๋ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ๋์ง ์๋๋ก ํ์ฉํด์๋ ์ ๋๋ฉฐ(์ ์ด๋ ๋ช ์ด ๋ด์ ํด๋ฆฝ๋ณด๋์์ ์ ๊ฑฐํด์ผ ํจ), ๊ทธ๋ ์ง ์์ผ๋ฉด ํด๋ฆฝ๋ณด๋๋ฅผ ๋ชจ๋ํฐ๋งํ๋ ํ๋ก์ธ์ค๋ค์ด ์ด๋ฅผ ํ๋ํ ์ ์์ต๋๋ค.
Loading an Extension in the Browser
- Download the Browser Extension & unzipped
- Go to
chrome://extensions/and enable theDeveloper Mode - Click the
Load unpackedbutton
In Firefox you go to about:debugging#/runtime/this-firefox and click Load Temporary Add-on button.
Getting the source code from the store
Chrome extension์ ์์ค ์ฝ๋๋ ์ฌ๋ฌ ๋ฐฉ๋ฒ์ผ๋ก ์ป์ ์ ์์ต๋๋ค. ์๋์๋ ๊ฐ ์ต์ ์ ๋ํ ์์ธํ ์ค๋ช ๊ณผ ์ง์นจ์ด ๋์ ์์ต๋๋ค.
Download Extension as ZIP via Command Line
Chrome extension์ ์์ค ์ฝ๋๋ ์ปค๋งจ๋ ๋ผ์ธ์ ํตํด ZIP ํ์ผ๋ก ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค. ์ด๋ ํน์ URL์์ curl์ ์ฌ์ฉํด ZIP ํ์ผ์ ๊ฐ์ ธ์ค๊ณ ZIP ํ์ผ์ ๋ด์ฉ์ ๋๋ ํฐ๋ฆฌ๋ก ์ถ์ถํ๋ ๊ณผ์ ์ ํฌํจํฉ๋๋ค. ๋จ๊ณ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
"extension_id"๋ฅผ ์ค์ ํ์ฅ ํ๋ก๊ทธ๋จ์ ID๋ก ๊ต์ฒดํฉ๋๋ค.- ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค:
extension_id=your_extension_id # Replace with the actual extension ID
curl -L -o "$extension_id.zip" "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=stable&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc"
unzip -d "$extension_id-source" "$extension_id.zip"
CRX Viewer ์น์ฌ์ดํธ ์ฌ์ฉ
CRX Viewer ํ์ฅ ํ๋ก๊ทธ๋จ ์ฌ์ฉ
๋ ๋ค๋ฅธ ํธ๋ฆฌํ ๋ฐฉ๋ฒ์ Chrome Extension Source Viewer๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค. ์ด ์คํ ์์ค ํ๋ก์ ํธ๋ Chrome Web Store์์ ์ค์นํ ์ ์์ต๋๋ค. ๋ทฐ์ด์ ์์ค ์ฝ๋๋ GitHub repository์์ ํ์ธํ ์ ์์ต๋๋ค.
๋ก์ปฌ์ ์ค์น๋ ํ์ฅ ํ๋ก๊ทธ๋จ์ ์์ค ๋ณด๊ธฐ
Chrome ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋ก์ปฌ์์ ์ค์นํ ๊ฒฝ์ฐ์๋ ๊ฒ์ฌํ ์ ์์ต๋๋ค. ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
chrome://version/์ ๋ฐฉ๋ฌธํ์ฌ Chrome ๋ก์ปฌ ํ๋กํ ๋๋ ํฐ๋ฆฌ์ ์ ๊ทผํ ๋ค์ โProfile Pathโ ํ๋๋ฅผ ์ฐพ์ต๋๋ค.- ํ๋กํ ๋๋ ํฐ๋ฆฌ ๋ด์
Extensions/ํ์ ํด๋๋ก ์ด๋ํฉ๋๋ค. - ์ด ํด๋์๋ ์ค์น๋ ๋ชจ๋ ํ์ฅ ํ๋ก๊ทธ๋จ์ด ๋ค์ด ์์ผ๋ฉฐ, ์ผ๋ฐ์ ์ผ๋ก ์์ค ์ฝ๋๋ฅผ ์ฝ์ ์ ์๋ ํ์์ผ๋ก ํฌํจ๋์ด ์์ต๋๋ค.
ํ์ฅ ํ๋ก๊ทธ๋จ์ ์๋ณํ๋ ค๋ฉด ID๋ฅผ ์ด๋ฆ์ ๋งคํํ ์ ์์ต๋๋ค:
about:extensionsํ์ด์ง์์ Developer Mode๋ฅผ ํ์ฑํํ๋ฉด ๊ฐ ํ์ฅ ํ๋ก๊ทธ๋จ์ ID๋ฅผ ๋ณผ ์ ์์ต๋๋ค.- ๊ฐ ํ์ฅ ํ๋ก๊ทธ๋จ ํด๋ ์์
manifest.jsonํ์ผ์๋ ์ฝ์ ์ ์๋nameํ๋๊ฐ ์์ด ํ์ฅ ํ๋ก๊ทธ๋จ์ ์๋ณํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค.
ํ์ผ ์์ถ ํด์ ๋๊ตฌ ์ฌ์ฉ
Chrome Web Store์์ ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋ค์ด๋ก๋ํ์ธ์. ํ์ผ์ .crx ํ์ฅ์๋ฅผ ๊ฐ์ง๋๋ค. ํ์ผ ํ์ฅ์๋ฅผ .crx์์ .zip์ผ๋ก ๋ณ๊ฒฝํ ํ WinRAR, 7-Zip ๋ฑ๊ณผ ๊ฐ์ ์์ถ ํด์ ๋๊ตฌ๋ก ZIP ํ์ผ์ ๋ด์ฉ์ ์ถ์ถํฉ๋๋ค.
Chrome์์ Developer Mode ์ฌ์ฉ
Chrome์ ์ด๊ณ chrome://extensions/๋ก ์ด๋ํฉ๋๋ค. ์ค๋ฅธ์ชฝ ์๋จ์์ โDeveloper modeโ๋ฅผ ํ์ฑํํฉ๋๋ค. โLoad unpacked extensionโฆโ์ ํด๋ฆญํฉ๋๋ค. ํ์ฅ ํ๋ก๊ทธ๋จ์ ๋๋ ํฐ๋ฆฌ๋ก ์ด๋ํฉ๋๋ค. ์ด๋ ์์ค ์ฝ๋๋ฅผ ๋ค์ด๋ก๋ํ์ง๋ ์์ง๋ง ์ด๋ฏธ ๋ค์ด๋ก๋ํ๊ฑฐ๋ ๊ฐ๋ฐ ์ค์ธ ํ์ฅ ํ๋ก๊ทธ๋จ์ ์ฝ๋๋ฅผ ๋ณด๊ธฐ ๋ฐ ์์ ํ๋ ๋ฐ ์ ์ฉํฉ๋๋ค.
Chrome extension manifest ๋ฐ์ดํฐ์
์ทจ์ฝํ ๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ์ ์ฐพ์๋ณด๋ ค๋ฉด thehttps://github.com/palant/chrome-extension-manifests-dataset ์ ์ฌ์ฉํ์ฌ manifest ํ์ผ์์ ์ ์ฌ์ ์ทจ์ฝ ์งํ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ์ฌ์ฉ์ ์๊ฐ 25000๋ช
์ด์์ด๊ณ , content_scripts๋ฅผ ํฌํจํ๋ฉฐ ๊ถํ nativeMessaing์ ๊ฐ์ง ํ์ฅ ํ๋ก๊ทธ๋จ์ ํ์ธํ๋ ค๋ฉด:
# Query example from https://spaceraccoon.dev/universal-code-execution-browser-extensions/
node query.js -f "metadata.user_count > 250000" "manifest.content_scripts?.length > 0 && manifest.permissions?.includes('nativeMessaging')"
Post-exploitation: Forced extension load & persistence (Windows)
์ฌ์ฉ์๋ณ Preferences๋ฅผ ์ง์ ํธ์งํ๊ณ ์ ํจํ HMACs๋ฅผ ์์กฐํ์ฌ Chromium์ ๋ฐฑ๋์ด๋ฅผ ์ฌ๋ ์๋ฐํ ๊ธฐ๋ฒ์ผ๋ก, ๋ธ๋ผ์ฐ์ ๊ฐ ํ๋กฌํํธ๋ ํ๋๊ทธ ์์ด ์์์ unpacked extension์ ์๋ฝํ๊ณ ํ์ฑํํ๊ฒ ๋ง๋ญ๋๋ค.
Forced Extension Load Preferences Mac Forgery Windows
๋ณด์ ๊ฐ์ฌ ์ฒดํฌ๋ฆฌ์คํธ
Even though Browser Extensions have a limited attack surface, some of them might contain vulnerabilities or potential hardening improvements. The following ones are the most common ones:
- ์์ฒญ๋
permissions์ ๊ฐ๋ฅํ ํ ์ ํํ์ธ์. - ์์ฒญ๋ **
host_permissions**๋ฅผ ๊ฐ๋ฅํ ํ ์ ํํ์ธ์. - ๊ฐ๋ ฅํ **
content_security_policy**๋ฅผ ์ฌ์ฉํ์ธ์. - **
externally_connectable**๋ฅผ ๊ฐ๋ฅํ ํ ์ ํํ์ธ์. ํ์ ์๊ณ ๊ฐ๋ฅํ๋ค๋ฉด ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋์ง ๋ง๊ณ **{}**๋ก ๋ช ์ํ์ธ์. - ์ฌ๊ธฐ์์ URL vulnerable to XSS or to takeover๊ฐ ์ธ๊ธ๋์ด ์๋ค๋ฉด, ๊ณต๊ฒฉ์๋ background scripts์ ์ง์ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ ์๊ฒ ๋ฉ๋๋ค. ๋งค์ฐ ๊ฐ๋ ฅํ ์ฐํ์ ๋๋ค.
- **
web_accessible_resources**๋ฅผ ๊ฐ๋ฅํ ํ ์ ํํ์ธ์. ๊ฐ๋ฅํ๋ฉด ๋น์๋์ธ์. - **
web_accessible_resources**๊ฐ ๋น์ด์์ง ์๋ค๋ฉด ClickJacking์ ํ์ธํ์ธ์. - ํ์ฅ์์ ์น ํ์ด์ง๋ก ์ด๋ค communication์ด ๋ฐ์ํ๋ค๋ฉด, ํต์ ๊ณผ์ ์์ ์ ๋ฐ๋๋ XSS vulnerabilities๋ฅผ ํ์ธํ์ธ์.
- Post Messages๊ฐ ์ฌ์ฉ๋๋ค๋ฉด Post Message vulnerabilities๋ฅผ ํ์ธํ์ธ์.
- Content Script๊ฐ DOM ์ธ๋ถ ์ ๋ณด๋ฅผ ์ ๊ทผํ๋ค๋ฉด, ์น์ ์ํด modified๋ ๊ฒฝ์ฐ XSS๋ฅผ ๋์ ํ์ง ์๋์ง ํ์ธํ์ธ์.
- ์ด ํต์ ์ด Content Script -> Background script communication์๋ ๊ด์ฌ๋์ด ์๋ค๋ฉด ํนํ ์ฃผ์ํ์ธ์.
- background script๊ฐ native messaging์ผ๋ก ํต์ ํ๋ค๋ฉด, ํต์ ์ด ์์ ํ๊ณ ์ ๋ ฅ์ด ์ ์ ํ ์ ์ ๋์ด ์๋์ง ํ์ธํ์ธ์.
- Browser Extension์ code ๋ด๋ถ์ ๋ฏผ๊ฐํ ์ ๋ณด๊ฐ ์ ์ฅ๋์ด์๋ ์ ๋ฉ๋๋ค.
- Browser Extension์ memory ์์ ๋ฏผ๊ฐํ ์ ๋ณด๊ฐ ์ ์ฅ๋์ด์๋ ์ ๋ฉ๋๋ค.
- file system unprotected์ ๋ฏผ๊ฐํ ์ ๋ณด๊ฐ ์ ์ฅ๋์ด์๋ ์ ๋ฉ๋๋ค.
Browser Extension Risks
- ์ฑ https://crxaminer.tech/์ permissions ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ Browser Extension ์ฌ์ฉ์ ์ํ ์์ค์ ์ ๊ณตํฉ๋๋ค.
Tools
Tarnish
- ์ ๊ณต๋ Chrome webstore ๋งํฌ์์ Chrome extension์ ๊ฐ์ ธ์ต๋๋ค.
- manifest.json viewer: ํ์ฅ์ manifest๋ฅผ JSON ํ์์ผ๋ก ๋ณด๊ธฐ ์ข๊ฒ ํ์ํฉ๋๋ค.
- Fingerprint Analysis: web_accessible_resources๋ฅผ ๊ฐ์งํ๊ณ ์๋์ผ๋ก Chrome extension fingerprinting JavaScript๋ฅผ ์์ฑํฉ๋๋ค.
- Potential Clickjacking Analysis: web_accessible_resources ์ง์์ด๊ฐ ์ค์ ๋ ํ์ฅ HTML ํ์ด์ง๋ฅผ ๊ฐ์งํฉ๋๋ค. ์ด๋ฌํ ํ์ด์ง๋ค์ ๋ชฉ์ ์ ๋ฐ๋ผ clickjacking์ ์ทจ์ฝํ ์ ์์ต๋๋ค.
- Permission Warning(s) viewer: ํ์ฅ ์ค์น ์ ์ฌ์ฉ์์๊ฒ ํ์๋๋ ๋ชจ๋ Chrome ๊ถํ ํ๋กฌํํธ ๊ฒฝ๊ณ ๋ชฉ๋ก์ ํ์ํฉ๋๋ค.
- Dangerous Function(s): innerHTML, chrome.tabs.executeScript ๊ฐ์ ๊ณต๊ฒฉ์๊ฐ ์ ์ฉํ ์ ์๋ ์ํํ ํจ์์ ์์น๋ฅผ ํ์ํฉ๋๋ค.
- Entry Point(s): ํ์ฅ์ด ์ฌ์ฉ์/์ธ๋ถ ์ ๋ ฅ์ ๋ฐ๋ ์์น๋ฅผ ํ์ํฉ๋๋ค. ์ด๋ ํ์ฅ์ ๊ณต๊ฒฉ ํ๋ฉด์ ์ดํดํ๊ณ ์ ์์ ์ผ๋ก ์กฐ์๋ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ผ ์ ์๋ ์ ์ฌ ์ง์ ์ ์ฐพ๋ ๋ฐ ์ ์ฉํฉ๋๋ค.
- Dangerous Function(s) ๋ฐ Entry Point(s) ์ค์บ๋์์ ์์ฑ๋ ๊ฒฝ๊ณ ์๋ ๋ค์์ด ํฌํจ๋ฉ๋๋ค:
- ๊ฒฝ๊ณ ๋ฅผ ๋ฐ์์ํจ ๊ด๋ จ ์ฝ๋ ์ค๋ํซ๊ณผ ๋ผ์ธ.
- ๋ฌธ์ ์ค๋ช .
- ์ ์ฒด ์์ค ํ์ผ์ ๋ณผ ์ ์๋ โView Fileโ ๋ฒํผ.
- ๊ฒฝ๊ณ ๊ฐ ๋ฐ์ํ ํ์ผ์ ๊ฒฝ๋ก.
- ํด๋น ํ์ผ์ ์ ์ฒด Chrome extension URI.
- Background Page script, Content Script, Browser Action ๋ฑ ํ์ผ ์ ํ.
- ์ทจ์ฝํ ๋ผ์ธ์ด JavaScript ํ์ผ์ธ ๊ฒฝ์ฐ, ํด๋น ํ์ผ์ด ํฌํจ๋ ๋ชจ๋ ํ์ด์ง์ ๊ฒฝ๋ก์ ํ์ด์ง ์ ํ ๋ฐ web_accessible_resource ์ํ.
- Content Security Policy (CSP) analyzer and bypass checker: ํ์ฅ์ CSP ์ฝ์ ์ ์ง์ ํ๊ณ , ํ์ดํธ๋ฆฌ์คํธ๋ CDN ๋ฑ์ผ๋ก ์ธํด CSP๋ฅผ ์ฐํํ ์ ์๋ ๊ฐ๋ฅ์ฑ์ ๋ฐํ๋๋ค.
- Known Vulnerable Libraries: Retire.js๋ฅผ ์ฌ์ฉํ์ฌ ์๋ ค์ง ์ทจ์ฝ JavaScript ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ์ ๊ฒ์ฌํฉ๋๋ค.
- ํ์ฅ ๋ค์ด๋ก๋ ๋ฐ ํฌ๋งคํ ๋ ๋ฒ์ ์ ๊ณต.
- ์๋ณธ ํ์ฅ ๋ค์ด๋ก๋.
- ์์๊ฒ ์ ๋ฆฌ๋(beautified) ํ์ฅ ๋ฒ์ ๋ค์ด๋ก๋(์๋์ผ๋ก prettified๋ HTML ๋ฐ JavaScript).
- ์ค์บ ๊ฒฐ๊ณผ ์๋ ์บ์: ์ฒ์ ์ค์บ์ ์๊ฐ์ด ๊ฑธ๋ฆฌ์ง๋ง, ํ์ฅ์ด ์ ๋ฐ์ดํธ๋์ง ์์๋ค๋ฉด ๋ ๋ฒ์งธ ์ค์บ์ ๊ฒฐ๊ณผ๊ฐ ์บ์๋์ด ๊ฑฐ์ ์ฆ์ ์๋ฃ๋ฉ๋๋ค.
- ๋งํฌ ๊ฐ๋ฅํ ๋ฆฌํฌํธ URL: tarnish๋ก ์์ฑ๋ ํ์ฅ ๋ฆฌํฌํธ๋ฅผ ๋ค๋ฅธ ์ฌ๋์๊ฒ ์ฝ๊ฒ ๊ณต์ ํ ์ ์์ต๋๋ค.
Neto
Project Neto๋ Firefox ๋ฐ Chrome๊ณผ ๊ฐ์ ์ ์๋ ค์ง ๋ธ๋ผ์ฐ์ ์ฉ ํ๋ฌ๊ทธ์ธ๊ณผ ํ์ฅ์ ์จ๊ฒจ์ง ๊ธฐ๋ฅ์ ๋ถ์ํ๊ณ ์ถ์ถํ๋๋ก ๊ณ ์๋ Python 3 ํจํค์ง์
๋๋ค. ํจํค์ง๋ ํ์ผ์ ์๋์ผ๋ก ์์ถ ํด์ ํ๊ณ manifest.json, ์ง์ญํ ํด๋(localization folders) ๋๋ Javascript ๋ฐ HTML ์์ค ํ์ผ ๊ฐ์ ๊ด๋ จ ๋ฆฌ์์ค์์ ์ด๋ฌํ ๊ธฐ๋ฅ์ ์ถ์ถํฉ๋๋ค.
์ฐธ๊ณ ์๋ฃ
- ๊ฐ์ฌ @naivenom ์ด ๋ฐฉ๋ฒ๋ก ์ ๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค
- https://www.cobalt.io/blog/introduction-to-chrome-browser-extension-security-testing
- https://palant.info/2022/08/10/anatomy-of-a-basic-extension/
- https://palant.info/2022/08/24/attack-surface-of-extension-pages/
- https://palant.info/2022/08/31/when-extension-pages-are-web-accessible/
- https://help.passbolt.com/assets/files/PBL-02-report.pdf
- https://developer.chrome.com/docs/extensions/develop/concepts/content-scripts
- https://developer.chrome.com/docs/extensions/mv2/background-pages
- https://thehackerblog.com/kicking-the-rims-a-guide-for-securely-writing-and-auditing-chrome-extensions/
- https://gist.github.com/LongJohnCoder/9ddf5735df3a4f2e9559665fb864eac0
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


