攻防演练之云函数的利用

攻防演练之云函数的利用

云函数(Serverless CloudFunction,SCF)是云计算厂商为企业和开发者们提供的无服务器执行环境,可在无需购买和管理服务器的情况下运行代码是实时文件处理和数据处理等场景下理想的计算平台。只需使用 SCF平台支持的语言编写核心代码并设置代码运行的条件,即可在某云基础设施上弹性、安全地运行代码。

由于云函数无法长驻,调用的时候创建,执行完之后立即就销毁,所以无法直接保存状态。也正是这一点,让我们无法代理像 SSH 这种需要长连接的服务,只能代理 HTTP(s) 这种无状态的协议。

云函数不能直接调用,同时还需要创建一个触发器来触发云函数,为了方便,我们选择使用API 网关触发器,只需要一个 HTTP 请求就能触发。

腾讯云函数地址:

https://console.cloud.tencent.com/scf/index

利用云函数的多出口、无需服务器承载的特性,我们可以在实战攻防演练中实现隐藏自身。

具体应用如下:

1、利用云函数API配置蚁剑实现隐藏自身IP连接Webshell

首先创建云函数:

image-202208011625530

函数代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import random
import requests
import ssl
from urllib.parse import unquote

#忽略证书校验
requests.packages.urllib3.disable_warnings()
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context

user_agent = ['Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0']

def requests_headers():
UA = random.choice(user_agent)
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'User-Agent': UA,
'X-Forwarded-For': '10.10.{}.{}'.format(str(random.randint(0, 255)), str(random.randint(0, 255))),
}
return headers

def main_handler(event, context):
#url = unquote(event['queryString']['url'])
url = event['queryString']['url']
agrs = event['queryString']
for key in agrs.keys():
if key != "url":
url += "&" + key + "=" + agrs[key]
method = event['httpMethod']
headers = requests_headers()
#headers = event['headers']
timeout = 60
try:
data = event['body']
except:
data = None
if method == "POST":
headers.update({'Content-Type': 'application/x-www-form-urlencoded'})
html = requests.post(url=url, headers=headers, timeout=timeout, verify=False, data=data)
elif method == "GET":
html = requests.get(url=url, headers=headers, timeout=timeout, verify=False, data=data)
print(len(html.text))
return {
"isBase64Encoded": False,
"statusCode": html.status_code,
"headers": {'Content-Type': 'text/html; charset=utf-8'},
"body": html.text
}

接着在函数管理这里将执行超时时间设置为900秒

image-20220802085326165

image-20220802085338583

创建触发器:

image-20220802085206404

image-20220802085237776

会得到一个访问路径

image-20220802085845373

利用蚁剑进行Webshell连接即可

路径为:

https://service-h8ew8bu0-xxxxxxxxxxx.gz.apigw.tencentcs.com/release/xxxxx?url=Webshell地址

image-20220802090055742

image-20220802104133594

image-20220802104151793

可以看到日志里的ip都是上海的

2、联动dirsearch多出口爆破目录防BanIP

首先下载一下SCF-Proxy

项目地址:GitHub - Sakurasan/scf-proxy: 云函数代理服务

Go环境下编译一下

1
sh build.sh

获得一个main.zip

接着在/scf-proxy/cmd 路径下编译一下 client.go

1
go build -trimpath client.go

新建云函数

image-20220802114215068

创建触发器

image-20220802114341667

同样别忘记了设置超时时间900秒

image-20220802114450106

然后客户端设置监听

1
./client -p 8888 -scfurl https://云函数访问路径

image-20220802115207900

这里就算成功了

效果测试

image-20220802120024033

使用dirsearch爆破目录

1
python dirsearch.py -u http://xxxxxxx.com --proxy=http://localhost:8888

image-20220802152238700

效果如下:

image-20220802153139164

出口一直在变化