-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
127 lines (116 loc) · 5.07 KB
/
Program.cs
File metadata and controls
127 lines (116 loc) · 5.07 KB
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
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Net;
using System.Net.WebSockets;
class Program
{
static async Task Main(string[] args)
{
// --- Show Help Early ---
if (args.Length > 0 && (args[0] == "--help" || args[0] == "-h"))
{
PrintHelp();
return;
}
// --- Default Configuration ---
string configPath = "targets.yaml";
int minInterval = 60; // in seconds
int maxInterval = 300; // in seconds
int loopCount = -1; // -1 = infinite
// --- Parse CLI Args ---
foreach (var arg in args)
{
if (arg.StartsWith("--config="))
configPath = arg.Substring("--config=".Length);
else if (arg.StartsWith("--minInterval="))
minInterval = int.Parse(arg.Substring("--minInterval=".Length));
else if (arg.StartsWith("--maxInterval="))
maxInterval = int.Parse(arg.Substring("--maxInterval=".Length));
else if (arg.StartsWith("--loopCount="))
loopCount = int.Parse(arg.Substring("--loopCount=".Length));
}
Console.WriteLine($"[i] Loading config from: {configPath}");
Console.WriteLine($"[i] Beacon interval: {minInterval}–{maxInterval} seconds");
Console.WriteLine(loopCount > 0 ? $"[i] Loop count: {loopCount}" : "[i] Loop count: infinite");
Console.WriteLine();
var rand = new Random();
var httpClient = new HttpClient();
var targets = TargetLoader.LoadYamlTargets(configPath);
int loop = 0;
while (loopCount < 0 || loop < loopCount)
{
loop++;
var target = targets[rand.Next(targets.Count)];
string method = target.Protocols[rand.Next(target.Protocols.Count)];
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] Attempt {loop}: {method.ToUpper()} → {target.Host}");
try
{
switch (method)
{
case "ping":
await BeaconUtils.TryPing(target.Host);
break;
case "http":
await BeaconUtils.TryHttp(target.Host, httpClient);
break;
case "https":
await BeaconUtils.TryHttps(target.Host);
break;
case "dns":
await BeaconUtils.TryDns(target.Host);
break;
case "ftp":
await BeaconUtils.TryFtp(target.Host);
break;
case "ssh":
await BeaconUtils.TrySsh(target.Host);
break;
case "tcp":
if (target.Ports?.Count > 0)
{
int port = target.Ports[rand.Next(target.Ports.Count)];
await BeaconUtils.TryTcp(target.Host, port);
}
else
{
Console.WriteLine(" [!] TCP requested but no ports defined.");
}
break;
case "websocket":
await BeaconUtils.TryWebSocket(target.Host);
break;
default:
Console.WriteLine($" [!] Unsupported method: {method}");
break;
}
}
catch (Exception ex)
{
Console.WriteLine($" [!] Exception during {method.ToUpper()} to {target.Host}: {ex.Message}");
}
int delay = rand.Next(minInterval, maxInterval + 1);
Console.WriteLine($"[i] Sleeping for {delay} seconds...\n");
await Task.Delay(TimeSpan.FromSeconds(delay));
}
Console.WriteLine("[✓] Beacon loop finished.");
}
static void PrintHelp()
{
Console.WriteLine("BeaconSim - C2 Beacon Simulator");
Console.WriteLine("---------------------------------");
Console.WriteLine("Usage:");
Console.WriteLine(" BeaconSim.exe [--config=path] [--minInterval=N] [--maxInterval=N] [--loopCount=N]");
Console.WriteLine();
Console.WriteLine("Options:");
Console.WriteLine(" --config=path Path to YAML config file (default: targets.yaml)");
Console.WriteLine(" --minInterval=N Minimum delay in seconds between beacons (default: 60)");
Console.WriteLine(" --maxInterval=N Maximum delay in seconds between beacons (default: 300)");
Console.WriteLine(" --loopCount=N Number of beacon attempts (-1 = infinite)");
Console.WriteLine(" --help, -h Show this help menu and exit");
Console.WriteLine();
Console.WriteLine("Example:");
Console.WriteLine(" BeaconSim.exe --config=mytargets.yaml --minInterval=30 --maxInterval=120 --loopCount=10");
Console.WriteLine();
}
}