-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathProgram.cs
109 lines (103 loc) · 3.4 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
using CommandLine;
using System;
using System.Security.Principal;
using System.Text;
namespace KnockOutlook
{
class Program
{
public static string Banner()
{
string banner = "\r\n";
banner += @" __ __ __ ____ __ __ __ " + "\r\n";
banner += @" / //_/____ ____ _____/ /__/ __ \__ __/ /_/ /___ ____ / /__" + "\r\n";
banner += @" / ,< / __ \/ __ \/ ___/ //_/ / / / / / / __/ / __ \/ __ \/ //_/" + "\r\n";
banner += @" / /| |/ / / / /_/ / /__/ ,< / /_/ / /_/ / /_/ / /_/ / /_/ / ,< " + "\r\n";
banner += @" /_/ |_/_/ /_/\____/\___/_/\_\\____/\__,_/\__/_/\____/\____/_/\_\ " + "\r\n";
banner += "\r\n\r\n";
return banner;
}
private static void ShowHelp()
{
string help = Banner();
help += "Parameters:\r\n";
help += " --operation : specify the operation to run\r\n";
help += " --keyword : specify a keyword for the 'search' operation\r\n";
help += " --id : specify an EntryID for the 'save' operation\r\n";
help += " --bypass : bypass the Programmatic Access Security settings (requires admin)\r\n";
help += "\r\nOperations:\r\n";
help += " check : perform a number of checks to ensure operational security\r\n";
help += " contacts : extract all contacts of every account\r\n";
help += " mails : extract mailbox metadata of every account\r\n";
help += " search : search for the provided keyword in every mailbox\r\n";
help += " save : save a specified mail by its EntryID\r\n";
help += "\r\nExamples:\r\n";
help += " KnockOutlook.exe --operation check\r\n";
help += " KnockOutlook.exe --operation contacts\r\n";
help += " KnockOutlook.exe --operation mails --bypass\r\n";
help += " KnockOutlook.exe --operation search --keyword password\r\n";
help += " KnockOutlook.exe --operation save --id {EntryID} --bypass\r\n";
Console.Write(help);
}
private static void ProcessArguments(Options options)
{
if (options.Bypass)
{
if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))
{
string output = Banner();
output += "The process is not running with high integrity level\r\n";
Console.Write(output);
Environment.Exit(0);
}
}
if (options.Operation == "check")
{
Operations.Check.Run();
}
else if (options.Operation == "contacts")
{
Operations.Contacts.Run(options.Bypass);
}
else if (options.Operation == "mails")
{
Operations.Mails.Run(options.Bypass);
}
else if (options.Operation == "search")
{
if (string.IsNullOrEmpty(options.Keyword))
{
ShowHelp();
}
else
{
Operations.Search.Run(options.Keyword, options.Bypass);
}
}
else if (options.Operation == "save")
{
if (string.IsNullOrEmpty(options.EntryID))
{
ShowHelp();
}
else
{
Operations.Save.Run(options.EntryID, options.Bypass);
}
}
else
{
ShowHelp();
}
}
static void Main(string[] args)
{
try
{
Console.OutputEncoding = Encoding.UTF8;
}
catch {}
new Parser(config => config.HelpWriter = null).ParseArguments<Options>(args).WithParsed(options => ProcessArguments(options)).WithNotParsed(errors => ShowHelp());
}
}
}