-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
274 lines (225 loc) · 10.8 KB
/
Program.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System;
using System.Drawing;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WorkshopUtils;
using GMADFileFormat;
using System.Net;
using Nito.AsyncEx;
using DiscordWebhook;
namespace BackdoorFinder
{
class Program
{
private static string steamApiKey = "";
private static string webhookURL = "";
static void Main(string[] args)
{
AsyncContext.Run(() => MainAsync());
}
static async Task MainAsync()
{
if (!DataLog.configExists())
{
Init();
steamApiKey = DataLog.getConfigVar("apikey");
webhookURL = DataLog.getConfigVar("webhookurl");
}else
{
steamApiKey = DataLog.getConfigVar("apikey");
webhookURL = DataLog.getConfigVar("webhookurl");
}
Console.Write("What do you want to do? ");
String Action = Console.ReadLine();
if (Action == "help")
{
Console.Write("Commands: \nhelp - print help text\nscanlink [workshopLink] - scans the individual file\nwhitelistaddon [workshopURL]\nscanworkshop - scans the entire workshop\nextractaddon [workshopLink] - extracts an addon\n");
await MainAsync();
}
else if (Action.StartsWith("scanlink"))
{
string workshopURL = Action.Split(' ')[1];
Int32 workshopID = WorkshopDownload.ParseID(workshopURL);
await ScanLink(workshopID);
await MainAsync();
}
else if (Action.StartsWith("whitelistaddon"))
{
string workshopURL = Action.Split(' ')[1];
Int32 workshopID = WorkshopDownload.ParseID(workshopURL);
WorkshopAddon Addon = await WorkshopHTTPAPI.GetAddonByIDAsync(workshopID, steamApiKey);
whiteListAddon(Addon);
await MainAsync();
}
else if (Action == "scanworkshop")
{
await ScanWorkshop();
}
else if (Action.StartsWith("extractaddon"))
{
string workshopURL = Action.Split(' ')[1];
Int32 workshopID = WorkshopDownload.ParseID(workshopURL);
WorkshopAddon workshopAddon = await WorkshopHTTPAPI.GetAddonByIDAsync(workshopID, steamApiKey);
Console.Write("Downloading Addon: {0}\n", workshopAddon.URL);
GMADAddon parsedAddon;
using (var wc = new WebClient())
{
Byte[] data = await wc.DownloadDataTaskAsync(workshopAddon.URL);
parsedAddon = GMADParser.Parse(data);
data = new Byte[0];
}
WorkshopDownload.Extract(parsedAddon);
await MainAsync();
}
}
static async Task ScanLink(Int32 workshopID)
{
WorkshopAddon Addon = await WorkshopHTTPAPI.GetAddonByIDAsync(workshopID, steamApiKey);
Console.Write("Downloading Addon: {0}\n", Addon.URL);
GMADAddon parsedAddon;
using (var wc = new WebClient())
{
Byte[] data = await wc.DownloadDataTaskAsync(Addon.URL);
parsedAddon = GMADParser.Parse(data);
data = new Byte[0];
}
Backdoor backdoorFinder = new Backdoor(parsedAddon);
try
{
List<List<Backdoor.FlagStruct>> flagList = backdoorFinder.scanFile();
foreach (var flagFile in flagList)
{
foreach (Backdoor.FlagStruct fileStruct in flagFile)
{
int lineNumber = fileStruct.lineNumber;
String FlagStr = fileStruct.FlagStr;
GMADAddon.File AddonFile = fileStruct.AddonFile;
GMADAddon._Author Author = parsedAddon.Author;
String FlagDescription = fileStruct.FlagDescription;
Regex CheckRegex = fileStruct.CheckRegex;
int CheckType = fileStruct.CheckType;
int Priority = fileStruct.Priority;
string AddonUrl = "https://steamcommunity.com/sharedfiles/filedetails/?id=" + Addon.ID.ToString();
Console.Write("Potential Backdoor found in Addon:\nline number: {0}\nAddon URL: {1}\nAuthor SteamID: {2}\nFlag: {3}\nCode: {4}\n",
lineNumber.ToString(),
AddonUrl,
Author.SteamID64,
FlagDescription,
FlagStr
);
}
}
}
catch (Exception ex)
{
Console.Write("Something went wrong...");
Console.Write(ex.Message + "\n");
Console.ReadLine();
}
}
static void whiteListAddon(WorkshopAddon Addon)
{
BackdoorData Data = DataLog.toData(Addon.ID.ToString(), Addon.URL);
DataLog.whitelistAddon(Data);
}
static void Init()
{
if (!DataLog.configExists())
{
Console.Write("Config file does not exist. Creating new one...\n");
Console.Write("Please enter a valid discord webhook URL ");
string webhookURL = Console.ReadLine();
Console.Write("Please enter a valid steam API key ");
string apiKey = Console.ReadLine();
ConfigData confData = new ConfigData();
confData.APIKEY = apiKey;
confData.WEBHOOKURL = webhookURL;
DataLog.writeConfig(confData);
}
}
static async Task ScanWorkshop()
{
uint pageNumber = 0;
while (true)
{
pageNumber++;
Console.Write("Page Number = " + pageNumber.ToString() + "\n");
WorkshopAddon[] Addons = await WorkshopHTTPAPI.GetWorkshopAddonsAsync(steamApiKey, EPublishedFileQueryType.RankedByPublicationDate, pageNumber, 100);
Console.Write("# Addons: {0}\n", Addons.Length.ToString());
if (Addons.Length < 1)
{
Console.Write("Reached end of workshop.");
if (Console.ReadLine() == "ok")
Environment.Exit(1);
}
foreach (WorkshopAddon Addon in Addons)
{
if (DataLog.hasBeenLogged(Addon.ID.ToString()) || DataLog.hasBeenWhitelisted(Addon.ID.ToString()))
continue;
Console.Write("Downloading Addon: {0}\n", Addon.URL);
GMADAddon parsedAddon;
try
{
using (var wc = new WebClient())
{
Byte[] data = await wc.DownloadDataTaskAsync(Addon.URL);
parsedAddon = GMADParser.Parse(data);
data = new Byte[0];
}
Backdoor backdoorFinder = new Backdoor(parsedAddon);
List<List<Backdoor.FlagStruct>> flagList = backdoorFinder.scanFile();
foreach (var flagFile in flagList)
{
foreach (Backdoor.FlagStruct fileStruct in flagFile)
{
int lineNumber = fileStruct.lineNumber;
String FlagStr = fileStruct.FlagStr;
GMADAddon.File AddonFile = fileStruct.AddonFile;
GMADAddon._Author Author = parsedAddon.Author;
String FlagDescription = fileStruct.FlagDescription;
Regex CheckRegex = fileStruct.CheckRegex;
int CheckType = fileStruct.CheckType;
int Priority = fileStruct.Priority;
string AddonUrl = "https://steamcommunity.com/sharedfiles/filedetails/?id=" + Addon.ID.ToString();
Webhook discordWebhook = new Webhook(webhookURL);
Embed discordEmbed = new Embed();
List<Embed> embedList = new List<Embed>();
Dictionary<string, string> fieldDict = new Dictionary<string, string>()
{
{"line number", lineNumber.ToString() },
{"Addon name", parsedAddon.Name },
{"Current File", AddonFile.Path },
{"Priority", Priority.ToString() },
{"Flag", FlagDescription },
{"Code", FlagStr.Length < 1024 ? FlagStr : "Code too long" },
{"Author Name", Author.Name},
{"Author SteamID", Author.SteamID64.ToString() },
{"Addon URL", AddonUrl}
};
discordEmbed.Title = "FLAG FOUND";
discordEmbed.Fields = Backdoor.makeEmbedList(fieldDict);
discordEmbed.Color = Extensions.ToRgb(Color.FromName("purple"));
embedList.Add(discordEmbed);
await discordWebhook.Send(null, null, null, false, embedList);
}
}
if (flagList.Count < 1)
Console.Write("No flags found.\n");
BackdoorData toLog = DataLog.toData(Addon.ID.ToString(), Addon.URL);
DataLog.addData(toLog);
flagList = null;
backdoorFinder = null;
GC.Collect();
}
catch (Exception ex)
{
Console.Write("Something went wrong...\n");
Console.Write(ex.Message + "\n");
}
}
}
}
}
}