-
Notifications
You must be signed in to change notification settings - Fork 30
/
OperatingSystemIdentifier.cpp
84 lines (63 loc) · 1.86 KB
/
OperatingSystemIdentifier.cpp
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
#include "OperatingSystemIdentifier.h"
#include "UbuntuIdentifier.h"
#include "DebianIdentifier.h"
#include "EnterpriseLinuxIdentifier.h"
#include "FedoraIdentifier.h"
#include "WindowsIdentifier.h"
using namespace std;
bool OperatingSystemIdentifier::AutoProcess(Host* host)
{
// Ubuntu is tried first, since some distributions tag them as
// "Debian-Ubuntu", which might trigger a false-positive with
// DebianIdentifier, if not ruled out by UbuntuIdentifier first
static UbuntuIdentifier ubuntu;
if (ubuntu.Scan(host))
{
return true;
}
// as OpenSSH in Debian has a DebianBanner feature added, which is
// on by default, Debian is the easiest to map based on SSH version
static DebianIdentifier debian;
if (debian.Scan(host))
{
return true;
}
// if everything failed so far, try RHEL/CentOS, however these
// cannot be mapped with 100% certainty by the SSH version alone
static EnterpriseLinuxIdentifier rhel;
if (rhel.Scan(host))
{
return true;
}
// lastly try Fedora, however since most packages overlap in
// Fedora, the identified distribution may not be completely
// accurate, depending on the update/upgrade habits of the admin
static FedoraIdentifier fedora;
if (fedora.Scan(host))
{
return true;
}
// try checking if any Windows-exclusive services are running
static WindowsIdentifier windows;
if (windows.Scan(host))
{
return true;
}
return false;
}
string OperatingSystemIdentifier::OpSysString(OpSys opsys)
{
static unordered_map<int, string> opsyses = {
{ Unidentified, "Unidentified" },
{ Debian, "Debian" },
{ Ubuntu, "Ubuntu" },
{ EnterpriseLinux, "Red Hat/CentOS" },
{ Fedora, "Fedora" },
{ WindowsNT, "Windows" },
};
auto iter = opsyses.find(opsys);
return iter != opsyses.end() ? iter->second : "Unkown";
}
OperatingSystemIdentifier::~OperatingSystemIdentifier()
{
}