-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig.go
179 lines (161 loc) · 6.94 KB
/
config.go
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package main
import (
"strconv"
"strings"
"github.com/Macmod/ldapx/middlewares"
attrentriesmid "github.com/Macmod/ldapx/middlewares/attrentries"
attrlistmid "github.com/Macmod/ldapx/middlewares/attrlist"
basednmid "github.com/Macmod/ldapx/middlewares/basedn"
filtermid "github.com/Macmod/ldapx/middlewares/filter"
)
// Taken from:
// https://learn.microsoft.com/en-us/windows/win32/adschema/attributes-anr
// (Windows Server 2012)
var ANRSet = []string{
"name", "displayname", "samaccountname",
"givenname", "legacyexchangedn", "sn", "proxyaddresses",
"physicaldeliveryofficename", "msds-additionalsamaccountName",
"msds-phoneticcompanyname", "msds-phoneticdepartment",
"msds-phoneticdisplayname", "msds-phoneticfirstname",
"msds-phoneticlastname",
}
var (
baseDNMidMap map[string]basednmid.BaseDNMiddleware
filterMidMap map[string]filtermid.FilterMiddleware
attrListMidMap map[string]attrlistmid.AttrListMiddleware
attrEntriesMidMap map[string]attrentriesmid.AttrEntriesMiddleware
)
var baseDNMidFlags map[rune]string = map[rune]string{
'O': "OIDAttribute",
'C': "Case",
'X': "HexValue",
'S': "Spacing",
'Q': "DoubleQuotes",
}
var filterMidFlags map[rune]string = map[rune]string{
'O': "OIDAttribute",
'C': "Case",
'X': "HexValue",
'S': "Spacing",
'T': "ReplaceTautologies",
't': "TimestampGarbage",
'B': "AddBool",
'D': "DblNegBool",
'M': "DeMorganBool",
'R': "ReorderBool",
'b': "ExactBitwiseBreakout",
'd': "BitwiseDecomposition",
'I': "EqInclusion",
'E': "EqExclusion",
'G': "Garbage",
'A': "EqApproxMatch",
'x': "EqExtensible",
'Z': "PrependZeros",
's': "SubstringSplit",
'N': "NamesToANR",
'n': "ANRGarbageSubstring",
}
var attrListMidFlags map[rune]string = map[rune]string{
'O': "OIDAttribute",
'C': "Case",
'D': "Duplicate",
'G': "GarbageNonExisting",
'g': "GarbageExisting",
'W': "ReplaceWithWildcard",
'w': "AddWildcard",
'p': "AddPlus",
'E': "ReplaceWithEmpty",
'R': "ReorderList",
}
var attrEntriesMidFlags map[rune]string = map[rune]string{
'O': "OIDAttribute",
'C': "Case",
/*
'D': "Duplicate",
'G': "GarbageNonExisting",
'g': "GarbageExisting",
*/
'R': "ReorderList",
'D': "Duplicate",
}
func SetupMiddlewaresMap() {
baseDNMidMap = map[string]basednmid.BaseDNMiddleware{
"OIDAttribute": basednmid.OIDAttributeBaseDNObf(optInt("BDNOIDAttributeMaxSpaces"), optInt("BDNOIDAttributeMaxZeros"), optBool("BDNOIDAttributeIncludePrefix")),
"Case": basednmid.RandCaseBaseDNObf(optFloat("BDNCaseProb")),
"HexValue": basednmid.RandHexValueBaseDNObf(optFloat("BDNHexValueProb")),
"Spacing": basednmid.RandSpacingBaseDNObf(optInt("BDNSpacingMaxElems")),
"DoubleQuotes": basednmid.DoubleQuotesBaseDNObf(),
}
filterMidMap = map[string]filtermid.FilterMiddleware{
"OIDAttribute": filtermid.OIDAttributeFilterObf(optInt("FiltOIDAttributeMaxSpaces"), optInt("FiltOIDAttributeMaxZeros"), optBool("FiltOIDAttributeIncludePrefix")),
"Case": filtermid.RandCaseFilterObf(optFloat("FiltCaseProb")),
"HexValue": filtermid.RandHexValueFilterObf(optFloat("FiltHexValueProb")),
"Spacing": filtermid.RandSpacingFilterObf(optInt("FiltSpacingMaxSpaces")),
"ReplaceTautologies": filtermid.ReplaceTautologiesFilterObf(),
"TimestampGarbage": filtermid.RandTimestampSuffixFilterObf(optInt("FiltTimestampGarbageMaxChars"), optStr("FiltGarbageCharset"), optBool("FiltTimestampGarbageUseComma")),
"AddBool": filtermid.RandAddBoolFilterObf(optInt("FiltAddBoolMaxDepth"), optFloat("FiltDeMorganBoolProb")),
"DblNegBool": filtermid.RandDblNegBoolFilterObf(optInt("FiltDblNegBoolMaxDepth"), optFloat("FiltDeMorganBoolProb")),
"DeMorganBool": filtermid.DeMorganBoolFilterObf(),
"ReorderBool": filtermid.RandBoolReorderFilterObf(),
"ExactBitwiseBreakout": filtermid.ExactBitwiseBreakoutFilterObf(),
"BitwiseDecomposition": filtermid.BitwiseDecomposeFilterObf(optInt("FiltBitwiseDecompositionMaxBits")),
"EqInclusion": filtermid.EqualityByInclusionFilterObf(),
"EqExclusion": filtermid.EqualityByExclusionFilterObf(),
"Garbage": filtermid.RandGarbageFilterObf(optInt("FiltGarbageMaxElems"), optInt("FiltGarbageMaxSize"), optStr("FiltGarbageCharset")),
"EqApproxMatch": filtermid.EqualityToApproxMatchFilterObf(),
"EqExtensible": filtermid.EqualityToExtensibleFilterObf(optBool("FiltEqExtensibleAppendDN")),
"PrependZeros": filtermid.RandPrependZerosFilterObf(optInt("FiltPrependZerosMaxElems")),
"SubstringSplit": filtermid.RandSubstringSplitFilterObf(optFloat("FiltSubstringSplitProb")),
"NamesToANR": filtermid.ANRAttributeFilterObf(ANRSet),
"ANRGarbageSubstring": filtermid.ANRSubstringGarbageFilterObf(optInt("FiltANRSubstringMaxElems"), optStr("FiltGarbageCharset")),
}
attrListMidMap = map[string]attrlistmid.AttrListMiddleware{
"OIDAttribute": attrlistmid.OIDAttributeAttrListObf(optInt("AttrsOIDAttributeMaxSpaces"), optInt("AttrsOIDAttributeMaxZeros"), optBool("AttrsOIDAttributePrefix")),
"Case": attrlistmid.RandCaseAttrListObf(optFloat("AttrsCaseProb")),
"Duplicate": attrlistmid.DuplicateAttrListObf(optFloat("AttrsDuplicateProb")),
"GarbageNonExisting": attrlistmid.GarbageNonExistingAttrListObf(optInt("AttrsGarbageNonExistingMaxElems"), optInt("AttrsGarbageNonExistingMaxSize"), optStr("AttrsGarbageCharset")),
"GarbageExisting": attrlistmid.GarbageExistingAttrListObf(optInt("AttrsGarbageExistingMaxElems")),
"ReplaceWithWildcard": attrlistmid.ReplaceWithWildcardAttrListObf(),
"AddWildcard": attrlistmid.AddWildcardAttrListObf(),
"AddPlus": attrlistmid.AddPlusAttrListObf(),
"ReplaceWithEmpty": attrlistmid.ReplaceWithEmptyAttrListObf(),
"ReorderList": attrlistmid.ReorderListAttrListObf(),
}
attrEntriesMidMap = map[string]attrentriesmid.AttrEntriesMiddleware{
"OIDAttribute": attrentriesmid.OIDAttributeAttrEntriesObf(optInt("AttrEntriesOIDAttributeMaxSpaces"), optInt("AttrEntriesOIDAttributeMaxZeros"), optBool("AttrEntriesOIDAttributePrefix")),
"Case": attrentriesmid.RandCaseAttrEntriesObf(optFloat("AttrEntriesCaseProb")),
"ReorderList": attrentriesmid.ReorderListAttrEntriesObf(),
}
}
func optStr(key string) string {
if value, ok := options.Get(key); ok {
return value
}
return middlewares.DefaultOptions[key]
}
func optInt(key string) int {
if value, ok := options.Get(key); ok {
i, err := strconv.Atoi(value)
if err == nil {
return i
}
}
result, _ := strconv.Atoi(middlewares.DefaultOptions[key])
return result
}
func optFloat(key string) float64 {
if value, ok := options.Get(key); ok {
i, err := strconv.ParseFloat(value, 64)
if err == nil {
return i
}
}
result, _ := strconv.ParseFloat(middlewares.DefaultOptions[key], 64)
return result
}
func optBool(key string) bool {
if value, ok := options.Get(key); ok {
return strings.ToLower(value) == "true"
}
return strings.ToLower(middlewares.DefaultOptions[key]) == "true"
}