This commit is contained in:
Muihd
2025-04-29 21:00:32 +08:00
34 changed files with 1048 additions and 454 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Reflection;
using BarrageGrab.Proxy.ProxyEventArgs;
namespace BarrageGrab.Proxy
@@ -42,5 +42,5 @@ namespace BarrageGrab.Proxy
/// 开始监听
/// </summary>
void Start();
}
}
}
@@ -30,7 +30,7 @@ namespace BarrageGrab.Proxy.ProxyEventArgs
/// <summary>
/// 域名
/// </summary>
public string HostName { get; set; }
public string HostName { get; set; }
/// <summary>
/// 有效载荷
@@ -6,11 +6,11 @@ using System.Threading.Tasks;
namespace BarrageGrab.Proxy.ProxyEventArgs
{
public class SystemProxyChangeEventArgs:EventArgs
public class SystemProxyChangeEventArgs : EventArgs
{
/// <summary>
/// True 以开启:False: 已关闭
/// </summary>
public bool Open { get; set; }
public bool Open { get; set; }
}
}
+6 -6
View File
@@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;
using System.Diagnostics;
using BarrageGrab.Proxy.ProxyEventArgs;
using Microsoft.Win32;
namespace BarrageGrab.Proxy
{
@@ -42,7 +42,7 @@ namespace BarrageGrab.Proxy
public abstract void Start();
public abstract void SetUpstreamProxy(string addr);
public abstract void SetUpstreamProxy(string addr);
//https://live.douyin.com/webcast/gift/list/ [礼物数据接口]
@@ -109,7 +109,7 @@ namespace BarrageGrab.Proxy
RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", $"127.0.0.1:{ProxyPort}");
OnProxyStatus?.Invoke(this, new SystemProxyChangeEventArgs()
{
Open = true
@@ -128,7 +128,7 @@ namespace BarrageGrab.Proxy
{
Open = false
});
}
}
public static bool ProxyIsOpen()
{
+32 -42
View File
@@ -1,31 +1,31 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using BarrageGrab.Modles;
using BarrageGrab.Modles.JsonEntity;
using BarrageGrab.Proxy.ProxyEventArgs;
using Newtonsoft.Json.Linq;
using BrotliSharpLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog.LayoutRenderers;
using Titanium.Web.Proxy;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.StreamExtended.Network;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using HtmlDocument = HtmlAgilityPack.HtmlDocument;
using System.Net.Http;
using System.Text;
using BrotliSharpLib;
using System.IO.Compression;
using System.Collections.Concurrent;
using System.Security.Policy;
using NLog.LayoutRenderers;
namespace BarrageGrab.Proxy
{
@@ -90,17 +90,18 @@ namespace BarrageGrab.Proxy
proxyServer.CertificateManager.CertificateValidDays = 365 * 10;
proxyServer.CertificateManager.SaveFakeCertificates = true;
proxyServer.CertificateManager.CertificateEngine = Titanium.Web.Proxy.Network.CertificateEngine.DefaultWindows;
proxyServer.CertificateManager.OverwritePfxFile = false;
proxyServer.CertificateManager.RootCertificate = GetCert();
if (proxyServer.CertificateManager.RootCertificate == null)
{
Logger.PrintColor("正在进行证书安装,需要信任该证书才可进行https解密,若有提示请确定");
proxyServer.CertificateManager.CreateRootCertificate();
}
//信任证书
proxyServer.CertificateManager.CreateRootCertificate();
proxyServer.CertificateManager.TrustRootCertificate(true);
//https://github.com/justcoding121/titanium-web-proxy/issues/828
proxyServer.ServerCertificateValidationCallback += ProxyServer_ServerCertificateValidationCallback;
//proxyServer.BeforeRequest += ProxyServer_BeforeRequest;
proxyServer.BeforeResponse += ProxyServer_BeforeResponse;
@@ -307,7 +308,7 @@ namespace BarrageGrab.Proxy
{
lock (rinfoRequestings) rinfoRequestings.Add(webroomid);
//查询后会自动缓存
DyServer.GetRoomInfoForApi(webroomid, cookie).ContinueWith(t =>
DyApiHelper.GetRoomInfoForApi(webroomid, cookie).ContinueWith(t =>
{
var rinfo = t.Result;
//限制只尝试一次
@@ -332,22 +333,6 @@ namespace BarrageGrab.Proxy
}
}
/// <summary>
/// 获取配置的注入的js
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private string GetInjectScript(string name)
{
//获取exe所在目录路径
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts", "inject", name + ".js");
if (File.Exists(path))
{
return File.ReadAllText(path);
}
return null;
}
// Hook 直播页面
private async Task HookPageAsync(SessionEventArgs e)
{
@@ -376,8 +361,7 @@ namespace BarrageGrab.Proxy
{
string webrid = liveRoomMactch.Groups[1].Value;
//获取直播页注入js
string liveRoomInjectScript = GetInjectScript("livePage");
string liveRoomInjectScript = EmbResource.GetFileContent("livePage.js");
//注入上下文变量;
var scriptContext = BuildContext(new Dictionary<string, string>()
{
@@ -434,7 +418,7 @@ namespace BarrageGrab.Proxy
script.InnerHtml = liveRoomInjectScript;
body.AppendChild(script);
html = doc.DocumentNode.OuterHtml;
Logger.PrintColor($"直播页{urlNoQuery},用户脚本已成功注入!\n", ConsoleColor.Green);
Logger.LogTrace($"直播页{urlNoQuery},用户脚本已成功注入!\n");
}
}
catch (Exception ex)
@@ -458,7 +442,7 @@ namespace BarrageGrab.Proxy
if (liveHomeMatch.Success)
{
//获取直播页注入js
string liveHoomInjectScript = GetInjectScript("livePage");
string liveHoomInjectScript = EmbResource.GetFileContent("livePage.js");
//注入上下文变量;
var scriptContext = BuildContext(new Dictionary<string, string>()
@@ -548,21 +532,20 @@ namespace BarrageGrab.Proxy
if (!contentType.Trim().ToLower().Contains("application/javascript")) return;
if (e.HttpClient.Response.StatusCode != 200) return;
//https://lf-webcast-platform.bytetos.com/obj/webcast-platform-cdn/webcast/douyin_live/chunks/island_a74ce.b55095a0.js
//判断响应内容是否为js application/javascript
if (hostname == SCRIPT_HOST
//这俩个进程不需要注入
&& processName != "直播伴侣" && processName != "douyin"
if (processName != "直播伴侣" && processName != "douyin"
&& fileName.StartsWith("island")
)
{
var js = await e.GetResponseBodyAsString();
var reg2 = new Regex(@"if\(!\((?<v1>\d,\w{1,2})\.DJ\)\(\)&&");
var match = reg2.Match(js);
var reg = new Regex(@"if\(!\(\d{1,},\w{1,}\.DJ\)\(\).+\w{1,}\.includes\(""live""\)\)\)\{");
var match = reg.Match(js);
if (match.Success)
{
js = reg2.Replace(js, "if(false &&");
js = reg.Replace(js, "if(false){");
e.SetResponseBodyString(js);
Logger.PrintColor($"已成功绕过页面无操作检测\n", ConsoleColor.Green);
Logger.PrintColor($"已成功绕过JS页面无操作检测 {urlNoQuery}\n", ConsoleColor.Green);
}
}
@@ -627,6 +610,8 @@ namespace BarrageGrab.Proxy
SCRIPT_HOST,
LIVE_HOST,
WEBCAST_AMEMV_HOST , //直播伴侣开播请求地址
"*-webcast-platform.bytetos.com", //新的脚本地址
"*webcast*" //所有带webcast的域名
};
if (decryptSsls.Contains(hostname))
@@ -634,6 +619,11 @@ namespace BarrageGrab.Proxy
return true;
}
if (hostname.WildcardMatchAny(decryptSsls))
{
return true;
}
hostname = hostname.Trim().ToLower();
return base.CheckHost(hostname);
}
@@ -648,7 +638,7 @@ namespace BarrageGrab.Proxy
var processid = args.HttpClient.ProcessId.Value;
List<byte> messageData = new List<byte>();
try
{
foreach (var frame in args.WebSocketDecoderReceive.Decode(e.Buffer, e.Offset, e.Count))