104104import static com .rapid7 .client .dcerpc .mserref .SystemErrorCode .ERROR_SUCCESS ;
105105
106106public class SecurityAccountManagerService extends Service {
107- private final static int MAXIMUM_ALLOWED = 33554432 ;
107+ public final static int MAXIMUM_ALLOWED = 33554432 ;
108108
109109 /**
110110 * Create a new {@link SecurityAccountManagerService} backed by the provided {@link RPCTransport}
@@ -127,19 +127,33 @@ public ServerHandle openServer() throws IOException {
127127
128128 /**
129129 * Open a new {@link ServerHandle} using the provided NETBIOS name of the server.
130+ * Uses {@link SecurityAccountManagerService#MAXIMUM_ALLOWED} as desired access.
130131 * @param serverName NETBIOS name of the server. Most targets ignore this value so an empty string is suggested.
131132 * @return A new {@link ServerHandle} for the given server identified by serverName.
132133 * @throws IOException Thrown if either a communication failure is encountered, or the call
133134 * returns an unsuccessful response.
134135 */
135- public ServerHandle openServer (String serverName ) throws IOException {
136+ public ServerHandle openServer (final String serverName ) throws IOException {
137+ return openServer (serverName , MAXIMUM_ALLOWED );
138+ }
139+
140+ /**
141+ * Open a new {@link ServerHandle} using the provided NETBIOS name of the server.
142+ * @param serverName NETBIOS name of the server. Most targets ignore this value so an empty string is suggested.
143+ * @param desiredAccess The desired access represented as a bitmask.
144+ * @return A new {@link ServerHandle} for the given server identified by serverName.
145+ * @throws IOException Thrown if either a communication failure is encountered, or the call
146+ * returns an unsuccessful response.
147+ */
148+ public ServerHandle openServer (final String serverName , final int desiredAccess ) throws IOException {
136149 final SamrConnect2Request request =
137- new SamrConnect2Request (parseWCharNT (serverName ), MAXIMUM_ALLOWED );
150+ new SamrConnect2Request (parseWCharNT (serverName ), desiredAccess );
138151 return parseServerHandle (callExpectSuccess (request , "SamrConnect2" ));
139152 }
140153
141154 /**
142155 * Open a new {@link DomainHandle} against a valid domain identified by the provided {@link SID}.
156+ * Uses {@link SecurityAccountManagerService#MAXIMUM_ALLOWED} as desired access.
143157 * @param serverHandle A valid server handle obtained from {@link #openServer()}
144158 * @param domainId A valid {@link SID} which identifies the domain.
145159 * Use {@link #getDomainsForServer(ServerHandle)} if you need to discover them.
@@ -148,44 +162,100 @@ public ServerHandle openServer(String serverName) throws IOException {
148162 * returns an unsuccessful response.
149163 */
150164 public DomainHandle openDomain (final ServerHandle serverHandle , final SID domainId ) throws IOException {
165+ return openDomain (serverHandle , domainId , MAXIMUM_ALLOWED );
166+ }
167+
168+ /**
169+ * Open a new {@link DomainHandle} against a valid domain identified by the provided {@link SID}.
170+ * @param serverHandle A valid server handle obtained from {@link #openServer()}
171+ * @param domainId A valid {@link SID} which identifies the domain.
172+ * Use {@link #getDomainsForServer(ServerHandle)} if you need to discover them.
173+ * @param desiredAccess The desired access represented as a bitmask.
174+ * @return A new {@link DomainHandle} for the resolved domain.
175+ * @throws IOException Thrown if either a communication failure is encountered, or the call
176+ * returns an unsuccessful response.
177+ */
178+ public DomainHandle openDomain (final ServerHandle serverHandle , final SID domainId , final int desiredAccess )
179+ throws IOException {
151180 final SamrOpenDomainRequest request =
152- new SamrOpenDomainRequest (parseHandle (serverHandle ), MAXIMUM_ALLOWED , parseSID (domainId ));
181+ new SamrOpenDomainRequest (parseHandle (serverHandle ), desiredAccess , parseSID (domainId ));
153182 return parseDomainHandle (callExpectSuccess (request , "SamrOpenDomain" ));
154183 }
155184
156185 /**
157186 * Open a new {@link GroupHandle} against a valid group identified by both the
158187 * provided {@link DomainHandle} and groupRID.
188+ * Uses {@link SecurityAccountManagerService#MAXIMUM_ALLOWED} as desired access.
159189 * @param domainHandle A valid domain handle obtained from {@link #openDomain(ServerHandle, SID)}.
160190 * @param groupRID A relative identifier for the group.
161191 * @return A new {@link GroupHandle} for the resolved group.
162192 * @throws IOException Thrown if either a communication failure is encountered, or the call
163193 * returns an unsuccessful response.
164194 */
165195 public GroupHandle openGroup (final DomainHandle domainHandle , final long groupRID ) throws IOException {
196+ return openGroup (domainHandle , groupRID , MAXIMUM_ALLOWED );
197+ }
198+
199+ /**
200+ * Open a new {@link GroupHandle} against a valid group identified by both the
201+ * provided {@link DomainHandle} and groupRID.
202+ * @param domainHandle A valid domain handle obtained from {@link #openDomain(ServerHandle, SID)}.
203+ * @param groupRID A relative identifier for the group.
204+ * @param desiredAccess The desired access represented as a bitmask.
205+ * @return A new {@link GroupHandle} for the resolved group.
206+ * @throws IOException Thrown if either a communication failure is encountered, or the call
207+ * returns an unsuccessful response.
208+ */
209+ public GroupHandle openGroup (final DomainHandle domainHandle , final long groupRID , final int desiredAccess )
210+ throws IOException {
166211 final SamrOpenGroupRequest request =
167- new SamrOpenGroupRequest (parseHandle (domainHandle ), MAXIMUM_ALLOWED , groupRID );
212+ new SamrOpenGroupRequest (parseHandle (domainHandle ), desiredAccess , groupRID );
168213 return parseGroupHandle (callExpectSuccess (request , "SamrOpenGroupRequest" ));
169214 }
170215
171216 /**
172217 * Open a new {@link UserHandle} against a valid user identified by both the
173218 * provided {@link DomainHandle} and userRID.
219+ * Uses 0x2011B as desired access.
174220 * @param domainHandle A valid domain handle obtained from {@link #openDomain(ServerHandle, SID)}.
175221 * @param userRID A relative identifier for the group.
176222 * @return A new {@link UserHandle} for the resolved user.
177223 * @throws IOException Thrown if either a communication failure is encountered, or the call
178224 * returns an unsuccessful response.
179225 */
180226 public UserHandle openUser (final DomainHandle domainHandle , final long userRID ) throws IOException {
227+ // Generic rights: 0x00000000
228+ // Standard rights: 0x00020000
229+ // SAMR User specific rights: 0x0000011b
230+ // Samr User Access Get
231+ // - Groups: SAMR_USER_ACCESS_GET_GROUPS is SET
232+ // - Attributes: SAMR_USER_ACCESS_GET_ATTRIBUTES is SET
233+ // - Logoninfo: SAMR_USER_ACCESS_GET_LOGONINFO is SET
234+ // <NDR: unsigned long> [in] unsigned long DesiredAccess
235+ return openUser (domainHandle , userRID , 0x2011B );
236+ }
237+
238+ /**
239+ * Open a new {@link UserHandle} against a valid user identified by both the
240+ * provided {@link DomainHandle} and userRID.
241+ * @param domainHandle A valid domain handle obtained from {@link #openDomain(ServerHandle, SID)}.
242+ * @param userRID A relative identifier for the group.
243+ * @param desiredAccess The desired access represented as a bitmask.
244+ * @return A new {@link UserHandle} for the resolved user.
245+ * @throws IOException Thrown if either a communication failure is encountered, or the call
246+ * returns an unsuccessful response.
247+ */
248+ public UserHandle openUser (final DomainHandle domainHandle , final long userRID , final int desiredAccess )
249+ throws IOException {
181250 final SamrOpenUserRequest request =
182- new SamrOpenUserRequest (parseHandle (domainHandle ), userRID );
251+ new SamrOpenUserRequest (parseHandle (domainHandle ), desiredAccess , userRID );
183252 return parseUserHandle (callExpectSuccess (request , "SamrOpenUserRequest" ));
184253 }
185254
186255 /**
187256 * Open a new {@link AliasHandle} against a valid user identified by both the
188257 * provided {@link DomainHandle} and aliasRID.
258+ * Uses 0x0002000C as desired access.
189259 * @param domainHandle A valid domain handle obtained from {@link #openDomain(ServerHandle, SID)}.
190260 * @param aliasRID A relative identifier for the group.
191261 * @return A new {@link AliasHandle} for the resolved alias.
@@ -197,8 +267,23 @@ public AliasHandle openAlias(final DomainHandle domainHandle, final long aliasRI
197267 // SAMR Alias specific rights: 0x0000000c
198268 // - SAMR_ALIAS_ACCESS_LOOKUP_INFO is SET(8)
199269 // - SAMR_ALIAS_ACCESS_GET_MEMBERS is SET(4)
270+ return openAlias (domainHandle , aliasRID , 0x0002000C );
271+ }
272+
273+ /**
274+ * Open a new {@link AliasHandle} against a valid user identified by both the
275+ * provided {@link DomainHandle} and aliasRID.
276+ * @param domainHandle A valid domain handle obtained from {@link #openDomain(ServerHandle, SID)}.
277+ * @param aliasRID A relative identifier for the group.
278+ * @param desiredAccess The desired access represented as a bitmask.
279+ * @return A new {@link AliasHandle} for the resolved alias.
280+ * @throws IOException Thrown if either a communication failure is encountered, or the call
281+ * returns an unsuccessful response.
282+ */
283+ public AliasHandle openAlias (final DomainHandle domainHandle , final long aliasRID , int desiredAccess )
284+ throws IOException {
200285 final SamrOpenAliasRequest request =
201- new SamrOpenAliasRequest (parseHandle (domainHandle ), 0x0002000C , aliasRID );
286+ new SamrOpenAliasRequest (parseHandle (domainHandle ), desiredAccess , aliasRID );
202287 return parseAliasHandle (callExpectSuccess (request , "SamrOpenAlias" ));
203288 }
204289
0 commit comments