-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetConfig.cs
More file actions
38 lines (31 loc) · 1.08 KB
/
TargetConfig.cs
File metadata and controls
38 lines (31 loc) · 1.08 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
using System.Collections.Generic;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
public class TargetEntry
{
public string Host { get; set; } = string.Empty;
public List<string> Protocols { get; set; } = new();
public List<int>? Ports { get; set; }
}
public class TargetConfig
{
public List<TargetEntry> Targets { get; set; } = new();
}
public static class TargetLoader
{
public static List<TargetEntry> LoadYamlTargets(string path)
{
if (!File.Exists(path))
{
Console.WriteLine($"[!] Cannot find YAML config at: {path}");
Environment.Exit(1);
}
var deserializer = new YamlDotNet.Serialization.DeserializerBuilder()
.WithNamingConvention(YamlDotNet.Serialization.NamingConventions.UnderscoredNamingConvention.Instance)
.Build();
var yaml = File.ReadAllText(path);
var config = deserializer.Deserialize<TargetConfig>(yaml);
Console.WriteLine($"Loaded {config.Targets.Count} targets from YAML.");
return config.Targets;
}
}