diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/ServerService.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/ServerService.java index 12685c41..b9dd94a0 100644 --- a/src/main/java/com/rapid7/client/dcerpc/mssrvs/ServerService.java +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/ServerService.java @@ -20,14 +20,31 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.lang3.mutable.MutableLong; import com.hierynomus.protocol.transport.TransportException; -import com.rapid7.client.dcerpc.RPCException; import com.rapid7.client.dcerpc.mserref.SystemErrorCode; -import com.rapid7.client.dcerpc.mssrvs.messages.*; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo0; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo1; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo2; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo501; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo502; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo503; +import com.rapid7.client.dcerpc.mssrvs.messages.NetprPathCanonicalizeRequest; +import com.rapid7.client.dcerpc.mssrvs.messages.NetrShareEnumRequest; +import com.rapid7.client.dcerpc.mssrvs.messages.NetrShareEnumResponse; +import com.rapid7.client.dcerpc.mssrvs.messages.NetrShareGetInfoRequest; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareEnumStruct; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo0; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo1; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo2; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo501; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo502; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo503; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfoContainer; +import com.rapid7.client.dcerpc.objects.WChar; import com.rapid7.client.dcerpc.service.Service; import com.rapid7.client.dcerpc.transport.RPCTransport; @@ -39,48 +56,305 @@ * @see [MS-SRVS]: Server Service Remote Protocol */ public class ServerService extends Service { + /** + * Specifies the preferred maximum length, in bytes, of the returned data. If the specified value is + * MAX_PREFERRED_LENGTH, the method MUST attempt to return all entries. + */ + private final static int MAX_BUFFER_SIZE = 1048576; public ServerService(final RPCTransport transport) { super(transport); } - public List getShares() throws IOException { - final List shares = new LinkedList<>(); - final MutableInt resumeHandle = new MutableInt(); - for (; ; ) { - final NetrShareEnumRequest request = new NetrShareEnumRequest(2, resumeHandle.getValue()); - final NetrShareEnumResponse response = call(request); - final int returnCode = response.getReturnValue(); - if (SystemErrorCode.ERROR_SUCCESS.is(returnCode) || SystemErrorCode.ERROR_MORE_DATA.is(returnCode)) { - final List responseShares = response.getShares(); - if (SystemErrorCode.ERROR_SUCCESS.is(returnCode)) { - shares.addAll(responseShares); - break; - } else { - if (responseShares.isEmpty()) { - throw new TransportException("NetrShareEnum shares empty."); - } - final Integer responseResumeHandle = response.getResumeHandle(); - if (responseResumeHandle == resumeHandle.getValue()) { - throw new TransportException("NetrShareEnum resume handle not updated."); - } - if (responseResumeHandle == null) { - throw new TransportException("NetrShareEnum resume handle null."); + public String getCanonicalizedName(String serverName, String pathName, String prefix, + int outBufLength, int pathType, int flags) throws IOException { + final NetprPathCanonicalizeRequest request = + new NetprPathCanonicalizeRequest(serverName, pathName, outBufLength, prefix, pathType, flags); + return callExpectSuccess(request, "NetprPathCanonicalize").getCanonicalizedPath(); + } + + public NetShareInfo0 getShare0(String shareName) throws IOException { + final NetrShareGetInfoRequest.NetrShareGetInfoRequest0 request = + new NetrShareGetInfoRequest.NetrShareGetInfoRequest0(WChar.NullTerminated.of(shareName)); + return parseShareInfo0(callExpectSuccess(request, "NetrShareGetInfo[0]").getShareInfo()); + } + + public NetShareInfo1 getShare1(String shareName) throws IOException { + final NetrShareGetInfoRequest.NetrShareGetInfoRequest1 request = + new NetrShareGetInfoRequest.NetrShareGetInfoRequest1(WChar.NullTerminated.of(shareName)); + return parseShareInfo1(callExpectSuccess(request, "NetrShareGetInfo[1]").getShareInfo()); + } + + public NetShareInfo2 getShare2(String shareName) throws IOException { + final NetrShareGetInfoRequest.NetrShareGetInfoRequest2 request = + new NetrShareGetInfoRequest.NetrShareGetInfoRequest2(WChar.NullTerminated.of(shareName)); + return parseShareInfo2(callExpectSuccess(request, "NetrShareGetInfo[2]").getShareInfo()); + } + + public NetShareInfo501 getShare501(String shareName) throws IOException { + final NetrShareGetInfoRequest.NetrShareGetInfoRequest501 request = + new NetrShareGetInfoRequest.NetrShareGetInfoRequest501(WChar.NullTerminated.of(shareName)); + return parseShareInfo501(callExpectSuccess(request, "NetrShareGetInfo[501]").getShareInfo()); + } + + public NetShareInfo502 getShare502(String shareName) throws IOException { + final NetrShareGetInfoRequest.NetrShareGetInfoRequest502 request = + new NetrShareGetInfoRequest.NetrShareGetInfoRequest502(WChar.NullTerminated.of(shareName)); + return parseShareInfo502(callExpectSuccess(request, "NetrShareGetInfo[502]").getShareInfo()); + } + + public NetShareInfo503 getShare503(String shareName) throws IOException { + final NetrShareGetInfoRequest.NetrShareGetInfoRequest503 request = + new NetrShareGetInfoRequest.NetrShareGetInfoRequest503(WChar.NullTerminated.of(shareName)); + return parseShareInfo503(callExpectSuccess(request, "NetrShareGetInfo[503]").getShareInfo()); + } + + public List getShares0() throws IOException { + return new GetSharesRequest0(MAX_BUFFER_SIZE).call().getShares(); + } + + public List getShares1() throws IOException { + return new GetSharesRequest1(MAX_BUFFER_SIZE).call().getShares(); + } + + public List getShares2() throws IOException { + return new GetSharesRequest2(MAX_BUFFER_SIZE).call().getShares(); + } + + public List getShares501() throws IOException { + return new GetSharesRequest501(MAX_BUFFER_SIZE).call().getShares(); + } + + public List getShares502() throws IOException { + return new GetSharesRequest502(MAX_BUFFER_SIZE).call().getShares(); + } + + public List getShares503() throws IOException { + return new GetSharesRequest503(MAX_BUFFER_SIZE).call().getShares(); + } + + private class GetSharesRequest0 extends GetSharesRequest { + GetSharesRequest0(long preferredMaximumLength) { + super(preferredMaximumLength); + } + + @Override + String getName() { + return "NetrShareEnum[0]"; + } + + @Override + NetShareInfo0 convert(ShareInfo0 src) { + return ServerService.this.parseShareInfo0(src); + } + + @Override + NetrShareEnumRequest>> createRequest( + long preferredMaximumLength, Long resumeHandle) { + return new NetrShareEnumRequest.NetShareEnumRequest0(preferredMaximumLength, resumeHandle); + } + } + + private class GetSharesRequest1 extends GetSharesRequest { + GetSharesRequest1(long preferredMaximumLength) { + super(preferredMaximumLength); + } + + @Override + String getName() { + return "NetrShareEnum[1]"; + } + + @Override + NetShareInfo1 convert(ShareInfo1 src) { + return ServerService.this.parseShareInfo1(src); + } + + @Override + NetrShareEnumRequest>> createRequest( + long preferredMaximumLength, Long resumeHandle) { + return new NetrShareEnumRequest.NetShareEnumRequest1(preferredMaximumLength, resumeHandle); + } + } + + private class GetSharesRequest2 extends GetSharesRequest { + GetSharesRequest2(long preferredMaximumLength) { + super(preferredMaximumLength); + } + + @Override + String getName() { + return "NetrShareEnum[2]"; + } + + @Override + NetShareInfo2 convert(ShareInfo2 src) { + return ServerService.this.parseShareInfo2(src); + } + + @Override + NetrShareEnumRequest>> createRequest( + long preferredMaximumLength, Long resumeHandle) { + return new NetrShareEnumRequest.NetShareEnumRequest2(preferredMaximumLength, resumeHandle); + } + } + + private class GetSharesRequest501 extends GetSharesRequest { + GetSharesRequest501(long preferredMaximumLength) { + super(preferredMaximumLength); + } + + @Override + String getName() { + return "NetrShareEnum[501]"; + } + + @Override + NetShareInfo501 convert(ShareInfo501 src) { + return ServerService.this.parseShareInfo501(src); + } + + @Override + NetrShareEnumRequest>> createRequest( + long preferredMaximumLength, Long resumeHandle) { + return new NetrShareEnumRequest.NetShareEnumRequest501(preferredMaximumLength, resumeHandle); + } + } + + private class GetSharesRequest502 extends GetSharesRequest { + GetSharesRequest502(long preferredMaximumLength) { + super(preferredMaximumLength); + } + + @Override + String getName() { + return "NetrShareEnum[502]"; + } + + @Override + NetShareInfo502 convert(ShareInfo502 src) { + return ServerService.this.parseShareInfo502(src); + } + + @Override + NetrShareEnumRequest>> createRequest( + long preferredMaximumLength, Long resumeHandle) { + return new NetrShareEnumRequest.NetShareEnumRequest502(preferredMaximumLength, resumeHandle); + } + } + + private class GetSharesRequest503 extends GetSharesRequest { + GetSharesRequest503(long preferredMaximumLength) { + super(preferredMaximumLength); + } + + @Override + String getName() { + return "NetrShareEnum[503]"; + } + + @Override + NetShareInfo503 convert(ShareInfo503 src) { + return ServerService.this.parseShareInfo503(src); + } + + @Override + NetrShareEnumRequest>> createRequest( + long preferredMaximumLength, Long resumeHandle) { + return new NetrShareEnumRequest.NetShareEnumRequest503(preferredMaximumLength, resumeHandle); + } + } + + private abstract class GetSharesRequest { + private final long preferredMaximumLength; + private final List shares; + + GetSharesRequest(long preferredMaximumLength) { + this.preferredMaximumLength = preferredMaximumLength; + this.shares = new ArrayList<>(); + } + + List getShares() { + return this.shares; + } + + abstract String getName(); + abstract N convert(S src); + abstract NetrShareEnumRequest>> createRequest(long preferredMaximumLength, Long resumeHandle); + + GetSharesRequest call() throws IOException { + final MutableLong resumeHandle = new MutableLong(); + while (true) { + final NetrShareEnumRequest>> request = + createRequest(this.preferredMaximumLength, resumeHandle.getValue()); + final NetrShareEnumResponse>> response = + ServerService.this.callExpect(request, getName(), + SystemErrorCode.ERROR_MORE_DATA, SystemErrorCode.ERROR_SUCCESS); + final ShareEnumStruct> shareEnumStruct = response.getShareEnumStruct(); + if (shareEnumStruct != null) { + final ShareInfoContainer shareInfoContainer = shareEnumStruct.getShareInfoContainer(); + if (shareInfoContainer != null) { + final S[] buffer = shareInfoContainer.getBuffer(); + if (buffer != null) { + for (final S src : buffer) + shares.add(convert(src)); + } } - shares.addAll(responseShares); - resumeHandle.setValue(responseResumeHandle); } - } else { - throw new RPCException("NetrShareEnum", response.getReturnValue()); + if (SystemErrorCode.ERROR_SUCCESS.is(response.getReturnValue())) + return this; + final Long responseResumeHandle = response.getResumeHandle(); + if (responseResumeHandle == null) { + throw new TransportException("NetrShareEnum resume handle null."); + } else if (responseResumeHandle.longValue() == resumeHandle.getValue()) { + throw new TransportException("NetrShareEnum resume handle not updated."); + } + resumeHandle.add(responseResumeHandle); } } - return Collections.unmodifiableList(new ArrayList<>(shares)); } - public String getCanonicalizedName(String serverName, String pathName, String prefix, - int outBufLength, int pathType, int flags) throws IOException { - final NetprPathCanonicalizeRequest request = - new NetprPathCanonicalizeRequest(serverName, pathName, outBufLength, prefix, pathType, flags); - return callExpectSuccess(request, "NetprPathCanonicalize").getCanonicalizedPath(); + private NetShareInfo0 parseShareInfo0(final ShareInfo0 obj) { + if (obj == null) + return null; + return new NetShareInfo0(parseWChar(obj.getNetName())); + } + + private NetShareInfo1 parseShareInfo1(final ShareInfo1 obj) { + if (obj == null) + return null; + return new NetShareInfo1(parseWChar(obj.getNetName()), obj.getType(), parseWChar(obj.getRemark())); + } + + private NetShareInfo2 parseShareInfo2(final ShareInfo2 obj) { + if (obj == null) + return null; + return new NetShareInfo2(parseWChar(obj.getNetName()), obj.getType(), parseWChar(obj.getRemark()), + obj.getPermissions(), obj.getMaxUses(), obj.getCurrentUses(), + parseWChar(obj.getPath()), parseWChar(obj.getPasswd())); + } + + private NetShareInfo501 parseShareInfo501(final ShareInfo501 obj) { + if (obj == null) + return null; + return new NetShareInfo501(parseWChar(obj.getNetName()), obj.getType(), parseWChar(obj.getRemark()), + obj.getFlags()); + } + + private NetShareInfo502 parseShareInfo502(final ShareInfo502 obj) { + if (obj == null) + return null; + return new NetShareInfo502(parseWChar(obj.getNetName()), obj.getType(), parseWChar(obj.getRemark()), + obj.getPermissions(), obj.getMaxUses(), obj.getCurrentUses(), + parseWChar(obj.getPath()), parseWChar(obj.getPasswd()), obj.getSecurityDescriptor()); + } + + private NetShareInfo503 parseShareInfo503(final ShareInfo503 obj) { + if (obj == null) + return null; + return new NetShareInfo503(parseWChar(obj.getNetName()), obj.getType(), parseWChar(obj.getRemark()), + obj.getPermissions(), obj.getMaxUses(), obj.getCurrentUses(), + parseWChar(obj.getPath()), parseWChar(obj.getPasswd()), parseWChar(obj.getServerName()), + obj.getSecurityDescriptor()); } } diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo.java new file mode 100644 index 00000000..cbf208db --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo.java @@ -0,0 +1,57 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import java.util.Objects; + +public abstract class NetShareInfo { + private final String netName; + + public NetShareInfo(final String netName) { + this.netName = netName; + } + + public String getNetName() { + return netName; + } + + @Override + public int hashCode() { + return Objects.hash(getNetName()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof NetShareInfo)) { + return false; + } + return Objects.equals(getNetName(), ((NetShareInfo) obj).getNetName()); + } + + String formatString(final String str) { + if (str == null) + return "null"; + return String.format("\"%s\"", str); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo0.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo0.java new file mode 100644 index 00000000..d05389ef --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo0.java @@ -0,0 +1,48 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +public class NetShareInfo0 extends NetShareInfo { + public NetShareInfo0(final String netName) { + super(netName); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof NetShareInfo0)) { + return false; + } + return super.equals(obj); + } + + @Override + public String toString() { + return String.format("NetShareInfo0{netName: %s}", formatString(getNetName())); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo1.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo1.java new file mode 100644 index 00000000..52b10911 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo1.java @@ -0,0 +1,67 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import java.util.Objects; + +public class NetShareInfo1 extends NetShareInfo0 { + private final int type; + private final String remark; + + public NetShareInfo1(final String netName, final int type, final String remark) { + super(netName); + this.type = type; + this.remark = remark; + } + + public int getType() { + return type; + } + + public String getRemark() { + return remark; + } + + @Override + public int hashCode() { + return (31 * super.hashCode()) + Objects.hash(getType(), getRemark()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof NetShareInfo1)) { + return false; + } + final NetShareInfo1 other = (NetShareInfo1) obj; + return super.equals(obj) + && getType() == other.getType() + && Objects.equals(getRemark(), other.getRemark()); + } + + @Override + public String toString() { + return String.format("NetShareInfo1{netName: %s, type: %d, remark: %s}", + formatString(getNetName()), getType(), formatString(getRemark())); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo2.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo2.java new file mode 100644 index 00000000..c0c34a6f --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo2.java @@ -0,0 +1,93 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import java.util.Objects; + +public class NetShareInfo2 extends NetShareInfo1 { + + private final int permissions; + private final int maxUses; + private final int currentUses; + private final String path; + private final String passwd; + + public NetShareInfo2(final String netName, final int type, final String remark, + final int permissions, final int maxUses, final int currentUses, final String path, final String passwd) { + super(netName, type, remark); + this.permissions = permissions; + this.maxUses = maxUses; + this.currentUses = currentUses; + this.path = path; + this.passwd = passwd; + } + + public int getPermissions() { + return permissions; + } + + public int getMaxUses() { + return maxUses; + } + + public int getCurrentUses() { + return currentUses; + } + + public String getPath() { + return path; + } + + public String getPasswd() { + return passwd; + } + + @Override + public int hashCode() { + return (31 * super.hashCode()) + + Objects.hash(getPermissions(), getMaxUses(), getCurrentUses(), getPath(), getPasswd()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof NetShareInfo2)) { + return false; + } + final NetShareInfo2 other = (NetShareInfo2) obj; + return super.equals(obj) + && getPermissions() == other.getPermissions() + && getMaxUses() == other.getMaxUses() + && getCurrentUses() == other.getCurrentUses() + && Objects.equals(getPath(), other.getPath()) + && Objects.equals(getPasswd(), other.getPasswd()); + } + + @Override + public String toString() { + return String.format("NetShareInfo2{netName: %s, type: %d, remark: %s, " + + "permissions: %d, maxUses: %d, currentUses: %d, path: %s, passwd: %s}", + formatString(getNetName()), getType(), formatString(getRemark()), + getPermissions(), getMaxUses(), getCurrentUses(), formatString(getPasswd()), formatString(getPasswd())); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo501.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo501.java new file mode 100644 index 00000000..e84e93bd --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo501.java @@ -0,0 +1,60 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import java.util.Objects; + +public class NetShareInfo501 extends NetShareInfo1 { + private final int flags; + + public NetShareInfo501(final String netName, final int type, final String remark, final int flags) { + super(netName, type, remark); + this.flags = flags; + } + + public int getFlags() { + return flags; + } + + @Override + public int hashCode() { + return (31 * super.hashCode()) + Objects.hash(getFlags()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof NetShareInfo501)) { + return false; + } + final NetShareInfo501 other = (NetShareInfo501) obj; + return super.equals(obj) + && getFlags() == other.getFlags(); + } + + @Override + public String toString() { + return String.format("NetShareInfo501{netName: %s, type: %d, remark: %s, flags: %d}", + formatString(getNetName()), getType(), formatString(getRemark()), getFlags()); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo502.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo502.java new file mode 100644 index 00000000..41813819 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo502.java @@ -0,0 +1,67 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import java.util.Arrays; + +public class NetShareInfo502 extends NetShareInfo2 { + + private final byte[] securityDescriptor; + + public NetShareInfo502(final String netName, final int type, final String remark, + final int permissions, final int maxUses, final int currentUses, final String path, + final String passwd, final byte[] securityDescriptor) { + super(netName, type, remark, permissions, maxUses, currentUses, path, passwd); + this.securityDescriptor = securityDescriptor; + } + + public byte[] getSecurityDescriptor() { + return securityDescriptor; + } + + @Override + public int hashCode() { + return (31 * super.hashCode()) + Arrays.hashCode(getSecurityDescriptor()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof NetShareInfo502)) { + return false; + } + final NetShareInfo502 other = (NetShareInfo502) obj; + return super.equals(obj) + && Arrays.equals(getSecurityDescriptor(), other.getSecurityDescriptor()); + } + + @Override + public String toString() { + return String.format("NetShareInfo502{netName: %s, type: %d, remark: %s, " + + "permissions: %d, maxUses: %d, currentUses: %d, path: %s, " + + "passwd: %s, size(securityDescriptor): %s}", + formatString(getNetName()), getType(), formatString(getRemark()), + getPermissions(), getMaxUses(), getCurrentUses(), formatString(getPasswd()), + formatString(getPasswd()), (getSecurityDescriptor() == null ? "null" : getSecurityDescriptor().length)); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo503.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo503.java new file mode 100644 index 00000000..06c6314d --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/dto/NetShareInfo503.java @@ -0,0 +1,68 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import java.util.Objects; + +public class NetShareInfo503 extends NetShareInfo502 { + + private final String serverName; + + public NetShareInfo503(final String netName, final int type, final String remark, + final int permissions, final int maxUses, final int currentUses, final String path, + final String passwd, final String serverName, final byte[] securityDescriptor) { + super(netName, type, remark, permissions, maxUses, currentUses, path, passwd, securityDescriptor); + this.serverName = serverName; + } + + public String getServerName() { + return this.serverName; + } + + @Override + public int hashCode() { + return (31 * super.hashCode()) + Objects.hash(getServerName()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof NetShareInfo503)) { + return false; + } + final NetShareInfo503 other = (NetShareInfo503) obj; + return super.equals(obj) + && Objects.equals(getServerName(), other.getServerName()); + } + + @Override + public String toString() { + return String.format("NetShareInfo503{netName: %s, type: %d, remark: %s, " + + "permissions: %d, maxUses: %d, currentUses: %d, path: %s, " + + "passwd: %s, serverName: %s, size(securityDescriptor): %s}", + formatString(getNetName()), getType(), formatString(getRemark()), + getPermissions(), getMaxUses(), getCurrentUses(), formatString(getPasswd()), + formatString(getPasswd()), formatString(getServerName()), + (getSecurityDescriptor() == null ? "null" : getSecurityDescriptor().length)); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo0.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo0.java deleted file mode 100644 index f2c253a6..00000000 --- a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo0.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2017, Rapid7, Inc. - * - * License: BSD-3-clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - */ -package com.rapid7.client.dcerpc.mssrvs.messages; - -import java.util.Objects; - -public class NetShareInfo0 { - private final String name; - - public NetShareInfo0(final String name) { - if (name == null) { - throw new IllegalArgumentException("name is invalid: " + name); - } - this.name = name; - } - - public String getName() { - return name; - } - - @Override - public String toString() { - return String.format("name=%s", name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - - @Override - public boolean equals(final Object anObject) { - return anObject instanceof NetShareInfo0 && Objects.equals(((NetShareInfo0) anObject).name, name); - } -} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo1.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo1.java deleted file mode 100644 index 78fb9851..00000000 --- a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo1.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2017, Rapid7, Inc. - * - * License: BSD-3-clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - */ -package com.rapid7.client.dcerpc.mssrvs.messages; - -import java.util.Objects; - -public class NetShareInfo1 extends NetShareInfo0 { - private final int type; - private final String comment; - - public NetShareInfo1(final String name, final int type, final String comment) { - super(name); - this.type = type; - this.comment = comment; - } - - public int getType() { - return type; - } - - public String getComment() { - return comment; - } - - @Override - public String toString() { - return String.format("%s, type=%d, comment=%s", super.toString(), type, comment); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), type, comment); - } - - @Override - public boolean equals(final Object anObject) { - return super.equals(anObject) && anObject instanceof NetShareInfo1 && Objects.equals(((NetShareInfo1) anObject).type, type) && Objects.equals(((NetShareInfo1) anObject).comment, comment); - } -} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo2.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo2.java deleted file mode 100644 index 00e5617f..00000000 --- a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetShareInfo2.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2017, Rapid7, Inc. - * - * License: BSD-3-clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - */ -package com.rapid7.client.dcerpc.mssrvs.messages; - -import java.util.Objects; - -public class NetShareInfo2 extends NetShareInfo1 { - private final Integer permissions; - private final Integer maximumUsers; - private final Integer currentUsers; - private final String path; - private final String password; - - public NetShareInfo2(final String name, final Integer type, final String comment, final Integer permissions, final Integer maximumUsers, final Integer currentUsers, final String path, final String password) { - super(name, type, comment); - this.permissions = permissions; - this.maximumUsers = maximumUsers; - this.currentUsers = currentUsers; - this.path = path; - this.password = password; - } - - public int getPermissions() { - return permissions; - } - - public int getMaximumUsers() { - return maximumUsers; - } - - public int getCurrentUsers() { - return currentUsers; - } - - public String getPath() { - return path; - } - - public String getPassword() { - return password; - } - - @Override - public String toString() { - return String.format("%s, permissions=%d, maximumUsers=%d, currentUsers=%d, path=%s, password=%s", super.toString(), permissions, maximumUsers, currentUsers, path, password); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), permissions, maximumUsers, currentUsers, path, password); - } - - @Override - public boolean equals(final Object anObject) { - return super.equals(anObject) && anObject instanceof NetShareInfo1 && Objects.equals(((NetShareInfo2) anObject).permissions, permissions) && Objects.equals(((NetShareInfo2) anObject).maximumUsers, maximumUsers) && Objects.equals(((NetShareInfo2) anObject).currentUsers, currentUsers) && Objects.equals(((NetShareInfo2) anObject).path, path) && Objects.equals(((NetShareInfo2) anObject).password, password); - } -} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumRequest.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumRequest.java index dc80a648..26be6110 100644 --- a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumRequest.java +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumRequest.java @@ -1,288 +1,200 @@ -/** +/* * Copyright 2017, Rapid7, Inc. * * License: BSD-3-clause * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, + * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - * * Redistributions in binary form must reproduce the above copyright + * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of the copyright holder nor the names of its contributors + * Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. + * + * */ + package com.rapid7.client.dcerpc.mssrvs.messages; import java.io.IOException; import com.rapid7.client.dcerpc.io.PacketOutput; import com.rapid7.client.dcerpc.messages.RequestCall; import com.rapid7.client.dcerpc.mssrvs.NetrOpCode; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareEnumLevel; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareEnumStruct; /** - * 3.1.4.8 NetrShareEnum (Opnum 15)
- * The NetrShareEnum method retrieves information about each shared resource on a server. + * NetrShareEnum + *
The NetrShareEnum method retrieves information about each shared resource on a server.
  *
- * 
- * NET_API_STATUS NetrShareEnum(
- *    [in, string, unique] SRVSVC_HANDLE ServerName,
- *    [in, out] LPSHARE_ENUM_STRUCT InfoStruct,
- *    [in] DWORD PreferedMaximumLength,
- *    [out] DWORD* TotalEntries,
- *    [in, out, unique] DWORD* ResumeHandle
- * );
- * 
+ * NET_API_STATUS NetrShareEnum( + * [in, string, unique] SRVSVC_HANDLE ServerName, + * [in, out] LPSHARE_ENUM_STRUCT InfoStruct, + * [in] DWORD PreferedMaximumLength, + * [out] DWORD* TotalEntries, + * [in, out, unique] DWORD* ResumeHandle + * ); * - * ServerName: An SRVSVC_HANDLE (section 2.2.1.1) pointer that identifies the server. The client MUST map this structure - * to an RPC binding handle (see [C706] sections 4.3.5 and 5.1.5.2). If this parameter is NULL, the local computer is - * used.
- *
- * InfoStruct: A pointer to a structure, in the format of a SHARE_ENUM_STRUCT (section 2.2.4.38), as specified in - * section 2.2.4.38. The SHARE_ENUM_STRUCT structure has a Level member that specifies the type of structure to return - * in the ShareInfo member. The Level member MUST be one of the values specified in section 2.2.4.38.
- *
- * PreferedMaximumLength: Specifies the preferred maximum length, in bytes, of the returned data. If the specified value - * is MAX_PREFERRED_LENGTH, the method MUST attempt to return all entries.
- *
- * TotalEntries: The total number of entries that could have been enumerated if the buffer had been big enough to hold - * all the entries.
- *
- * ResumeHandle: A pointer to a value that contains a handle, which is used to continue an existing share search in - * ShareList. The handle MUST be zero on the first call and remain unchanged for subsequent calls. If the ResumeHandle - * parameter is NULL, no resume handle MUST be stored. If this parameter is not NULL and the method returns - * ERROR_MORE_DATA, this parameter receives a nonzero value that can be passed in subsequent calls to this method to - * continue with the enumeration in ShareList.
- *
- *
    - *
  • If this parameter is NULL or points to 0x00000000, the enumeration starts from the beginning of the - * ShareList.
  • - *
- *
- * Return Values: The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero - * error code. The method can take any specific error code value, as specified in [MS-ERREF] section 2.2. The most - * common error codes are listed in the following table.
- *
- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Return value/codeDescription
NERR_Success (0x00000000)The client request succeeded.
ERROR_MORE_DATA (0x000000EA)The client request succeeded. More entries are available. Not all entries could be returned in the buffer size - * that is specified by PreferedMaximumLength.
ERROR_INVALID_LEVEL (0x0000007C)The system call level is not correct.
- * If ServerName does not match any Transport.ServerName in TransportList with the SVTI2_SCOPED_NAME bit set in - * Transport.Flags, the server MUST reset ServerName as "*".
- *
- * The server MUST remove any preceding "\\" from the ServerName parameter and normalize the ServerName parameter as - * specified in section 3.1.6.8, passing in the updated ServerName parameter as the ServerName, and an empty string as - * the ShareName.
- *
- * In response to a NetrShareEnum request, the server MUST enumerate the Share entries in ShareList based on the value - * of the ResumeHandle parameter and query share properties by invoking the underlying server events as specified in - * [MS-CIFS] section 3.3.4.12 or [MS-SMB] section 3.3.4.7, and [MS-SMB2] section 3.3.4.16, providing the tuple - * <normalized server name, Share.ShareName> as the input parameter. When the server receives STATUS_SUCCESS for a - * share, it MUST consider the received SHARE_INFO_503_I and SHARE_INFO_1005 structures as valid. The server MUST return - * information about each shared resource on a server.
- *
- * The InfoStruct parameter has a Level member. The valid values of Level are 0, 1, 2, 501, 502, and 503. If the Level - * member is not equal to one of the valid values, the server MUST fail the call with an ERROR_INVALID_LEVEL error - * code.
- *
- * The server MUST use the shares in valid SHARE_INFO_503_I and SHARE_INFO_1005 structures returned from either CIFS or - * SMB2 server and fill the return structures as follows. For each share, the server MUST discard the structures - * received from other file server except the value of share.shi503_current_uses.
- *
- * If the Level member is 503, the server MUST return all shares in SHARE_INFO_503_I structures. Otherwise, the server - * MUST return the shares in which share.shi503_servername matches ServerName.
- *
- * If the Level member is 0, the server MUST return the information about share resources by filling the - * SHARE_INFO_0_CONTAINER structure in the ShareInfo member of the InfoStruct parameter. The SHARE_INFO_0_CONTAINER - * structure contains an array of SHARE_INFO_0 structures.
- *
- *
    - *
  • shi0_netname MUST be set to share.shi503_netname.
  • - *
- *
- * If the Level member is 1, the server MUST return the information about share resources by filling the - * SHARE_INFO_1_CONTAINER structure in the ShareInfo member of the InfoStruct parameter. The SHARE_INFO_1_CONTAINER - * structure contains an array of SHARE_INFO_1 structures.
- *
- *
    - *
  • shi1_netname MUST be set to share.shi503_netname.
  • - *
  • shi1_type MUST be set to share.shi503_type.
  • - *
  • shi1_remark MUST be set to share.shi503_remark.
  • - *
- *
- * If the Level member is 2, the server MUST return the information about share resources by filling the - * SHARE_INFO_2_CONTAINER structure in the ShareInfo member of the InfoStruct parameter. The SHARE_INFO_2_CONTAINER - * structure contains an array of SHARE_INFO_2 structures.
- *
- *
    - *
  • shi2_netname MUST be set to share.shi503_netname.
  • - *
  • shi2_type MUST be set to share.shi503_type.
  • - *
  • shi2_remark MUST be set to share.shi503_remark.
  • - *
  • shi2_permissions MUST be set to share.shi503_permissions.
  • - *
  • shi2_max_uses MUST be set to share.shi503_max_uses.
  • - *
  • shi2_current_uses MUST be set to the sum of share.shi503_current_uses values retrieved from both CIFS and SMB2 - * servers.
  • - *
  • shi2_path MUST be set to share.shi503_path.
  • - *
  • shi2_passwd MUST be set to share.shi503_passwd.
  • - *
- *
- * If the Level member is 501, the server MUST return the information about share resources by filling the - * SHARE_INFO_501_CONTAINER structure in the ShareInfo member of the InfoStruct parameter. The SHARE_INFO_501_CONTAINER - * structure contains an array of SHARE_INFO_501 structures.
- *
- *
    - *
  • shi501_netname MUST be set to share.shi503_netname.
  • - *
  • shi501_type MUST be set to share.shi503_type.
  • - *
  • shi501_remark MUST be set to share.shi503_remark.
  • - *
  • shi501_flags MUST be set to share.ShareFlags.
  • - *
- *
- * If the Level member is 502, the server MUST return the information about Share resources by filling the - * SHARE_INFO_502_CONTAINER structure in the ShareInfo member of the InfoStruct parameter. The SHARE_INFO_502_CONTAINER - * structure contains an array of SHARE_INFO_502_I structures.
- *
- *
    - *
  • shi502_netname MUST be set to share.shi503_netname.
  • - *
  • shi502_type MUST be set to share.shi503_type.
  • - *
  • shi502_remark MUST be set to share.shi503_remark.
  • - *
  • shi502_permissions MUST be set to share.shi503_permissions.
  • - *
  • shi502_max_uses MUST be set to share.shi503_max_uses.
  • - *
  • shi502_current_uses MUST be set to the sum of share.shi503_current_uses values retrieved from both CIFS and SMB2 - * servers.
  • - *
  • shi502_path MUST be set to share.shi503_path.
  • - *
  • shi502_passwd MUST be set to share.shi503_passwd.
  • - *
  • shi502_security_descriptor MUST be set to share.shi503_security_descriptor
  • - *
- *
- * If the Level member is 503, the server MUST return the information about share resources in the SHARE_INFO_503_I - * structure by filling the SHARE_INFO_503_CONTAINER structure in the ShareInfo member of the InfoStruct parameter, - * except that shi503_current_uses MUST be set to the sum of share.shi503_current_uses values retrieved from both CIFS - * and SMB2 server. The SHARE_INFO_503_CONTAINER structure contains an array of SHARE_INFO_503_I structures.
- *
- * The server MUST set the STYPE_CLUSTER_FS, STYPE_CLUSTER_SOFS, and STYPE_CLUSTER_DFS bits in the shi*_type field to - * zero; the client MUST ignore them on receipt.
- *
- * The PreferedMaximumLength parameter specifies the maximum number of bytes that the server can return for the - * ShareInfo buffer. If PreferedMaximumLength is insufficient to hold all the entries, the server MUST return the - * maximum number of entries that will fit in the ShareInfo buffer and return ERROR_MORE_DATA. If this parameter is - * equal to MAX_PREFERRED_LENGTH (section 2.2.2.2), the server MUST return all the requested data.
- *
- * If the server returns NERR_Success or ERROR_MORE_DATA, it MUST set the TotalEntries parameter to equal the total - * number of entries that could have been enumerated from the current resume position.
- *
- * If PreferedMaximumLength is insufficient to hold all the entries and if the client has specified a ResumeHandle, the - * server MUST set ResumeHandle to some implementation-specific value that allows the server to continue with this - * enumeration on a subsequent call to this method with the same value for ResumeHandle.
- *
- * The server MUST maintain the share list in the order in which shares are inserted into ShareList.
- *
- * The following rules specify processing of the ResumeHandle parameter:
- *
- *
    - *
  • If the ResumeHandle parameter is either NULL or points to 0x00000000, the enumeration MUST start from the - * beginning of the ShareList.
  • - *
  • If the ResumeHandle parameter points to a nonzero value, the server MUST validate the ResumeHandle. - *
      - *
    • If the value of the ResumeHandle is less than the size of the ShareList, the server MUST continue enumeration - * based on the value of ResumeHandle. The value of ResumeHandle specifies the index into the ShareList after which - * enumeration is to begin.
    • - *
    • If the value of the ResumeHandle is greater than or equal to the size of the ShareList, the server MUST return - * NERR_Success and zero entries.
    • - *
    - *
  • - *
  • If the client specified a ResumeHandle and if the server returns ERROR_MORE_DATA (0x000000EA), the server MUST - * set ResumeHandle to the index of the last enumerated share in the ShareList.
  • - *
- *
- * Because the ResumeHandle specifies the index into the ShareList, and the ShareList can be modified between multiple - * requests, the results of a query spanning multiple requests using the ResumeHandle can be unreliable, offering either - * duplicate or unavailable shares.
- *
- * The server SHOULD enforce security measures to verify that the caller has the required permissions to execute this - * routine. If the caller does not have the required credentials, the server SHOULD fail the call. - * - * @see 3.1.4.8 NetrShareEnum (Opnum 15) + * ServerName: An SRVSVC_HANDLE (section 2.2.1.1) pointer that identifies the server. The client MUST map this structure to an RPC binding handle (see [C706] sections 4.3.5 and 5.1.5.2). If this parameter is NULL, the local computer is used. + * InfoStruct: A pointer to a structure, in the format of a SHARE_ENUM_STRUCT (section 2.2.4.38), as specified in section 2.2.4.38. The SHARE_ENUM_STRUCT structure has a Level member that specifies the type of structure to return in the ShareInfo member. The Level member MUST be one of the values specified in section 2.2.4.38. + * PreferedMaximumLength: Specifies the preferred maximum length, in bytes, of the returned data. If the specified value is MAX_PREFERRED_LENGTH, the method MUST attempt to return all entries. + * TotalEntries: The total number of entries that could have been enumerated if the buffer had been big enough to hold all the entries. + * ResumeHandle: A pointer to a value that contains a handle, which is used to continue an existing share search in ShareList. The handle MUST be zero on the first call and remain unchanged for subsequent calls. If the ResumeHandle parameter is NULL, no resume handle MUST be stored. If this parameter is not NULL and the method returns ERROR_MORE_DATA, this parameter receives a nonzero value that can be passed in subsequent calls to this method to continue with the enumeration in ShareList. + * If this parameter is NULL or points to 0x00000000, the enumeration starts from the beginning of the ShareList.
*/ -public class NetrShareEnumRequest extends RequestCall { - /** - * A constant of type DWORD that is set to -1. This value is valid as an input parameter to any method in section - * 3.1.4 that takes a PreferedMaximumLength parameter. When specified as an input parameter, this value indicates - * that the method MUST allocate as much space as the data requires. - */ - public final static int MAX_PREFERRED_LENGTH = -1; - - /** - * Specifies the preferred maximum length, in bytes, of the returned data. If the specified value is - * MAX_PREFERRED_LENGTH, the method MUST attempt to return all entries. - */ - private final static int MAX_BUFFER_SIZE = 1048576; - - /** - * The InfoStruct parameter has a Level member. The valid values of Level are 0, 1, 2, 501, 502, and 503. If the - * Level member is not equal to one of the valid values, the server MUST fail the call with an ERROR_INVALID_LEVEL - * error code. - */ - private final int level; - - /** - * A pointer to a value that contains a handle, which is used to continue an existing share search in ShareList. The - * handle MUST be zero on the first call and remain unchanged for subsequent calls. If the ResumeHandle parameter is - * NULL, no resume handle MUST be stored. If this parameter is not NULL and the method returns ERROR_MORE_DATA, this - * parameter receives a nonzero value that can be passed in subsequent calls to this method to continue with the - * enumeration in ShareList. - */ - private final Integer resumeHandle; +public abstract class NetrShareEnumRequest extends RequestCall> { + // [in, string, unique] SRVSVC_HANDLE ServerName, + // Always use local + // [in, out] LPSHARE_ENUM_STRUCT InfoStruct, + // Implied from ShareEnumLevel + // [in] DWORD PreferedMaximumLength + private final long preferredMaximumLength; + // [in, out, unique] DWORD* ResumeHandle + private final Long resumeHandle; - /** - * The NetrShareEnum method retrieves information about each shared resource on a server. - * - * @param level The InfoStruct parameter has a Level member. The valid values of Level are 0, 1, 2, 501, 502, and - * 503. If the Level member is not equal to one of the valid values, the server MUST fail the call with an - * ERROR_INVALID_LEVEL error code. - * @param resumeHandle A pointer to a value that contains a handle, which is used to continue an existing share - * search in ShareList. The handle MUST be zero on the first call and remain unchanged for subsequent calls. - * If the ResumeHandle parameter is NULL, no resume handle MUST be stored. If this parameter is not NULL and - * the method returns ERROR_MORE_DATA, this parameter receives a nonzero value that can be passed in - * subsequent calls to this method to continue with the enumeration in ShareList. - */ - public NetrShareEnumRequest(final int level, final Integer resumeHandle) { + public NetrShareEnumRequest(final long preferredMaximumLength, final Long resumeHandle) { super(NetrOpCode.NetrShareEnum.getOpCode()); - this.level = level; + this.preferredMaximumLength = preferredMaximumLength; this.resumeHandle = resumeHandle; } + public abstract ShareEnumLevel getShareEnumLevel(); + @Override - public NetrShareEnumResponse getResponseObject() { - return new NetrShareEnumResponse(); + public void marshal(PacketOutput packetOut) throws IOException { + // [in, string, unique] SRVSVC_HANDLE ServerName, + packetOut.writeNull(); + // [in, out] LPSHARE_ENUM_STRUCT InfoStruct + // DWORD Level + // Alignment: 4 - Already aligned + packetOut.writeInt(getShareEnumLevel().getInfoLevel()); + // [switch_is(Level)] SHARE_ENUM_UNION ShareInfo; + // Alignment: 4 - Already aligned + packetOut.writeInt(getShareEnumLevel().getInfoLevel()); + // [switch_is(Level)] SHARE_ENUM_UNION ShareInfo; + // Alignment: 4 - Already aligned + packetOut.writeReferentID(); + // SHARE_INFO_*_CONTAINER + // Entries: 0 + // Alignment: 4 - Already aligned + packetOut.writeInt(0); + // SHARE_INFO_*_CONTAINER + // No buffer + // Alignment: 4 - Already aligned + packetOut.writeNull(); + // [in] DWORD PreferedMaximumLength + // Alignment: 4 - Already aligned + packetOut.writeInt(this.preferredMaximumLength); + // [in, out, unique] DWORD* ResumeHandle + // Alignment: 4 - Already aligned + if (resumeHandle != null) { + packetOut.writeReferentID(); + // [in, out, unique] DWORD* ResumeHandle + // Alignment: 4 - Already aligned + packetOut.writeInt(this.resumeHandle); + } else { + packetOut.writeNull(); + } } - @Override - public void marshal(final PacketOutput stubOut) throws IOException { - stubOut.writeNull(); - stubOut.writeInt(level); - stubOut.writeInt(level); - stubOut.writeReferentID(); - stubOut.writeInt(0); - stubOut.writeNull(); - stubOut.writeInt(MAX_BUFFER_SIZE); - stubOut.writeIntRef(resumeHandle); + public static class NetShareEnumRequest0 extends NetrShareEnumRequest { + public NetShareEnumRequest0(final long preferredMaximumLength, final Long resumeHandle) { + super(preferredMaximumLength, resumeHandle); + } + + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_0_CONTAINER; + } + + @Override + public NetrShareEnumResponse getResponseObject() { + return new NetrShareEnumResponse.NetShareEnumResponse0(); + } + } + + public static class NetShareEnumRequest1 extends NetrShareEnumRequest { + public NetShareEnumRequest1(final long preferredMaximumLength, final Long resumeHandle) { + super(preferredMaximumLength, resumeHandle); + } + + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_1_CONTAINER; + } + + @Override + public NetrShareEnumResponse getResponseObject() { + return new NetrShareEnumResponse.NetShareEnumResponse1(); + } + } + + public static class NetShareEnumRequest2 extends NetrShareEnumRequest { + public NetShareEnumRequest2(final long preferredMaximumLength, final Long resumeHandle) { + super(preferredMaximumLength, resumeHandle); + } + + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_2_CONTAINER; + } + + @Override + public NetrShareEnumResponse getResponseObject() { + return new NetrShareEnumResponse.NetShareEnumResponse2(); + } + } + + public static class NetShareEnumRequest501 extends NetrShareEnumRequest { + public NetShareEnumRequest501(final long preferredMaximumLength, final Long resumeHandle) { + super(preferredMaximumLength, resumeHandle); + } + + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_501_CONTAINER; + } + + @Override + public NetrShareEnumResponse getResponseObject() { + return new NetrShareEnumResponse.NetShareEnumResponse501(); + } + } + + public static class NetShareEnumRequest502 extends NetrShareEnumRequest { + public NetShareEnumRequest502(final long preferredMaximumLength, final Long resumeHandle) { + super(preferredMaximumLength, resumeHandle); + } + + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_502_CONTAINER; + } + + @Override + public NetrShareEnumResponse getResponseObject() { + return new NetrShareEnumResponse.NetShareEnumResponse502(); + } + } + + public static class NetShareEnumRequest503 extends NetrShareEnumRequest { + public NetShareEnumRequest503(final long preferredMaximumLength, final Long resumeHandle) { + super(preferredMaximumLength, resumeHandle); + } + + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_503_CONTAINER; + } + + @Override + public NetrShareEnumResponse getResponseObject() { + return new NetrShareEnumResponse.NetShareEnumResponse503(); + } } } diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumResponse.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumResponse.java index aab7e509..dd20ece3 100644 --- a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumResponse.java +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareEnumResponse.java @@ -1,192 +1,141 @@ -/** +/* * Copyright 2017, Rapid7, Inc. * * License: BSD-3-clause * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, + * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - * * Redistributions in binary form must reproduce the above copyright + * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of the copyright holder nor the names of its contributors + * Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. + * + * */ + package com.rapid7.client.dcerpc.mssrvs.messages; import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import com.hierynomus.protocol.transport.TransportException; import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; import com.rapid7.client.dcerpc.messages.RequestResponse; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareEnumLevel; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareEnumStruct; -/** - *
- * Example:
- * - *
- * Server Service, NetShareEnumAll
- *     Operation: NetShareEnumAll (15)
- *     [Request in frame: 17]
- *     Pointer to Level (uint32)
- *         Level: 1
- *     Pointer to Ctr (srvsvc_NetShareCtr)
- *         srvsvc_NetShareCtr
- *             Ctr
- *             Pointer to Ctr1 (srvsvc_NetShareCtr1)
- *                 Referent ID: 0x00020000
- *                 Ctr1
- *                     Count: 3
- *                     Pointer to Array (srvsvc_NetShareInfo1)
- *                         Referent ID: 0x00020004
- *                         Max Count: 3
- *                         Array
- *                             Pointer to Name (uint16)
- *                                 Referent ID: 0x00020008
- *                                 Max Count: 7
- *                                 Offset: 0
- *                                 Actual Count: 7
- *                                 Name: ADMIN$
- *                             Type: STYPE_DISKTREE_HIDDEN (2147483648)
- *                             Pointer to Comment (uint16)
- *                                 Referent ID: 0x0002000c
- *                                 Max Count: 13
- *                                 Offset: 0
- *                                 Actual Count: 13
- *                                 Comment: Remote Admin
- *                         Array
- *                             Pointer to Name (uint16)
- *                                 Referent ID: 0x00020010
- *                                 Max Count: 3
- *                                 Offset: 0
- *                                 Actual Count: 3
- *                                 Name: C$
- *                             Type: STYPE_DISKTREE_HIDDEN (2147483648)
- *                             Pointer to Comment (uint16)
- *                                 Referent ID: 0x00020014
- *                                 Max Count: 14
- *                                 Offset: 0
- *                                 Actual Count: 14
- *                                 Comment: Default share
- *                         Array
- *                             Pointer to Name (uint16)
- *                                 Referent ID: 0x00020018
- *                                 Max Count: 5
- *                                 Offset: 0
- *                                 Actual Count: 5
- *                                 Name: IPC$
- *                             Type: STYPE_IPC_HIDDEN (2147483651)
- *                             Pointer to Comment (uint16)
- *                                 Referent ID: 0x0002001c
- *                                 Max Count: 11
- *                                 Offset: 0
- *                                 Actual Count: 11
- *                                 Comment: Remote IPC
- *     Pointer to Totalentries (uint32)
- *         Totalentries: 3
- *     NULL Pointer: Pointer to Resume Handle (uint32)
- *     Windows Error: WERR_OK (0x00000000)
- * 
- */ -public class NetrShareEnumResponse extends RequestResponse { - private int level; - private List shares; - private int shareCount; - private Integer resumeHandle; - - public int getLevel() { - return level; - } +public abstract class NetrShareEnumResponse extends RequestResponse { + private T shareEnumStruct; + private long totalEntries; + private Long resumeHandle; + + public abstract ShareEnumLevel getShareEnumLevel(); - public List getShares() { - return shares; + public T getShareEnumStruct() { + return shareEnumStruct; } - public int getShareCount() { - return shareCount; + public long getTotalEntries() { + return totalEntries; } - public Integer getResumeHandle() { + public Long getResumeHandle() { return resumeHandle; } + abstract T createShareEnumStruct(); + @Override - public void unmarshalResponse(final PacketInput packetIn) throws IOException { - shares = new LinkedList<>(); - level = packetIn.readInt(); - packetIn.readInt(); - - switch (level) { - case 1: - if (0 != packetIn.readReferentID()) { - final int count = packetIn.readInt(); - if (0 != packetIn.readReferentID()) { - final List nameRefs = new LinkedList<>(); - final List types = new LinkedList<>(); - final List commentRefs = new LinkedList<>(); - packetIn.readInt(); // Maximum count - for (int index = 0; index < count; index++) { - nameRefs.add(packetIn.readReferentID()); - types.add(packetIn.readInt()); - commentRefs.add(packetIn.readReferentID()); - } - for (int index = 0; index < count; index++) { - final String name = nameRefs.get(index) == 0 ? null : packetIn.readString(true); - final int type = types.get(index); - final String comment = commentRefs.get(index) == 0 ? null : packetIn.readString(true); - shares.add(new NetShareInfo1(name, type, comment)); - } - } - } - break; - case 2: - if (0 != packetIn.readReferentID()) { - final int count = packetIn.readInt(); - if (0 != packetIn.readReferentID()) { - final List nameRefs = new LinkedList<>(); - final List types = new LinkedList<>(); - final List commentRefs = new LinkedList<>(); - final List permissions = new LinkedList<>(); - final List maximumUsers = new LinkedList<>(); - final List currentUsers = new LinkedList<>(); - final List pathRefs = new LinkedList<>(); - final List passwordRefs = new LinkedList<>(); - packetIn.readInt(); // Maximum count - for (int index = 0; index < count; index++) { - nameRefs.add(packetIn.readReferentID()); - types.add(packetIn.readInt()); - commentRefs.add(packetIn.readReferentID()); - permissions.add(packetIn.readInt()); - maximumUsers.add(packetIn.readInt()); - currentUsers.add(packetIn.readInt()); - pathRefs.add(packetIn.readReferentID()); - passwordRefs.add(packetIn.readReferentID()); - } - for (int index = 0; index < count; index++) { - final String name = nameRefs.get(index) == 0 ? null : packetIn.readString(true); - final int type = types.get(index); - final String comment = commentRefs.get(index) == 0 ? null : packetIn.readString(true); - final int permission = permissions.get(index); - final int maximumUser = maximumUsers.get(index); - final int currentUser = currentUsers.get(index); - final String path = pathRefs.get(index) == 0 ? null : packetIn.readString(true); - final String password = passwordRefs.get(index) == 0 ? null : packetIn.readString(true); - final NetShareInfo2 shareInfo = new NetShareInfo2(name, type, comment, permission, maximumUser, currentUser, path, password); - shares.add(shareInfo); - } - } - } - break; - default: - throw new TransportException("Unsupported share info container."); + public void unmarshalResponse(PacketInput packetIn) throws IOException { + this.shareEnumStruct = createShareEnumStruct(); + // [in, out] LPSHARE_ENUM_STRUCT InfoStruct + packetIn.readUnmarshallable(this.shareEnumStruct); + // [out] DWORD* TotalEntries + packetIn.align(Alignment.FOUR); + this.totalEntries = packetIn.readUnsignedInt(); + // [in, out, unique] DWORD* ResumeHandle + // Alignment: 4 - Already aligned + if (packetIn.readReferentID() != 0) + // [in, out, unique] DWORD* ResumeHandle + // Alignment: 4 - Already aligned + this.resumeHandle = packetIn.readUnsignedInt(); + else + this.resumeHandle = null; + } + + public static class NetShareEnumResponse0 extends NetrShareEnumResponse { + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_0_CONTAINER; + } + + @Override + ShareEnumStruct.ShareEnumStruct0 createShareEnumStruct() { + return new ShareEnumStruct.ShareEnumStruct0(); + } + } + + public static class NetShareEnumResponse1 extends NetrShareEnumResponse { + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_1_CONTAINER; + } + + @Override + ShareEnumStruct.ShareEnumStruct1 createShareEnumStruct() { + return new ShareEnumStruct.ShareEnumStruct1(); + } + } + + public static class NetShareEnumResponse2 extends NetrShareEnumResponse { + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_1_CONTAINER; + } + + @Override + ShareEnumStruct.ShareEnumStruct2 createShareEnumStruct() { + return new ShareEnumStruct.ShareEnumStruct2(); + } + } + + public static class NetShareEnumResponse501 extends NetrShareEnumResponse { + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_501_CONTAINER; + } + + @Override + ShareEnumStruct.ShareEnumStruct501 createShareEnumStruct() { + return new ShareEnumStruct.ShareEnumStruct501(); + } + } + + public static class NetShareEnumResponse502 extends NetrShareEnumResponse { + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_502_CONTAINER; } - shareCount = packetIn.readInt(); - resumeHandle = packetIn.readIntRef(); + @Override + ShareEnumStruct.ShareEnumStruct502 createShareEnumStruct() { + return new ShareEnumStruct.ShareEnumStruct502(); + } + } + + public static class NetShareEnumResponse503 extends NetrShareEnumResponse { + @Override + public ShareEnumLevel getShareEnumLevel() { + return ShareEnumLevel.SHARE_INFO_503_CONTAINER; + } + + @Override + ShareEnumStruct.ShareEnumStruct503 createShareEnumStruct() { + return new ShareEnumStruct.ShareEnumStruct503(); + } } } diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareGetInfoRequest.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareGetInfoRequest.java new file mode 100644 index 00000000..60d43676 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareGetInfoRequest.java @@ -0,0 +1,188 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.messages; + +import java.io.IOException; +import com.rapid7.client.dcerpc.io.PacketOutput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; +import com.rapid7.client.dcerpc.messages.RequestCall; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo0; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo1; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo2; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo501; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo502; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo503; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfoLevel; +import com.rapid7.client.dcerpc.objects.WChar; + +/** + * NetrShareGetInfo + *
The NetrShareGetInfo method retrieves information about a particular shared resource on the server from the ShareList.
+ *
+ *      NET_API_STATUS NetrShareGetInfo(
+ *          [in, string, unique] SRVSVC_HANDLE ServerName,
+ *          [in, string] WCHAR* NetName,
+ *          [in] DWORD Level,
+ *          [out, switch_is(Level)] LPSHARE_INFO InfoStruct
+ *      );
+ *
+ *  ServerName: An SRVSVC_HANDLE (section 2.2.1.1) pointer that identifies the server. The client MUST map this structure to an RPC binding handle ([C706] sections 4.3.5 and 5.1.5.2). If this parameter is NULL, the local computer is used.
+ *  NetName: A pointer to a null-terminated UTF-16 string that specifies the name of the share to return information for.
+ *  Level: Specifies the information level of the data. This parameter MUST be one of the following values.
+ *      0       LPSHARE_INFO_0
+ *      1       LPSHARE_INFO_1
+ *      2       LPSHARE_INFO_2
+ *      501     LPSHARE_INFO_501
+ *      502     LPSHARE_INFO_502_I
+ *      503     LPSHARE_INFO_503_I
+ *      1005    LPSHARE_INFO_1005
+ *  InfoStruct: This parameter is of type LPSHARE_INFO union, as specified in section 2.2.3.6. Its contents are determined by the value of the Level parameter, as shown in the preceding table.
+ */ +public abstract class NetrShareGetInfoRequest extends RequestCall> { + public static final short OP_NUM = 16; + + // [in, string, unique] SRVSVC_HANDLE ServerName + // Always use local + // [in, string] WCHAR* NetName + private final WChar.NullTerminated shareName; + // [in] DWORD Level + // This is dervied from getShareInfoLevel() + + public NetrShareGetInfoRequest(final WChar.NullTerminated shareName) { + super(OP_NUM); + if (shareName == null) + throw new IllegalArgumentException("Despite what the documentation states, this is not a pointer"); + this.shareName = shareName; + } + + public abstract ShareInfoLevel getShareInfoLevel(); + + @Override + public void marshal(PacketOutput packetOut) throws IOException { + // [in, string, unique] SRVSVC_HANDLE ServerName + // Always use local + packetOut.writeNull(); + // [in, string] WCHAR* NetName + // Despite what the documentation states, this is not a pointer + packetOut.writeMarshallable(this.shareName); + // [in] DWORD Level + packetOut.align(Alignment.FOUR); + packetOut.writeInt(getShareInfoLevel().getInfoLevel()); + } + + public static class NetrShareGetInfoRequest0 extends NetrShareGetInfoRequest { + public NetrShareGetInfoRequest0(WChar.NullTerminated shareName) { + super(shareName); + } + + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_0; + } + + @Override + public NetrShareGetInfoResponse.NetrShareGetInfoResponse0 getResponseObject() { + return new NetrShareGetInfoResponse.NetrShareGetInfoResponse0(); + } + } + + public static class NetrShareGetInfoRequest1 extends NetrShareGetInfoRequest { + public NetrShareGetInfoRequest1(WChar.NullTerminated shareName) { + super(shareName); + } + + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_1; + } + + @Override + public NetrShareGetInfoResponse.NetrShareGetInfoResponse1 getResponseObject() { + return new NetrShareGetInfoResponse.NetrShareGetInfoResponse1(); + } + } + + public static class NetrShareGetInfoRequest2 extends NetrShareGetInfoRequest { + public NetrShareGetInfoRequest2(WChar.NullTerminated shareName) { + super(shareName); + } + + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_2; + } + + @Override + public NetrShareGetInfoResponse.NetrShareGetInfoResponse2 getResponseObject() { + return new NetrShareGetInfoResponse.NetrShareGetInfoResponse2(); + } + } + + public static class NetrShareGetInfoRequest501 extends NetrShareGetInfoRequest { + public NetrShareGetInfoRequest501(WChar.NullTerminated shareName) { + super(shareName); + } + + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_501; + } + + @Override + public NetrShareGetInfoResponse.NetrShareGetInfoResponse501 getResponseObject() { + return new NetrShareGetInfoResponse.NetrShareGetInfoResponse501(); + } + } + + public static class NetrShareGetInfoRequest502 extends NetrShareGetInfoRequest { + public NetrShareGetInfoRequest502(WChar.NullTerminated shareName) { + super(shareName); + } + + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_502; + } + + @Override + public NetrShareGetInfoResponse.NetrShareGetInfoResponse502 getResponseObject() { + return new NetrShareGetInfoResponse.NetrShareGetInfoResponse502(); + } + } + + public static class NetrShareGetInfoRequest503 extends NetrShareGetInfoRequest { + public NetrShareGetInfoRequest503(WChar.NullTerminated shareName) { + super(shareName); + } + + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_503; + } + + @Override + public NetrShareGetInfoResponse.NetrShareGetInfoResponse503 getResponseObject() { + return new NetrShareGetInfoResponse.NetrShareGetInfoResponse503(); + } + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareGetInfoResponse.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareGetInfoResponse.java new file mode 100644 index 00000000..24eac5a4 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/messages/NetrShareGetInfoResponse.java @@ -0,0 +1,140 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.messages; + +import java.io.IOException; +import java.rmi.UnmarshalException; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.messages.RequestResponse; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo0; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo1; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo2; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo501; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo502; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo503; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfoLevel; + +/** + * NetrShareGetInfo + */ +public abstract class NetrShareGetInfoResponse extends RequestResponse { + + private T shareInfo; + + public T getShareInfo() { + return this.shareInfo; + } + + public abstract ShareInfoLevel getShareInfoLevel(); + + abstract T createShareInfo(); + + @Override + public void unmarshalResponse(PacketInput packetIn) throws IOException { + // [out, switch_is(Level)] LPSHARE_INFO InfoStruct + final int infoLevel = packetIn.readInt(); + if (infoLevel != getShareInfoLevel().getInfoLevel()) { + throw new UnmarshalException(String.format( + "Incoming LPSHARE_INFO level %d does not match expected: %d", + infoLevel, getShareInfoLevel().getInfoLevel())); + } + if (packetIn.readReferentID() != 0) { + this.shareInfo = createShareInfo(); + packetIn.readUnmarshallable(this.shareInfo); + } else { + this.shareInfo = null; + } + } + + public static class NetrShareGetInfoResponse0 extends NetrShareGetInfoResponse { + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_0; + } + + @Override + ShareInfo0 createShareInfo() { + return new ShareInfo0(); + } + } + + public static class NetrShareGetInfoResponse1 extends NetrShareGetInfoResponse { + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_1; + } + + @Override + ShareInfo1 createShareInfo() { + return new ShareInfo1(); + } + } + + public static class NetrShareGetInfoResponse2 extends NetrShareGetInfoResponse { + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_2; + } + + @Override + ShareInfo2 createShareInfo() { + return new ShareInfo2(); + } + } + + public static class NetrShareGetInfoResponse501 extends NetrShareGetInfoResponse { + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_501; + } + + @Override + ShareInfo501 createShareInfo() { + return new ShareInfo501(); + } + } + + public static class NetrShareGetInfoResponse502 extends NetrShareGetInfoResponse { + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_502; + } + + @Override + ShareInfo502 createShareInfo() { + return new ShareInfo502(); + } + } + + public static class NetrShareGetInfoResponse503 extends NetrShareGetInfoResponse { + @Override + public ShareInfoLevel getShareInfoLevel() { + return ShareInfoLevel.LPSHARE_INFO_503; + } + + @Override + ShareInfo503 createShareInfo() { + return new ShareInfo503(); + } + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareEnumLevel.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareEnumLevel.java new file mode 100644 index 00000000..8e8dd382 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareEnumLevel.java @@ -0,0 +1,44 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +/** + * SHARE_ENUM_UNION + */ +public enum ShareEnumLevel { + SHARE_INFO_0_CONTAINER(0), + SHARE_INFO_1_CONTAINER(1), + SHARE_INFO_2_CONTAINER(2), + SHARE_INFO_501_CONTAINER(501), + SHARE_INFO_502_CONTAINER(502), + SHARE_INFO_503_CONTAINER(503); + + private final int infoLevel; + + ShareEnumLevel(final int infoLevel) { + this.infoLevel = infoLevel; + } + + public int getInfoLevel() { + return infoLevel; + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareEnumStruct.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareEnumStruct.java new file mode 100644 index 00000000..1888df26 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareEnumStruct.java @@ -0,0 +1,173 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.rmi.UnmarshalException; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; +import com.rapid7.client.dcerpc.io.ndr.Unmarshallable; + +/** + * Alignment: 4 + * SHARE_ENUM_STRUCT + * This class also encompasses SHARE_ENUM_UNION, as + * that class adds no real value as its own entity. + *
The SHARE_ENUM_STRUCT structure specifies the information level that the client requests in the NetrShareEnum method and encapsulates the SHARE_ENUM_UNION union that receives the entries enumerated by the server.
+ *
+ *      typedef struct _SHARE_ENUM_STRUCT {
+ *          DWORD Level;
+ *          [switch_is(Level)] SHARE_ENUM_UNION ShareInfo;
+ *      } SHARE_ENUM_STRUCT,
+ *      *PSHARE_ENUM_STRUCT,
+ *      *LPSHARE_ENUM_STRUCT;
+ *
+ * Level: Specifies the information level of the data. This parameter MUST have one of the following values.
+ *      0       SHARE_INFO_0_CONTAINER
+ *      1       SHARE_INFO_1_CONTAINER
+ *      2       SHARE_INFO_2_CONTAINER
+ *      501     SHARE_INFO_501_CONTAINER
+ *      502     SHARE_INFO_502_CONTAINER
+ *      503     SHARE_INFO_503_CONTAINER
+ */ +public abstract class ShareEnumStruct implements Unmarshallable { + + private T shareInfoContainer; + + public abstract ShareEnumLevel getLevel(); + + public T getShareInfoContainer() { + return shareInfoContainer; + } + + abstract T createShareInfoContainer(); + + @Override + public void unmarshalPreamble(PacketInput in) throws IOException { + // No preamble + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + // Structure alignment: 4 + in.align(Alignment.FOUR); + // DWORD Level; + // Alignment: 4 - Already aligned + final int level = in.readInt(); + if (level != getLevel().getInfoLevel()) { + throw new UnmarshalException(String.format( + "Expected info level %d, got: %d", getLevel().getInfoLevel(), level)); + } + // [switch_is(Level)] + // Alignment: 4 - Already aligned + final int enumLevel = in.readInt(); + if (enumLevel != level) { + throw new UnmarshalException(String.format( + "Expected info level %d to match enum level, got: %d", level, enumLevel)); + } + // [switch_is(Level)] SHARE_ENUM_UNION ShareInfo; + // Alignment: 4 - Already aligned + if (in.readReferentID() != 0) + this.shareInfoContainer = createShareInfoContainer(); + else + this.shareInfoContainer = null; + } + + @Override + public void unmarshalDeferrals(PacketInput in) throws IOException { + if (getShareInfoContainer() != null) { + in.readUnmarshallable(getShareInfoContainer()); + } + } + + public static class ShareEnumStruct0 extends ShareEnumStruct { + @Override + public ShareEnumLevel getLevel() { + return ShareEnumLevel.SHARE_INFO_0_CONTAINER; + } + + @Override + ShareInfoContainer.ShareInfo0Container createShareInfoContainer() { + return new ShareInfoContainer.ShareInfo0Container(); + } + } + + public static class ShareEnumStruct1 extends ShareEnumStruct { + @Override + public ShareEnumLevel getLevel() { + return ShareEnumLevel.SHARE_INFO_1_CONTAINER; + } + + @Override + ShareInfoContainer.ShareInfo1Container createShareInfoContainer() { + return new ShareInfoContainer.ShareInfo1Container(); + } + } + + public static class ShareEnumStruct2 extends ShareEnumStruct { + @Override + public ShareEnumLevel getLevel() { + return ShareEnumLevel.SHARE_INFO_2_CONTAINER; + } + + @Override + ShareInfoContainer.ShareInfo2Container createShareInfoContainer() { + return new ShareInfoContainer.ShareInfo2Container(); + } + } + + public static class ShareEnumStruct501 extends ShareEnumStruct { + @Override + public ShareEnumLevel getLevel() { + return ShareEnumLevel.SHARE_INFO_501_CONTAINER; + } + + @Override + ShareInfoContainer.ShareInfo501Container createShareInfoContainer() { + return new ShareInfoContainer.ShareInfo501Container(); + } + } + + public static class ShareEnumStruct502 extends ShareEnumStruct { + @Override + public ShareEnumLevel getLevel() { + return ShareEnumLevel.SHARE_INFO_502_CONTAINER; + } + + @Override + ShareInfoContainer.ShareInfo502Container createShareInfoContainer() { + return new ShareInfoContainer.ShareInfo502Container(); + } + } + + public static class ShareEnumStruct503 extends ShareEnumStruct { + @Override + public ShareEnumLevel getLevel() { + return ShareEnumLevel.SHARE_INFO_503_CONTAINER; + } + + @Override + ShareInfoContainer.ShareInfo503Container createShareInfoContainer() { + return new ShareInfoContainer.ShareInfo503Container(); + } + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo.java new file mode 100644 index 00000000..62120920 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo.java @@ -0,0 +1,82 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.util.Objects; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; +import com.rapid7.client.dcerpc.io.ndr.Unmarshallable; +import com.rapid7.client.dcerpc.objects.WChar; + +public class ShareInfo implements Unmarshallable { + // wchar_t* shi0_netname; + private WChar.NullTerminated netName; + + public WChar.NullTerminated getNetName() { + return this.netName; + } + + public void setNetName(final WChar.NullTerminated netName) { + this.netName = netName; + } + + @Override + public void unmarshalPreamble(PacketInput in) throws IOException { + //No preamble + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + // Structure Alignment: 4 + // NOTE: It is assumed that all ShareInfo instances have the same alignment + in.align(Alignment.FOUR); + // wchar_t* shi0_netname; + // Alignment: 4 - Already aligned + if (in.readReferentID() != 0) + this.netName = new WChar.NullTerminated(); + else + this.netName = null; + } + + @Override + public void unmarshalDeferrals(PacketInput in) throws IOException { + if (this.netName != null) + in.readUnmarshallable(this.netName); + } + + @Override + public int hashCode() { + return Objects.hash(this.netName); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof ShareInfo)) { + return false; + } + final ShareInfo other = (ShareInfo) obj; + return Objects.equals(this.netName, other.netName); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo0.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo0.java new file mode 100644 index 00000000..68c39c41 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo0.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +/** + * Alignment: 4 + * SHARE_INFO_0 + *
The SHARE_INFO_0 structure contains the name of the shared resource. For a description of the fields in this structure, see the description for the SHARE_INFO_502_I (section 2.2.4.26) structure (shi0_xxx denotes the same information as shi502_xxx).
+ *
+ *      typedef struct _SHARE_INFO_0 {
+ *          [string] wchar_t* shi0_netname;
+ *      } SHARE_INFO_0,
+ *      *PSHARE_INFO_0,
+ *      LPSHARE_INFO_0;
+ */ +public class ShareInfo0 extends ShareInfo { + @Override + public String toString() { + return String.format("SHARE_INFO_0{shi0_netname: %s}", getNetName()); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo1.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo1.java new file mode 100644 index 00000000..993e85f0 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo1.java @@ -0,0 +1,110 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.util.Objects; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; +import com.rapid7.client.dcerpc.io.ndr.Unmarshallable; +import com.rapid7.client.dcerpc.objects.WChar; + +/** + * Alignment: 4 + * SHARE_INFO_1 + *
The SHARE_INFO_1 structure contains information about the shared resource, including the name and type of the resource and a comment associated with the resource. For a description of the fields in this structure, see the description for the SHARE_INFO_502_I (section 2.2.4.26) structure (shi1_xxx denotes the same information as shi502_xxx).
+ *
+ *      typedef struct _SHARE_INFO_1 {
+ *          [string] wchar_t* shi1_netname;
+ *          DWORD shi1_type;
+ *          [string] wchar_t* shi1_remark;
+ *      } SHARE_INFO_1,
+ *      *PSHARE_INFO_1,
+ *      *LPSHARE_INFO_1;
+ */ +public class ShareInfo1 extends ShareInfo0 { + // DWORD shi1_type; + private int type; + // wchar_t* shi1_remark; + private WChar.NullTerminated remark; + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public WChar.NullTerminated getRemark() { + return this.remark; + } + + public void setRemark(final WChar.NullTerminated remark) { + this.remark = remark; + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + super.unmarshalEntity(in); + // DWORD shi1_type; + // Alignment: 4 - Already aligned + this.type = (int) in.readUnsignedInt(); // We don't expect this to require an unsigned int + // wchar_t* shi1_remark; + // Alignment: 4 - Already aligned + if (in.readReferentID() != 0) + this.remark = new WChar.NullTerminated(); + else + this.remark = null; + } + + @Override + public void unmarshalDeferrals(PacketInput in) throws IOException { + super.unmarshalDeferrals(in); + if (this.remark != null) + in.readUnmarshallable(this.remark); + } + + @Override + public int hashCode() { + return (super.hashCode() * 31) + Objects.hash(getType(), getRemark()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof ShareInfo1)) { + return false; + } + final ShareInfo1 other = (ShareInfo1) obj; + return super.equals(obj) + && this.type == other.type + && Objects.equals(getRemark(), other.getRemark()); + } + + @Override + public String toString() { + return String.format("SHARE_INFO_1{shi1_netname: %s, shi1_type: %d, shi1_remark: %s}", + getNetName(), getType(), getRemark()); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo2.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo2.java new file mode 100644 index 00000000..f333da25 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo2.java @@ -0,0 +1,165 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.util.Objects; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; +import com.rapid7.client.dcerpc.io.ndr.Unmarshallable; +import com.rapid7.client.dcerpc.objects.WChar; + +/** + * Alignment: 4 + * SHARE_INFO_1 + *
The SHARE_INFO_2 structure contains information about the shared resource, including the name, type, and permissions of the resource, comments associated with the resource, the maximum number of concurrent connections, the number of current connections, the local path for the resource, and a password for the current connection. For a description of the fields in this structure, see the description for the SHARE_INFO_502_I (section 2.2.4.26) structure (shi2_xxx denotes the same information as shi502_xxx).
+ *
+ *      typedef struct _SHARE_INFO_2 {
+ *          [string] wchar_t* shi2_netname;
+ *          DWORD shi2_type;
+ *          [string] wchar_t* shi2_remark;
+ *          DWORD shi2_permissions;
+ *          DWORD shi2_max_uses;
+ *          DWORD shi2_current_uses;
+ *          [string] wchar_t* shi2_path;
+ *          [string] wchar_t* shi2_passwd;
+ *      } SHARE_INFO_2,
+ *      *PSHARE_INFO_2,
+ *      *LPSHARE_INFO_2;
+ */ +public class ShareInfo2 extends ShareInfo1 { + // DWORD shi2_permissions; + private int permissions; + // DWORD shi2_max_uses; + private int maxUses; + // DWORD shi2_current_uses; + private int currentUses; + // wchar_t* shi2_path; + private WChar.NullTerminated path; + // wchar_t* shi2_passwd; + private WChar.NullTerminated passwd; + + public int getPermissions() { + return permissions; + } + + public void setPermissions(final int permissions) { + this.permissions = permissions; + } + + public int getMaxUses() { + return maxUses; + } + + public void setMaxUses(final int maxUses) { + this.maxUses = maxUses; + } + + public int getCurrentUses() { + return currentUses; + } + + public void setCurrentUses(final int currentUses) { + this.currentUses = currentUses; + } + + public WChar.NullTerminated getPath() { + return this.path; + } + + public void setPath(final WChar.NullTerminated path) { + this.path = path; + } + + public WChar.NullTerminated getPasswd() { + return this.passwd; + } + + public void setPasswd(final WChar.NullTerminated passwd) { + this.passwd = passwd; + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + super.unmarshalEntity(in); + // DWORD shi2_permissions; + // Alignment: 4 - Already aligned + this.permissions = in.readInt(); + // DWORD shi2_max_uses; + // Alignment: 4 - Already aligned + this.maxUses = in.readInt(); + // DWORD shi2_current_uses; + // Alignment: 4 - Already aligned + this.currentUses = in.readInt(); + // wchar_t* shi2_path; + // Alignment: 4 - Already aligned + if (in.readReferentID() != 0) + this.path = new WChar.NullTerminated(); + else + this.path = null; + // wchar_t* shi2_passwd; + // Alignment: 4 - Already aligned + if (in.readReferentID() != 0) + this.passwd = new WChar.NullTerminated(); + else + this.passwd = null; + } + + @Override + public void unmarshalDeferrals(PacketInput in) throws IOException { + super.unmarshalDeferrals(in); + if (this.path != null) + in.readUnmarshallable(this.path); + if (this.passwd != null) + in.readUnmarshallable(this.passwd); + } + + @Override + public int hashCode() { + return (super.hashCode() * 31) + Objects.hash(getPermissions(), getMaxUses(), + getCurrentUses(), getPath(), getPasswd()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof ShareInfo2)) { + return false; + } + final ShareInfo2 other = (ShareInfo2) obj; + return super.equals(obj) + && getPermissions() == other.getPermissions() + && getMaxUses() == other.getMaxUses() + && getCurrentUses() == other.getCurrentUses() + && Objects.equals(getPath(), other.getPath()) + && Objects.equals(getPasswd(), other.getPasswd()); + } + + @Override + public String toString() { + return String.format("SHARE_INFO_2{shi2_netname: %s, shi2_type: %d, shi2_remark: %s, shi2_permissions: %d, " + + "shi2_max_uses: %d, shi2_current_uses: %d, shi2_path: %s, shi2_passwd: %s}", + getNetName(), getType(), getRemark(), getPermissions(), getMaxUses(), + getCurrentUses(), getPath(), getPasswd()); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo501.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo501.java new file mode 100644 index 00000000..725b3c68 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo501.java @@ -0,0 +1,84 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.util.Objects; +import com.rapid7.client.dcerpc.io.PacketInput; + +/** + * Alignment: 4 + * SHARE_INFO_501 + *
The SHARE_INFO_501 structure contains information about the shared resource, including the name and type of the resource and a comment that is associated with the resource. For a description of the fields in this structure, see the description for the SHARE_INFO_502_I (section 2.2.4.26) structure (shi501_netname, shi501_type, and shi501_remark denote the same information as shi502_xxx in section 2.2.4.26, and shi501_flags denotes the same information as shi1005_flags in section 2.2.4.29).
+ *
+ *      typedef struct _SHARE_INFO_501 {
+ *          [string] wchar_t* shi501_netname;
+ *          DWORD shi501_type;
+ *          [string] wchar_t* shi501_remark;
+ *          DWORD shi501_flags;
+ *      } SHARE_INFO_501,
+ *      *PSHARE_INFO_501,
+ *      *LPSHARE_INFO_501;
+ */ +public class ShareInfo501 extends ShareInfo1 { + // DWORD shi501_flags; + private int flags; + + public int getFlags() { + return flags; + } + + public void setFlags(int flags) { + this.flags = flags; + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + super.unmarshalEntity(in); + // DWORD shi501_flags; + // Alignment: 4 - Already aligned + this.flags = in.readInt(); + } + + @Override + public int hashCode() { + return (super.hashCode() * 31) + Objects.hash(getFlags()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof ShareInfo501)) { + return false; + } + final ShareInfo501 other = (ShareInfo501) obj; + return super.equals(obj) + && getFlags() == other.getFlags(); + } + + @Override + public String toString() { + return String.format("SHARE_INFO_501{shi501_netname: %s, shi501_type: %d, shi501_remark: %s, shi501_flags: %d}", + getNetName(), getType(), getRemark(), getFlags()); + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo502.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo502.java new file mode 100644 index 00000000..c3f80cf7 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo502.java @@ -0,0 +1,139 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.rmi.UnmarshalException; +import java.util.Arrays; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; + +/** + * Alignment: 4 + * SHARE_INFO_502 + *
The SHARE_INFO_502_I structure contains information about the shared resource, including the name of the resource, type, and permissions, the number of connections, and other pertinent information.
+ *
+ *      typedef struct _SHARE_INFO_502_I {
+ *          [string] WCHAR* shi502_netname;
+ *          DWORD shi502_type;
+ *          [string] WCHAR* shi502_remark;
+ *          DWORD shi502_permissions;
+ *          DWORD shi502_max_uses;
+ *          DWORD shi502_current_uses;
+ *          [string] WCHAR* shi502_path;
+ *          [string] WCHAR* shi502_passwd;
+ *          DWORD shi502_reserved;
+ *          [size_is(shi502_reserved)] unsigned char* shi502_security_descriptor;
+ *      } SHARE_INFO_502_I,
+ *      *PSHARE_INFO_502_I,
+ *      *LPSHARE_INFO_502_I;
+ *
+ *  shi502_netname: A pointer to a null-terminated Unicode UTF-16 string that specifies the name of a shared resource. The server MUST ignore this member when processing the NetrShareSetInfo (section 3.1.4.11) method.
+ *  shi502_type: Specifies a DWORD value that indicates the type of share. The server MUST ignore this member when processing the NetrShareSetInfo method; otherwise, it MUST be one of the values that are listed in section 2.2.2.4.
+ *  shi502_remark: A pointer to a null-terminated Unicode UTF-16 string that specifies an optional comment about the shared resource.
+ *  shi502_permissions: This field is not used. The server MUST ignore the value of this parameter on receipt.
+ *  shi502_max_uses: Specifies a DWORD value that indicates the maximum number of concurrent connections that the shared resource can accommodate. If the value that is specified by shi502_max_uses is 0xFFFFFFFF, the maximum number of connections MUST be unlimited.
+ *  shi502_current_uses: Specifies a DWORD value that indicates the number of current connections to the resource. The server MUST ignore this member on receipt.
+ *  shi502_path: A pointer to a null-terminated Unicode UTF-16 string that contains the local path for the shared resource. For disks, shi502_path is the path that is being shared. For print queues, shi502_path is the name of the print queue that is being shared. For communication devices, shi502_path is the name of the communication device that is being shared. For interprocess communications (IPC), shi502_path is the name of the interprocess communication that is being shared. The server MUST ignore this member when processing the NetrShareSetInfo method.
+ *  shi502_passwd: This field is not used. The client MUST send a NULL (zero-length) string and the server MUST ignore the value of this parameter on receipt.
+ *  shi502_reserved: The length of the security descriptor that is being passed in the shi502_security_descriptor member.
+ *  shi502_security_descriptor: Specifies the SECURITY_DESCRIPTOR, as described in [MS-DTYP] section 2.4.6, that is associated with this share.
+ */ +public class ShareInfo502 extends ShareInfo2 { + // DWORD shi502_reserved; + // Used internally + // [size_is(shi502_reserved)] unsigned char* shi502_security_descriptor; + private byte[] securityDescriptor; + + public byte[] getSecurityDescriptor() { + return securityDescriptor; + } + + public void setSecurityDescriptor(byte[] securityDescriptor) { + this.securityDescriptor = securityDescriptor; + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + super.unmarshalEntity(in); + // DWORD shi502_reserved; + // Alignment: 4 - Already aligned + final int reserved = readIndex("reserved", in); + // [size_is(shi502_reserved)] unsigned char* shi502_security_descriptor; + // Alignment: 4 - Already aligned + //noinspection Duplicates + if (in.readReferentID() != 0) { + if (reserved < 0) + throw new UnmarshalException(String.format("Expected reserved >= 0, got: %d", reserved)); + this.securityDescriptor = new byte[reserved]; + } else { + this.securityDescriptor = null; + } + } + + @Override + public void unmarshalDeferrals(PacketInput in) throws IOException { + super.unmarshalDeferrals(in); + if (this.securityDescriptor != null) { + // [size_is(shi502_reserved)] unsigned char* shi502_security_descriptor; + // MaximumSize + in.align(Alignment.FOUR); + in.fullySkipBytes(4); + in.readRawBytes(this.securityDescriptor); + } + } + + @Override + public int hashCode() { + return (super.hashCode() * 31) + Arrays.hashCode(this.securityDescriptor); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof ShareInfo502)) { + return false; + } + final ShareInfo502 other = (ShareInfo502) obj; + return super.equals(obj) + && Arrays.equals(this.securityDescriptor, other.securityDescriptor); + } + + @Override + public String toString() { + return String.format("SHARE_INFO_502{shi502_netname: %s, shi502_type: %d, shi502_remark: %s, " + + "shi502_permissions: %d, shi502_max_uses: %d, shi502_current_uses: %d, shi502_path: %s, " + + "shi502_passwd: %s, size(shi502_security_descriptor): %s}", + getNetName(), getType(), getRemark(), getPermissions(), getMaxUses(), getCurrentUses(), getPath(), + getPasswd(), (getSecurityDescriptor() == null ? "null" : getSecurityDescriptor().length)); + } + + private int readIndex(String name, PacketInput in) throws IOException { + final long ret = in.readUnsignedInt(); + // Don't allow array length or index values bigger than signed int + if (ret > Integer.MAX_VALUE) { + throw new UnmarshalException(String.format("%s %d > %d", name, ret, Integer.MAX_VALUE)); + } + return (int) ret; + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo503.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo503.java new file mode 100644 index 00000000..6229d6d5 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfo503.java @@ -0,0 +1,167 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.rmi.UnmarshalException; +import java.util.Arrays; +import java.util.Objects; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; +import com.rapid7.client.dcerpc.objects.WChar; + +/** + * Alignment: 4 + * SHARE_INFO_503 + *
The SHARE_INFO_503_I structure contains information about the shared resource, including the name of the resource, type, and permissions, the number of connections, and other pertinent information.
+ *
+ *      typedef struct _SHARE_INFO_503_I {
+ *          [string] WCHAR* shi503_netname;
+ *          DWORD shi503_type;
+ *          [string] WCHAR* shi503_remark;
+ *          DWORD shi503_permissions;
+ *          DWORD shi503_max_uses;
+ *          DWORD shi503_current_uses;
+ *          [string] WCHAR* shi503_path;
+ *          [string] WCHAR* shi503_passwd;
+ *          [string] WCHAR* shi503_servername;
+ *          DWORD shi503_reserved;
+ *          [size_is(shi503_reserved)] PUCHAR shi503_security_descriptor;
+ *      } SHARE_INFO_503_I,
+ *      *PSHARE_INFO_503_I,
+ *      *LPSHARE_INFO_503_I;
+ *
+ *  shi503_netname: A pointer to a null-terminated Unicode UTF-16 string that specifies the name of a shared resource. The server MUST ignore this member when processing the NetrShareSetInfo (section 3.1.4.11) method.
+ *  shi503_type: Specifies a DWORD value that indicates the type of share. The server MUST ignore this member when processing the NetrShareSetInfo method. Otherwise, it MUST be one of the values listed in section 2.2.2.4.
+ *  shi503_remark: A pointer to a null-terminated Unicode UTF-16 string that specifies an optional comment about the shared resource.
+ *  shi503_permissions: This field is not used. The server MUST ignore the value of this parameter on receipt.
+ *  shi503_max_uses: Specifies a DWORD value that indicates the maximum number of concurrent connections that the shared resource can accommodate. If the value is 0xFFFFFFFF, the maximum number of connections MUST be unlimited.
+ *  shi503_current_uses: Specifies a DWORD value that indicates the number of current connections to the resource. The server MUST ignore this member on receipt.
+ *  shi503_path: A pointer to a null-terminated Unicode UTF-16 string that contains the local path for the shared resource. For disks, it is the path being shared. For print queues, it is the name of the print queue being shared. The server MUST ignore this member when processing the NetrShareSetInfo method.
+ *  shi503_passwd: This field is not used. The client MUST send a NULL (zero-length) string, and the server MUST ignore the value of this parameter on receipt.
+ *  shi503_servername: A pointer to a string that specifies the DNS or NetBIOS name of the server on which the shared resource resides. It SHOULD be either "*" or the string matching one of the server names. Otherwise, the default server name will be used in [shi503_netname, default server name] to locate a scoped share as specified in section 2.2.4.102. A value of "*" indicates that there is no configured server name.
+ *  shi503_reserved: The length of the security descriptor passed in the shi503_security_descriptor member.
+ *  shi503_security_descriptor: Specifies the SECURITY_DESCRIPTOR, as described in [MS-DTYP] section 2.4.6, that is associated with this share.
+ */ +public class ShareInfo503 extends ShareInfo2 { + // [string] WCHAR* shi503_servername; + private WChar.NullTerminated serverName; + // DWORD shi502_reserved; + // Used internally + // [size_is(shi502_reserved)] unsigned char* shi502_security_descriptor; + private byte[] securityDescriptor; + + public WChar.NullTerminated getServerName() { + return this.serverName; + } + + public void setServerName(WChar.NullTerminated serverName) { + this.serverName = serverName; + } + + public byte[] getSecurityDescriptor() { + return securityDescriptor; + } + + public void setSecurityDescriptor(byte[] securityDescriptor) { + this.securityDescriptor = securityDescriptor; + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + super.unmarshalEntity(in); + // [string] WCHAR* shi503_servername; + // Alignment: 4 - Already aligned + if (in.readReferentID() != 0) + this.serverName = new WChar.NullTerminated(); + else + this.serverName = null; + // DWORD shi502_reserved; + // Alignment: 4 - Already aligned + final int reserved = readIndex("reserved", in); + // [size_is(shi502_reserved)] unsigned char* shi502_security_descriptor; + // Alignment: 4 - Already aligned + //noinspection Duplicates + if (in.readReferentID() != 0) { + if (reserved < 0) + throw new UnmarshalException(String.format("Expected reserved >= 0, got: %d", reserved)); + this.securityDescriptor = new byte[reserved]; + } else { + this.securityDescriptor = null; + } + } + + @Override + public void unmarshalDeferrals(PacketInput in) throws IOException { + super.unmarshalDeferrals(in); + if (this.serverName != null) { + // [string] WCHAR* shi503_servername; + in.readUnmarshallable(this.serverName); + } + if (this.securityDescriptor != null) { + // [size_is(shi502_reserved)] unsigned char* shi502_security_descriptor; + // MaximumSize + in.align(Alignment.FOUR); + in.fullySkipBytes(4); + in.readRawBytes(this.securityDescriptor); + } + } + + @Override + public int hashCode() { + int ret = super.hashCode(); + ret = (ret * 31) + Objects.hash(getServerName()); + return (ret * 31) + Arrays.hashCode(getSecurityDescriptor()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof ShareInfo503)) { + return false; + } + final ShareInfo503 other = (ShareInfo503) obj; + return super.equals(obj) + && Objects.equals(getServerName(), other.getServerName()) + && Arrays.equals(getSecurityDescriptor(), other.getSecurityDescriptor()); + } + + @Override + public String toString() { + return String.format("SHARE_INFO_503{shi503_netname: %s, shi503_type: %d, shi503_remark: %s, " + + "shi503_permissions: %d, shi503_max_uses: %d, shi503_current_uses: %d, shi503_path: %s, " + + "shi503_passwd: %s, shi503_server_name: %s, size(shi503_security_descriptor): %s}", + getNetName(), getType(), getRemark(), getPermissions(), getMaxUses(), + getCurrentUses(), getPath(), getPasswd(), getServerName(), + (getSecurityDescriptor() == null ? "null" : getSecurityDescriptor().length)); + } + + private int readIndex(String name, PacketInput in) throws IOException { + final long ret = in.readUnsignedInt(); + // Don't allow array length or index values bigger than signed int + if (ret > Integer.MAX_VALUE) { + throw new UnmarshalException(String.format("%s %d > %d", name, ret, Integer.MAX_VALUE)); + } + return (int) ret; + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfoContainer.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfoContainer.java new file mode 100644 index 00000000..152706d2 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfoContainer.java @@ -0,0 +1,258 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.IOException; +import java.rmi.UnmarshalException; +import java.util.Arrays; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.io.ndr.Alignment; +import com.rapid7.client.dcerpc.io.ndr.Unmarshallable; + +public abstract class ShareInfoContainer implements Unmarshallable { + + private T[] buffer; + + public T[] getBuffer() { + return buffer; + } + + abstract T[] createBuffer(final int size); + + abstract T createEntry(); + + @Override + public void unmarshalPreamble(PacketInput in) throws IOException { + // No preamble + } + + @Override + public void unmarshalEntity(PacketInput in) throws IOException { + // Structure Alignment: 4 + in.align(Alignment.FOUR); + final int entriesRead = readIndex("EntriesRead", in); + if (in.readReferentID() != 0) { + if (entriesRead < 0) { + throw new UnmarshalException(String.format( + "Expected entriesRead >= 0, got: %d", entriesRead)); + } + this.buffer = createBuffer(entriesRead); + } else { + this.buffer = null; + } + } + + @Override + public void unmarshalDeferrals(PacketInput in) throws IOException { + if (this.buffer != null) { + // Maximum Size + in.align(Alignment.FOUR); + in.fullySkipBytes(4); + for (int i = 0; i < this.buffer.length; i++) { + this.buffer[i] = createEntry(); + this.buffer[i].unmarshalPreamble(in); + } + for (final T entry : this.buffer) { + entry.unmarshalEntity(in); + } + for (final T entry : this.buffer) { + entry.unmarshalDeferrals(in); + } + } + } + + @Override + public int hashCode() { + return Arrays.hashCode(this.buffer); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (! (obj instanceof ShareInfoContainer)) { + return false; + } + return Arrays.equals(this.buffer, ((ShareInfoContainer) obj).buffer); + } + + private int readIndex(String name, PacketInput in) throws IOException { + final long ret = in.readUnsignedInt(); + // Don't allow array length or index values bigger than signed int + if (ret > Integer.MAX_VALUE) { + throw new UnmarshalException(String.format("%s %d > %d", name, ret, Integer.MAX_VALUE)); + } + return (int) ret; + } + + /** + * SHARE_INFO_0_CONTAINER + *
The SHARE_INFO_0_CONTAINER structure contains a value that indicates the number of entries that the NetrShareEnum method returns and a pointer to the buffer that contains the entries.
+     *
+     *      typedef struct _SHARE_INFO_0_CONTAINER {
+     *          DWORD EntriesRead;
+     *          [size_is(EntriesRead)] LPSHARE_INFO_0 Buffer;
+     *      } SHARE_INFO_0_CONTAINER;
+     *
+     *  EntriesRead: The number of entries returned by the method.
+     *  Buffer: A pointer to the SHARE_INFO_0 entries returned by the method.
+ */ + public static class ShareInfo0Container extends ShareInfoContainer { + @Override + ShareInfo0 createEntry() { + return new ShareInfo0(); + } + + @Override + ShareInfo0[] createBuffer(int size) { + return new ShareInfo0[size]; + } + } + + /** + * SHARE_INFO_1_CONTAINER + *
The SHARE_INFO_1_CONTAINER structure contains a value that indicates the number of entries that the NetrShareEnum method returns and a pointer to the buffer that contains the entries.
+     *
+     *      typedef struct _SHARE_INFO_1_CONTAINER {
+     *          DWORD EntriesRead;
+     *          [size_is(EntriesRead)] LPSHARE_INFO_1 Buffer;
+     *      } SHARE_INFO_1_CONTAINER;
+     *
+     *  EntriesRead: The number of entries returned by the method.
+     *  Buffer: A pointer to the SHARE_INFO_1 entries returned by the method.
+ */ + public static class ShareInfo1Container extends ShareInfoContainer { + @Override + ShareInfo1 createEntry() { + return new ShareInfo1(); + } + + @Override + ShareInfo1[] createBuffer(int size) { + return new ShareInfo1[size]; + } + } + + /** + * SHARE_INFO_2_CONTAINER + *
The SHARE_INFO_2_CONTAINER structure contains a value that indicates the number of entries that the NetrShareEnum method returns and a pointer to the buffer that contains the entries.
+     *
+     *      typedef struct _SHARE_INFO_2_CONTAINER {
+     *          DWORD EntriesRead;
+     *          [size_is(EntriesRead)] LPSHARE_INFO_2 Buffer;
+     *      } SHARE_INFO_2_CONTAINER,
+     *      *PSHARE_INFO_2_CONTAINER,
+     *      *LPSHARE_INFO_2_CONTAINER;
+     *
+     *  EntriesRead: The number of entries returned by the method.
+     *  Buffer: A pointer to the SHARE_INFO_2 entries returned by the method.
+ */ + public static class ShareInfo2Container extends ShareInfoContainer { + @Override + ShareInfo2 createEntry() { + return new ShareInfo2(); + } + + @Override + ShareInfo2[] createBuffer(int size) { + return new ShareInfo2[size]; + } + } + + /** + * SHARE_INFO_501_CONTAINER + *
The SHARE_INFO_501_CONTAINER structure contains a value that indicates the number of entries that the NetrShareEnum method returns and a pointer to the buffer that contains the entries.
+     *
+     *      typedef struct _SHARE_INFO_501_CONTAINER {
+     *          DWORD EntriesRead;
+     *          [size_is(EntriesRead)] LPSHARE_INFO_501 Buffer;
+     *      } SHARE_INFO_501_CONTAINER,
+     *      *PSHARE_INFO_501_CONTAINER,
+     *      *LPSHARE_INFO_501_CONTAINER;
+     *
+     *  EntriesRead: The number of entries returned by the method.
+     *  Buffer: A pointer to the SHARE_INFO_501 entries returned by the method.
+ */ + public static class ShareInfo501Container extends ShareInfoContainer { + @Override + ShareInfo501 createEntry() { + return new ShareInfo501(); + } + + @Override + ShareInfo501[] createBuffer(int size) { + return new ShareInfo501[size]; + } + } + + /** + * SHARE_INFO_502_CONTAINER + *
The SHARE_INFO_502_CONTAINER structure contains a value that indicates the number of entries that the NetrShareEnum method returns and a pointer to the buffer that contains the entries.
+     *
+     *      typedef struct _SHARE_INFO_502_CONTAINER {
+     *          DWORD EntriesRead;
+     *          [size_is(EntriesRead)] LPSHARE_INFO_502_I Buffer;
+     *      } SHARE_INFO_502_CONTAINER,
+     *      *PSHARE_INFO_502_CONTAINER,
+     *      *LPSHARE_INFO_502_CONTAINER;
+     *
+     *  EntriesRead: The number of entries returned by the method.
+     *  Buffer: A pointer to the SHARE_INFO_502_I entries returned by the method.
+ */ + public static class ShareInfo502Container extends ShareInfoContainer { + @Override + ShareInfo502 createEntry() { + return new ShareInfo502(); + } + + @Override + ShareInfo502[] createBuffer(int size) { + return new ShareInfo502[size]; + } + } + + /** + * SHARE_INFO_503_CONTAINER + *
The SHARE_INFO_503_CONTAINER structure contains a value that indicates the number of entries the NetrShareEnum method returns and a pointer to the buffer that contains the entries.
+     *
+     *      typedef struct _SHARE_INFO_503_CONTAINER {
+     *          DWORD EntriesRead;
+     *          [size_is(EntriesRead)] LPSHARE_INFO_503_I Buffer;
+     *      } SHARE_INFO_503_CONTAINER,
+     *      *PSHARE_INFO_503_CONTAINER,
+     *      *LPSHARE_INFO_503_CONTAINER;
+     *
+     * EntriesRead: The number of entries returned by the method.
+     * Buffer: A pointer to the SHARE_INFO_503_I entries returned by the method.
+ */ + public static class ShareInfo503Container extends ShareInfoContainer { + @Override + ShareInfo503 createEntry() { + return new ShareInfo503(); + } + + @Override + ShareInfo503[] createBuffer(int size) { + return new ShareInfo503[size]; + } + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfoLevel.java b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfoLevel.java new file mode 100644 index 00000000..052a0184 --- /dev/null +++ b/src/main/java/com/rapid7/client/dcerpc/mssrvs/objects/ShareInfoLevel.java @@ -0,0 +1,44 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +/** + * LPSHARE_INFO + */ +public enum ShareInfoLevel { + LPSHARE_INFO_0(0), + LPSHARE_INFO_1(1), + LPSHARE_INFO_2(2), + LPSHARE_INFO_501(501), + LPSHARE_INFO_502(502), + LPSHARE_INFO_503(503); + + private final int infoLevel; + + ShareInfoLevel(final int infoLevel) { + this.infoLevel = infoLevel; + } + + public int getInfoLevel() { + return infoLevel; + } +} diff --git a/src/main/java/com/rapid7/client/dcerpc/service/Service.java b/src/main/java/com/rapid7/client/dcerpc/service/Service.java index df218c2a..1a23e228 100644 --- a/src/main/java/com/rapid7/client/dcerpc/service/Service.java +++ b/src/main/java/com/rapid7/client/dcerpc/service/Service.java @@ -30,6 +30,7 @@ import com.rapid7.client.dcerpc.objects.RPCSID; import com.rapid7.client.dcerpc.dto.SID; import com.rapid7.client.dcerpc.objects.RPCUnicodeString; +import com.rapid7.client.dcerpc.objects.WChar; import com.rapid7.client.dcerpc.transport.RPCTransport; public abstract class Service { @@ -121,4 +122,10 @@ protected SID parseRPCSID(final RPCSID rpcsid) { return null; return new SID((byte) rpcsid.getRevision(), rpcsid.getIdentifierAuthority(), rpcsid.getSubAuthority()); } + + protected String parseWChar(final WChar wChar) { + if (wChar == null) + return null; + return wChar.getValue(); + } } diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/Test_ServerService.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/Test_ServerService.java index 68bea64d..553a519e 100644 --- a/src/test/java/com/rapid7/client/dcerpc/mssrvs/Test_ServerService.java +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/Test_ServerService.java @@ -19,25 +19,26 @@ package com.rapid7.client.dcerpc.mssrvs; import java.io.IOException; -import java.util.LinkedList; import java.util.List; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import com.google.common.collect.Lists; -import com.hierynomus.protocol.transport.TransportException; -import com.rapid7.client.dcerpc.RPCException; import com.rapid7.client.dcerpc.messages.RequestCall; import com.rapid7.client.dcerpc.mserref.SystemErrorCode; -import com.rapid7.client.dcerpc.mssrvs.messages.NetShareInfo0; +import com.rapid7.client.dcerpc.mssrvs.dto.NetShareInfo0; import com.rapid7.client.dcerpc.mssrvs.messages.NetrShareEnumResponse; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareEnumStruct; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfo0; +import com.rapid7.client.dcerpc.mssrvs.objects.ShareInfoContainer; +import com.rapid7.client.dcerpc.objects.WChar; import com.rapid7.client.dcerpc.transport.RPCTransport; -import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; + public class Test_ServerService { @Rule public final ExpectedException thrown = ExpectedException.none(); @@ -50,16 +51,24 @@ public void getShares() throws IOException { when(transport.call((RequestCall) any())).thenReturn(response); when(response.getReturnValue()).thenReturn(SystemErrorCode.ERROR_SUCCESS.getValue()); - when(response.getShares()).thenReturn(Lists.newArrayList(new NetShareInfo0("test1"))); + ShareEnumStruct.ShareEnumStruct0 shareEnumStruct0 = mock(ShareEnumStruct.ShareEnumStruct0.class); + ShareInfoContainer.ShareInfo0Container shareInfo0Container = mock(ShareInfoContainer.ShareInfo0Container.class); + when(shareEnumStruct0.getShareInfoContainer()).thenReturn(shareInfo0Container); + ShareInfo0[] shareInfo0s = new ShareInfo0[1]; + ShareInfo0 shareInfo0 = new ShareInfo0(); + shareInfo0.setNetName(WChar.NullTerminated.of("test1")); + shareInfo0s[0] = shareInfo0; + when(shareInfo0Container.getBuffer()).thenReturn(shareInfo0s); + when(response.getShareEnumStruct()).thenReturn(shareEnumStruct0); final ServerService serverService = new ServerService(transport); - final List shares = serverService.getShares(); + final List shares = serverService.getShares0(); final NetShareInfo0 share0 = shares.get(0); assertEquals(1, shares.size()); - assertEquals("test1", share0.getName()); + assertEquals("test1", share0.getNetName()); } - +/* @SuppressWarnings("unchecked") @Test public void getSharesTruncated() throws IOException { @@ -149,5 +158,5 @@ public void getSharesMoreDataNullResume() throws IOException { final ServerService serverService = new ServerService(transport); serverService.getShares(); - } + }*/ } diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo0.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo0.java new file mode 100644 index 00000000..0b71f654 --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo0.java @@ -0,0 +1,82 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_NetShareInfo0 { + + @Test + public void test_init_null() { + NetShareInfo0 obj = new NetShareInfo0(null); + assertNull(obj.getNetName()); + } + + @Test + public void test_init() { + String netName = "NetName"; + NetShareInfo0 obj = new NetShareInfo0(netName); + assertSame(obj.getNetName(), netName); + } + + @Test + public void test_hashCode() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + NetShareInfo0 obj1 = new NetShareInfo0(netName1); + NetShareInfo0 obj2 = new NetShareInfo0(netName1); + NetShareInfo0 obj3 = new NetShareInfo0(netName2); + assertEquals(obj1.hashCode(), obj2.hashCode()); + assertNotEquals(obj1.hashCode(), obj3.hashCode()); + } + + @Test + public void test_equals() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + NetShareInfo0 obj1 = new NetShareInfo0(netName1); + NetShareInfo0 obj2 = new NetShareInfo0(netName1); + NetShareInfo0 obj3 = new NetShareInfo0(netName2); + assertEquals(obj1, obj1); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test"); + assertEquals(obj1, obj2); + assertNotEquals(obj1, obj3); + } + + @Test + public void test_toString_null() { + NetShareInfo0 obj = new NetShareInfo0(null); + assertEquals(obj.toString(), "NetShareInfo0{netName: null}"); + } + + @Test + public void test_toString() { + NetShareInfo0 obj = new NetShareInfo0("NetName"); + assertEquals(obj.toString(), "NetShareInfo0{netName: \"NetName\"}"); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo1.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo1.java new file mode 100644 index 00000000..b91e022b --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo1.java @@ -0,0 +1,102 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_NetShareInfo1 { + + @Test + public void test_init_null() { + NetShareInfo1 obj = new NetShareInfo1(null, 25, null); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 25); + assertNull(obj.getRemark()); + } + + @Test + public void test_init() { + String netName = "NetName"; + String remark = "Remark"; + NetShareInfo1 obj = new NetShareInfo1(netName, 25, remark); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + } + + @Test + public void test_hashCode() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + NetShareInfo1 obj1 = new NetShareInfo1(netName1, type1, remark1); + NetShareInfo1 obj2 = new NetShareInfo1(netName1, type1, remark1); + NetShareInfo1 obj3 = new NetShareInfo1(netName2, type1, remark1); + NetShareInfo1 obj4 = new NetShareInfo1(netName1, type2, remark1); + NetShareInfo1 obj5 = new NetShareInfo1(netName1, type1, remark2); + assertEquals(obj1.hashCode(), obj2.hashCode()); + assertNotEquals(obj1.hashCode(), obj3.hashCode()); + assertNotEquals(obj1.hashCode(), obj4.hashCode()); + assertNotEquals(obj1.hashCode(), obj5.hashCode()); + } + + @Test + public void test_equals() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + NetShareInfo1 obj1 = new NetShareInfo1(netName1, type1, remark1); + NetShareInfo1 obj2 = new NetShareInfo1(netName1, type1, remark1); + NetShareInfo1 obj3 = new NetShareInfo1(netName2, type1, remark1); + NetShareInfo1 obj4 = new NetShareInfo1(netName1, type2, remark1); + NetShareInfo1 obj5 = new NetShareInfo1(netName1, type1, remark2); + assertEquals(obj1, obj2); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test"); + assertNotEquals(obj1, obj3); + assertNotEquals(obj1, obj4); + assertNotEquals(obj1, obj5); + } + + @Test + public void test_toString_null() { + NetShareInfo1 obj = new NetShareInfo1(null, 25, null); + assertEquals(obj.toString(), "NetShareInfo1{netName: null, type: 25, remark: null}"); + } + + @Test + public void test_toString() { + NetShareInfo1 obj = new NetShareInfo1("NetName", 25, "Remark"); + assertEquals(obj.toString(), "NetShareInfo1{netName: \"NetName\", type: 25, remark: \"Remark\"}"); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo2.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo2.java new file mode 100644 index 00000000..cd0c7538 --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo2.java @@ -0,0 +1,155 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_NetShareInfo2 { + + @Test + public void test_init_null() { + NetShareInfo2 obj = new NetShareInfo2(null, 25, null, 30, 35, 40, null, null); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 25); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + } + + @Test + public void test_init() { + String netName = "NetName"; + String remark = "Remark"; + String path = "Path"; + String passwd = "Passwd"; + NetShareInfo2 obj = new NetShareInfo2(netName, 25, remark, 30, 35, 40, path, passwd); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertSame(obj.getPath(), path); + assertSame(obj.getPasswd(), passwd); + } + + @Test + public void test_hashCode() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int permissions1 = 35; + int permissions2 = 40; + int maxUses1 = 45; + int maxUses2 = 50; + int currentUses1 = 55; + int currentUses2 = 60; + String path1 = "Path1"; + String path2 = "Path2"; + String passwd1 = "Passwd1"; + String passwd2 = "Passwd2"; + NetShareInfo2 obj1 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj2 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj3 = new NetShareInfo2(netName2, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj4 = new NetShareInfo2(netName1, type2, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj5 = new NetShareInfo2(netName1, type1, remark2, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj6 = new NetShareInfo2(netName1, type1, remark1, permissions2, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj7 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses2, currentUses1, path1, passwd1); + NetShareInfo2 obj8 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses2, path1, passwd1); + NetShareInfo2 obj9 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path2, passwd1); + NetShareInfo2 obj10 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd2); + assertEquals(obj1.hashCode(), obj2.hashCode()); + assertNotEquals(obj1.hashCode(), obj3.hashCode()); + assertNotEquals(obj1.hashCode(), obj4.hashCode()); + assertNotEquals(obj1.hashCode(), obj5.hashCode()); + assertNotEquals(obj1.hashCode(), obj6.hashCode()); + assertNotEquals(obj1.hashCode(), obj7.hashCode()); + assertNotEquals(obj1.hashCode(), obj8.hashCode()); + assertNotEquals(obj1.hashCode(), obj9.hashCode()); + assertNotEquals(obj1.hashCode(), obj10.hashCode()); + } + + @Test + public void test_equals() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int permissions1 = 35; + int permissions2 = 40; + int maxUses1 = 45; + int maxUses2 = 50; + int currentUses1 = 55; + int currentUses2 = 60; + String path1 = "Path1"; + String path2 = "Path2"; + String passwd1 = "Passwd1"; + String passwd2 = "Passwd2"; + NetShareInfo2 obj1 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj2 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj3 = new NetShareInfo2(netName2, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj4 = new NetShareInfo2(netName1, type2, remark1, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj5 = new NetShareInfo2(netName1, type1, remark2, permissions1, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj6 = new NetShareInfo2(netName1, type1, remark1, permissions2, maxUses1, currentUses1, path1, passwd1); + NetShareInfo2 obj7 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses2, currentUses1, path1, passwd1); + NetShareInfo2 obj8 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses2, path1, passwd1); + NetShareInfo2 obj9 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path2, passwd1); + NetShareInfo2 obj10 = new NetShareInfo2(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd2); + assertEquals(obj1, obj1); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test"); + assertEquals(obj1, obj2); + assertNotEquals(obj1, obj3); + assertNotEquals(obj1, obj4); + assertNotEquals(obj1, obj5); + assertNotEquals(obj1, obj6); + assertNotEquals(obj1, obj7); + assertNotEquals(obj1, obj8); + assertNotEquals(obj1, obj9); + assertNotEquals(obj1, obj10); + } + + @Test + public void test_toString_null() { + NetShareInfo2 obj = new NetShareInfo2(null, 25, null, 30, 35, 40, null, null); + assertEquals(obj.toString(), "NetShareInfo2{netName: null, type: 25, remark: null, permissions: 30, maxUses: 35, currentUses: 40, path: null, passwd: null}"); + } + + @Test + public void test_toString() { + NetShareInfo2 obj = new NetShareInfo2("NetName", 25, "Remark", 30, 35, 40, "Path", "Passwd"); + assertEquals(obj.toString(), "NetShareInfo2{netName: \"NetName\", type: 25, remark: \"Remark\", permissions: 30, maxUses: 35, currentUses: 40, path: \"Passwd\", passwd: \"Passwd\"}"); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo501.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo501.java new file mode 100644 index 00000000..033c31cb --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo501.java @@ -0,0 +1,113 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_NetShareInfo501 { + + @Test + public void test_init_null() { + NetShareInfo501 obj = new NetShareInfo501(null, 25, null, 30); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 25); + assertNull(obj.getRemark()); + assertEquals(obj.getFlags(), 30); + } + + @Test + public void test_init() { + String netName = "NetName"; + String remark = "Remark"; + NetShareInfo501 obj = new NetShareInfo501(netName, 25, remark, 30); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getFlags(), 30); + } + + @Test + public void test_hashCode() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int flags1 = 35; + int flags2 = 40; + NetShareInfo501 obj1 = new NetShareInfo501(netName1, type1, remark1, flags1); + NetShareInfo501 obj2 = new NetShareInfo501(netName1, type1, remark1, flags1); + NetShareInfo501 obj3 = new NetShareInfo501(netName2, type1, remark1, flags1); + NetShareInfo501 obj4 = new NetShareInfo501(netName1, type2, remark1, flags1); + NetShareInfo501 obj5 = new NetShareInfo501(netName1, type1, remark2, flags1); + NetShareInfo501 obj6 = new NetShareInfo501(netName1, type1, remark1, flags2); + assertEquals(obj1.hashCode(), obj2.hashCode()); + assertNotEquals(obj1.hashCode(), obj3.hashCode()); + assertNotEquals(obj1.hashCode(), obj4.hashCode()); + assertNotEquals(obj1.hashCode(), obj5.hashCode()); + assertNotEquals(obj1.hashCode(), obj6.hashCode()); + } + + @Test + public void test_equals() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int flags1 = 35; + int flags2 = 40; + NetShareInfo501 obj1 = new NetShareInfo501(netName1, type1, remark1, flags1); + NetShareInfo501 obj2 = new NetShareInfo501(netName1, type1, remark1, flags1); + NetShareInfo501 obj3 = new NetShareInfo501(netName2, type1, remark1, flags1); + NetShareInfo501 obj4 = new NetShareInfo501(netName1, type2, remark1, flags1); + NetShareInfo501 obj5 = new NetShareInfo501(netName1, type1, remark2, flags1); + NetShareInfo501 obj6 = new NetShareInfo501(netName1, type1, remark1, flags2); + assertEquals(obj1, obj1); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test"); + assertEquals(obj1, obj2); + assertNotEquals(obj1, obj3); + assertNotEquals(obj1, obj4); + assertNotEquals(obj1, obj5); + assertNotEquals(obj1, obj6); + } + + @Test + public void test_toString_null() { + NetShareInfo501 obj = new NetShareInfo501(null, 25, null, 30); + assertEquals(obj.toString(), "NetShareInfo501{netName: null, type: 25, remark: null, flags: 30}"); + } + + @Test + public void test_toString() { + NetShareInfo501 obj = new NetShareInfo501("NetName", 25, "Remark", 30); + assertEquals(obj.toString(), "NetShareInfo501{netName: \"NetName\", type: 25, remark: \"Remark\", flags: 30}"); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo502.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo502.java new file mode 100644 index 00000000..cb3f85d7 --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo502.java @@ -0,0 +1,166 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_NetShareInfo502 { + + @Test + public void test_init_null() { + NetShareInfo502 obj = new NetShareInfo502(null, 25, null, 30, 35, 40, null, null, null); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 25); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + assertNull(obj.getSecurityDescriptor()); + } + + @Test + public void test_init() { + String netName = "NetName"; + String remark = "Remark"; + String path = "Path"; + String passwd = "Passwd"; + byte[] securityDescriptor = new byte[2]; + NetShareInfo502 obj = new NetShareInfo502(netName, 25, remark, 30, 35, 40, path, passwd, securityDescriptor); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertSame(obj.getPath(), path); + assertSame(obj.getPasswd(), passwd); + assertSame(obj.getSecurityDescriptor(), securityDescriptor); + } + + @Test + public void test_hashCode() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int permissions1 = 35; + int permissions2 = 40; + int maxUses1 = 45; + int maxUses2 = 50; + int currentUses1 = 55; + int currentUses2 = 60; + String path1 = "Path1"; + String path2 = "Path2"; + String passwd1 = "Passwd1"; + String passwd2 = "Passwd2"; + byte[] securityDescriptor1 = new byte[]{1, 2}; + byte[] securityDescriptor2 = new byte[]{3, 4, 5}; + NetShareInfo502 obj1 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj2 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj3 = new NetShareInfo502(netName2, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj4 = new NetShareInfo502(netName1, type2, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj5 = new NetShareInfo502(netName1, type1, remark2, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj6 = new NetShareInfo502(netName1, type1, remark1, permissions2, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj7 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses2, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj8 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses2, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj9 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path2, passwd1, securityDescriptor1); + NetShareInfo502 obj10 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd2, securityDescriptor1); + NetShareInfo502 obj11 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor2); + assertEquals(obj1.hashCode(), obj2.hashCode()); + assertNotEquals(obj1.hashCode(), obj3.hashCode()); + assertNotEquals(obj1.hashCode(), obj4.hashCode()); + assertNotEquals(obj1.hashCode(), obj5.hashCode()); + assertNotEquals(obj1.hashCode(), obj6.hashCode()); + assertNotEquals(obj1.hashCode(), obj7.hashCode()); + assertNotEquals(obj1.hashCode(), obj8.hashCode()); + assertNotEquals(obj1.hashCode(), obj9.hashCode()); + assertNotEquals(obj1.hashCode(), obj10.hashCode()); + assertNotEquals(obj1.hashCode(), obj11.hashCode()); + } + + @Test + public void test_equals() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int permissions1 = 35; + int permissions2 = 40; + int maxUses1 = 45; + int maxUses2 = 50; + int currentUses1 = 55; + int currentUses2 = 60; + String path1 = "Path1"; + String path2 = "Path2"; + String passwd1 = "Passwd1"; + String passwd2 = "Passwd2"; + byte[] securityDescriptor1 = new byte[]{1, 2}; + byte[] securityDescriptor2 = new byte[]{3, 4, 5}; + NetShareInfo502 obj1 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj2 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj3 = new NetShareInfo502(netName2, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj4 = new NetShareInfo502(netName1, type2, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj5 = new NetShareInfo502(netName1, type1, remark2, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj6 = new NetShareInfo502(netName1, type1, remark1, permissions2, maxUses1, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj7 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses2, currentUses1, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj8 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses2, path1, passwd1, securityDescriptor1); + NetShareInfo502 obj9 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path2, passwd1, securityDescriptor1); + NetShareInfo502 obj10 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd2, securityDescriptor1); + NetShareInfo502 obj11 = new NetShareInfo502(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, securityDescriptor2); + assertEquals(obj1, obj1); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test"); + assertEquals(obj1, obj2); + assertNotEquals(obj1, obj3); + assertNotEquals(obj1, obj4); + assertNotEquals(obj1, obj5); + assertNotEquals(obj1, obj6); + assertNotEquals(obj1, obj7); + assertNotEquals(obj1, obj8); + assertNotEquals(obj1, obj9); + assertNotEquals(obj1, obj10); + assertNotEquals(obj1, obj11); + } + + @Test + public void test_toString_null() { + NetShareInfo502 obj = new NetShareInfo502(null, 25, null, 30, 35, 40, null, null, null); + assertEquals(obj.toString(), "NetShareInfo502{netName: null, type: 25, remark: null, permissions: 30, maxUses: 35, currentUses: 40, path: null, passwd: null, size(securityDescriptor): null}"); + } + + @Test + public void test_toString() { + NetShareInfo502 obj = new NetShareInfo502("NetName", 25, "Remark", 30, 35, 40, "Path", "Passwd", new byte[]{1, 2}); + assertEquals(obj.toString(), "NetShareInfo502{netName: \"NetName\", type: 25, remark: \"Remark\", permissions: 30, maxUses: 35, currentUses: 40, path: \"Passwd\", passwd: \"Passwd\", size(securityDescriptor): 2}"); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo503.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo503.java new file mode 100644 index 00000000..caa6581c --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/dto/Test_NetShareInfo503.java @@ -0,0 +1,177 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.dto; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_NetShareInfo503 { + + @Test + public void test_init_null() { + NetShareInfo503 obj = new NetShareInfo503(null, 25, null, 30, 35, 40, null, null, null, null); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 25); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + assertNull(obj.getServerName()); + assertNull(obj.getSecurityDescriptor()); + } + + @Test + public void test_init() { + String netName = "NetName"; + String remark = "Remark"; + String path = "Path"; + String passwd = "Passwd"; + String serverName = "ServerName"; + byte[] securityDescriptor = new byte[2]; + NetShareInfo503 obj = new NetShareInfo503(netName, 25, remark, 30, 35, 40, path, passwd, serverName, securityDescriptor); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertSame(obj.getPath(), path); + assertSame(obj.getPasswd(), passwd); + assertSame(obj.getServerName(), serverName); + assertSame(obj.getSecurityDescriptor(), securityDescriptor); + } + + @Test + public void test_hashCode() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int permissions1 = 35; + int permissions2 = 40; + int maxUses1 = 45; + int maxUses2 = 50; + int currentUses1 = 55; + int currentUses2 = 60; + String path1 = "Path1"; + String path2 = "Path2"; + String passwd1 = "Passwd1"; + String passwd2 = "Passwd2"; + String serverName1 = "ServerName1"; + String serverName2 = "ServerName2"; + byte[] securityDescriptor1 = new byte[]{1, 2}; + byte[] securityDescriptor2 = new byte[]{3, 4, 5}; + NetShareInfo503 obj1 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj2 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj3 = new NetShareInfo503(netName2, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj4 = new NetShareInfo503(netName1, type2, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj5 = new NetShareInfo503(netName1, type1, remark2, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj6 = new NetShareInfo503(netName1, type1, remark1, permissions2, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj7 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses2, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj8 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses2, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj9 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path2, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj10 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd2, serverName1, securityDescriptor1); + NetShareInfo503 obj11 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName2, securityDescriptor1); + NetShareInfo503 obj12 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor2); + assertEquals(obj1.hashCode(), obj2.hashCode()); + assertNotEquals(obj1.hashCode(), obj3.hashCode()); + assertNotEquals(obj1.hashCode(), obj4.hashCode()); + assertNotEquals(obj1.hashCode(), obj5.hashCode()); + assertNotEquals(obj1.hashCode(), obj6.hashCode()); + assertNotEquals(obj1.hashCode(), obj7.hashCode()); + assertNotEquals(obj1.hashCode(), obj8.hashCode()); + assertNotEquals(obj1.hashCode(), obj9.hashCode()); + assertNotEquals(obj1.hashCode(), obj10.hashCode()); + assertNotEquals(obj1.hashCode(), obj11.hashCode()); + assertNotEquals(obj1.hashCode(), obj12.hashCode()); + } + + @Test + public void test_equals() { + String netName1 = "NetName1"; + String netName2 = "NetName2"; + int type1 = 25; + int type2 = 30; + String remark1 = "Remark1"; + String remark2 = "Remark2"; + int permissions1 = 35; + int permissions2 = 40; + int maxUses1 = 45; + int maxUses2 = 50; + int currentUses1 = 55; + int currentUses2 = 60; + String path1 = "Path1"; + String path2 = "Path2"; + String passwd1 = "Passwd1"; + String passwd2 = "Passwd2"; + String serverName1 = "ServerName1"; + String serverName2 = "ServerName2"; + byte[] securityDescriptor1 = new byte[]{1, 2}; + byte[] securityDescriptor2 = new byte[]{3, 4, 5}; + NetShareInfo503 obj1 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj2 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj3 = new NetShareInfo503(netName2, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj4 = new NetShareInfo503(netName1, type2, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj5 = new NetShareInfo503(netName1, type1, remark2, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj6 = new NetShareInfo503(netName1, type1, remark1, permissions2, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj7 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses2, currentUses1, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj8 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses2, path1, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj9 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path2, passwd1, serverName1, securityDescriptor1); + NetShareInfo503 obj10 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd2, serverName1, securityDescriptor1); + NetShareInfo503 obj11 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName2, securityDescriptor1); + NetShareInfo503 obj12 = new NetShareInfo503(netName1, type1, remark1, permissions1, maxUses1, currentUses1, path1, passwd1, serverName1, securityDescriptor2); + assertEquals(obj1, obj1); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test"); + assertEquals(obj1, obj2); + assertNotEquals(obj1, obj3); + assertNotEquals(obj1, obj4); + assertNotEquals(obj1, obj5); + assertNotEquals(obj1, obj6); + assertNotEquals(obj1, obj7); + assertNotEquals(obj1, obj8); + assertNotEquals(obj1, obj9); + assertNotEquals(obj1, obj10); + assertNotEquals(obj1, obj11); + assertNotEquals(obj1, obj12); + } + + @Test + public void test_toString_null() { + NetShareInfo503 obj = new NetShareInfo503(null, 25, null, 30, 35, 40, null, null, null, null); + assertEquals(obj.toString(), "NetShareInfo503{netName: null, type: 25, remark: null, permissions: 30, maxUses: 35, currentUses: 40, path: null, passwd: null, serverName: null, size(securityDescriptor): null}"); + } + + @Test + public void test_toString() { + NetShareInfo503 obj = new NetShareInfo503("NetName", 25, "Remark", 30, 35, 40, "Path", "Passwd", "ServerName", new byte[]{1, 2}); + assertEquals(obj.toString(), "NetShareInfo503{netName: \"NetName\", type: 25, remark: \"Remark\", permissions: 30, maxUses: 35, currentUses: 40, path: \"Passwd\", passwd: \"Passwd\", serverName: \"ServerName\", size(securityDescriptor): 2}"); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo0.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo0.java deleted file mode 100644 index 070f1193..00000000 --- a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo0.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017, Rapid7, Inc. - * - * License: BSD-3-clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - */ -package com.rapid7.client.dcerpc.mssrvs.messages; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -public class Test_NetShareInfo0 { - @Test(expected = IllegalArgumentException.class) - public void nameIsNull() { - new NetShareInfo0(null); - } - - @Test - public void getName() { - final NetShareInfo0 share = new NetShareInfo0("test"); - assertEquals("test", share.getName()); - } - - @Test - public void testToString() { - final NetShareInfo0 share = new NetShareInfo0("test"); - assertEquals("name=test", share.toString()); - } - - @Test - public void testHashCode() { - final NetShareInfo0 share1 = new NetShareInfo0("test1"); - final NetShareInfo0 share2 = new NetShareInfo0("test2"); - - assertEquals(share1.hashCode(), share1.hashCode()); - assertNotEquals(share2.hashCode(), share1.hashCode()); - } - - @Test - public void testEquals() { - final NetShareInfo0 share1 = new NetShareInfo0("test1"); - final NetShareInfo0 share2 = new NetShareInfo0("test2"); - - assertEquals(share1, share1); - assertNotEquals(share1, share2); - assertNotEquals(share2, share1); - assertEquals(share2, share2); - } -} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo1.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo1.java deleted file mode 100644 index 6b84c842..00000000 --- a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo1.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright 2017, Rapid7, Inc. - * - * License: BSD-3-clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - */ -package com.rapid7.client.dcerpc.mssrvs.messages; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class Test_NetShareInfo1 { - @Test - public void getType() { - final NetShareInfo1 share = new NetShareInfo1("", 123456789, null); - assertEquals(123456789, share.getType()); - } - - @Test - public void getComment() { - final NetShareInfo1 share = new NetShareInfo1("", 0, "comment"); - assertEquals("comment", share.getComment()); - } - - @Test - public void getCommentIsNull() { - final NetShareInfo1 share = new NetShareInfo1("", 0, null); - assertNull("comment", share.getComment()); - } - - @Test - public void testToString() { - final NetShareInfo1 share1 = new NetShareInfo1("share", 1, null); - final NetShareInfo1 share2 = new NetShareInfo1("share", 1, "comment"); - assertEquals("name=share, type=1, comment=null", share1.toString()); - assertEquals("name=share, type=1, comment=comment", share2.toString()); - } - - @Test - public void testHashCode() { - final NetShareInfo1 share1 = new NetShareInfo1("share", 0, null); - final NetShareInfo1 share2 = new NetShareInfo1("", 0, null); - final NetShareInfo1 share3 = new NetShareInfo1("", 123456789, null); - final NetShareInfo1 share4 = new NetShareInfo1("", 123456789, "comment1"); - final NetShareInfo1 share5 = new NetShareInfo1("", 123456789, "comment2"); - - assertEquals(share1.hashCode(), share1.hashCode()); - assertNotEquals(share2.hashCode(), share1.hashCode()); - assertNotEquals(share3.hashCode(), share1.hashCode()); - assertNotEquals(share4.hashCode(), share1.hashCode()); - assertNotEquals(share5.hashCode(), share1.hashCode()); - } - - @Test - public void testEquals() { - final NetShareInfo1 share1 = new NetShareInfo1("share", 0, null); - final NetShareInfo1 share2 = new NetShareInfo1("", 0, null); - final NetShareInfo1 share3 = new NetShareInfo1("", 123456789, null); - final NetShareInfo1 share4 = new NetShareInfo1("", 123456789, "comment1"); - final NetShareInfo1 share5 = new NetShareInfo1("", 123456789, "comment2"); - - assertEquals(share1, share1); - assertNotEquals(share1, share2); - assertNotEquals(share1, share3); - assertNotEquals(share1, share4); - assertNotEquals(share1, share5); - - assertNotEquals(share2, share1); - assertEquals(share2, share2); - assertNotEquals(share2, share3); - assertNotEquals(share2, share4); - assertNotEquals(share2, share5); - - assertNotEquals(share3, share1); - assertNotEquals(share3, share2); - assertEquals(share3, share3); - assertNotEquals(share3, share4); - assertNotEquals(share3, share5); - - assertNotEquals(share4, share1); - assertNotEquals(share4, share2); - assertNotEquals(share4, share3); - assertEquals(share4, share4); - assertNotEquals(share4, share5); - - assertNotEquals(share5, share1); - assertNotEquals(share5, share2); - assertNotEquals(share5, share3); - assertNotEquals(share5, share4); - assertEquals(share5, share5); - } -} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo2.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo2.java deleted file mode 100644 index 3d48621e..00000000 --- a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetShareInfo2.java +++ /dev/null @@ -1,249 +0,0 @@ -/** - * Copyright 2017, Rapid7, Inc. - * - * License: BSD-3-clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - */ -package com.rapid7.client.dcerpc.mssrvs.messages; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class Test_NetShareInfo2 { - @Test - public void getPermissions() { - final NetShareInfo2 share = new NetShareInfo2("", 0, null, 123456789, 0, 0, null, null); - assertEquals(123456789, share.getPermissions()); - } - - @Test - public void getMaximumUsers() { - final NetShareInfo2 share = new NetShareInfo2("", 0, null, 0, 123456789, 0, null, null); - assertEquals(123456789, share.getMaximumUsers()); - } - - @Test - public void getCurrentUsers() { - final NetShareInfo2 share = new NetShareInfo2("", 0, null, 0, 0, 123456789, null, null); - assertEquals(123456789, share.getCurrentUsers()); - } - - @Test - public void getPath() { - final NetShareInfo2 share = new NetShareInfo2("", 0, null, 0, 0, 0, "C:", null); - assertEquals("C:", share.getPath()); - } - - @Test - public void getPathIsNull() { - final NetShareInfo2 share = new NetShareInfo2("", 0, null, 0, 0, 0, null, null); - assertNull(share.getPath()); - } - - @Test - public void getPassword() { - final NetShareInfo2 share = new NetShareInfo2("", 0, null, 0, 0, 0, null, "password"); - assertEquals("password", share.getPassword()); - } - - @Test - public void getPasswordIsNull() { - final NetShareInfo2 share = new NetShareInfo2("", 0, null, 0, 0, 0, null, null); - assertNull(share.getPassword()); - } - - @Test - public void testToString() { - final NetShareInfo2 share1 = new NetShareInfo2("share", 1, null, 2, 3, 4, null, null); - final NetShareInfo2 share2 = new NetShareInfo2("share", 1, "comment", 2, 3, 4, "C:", "password"); - assertEquals("name=share, type=1, comment=null, permissions=2, maximumUsers=3, currentUsers=4, path=null, password=null", share1.toString()); - assertEquals("name=share, type=1, comment=comment, permissions=2, maximumUsers=3, currentUsers=4, path=C:, password=password", share2.toString()); - } - - @Test - public void testHashCode() { - final NetShareInfo2 share1 = new NetShareInfo2("share", 0, null, 0, 0, 0, null, null); - final NetShareInfo2 share2 = new NetShareInfo2("", 123456789, null, 0, 0, 0, null, null); - final NetShareInfo2 share3 = new NetShareInfo2("", 0, "comment", 0, 0, 0, null, null); - final NetShareInfo2 share4 = new NetShareInfo2("", 0, null, 123456789, 0, 0, null, null); - final NetShareInfo2 share5 = new NetShareInfo2("", 0, null, 0, 123456789, 0, null, null); - final NetShareInfo2 share6 = new NetShareInfo2("", 0, null, 0, 0, 123456789, null, null); - final NetShareInfo2 share7 = new NetShareInfo2("", 0, null, 0, 0, 0, null, null); - final NetShareInfo2 share8 = new NetShareInfo2("", 0, null, 0, 0, 0, "C:", null); - final NetShareInfo2 share9 = new NetShareInfo2("", 0, null, 0, 0, 0, "D:", null); - final NetShareInfo2 share10 = new NetShareInfo2("", 0, null, 0, 0, 0, null, "password1"); - final NetShareInfo2 share11 = new NetShareInfo2("", 0, null, 0, 0, 0, null, "password2"); - - assertEquals(share1.hashCode(), share1.hashCode()); - assertNotEquals(share2.hashCode(), share1.hashCode()); - assertNotEquals(share3.hashCode(), share1.hashCode()); - assertNotEquals(share4.hashCode(), share1.hashCode()); - assertNotEquals(share5.hashCode(), share1.hashCode()); - assertNotEquals(share6.hashCode(), share1.hashCode()); - assertNotEquals(share7.hashCode(), share1.hashCode()); - assertNotEquals(share8.hashCode(), share1.hashCode()); - assertNotEquals(share9.hashCode(), share1.hashCode()); - assertNotEquals(share10.hashCode(), share1.hashCode()); - assertNotEquals(share11.hashCode(), share1.hashCode()); - } - - @Test - public void testEquals() { - final NetShareInfo2 share1 = new NetShareInfo2("share", 0, null, 0, 0, 0, null, null); - final NetShareInfo2 share2 = new NetShareInfo2("", 123456789, null, 0, 0, 0, null, null); - final NetShareInfo2 share3 = new NetShareInfo2("", 0, "comment", 0, 0, 0, null, null); - final NetShareInfo2 share4 = new NetShareInfo2("", 0, null, 123456789, 0, 0, null, null); - final NetShareInfo2 share5 = new NetShareInfo2("", 0, null, 0, 123456789, 0, null, null); - final NetShareInfo2 share6 = new NetShareInfo2("", 0, null, 0, 0, 123456789, null, null); - final NetShareInfo2 share7 = new NetShareInfo2("", 0, null, 0, 0, 0, null, null); - final NetShareInfo2 share8 = new NetShareInfo2("", 0, null, 0, 0, 0, "C:", null); - final NetShareInfo2 share9 = new NetShareInfo2("", 0, null, 0, 0, 0, "D:", null); - final NetShareInfo2 share10 = new NetShareInfo2("", 0, null, 0, 0, 0, null, "password1"); - final NetShareInfo2 share11 = new NetShareInfo2("", 0, null, 0, 0, 0, null, "password2"); - - assertEquals(share1, share1); - assertNotEquals(share1, share2); - assertNotEquals(share1, share3); - assertNotEquals(share1, share4); - assertNotEquals(share1, share5); - assertNotEquals(share1, share6); - assertNotEquals(share1, share7); - assertNotEquals(share1, share8); - assertNotEquals(share1, share9); - assertNotEquals(share1, share10); - assertNotEquals(share1, share11); - - assertNotEquals(share2, share1); - assertEquals(share2, share2); - assertNotEquals(share2, share3); - assertNotEquals(share2, share4); - assertNotEquals(share2, share5); - assertNotEquals(share2, share6); - assertNotEquals(share2, share7); - assertNotEquals(share2, share8); - assertNotEquals(share2, share9); - assertNotEquals(share2, share10); - assertNotEquals(share2, share11); - - assertNotEquals(share3, share1); - assertNotEquals(share3, share2); - assertEquals(share3, share3); - assertNotEquals(share3, share4); - assertNotEquals(share3, share5); - assertNotEquals(share3, share6); - assertNotEquals(share3, share7); - assertNotEquals(share3, share8); - assertNotEquals(share3, share9); - assertNotEquals(share3, share10); - assertNotEquals(share3, share11); - - assertNotEquals(share4, share1); - assertNotEquals(share4, share2); - assertNotEquals(share4, share3); - assertEquals(share4, share4); - assertNotEquals(share4, share5); - assertNotEquals(share4, share6); - assertNotEquals(share4, share7); - assertNotEquals(share4, share8); - assertNotEquals(share4, share9); - assertNotEquals(share4, share10); - assertNotEquals(share4, share11); - - assertNotEquals(share5, share1); - assertNotEquals(share5, share2); - assertNotEquals(share5, share3); - assertNotEquals(share5, share4); - assertEquals(share5, share5); - assertNotEquals(share5, share6); - assertNotEquals(share5, share7); - assertNotEquals(share5, share8); - assertNotEquals(share5, share9); - assertNotEquals(share5, share10); - assertNotEquals(share5, share11); - - assertNotEquals(share6, share1); - assertNotEquals(share6, share2); - assertNotEquals(share6, share3); - assertNotEquals(share6, share4); - assertNotEquals(share6, share5); - assertEquals(share6, share6); - assertNotEquals(share6, share7); - assertNotEquals(share6, share8); - assertNotEquals(share6, share9); - assertNotEquals(share6, share10); - assertNotEquals(share6, share11); - - assertNotEquals(share7, share1); - assertNotEquals(share7, share2); - assertNotEquals(share7, share3); - assertNotEquals(share7, share4); - assertNotEquals(share7, share5); - assertNotEquals(share7, share6); - assertEquals(share7, share7); - assertNotEquals(share7, share8); - assertNotEquals(share7, share9); - assertNotEquals(share7, share10); - assertNotEquals(share7, share11); - - assertNotEquals(share8, share1); - assertNotEquals(share8, share2); - assertNotEquals(share8, share3); - assertNotEquals(share8, share4); - assertNotEquals(share8, share5); - assertNotEquals(share8, share6); - assertNotEquals(share8, share7); - assertEquals(share8, share8); - assertNotEquals(share8, share9); - assertNotEquals(share8, share10); - assertNotEquals(share8, share11); - - assertNotEquals(share9, share1); - assertNotEquals(share9, share2); - assertNotEquals(share9, share3); - assertNotEquals(share9, share4); - assertNotEquals(share9, share5); - assertNotEquals(share9, share6); - assertNotEquals(share9, share7); - assertNotEquals(share9, share8); - assertEquals(share9, share9); - assertNotEquals(share9, share10); - assertNotEquals(share9, share11); - - assertNotEquals(share10, share1); - assertNotEquals(share10, share2); - assertNotEquals(share10, share3); - assertNotEquals(share10, share4); - assertNotEquals(share10, share5); - assertNotEquals(share10, share6); - assertNotEquals(share10, share7); - assertNotEquals(share10, share8); - assertNotEquals(share10, share9); - assertEquals(share10, share10); - assertNotEquals(share10, share11); - - assertNotEquals(share11, share1); - assertNotEquals(share11, share2); - assertNotEquals(share11, share3); - assertNotEquals(share11, share4); - assertNotEquals(share11, share5); - assertNotEquals(share11, share6); - assertNotEquals(share11, share7); - assertNotEquals(share11, share8); - assertNotEquals(share11, share9); - assertNotEquals(share11, share10); - assertEquals(share11, share11); - } -} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetrShareEnum.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetrShareEnum.java deleted file mode 100644 index 182f7a13..00000000 --- a/src/test/java/com/rapid7/client/dcerpc/mssrvs/messages/Test_NetrShareEnum.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2017, Rapid7, Inc. - * - * License: BSD-3-clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - */ -package com.rapid7.client.dcerpc.mssrvs.messages; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.List; -import org.bouncycastle.util.encoders.Hex; -import org.junit.Test; -import com.rapid7.client.dcerpc.io.PacketInput; -import com.rapid7.client.dcerpc.mserref.SystemErrorCode; - -import static org.bouncycastle.util.encoders.Hex.toHexString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -public class Test_NetrShareEnum { - private final NetrShareEnumRequest request = new NetrShareEnumRequest(1, null); - - @Test - public void getOpNum() { - assertEquals(15, request.getOpNum()); - } - - @Test - public void getStub() throws IOException { - assertEquals("0000000001000000010000000000020000000000000000000000100000000000", toHexString(request.getStub())); - } - - @Test - public void getResponseObject() throws IOException { - final NetrShareEnumResponse response = request.getResponseObject(); - final ByteArrayInputStream packetInputStream = new ByteArrayInputStream(Hex.decode("01000000010000000000020003000000040002000300000008000200000000800c00020010000200000000801400020018000200030000801c000200070000000000000007000000410044004d0049004e002400000000000d000000000000000d000000520065006d006f00740065002000410064006d0069006e000000000003000000000000000300000043002400000000000e000000000000000e000000440065006600610075006c00740020007300680061007200650000000500000000000000050000004900500043002400000000000b000000000000000b000000520065006d006f0074006500200049005000430000000000030000000000000000000000")); - final PacketInput packetIn = new PacketInput(packetInputStream); - - response.unmarshal(packetIn); - - assertEquals(1, response.getLevel()); - - final List shares = response.getShares(); - final NetShareInfo1 share0 = (NetShareInfo1) shares.get(0); - final NetShareInfo1 share1 = (NetShareInfo1) shares.get(1); - final NetShareInfo1 share2 = (NetShareInfo1) shares.get(2); - - assertEquals(3, shares.size()); - assertEquals("ADMIN$", share0.getName()); - assertEquals(-2147483648, share0.getType()); - assertEquals("Remote Admin", share0.getComment()); - assertEquals("C$", share1.getName()); - assertEquals(-2147483648, share1.getType()); - assertEquals("Default share", share1.getComment()); - assertEquals("IPC$", share2.getName()); - assertEquals(-2147483645, share2.getType()); - assertEquals("Remote IPC", share2.getComment()); - - assertNull(response.getResumeHandle()); - assertEquals(SystemErrorCode.ERROR_SUCCESS.getValue(), response.getReturnValue()); - } -} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareEnumLevel.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareEnumLevel.java new file mode 100644 index 00000000..e2835c1a --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareEnumLevel.java @@ -0,0 +1,46 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +public class Test_ShareEnumLevel { + @DataProvider + public Object[][] data_getInfoLevel() { + return new Object[][] { + {ShareEnumLevel.SHARE_INFO_0_CONTAINER, 0}, + {ShareEnumLevel.SHARE_INFO_1_CONTAINER, 1}, + {ShareEnumLevel.SHARE_INFO_2_CONTAINER, 2}, + {ShareEnumLevel.SHARE_INFO_501_CONTAINER, 501}, + {ShareEnumLevel.SHARE_INFO_502_CONTAINER, 502}, + {ShareEnumLevel.SHARE_INFO_503_CONTAINER, 503}, + }; + } + + @Test(dataProvider = "data_getInfoLevel") + public void test_getInfoLevel(ShareEnumLevel obj, int expected) { + assertEquals(obj.getInfoLevel(), expected); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareEnumStruct.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareEnumStruct.java new file mode 100644 index 00000000..f165fcb7 --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareEnumStruct.java @@ -0,0 +1,155 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.rmi.UnmarshalException; +import org.apache.commons.lang3.mutable.MutableBoolean; +import org.bouncycastle.util.encoders.Hex; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import com.rapid7.client.dcerpc.io.PacketInput; + +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doCallRealMethod; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +public class Test_ShareEnumStruct { + + @DataProvider + public Object[][] data_allInstances() { + return new Object[][] { + // ShareEnumStruct0 + {new ShareEnumStruct.ShareEnumStruct0()}, + {new ShareEnumStruct.ShareEnumStruct1()}, + {new ShareEnumStruct.ShareEnumStruct2()}, + {new ShareEnumStruct.ShareEnumStruct501()}, + {new ShareEnumStruct.ShareEnumStruct502()}, + {new ShareEnumStruct.ShareEnumStruct503()}, + }; + } + + @Test(dataProvider = "data_allInstances") + public void test_unmarshalPreamble(ShareEnumStruct struct) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + struct.unmarshalPreamble(in); + assertEquals(bin.available(), 0); + assertNull(struct.getShareInfoContainer()); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + // ShareEnumStruct0 + {"00000000 00000000 02000000", new ShareEnumStruct.ShareEnumStruct0(), false}, + {"00000000 00000000 00000000", new ShareEnumStruct.ShareEnumStruct0(), true}, + // ShareEnumStruct1 + {"01000000 01000000 02000000", new ShareEnumStruct.ShareEnumStruct1(), false}, + {"01000000 01000000 00000000", new ShareEnumStruct.ShareEnumStruct1(), true}, + // ShareEnumStruct2 + {"02000000 02000000 02000000", new ShareEnumStruct.ShareEnumStruct2(), false}, + {"02000000 02000000 00000000", new ShareEnumStruct.ShareEnumStruct2(), true}, + // ShareEnumStruct501 + {"F5010000 F5010000 02000000", new ShareEnumStruct.ShareEnumStruct501(), false}, + {"F5010000 F5010000 00000000", new ShareEnumStruct.ShareEnumStruct501(), true}, + // ShareEnumStruct502 + {"F6010000 F6010000 02000000", new ShareEnumStruct.ShareEnumStruct502(), false}, + {"F6010000 F6010000 00000000", new ShareEnumStruct.ShareEnumStruct502(), true}, + // ShareEnumStruct503 + {"F7010000 F7010000 02000000", new ShareEnumStruct.ShareEnumStruct503(), false}, + {"F7010000 F7010000 00000000", new ShareEnumStruct.ShareEnumStruct503(), true}, + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, ShareEnumStruct struct, boolean expectNullContainer) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + struct.unmarshalEntity(in); + assertEquals(bin.available(), 0); + if (expectNullContainer) + assertNull(struct.getShareInfoContainer()); + else + assertNotNull(struct.getShareInfoContainer()); + } + + @Test(dataProvider = "data_allInstances", + expectedExceptions = {UnmarshalException.class}, + expectedExceptionsMessageRegExp = "Expected info level [0-9]+, got: 2139062143") + public void test_unmarshalEntity_levelMismatch1(ShareEnumStruct struct) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[]{127, 127, 127, 127}); + PacketInput in = new PacketInput(bin); + struct.unmarshalEntity(in); + } + + @Test(dataProvider = "data_allInstances", + expectedExceptions = {UnmarshalException.class}, + expectedExceptionsMessageRegExp = "Expected info level [0-9]+ to match enum level, got: 2139062143") + public void test_unmarshalEntity_levelMismatch2(ShareEnumStruct struct) throws IOException { + ByteBuffer buff = ByteBuffer.allocate(8); + buff.order(ByteOrder.LITTLE_ENDIAN); + buff.putInt(struct.getLevel().getInfoLevel()); + buff.putInt(2139062143); + ByteArrayInputStream bin = new ByteArrayInputStream(buff.array()); + PacketInput in = new PacketInput(bin); + struct.unmarshalEntity(in); + } + + @DataProvider + public Object[][] data_unmarshalDeferrals() { + return new Object[][] { + {mock(ShareInfoContainer.class), true}, + {null, false} + }; + } + + @Test(dataProvider = "data_unmarshalDeferrals") + public void test_unmarshalDeferrals(ShareInfoContainer container, boolean expectUnmarshall) throws IOException { + final MutableBoolean unmarshallCalled = new MutableBoolean(false); + PacketInput in = mock(PacketInput.class); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocationOnMock) { + unmarshallCalled.setTrue(); + return null; + } + }).when(in).readUnmarshallable(container); + + ShareEnumStruct struct = mock(ShareEnumStruct.class); + when(struct.getShareInfoContainer()).thenReturn(container); + doCallRealMethod().when(struct).unmarshalDeferrals(in); + struct.unmarshalDeferrals(in); + assertEquals(unmarshallCalled.booleanValue(), expectUnmarshall); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo0.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo0.java new file mode 100644 index 00000000..72be5aeb --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo0.java @@ -0,0 +1,155 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.bouncycastle.util.encoders.Hex; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.objects.WChar; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_ShareInfo0 { + + @Test + public void test_getters() { + ShareInfo0 obj = new ShareInfo0(); + assertNull(obj.getNetName()); + } + + @Test + public void test_setters() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + ShareInfo0 obj = new ShareInfo0(); + obj.setNetName(netName); + assertSame(obj.getNetName(), netName); + } + + @Test + public void test_hashCode() { + ShareInfo0 obj1 = new ShareInfo0(); + ShareInfo0 obj2 = new ShareInfo0(); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + } + + @Test + public void test_equals() { + ShareInfo0 obj1 = new ShareInfo0(); + ShareInfo0 obj2 = new ShareInfo0(); + assertEquals(obj1, obj2); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test123"); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1, obj2); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1, obj2); + } + + @Test + public void test_toString_default() { + assertEquals(new ShareInfo0().toString(), "SHARE_INFO_0{shi0_netname: null}"); + } + + @Test + public void test_toString() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + ShareInfo0 obj = new ShareInfo0(); + obj.setNetName(netName); + assertEquals(obj.toString(), "SHARE_INFO_0{shi0_netname: \"NetName\"}"); + } + + @Test + public void test_unmarshalPreamble() throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + + ShareInfo0 obj = new ShareInfo0(); + obj.unmarshalPreamble(in); + assertEquals(bin.available(), 0); + assertNull(obj.getNetName()); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + // NetName[pointer=0] + {"00000000", 0, null}, + // NetName[pointer=2] + {"02000000", 0, ""}, + // Alignments + {"00000000 00000002", 1, ""}, + {"00000000 00000002", 2, ""}, + {"00000000 00000002", 3, ""} + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, int mark, String expectNetName) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + in.fullySkipBytes(mark); + + ShareInfo0 obj = new ShareInfo0(); + obj.unmarshalEntity(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + } + + @DataProvider + public Object[][] data_unmarshalDeferrals() { + return new Object[][] { + // null + {"", 0, null}, + // NetName[MaximumCount=9, Offset=0, ActualCount=9] + {"09000000000000000900000074006500730074009f013100320033000000", 0, "testƟ123"}, + // Alignments + {"00000000 09000000000000000900000074006500730074009f013100320033000000", 1, "testƟ123"}, + {"00000000 09000000000000000900000074006500730074009f013100320033000000", 2, "testƟ123"}, + {"00000000 09000000000000000900000074006500730074009f013100320033000000", 3, "testƟ123"}, + }; + } + + @Test(dataProvider = "data_unmarshalDeferrals") + public void test_unmarshalDeferrals(String hex, int mark, String expectNetName) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + in.fullySkipBytes(mark); + + ShareInfo0 obj = new ShareInfo0(); + if (expectNetName != null) + obj.setNetName(new WChar.NullTerminated()); + obj.unmarshalDeferrals(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo1.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo1.java new file mode 100644 index 00000000..b7586c1b --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo1.java @@ -0,0 +1,187 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.bouncycastle.util.encoders.Hex; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.objects.WChar; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_ShareInfo1 { + + @Test + public void test_getters() { + ShareInfo1 obj = new ShareInfo1(); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + } + + @Test + public void test_setters() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + ShareInfo1 obj = new ShareInfo1(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + } + + @Test + public void test_hashCode() { + ShareInfo1 obj1 = new ShareInfo1(); + ShareInfo1 obj2 = new ShareInfo1(); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setType(25); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setType(25); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + } + + @Test + public void test_equals() { + ShareInfo1 obj1 = new ShareInfo1(); + ShareInfo1 obj2 = new ShareInfo1(); + assertEquals(obj1, obj2); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test123"); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1, obj2); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1, obj2); + obj1.setType(25); + assertNotEquals(obj1, obj2); + obj2.setType(25); + assertEquals(obj1, obj2); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1, obj2); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1, obj2); + } + + @Test + public void test_toString_default() { + assertEquals(new ShareInfo1().toString(), "SHARE_INFO_1{shi1_netname: null, shi1_type: 0, shi1_remark: null}"); + } + + @Test + public void test_toString() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + ShareInfo1 obj = new ShareInfo1(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + assertEquals(obj.toString(), "SHARE_INFO_1{shi1_netname: \"NetName\", shi1_type: 25, shi1_remark: \"Remark\"}"); + } + + @Test + public void test_unmarshalPreamble() throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + + ShareInfo1 obj = new ShareInfo1(); + obj.unmarshalPreamble(in); + assertEquals(bin.available(), 0); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + // NetName[pointer=0], Type=25, Remark[pointer=0] + {"00000000 19000000 00000000", null, 25, null}, + // NetName[pointer=2], Type=25, Remark[pointer=4] + {"02000000 19000000 04000000", "", 25, ""}, + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, String expectNetName, + int expectType, String expectRemark) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo1 obj = new ShareInfo1(); + obj.unmarshalEntity(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), expectType); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + } + + @DataProvider + public Object[][] data_unmarshalDeferrals() { + return new Object[][] { + // Null + {"", null, null}, + { + // NetName[MaximumCount=9, Offset=0, ActualCount=9, data=testƟ123] + "09000000000000000900000074006500730074009f013100320033000000" + + // Alignment + "0000" + + // Remark[MaximumCount=8, Offset=0, ActualCount=8, data=testƟ12] + "08000000000000000800000074006500730074009f01310032000000", + "testƟ123", "testƟ12" + }, + }; + } + + @Test(dataProvider = "data_unmarshalDeferrals") + public void test_unmarshalDeferrals(String hex, String expectNetName, String expectRemark) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo1 obj = new ShareInfo1(); + if (expectNetName != null) + obj.setNetName(new WChar.NullTerminated()); + obj.setType(25); + if (expectRemark != null) + obj.setRemark(new WChar.NullTerminated()); + obj.unmarshalDeferrals(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), 25); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo2.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo2.java new file mode 100644 index 00000000..8cdebc0d --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo2.java @@ -0,0 +1,293 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.bouncycastle.util.encoders.Hex; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.objects.WChar; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_ShareInfo2 { + + @Test + public void test_getters() { + ShareInfo2 obj = new ShareInfo2(); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 0); + assertEquals(obj.getMaxUses(), 0); + assertEquals(obj.getCurrentUses(), 0); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + } + + @Test + public void test_setters() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + WChar.NullTerminated path = WChar.NullTerminated.of("Path"); + WChar.NullTerminated passwd = WChar.NullTerminated.of("Passwd"); + ShareInfo2 obj = new ShareInfo2(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + obj.setPath(path); + obj.setPasswd(passwd); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertSame(obj.getPath(), path); + assertSame(obj.getPasswd(), passwd); + } + + @Test + public void test_hashCode() { + ShareInfo2 obj1 = new ShareInfo2(); + ShareInfo2 obj2 = new ShareInfo2(); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setType(25); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setType(25); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPermissions(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPermissions(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setMaxUses(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setMaxUses(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setCurrentUses(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setCurrentUses(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPath(WChar.NullTerminated.of("Path")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPath(WChar.NullTerminated.of("Path")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPasswd(WChar.NullTerminated.of("Passwd")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPasswd(WChar.NullTerminated.of("Passwd")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + } + + @Test + public void test_equals() { + ShareInfo2 obj1 = new ShareInfo2(); + ShareInfo2 obj2 = new ShareInfo2(); + assertEquals(obj1, obj2); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1, obj2); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1, obj2); + obj1.setType(25); + assertNotEquals(obj1, obj2); + obj2.setType(25); + assertEquals(obj1, obj2); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1, obj2); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1, obj2); + obj1.setPermissions(30); + assertNotEquals(obj1, obj2); + obj2.setPermissions(30); + assertEquals(obj1, obj2); + obj1.setMaxUses(30); + assertNotEquals(obj1, obj2); + obj2.setMaxUses(30); + assertEquals(obj1, obj2); + obj1.setCurrentUses(30); + assertNotEquals(obj1, obj2); + obj2.setCurrentUses(30); + assertEquals(obj1, obj2); + obj1.setPath(WChar.NullTerminated.of("Path")); + assertNotEquals(obj1, obj2); + obj2.setPath(WChar.NullTerminated.of("Path")); + assertEquals(obj1, obj2); + obj1.setPasswd(WChar.NullTerminated.of("Passwd")); + assertNotEquals(obj1, obj2); + obj2.setPasswd(WChar.NullTerminated.of("Passwd")); + assertEquals(obj1, obj2); + } + + @Test + public void test_toString_default() { + assertEquals(new ShareInfo2().toString(), "SHARE_INFO_2{shi2_netname: null, shi2_type: 0, shi2_remark: null, shi2_permissions: 0, shi2_max_uses: 0, shi2_current_uses: 0, shi2_path: null, shi2_passwd: null}"); + } + + @Test + public void test_toString() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + WChar.NullTerminated path = WChar.NullTerminated.of("Path"); + WChar.NullTerminated passwd = WChar.NullTerminated.of("Passwd"); + ShareInfo2 obj = new ShareInfo2(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + obj.setPath(path); + obj.setPasswd(passwd); + assertEquals(obj.toString(), "SHARE_INFO_2{shi2_netname: \"NetName\", shi2_type: 25, shi2_remark: \"Remark\", shi2_permissions: 30, shi2_max_uses: 35, shi2_current_uses: 40, shi2_path: \"Path\", shi2_passwd: \"Passwd\"}"); + } + + @Test + public void test_unmarshalPreamble() throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + + ShareInfo2 obj = new ShareInfo2(); + obj.unmarshalPreamble(in); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 0); + assertEquals(obj.getMaxUses(), 0); + assertEquals(obj.getCurrentUses(), 0); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + { + // NetName[pointer=0], Type=25, Remark[pointer=0] + "00000000 19000000 00000000" + + // Permissions=30, MaxUses=35, CurrentUses=40 + "1E000000 23000000 28000000" + + // Path=[pointer=0], Passwd=[pointer=0] + "00000000 00000000", + null, 25, null, 30, 35, 40, null, null + }, + { + // NetName[pointer=2], Type=25, Remark[pointer=4] + "02000000 19000000 04000000" + + // Permissions=30, MaxUses=35, CurrentUses=40 + "1E000000 23000000 28000000" + + // Path=[pointer=6], Passwd=[pointer=8] + "06000000 08000000", + "", 25, "", 30, 35, 40, "", "" + }, + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, String expectNetName, + int expectType, String expectRemark, int expectPermissions, + int expectMaxUses, int expectCurrentUses, String expectPath, + String expectPasswd) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo2 obj = new ShareInfo2(); + obj.unmarshalEntity(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), expectType); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getPermissions(), expectPermissions); + assertEquals(obj.getMaxUses(), expectMaxUses); + assertEquals(obj.getCurrentUses(), expectCurrentUses); + assertEquals(obj.getPath(), (expectPath == null ? null : WChar.NullTerminated.of(expectPath))); + assertEquals(obj.getPasswd(), (expectPasswd == null ? null : WChar.NullTerminated.of(expectPasswd))); + } + + @DataProvider + public Object[][] data_unmarshalDeferrals() { + return new Object[][] { + // Null + {"", null, null, null, null}, + { + // NetName[MaximumCount=9, Offset=0, ActualCount=9, data=testƟ123] + "09000000000000000900000074006500730074009f013100320033000000" + + // Alignment + "0000" + + // Remark[MaximumCount=8, Offset=0, ActualCount=8, data=testƟ12] + "08000000000000000800000074006500730074009f01310032000000" + + // Path[MaximumCount=7, Offset=0, ActualCount=7, data=testƟ1] + "07000000000000000700000074006500730074009f0131000000" + + // Alignment + "0000" + + // Passwd[MaximumCount=6, Offset=0, ActualCount=6, data=testƟ] + "06000000000000000600000074006500730074009f010000", + "testƟ123", "testƟ12", "testƟ1", "testƟ" + }, + }; + } + + @Test(dataProvider = "data_unmarshalDeferrals") + public void test_unmarshalDeferrals(String hex, String expectNetName, String expectRemark, + String expectPath, String expectPasswd) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo2 obj = new ShareInfo2(); + if (expectNetName != null) + obj.setNetName(new WChar.NullTerminated()); + obj.setType(25); + if (expectRemark != null) + obj.setRemark(new WChar.NullTerminated()); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + if (expectPath != null) + obj.setPath(new WChar.NullTerminated()); + if (expectPasswd != null) + obj.setPasswd(new WChar.NullTerminated()); + obj.unmarshalDeferrals(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), 25); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertEquals(obj.getPath(), (expectPath == null ? null : WChar.NullTerminated.of(expectPath))); + assertEquals(obj.getPasswd(), (expectPasswd == null ? null : WChar.NullTerminated.of(expectPasswd))); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo501.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo501.java new file mode 100644 index 00000000..3437fc6c --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo501.java @@ -0,0 +1,203 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.bouncycastle.util.encoders.Hex; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.objects.WChar; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_ShareInfo501 { + + @Test + public void test_getters() { + ShareInfo501 obj = new ShareInfo501(); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getFlags(), 0); + } + + @Test + public void test_setters() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + ShareInfo501 obj = new ShareInfo501(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setFlags(30); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getFlags(), 30); + } + + @Test + public void test_hashCode() { + ShareInfo501 obj1 = new ShareInfo501(); + ShareInfo501 obj2 = new ShareInfo501(); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setType(25); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setType(25); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setFlags(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setFlags(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + } + + @Test + public void test_equals() { + ShareInfo501 obj1 = new ShareInfo501(); + ShareInfo501 obj2 = new ShareInfo501(); + assertEquals(obj1, obj2); + assertNotEquals(obj1, null); + assertNotEquals(obj1, "test123"); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1, obj2); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1, obj2); + obj1.setType(25); + assertNotEquals(obj1, obj2); + obj2.setType(25); + assertEquals(obj1, obj2); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1, obj2); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1, obj2); + obj1.setFlags(30); + assertNotEquals(obj1, obj2); + obj2.setFlags(30); + assertEquals(obj1, obj2); + } + + @Test + public void test_toString_default() { + assertEquals(new ShareInfo501().toString(), "SHARE_INFO_501{shi501_netname: null, shi501_type: 0, shi501_remark: null, shi501_flags: 0}"); + } + + @Test + public void test_toString() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + ShareInfo501 obj = new ShareInfo501(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setFlags(30); + assertEquals(obj.toString(), "SHARE_INFO_501{shi501_netname: \"NetName\", shi501_type: 25, shi501_remark: \"Remark\", shi501_flags: 30}"); + } + + @Test + public void test_unmarshalPreamble() throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + + ShareInfo501 obj = new ShareInfo501(); + obj.unmarshalPreamble(in); + assertEquals(bin.available(), 0); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getFlags(), 0); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + // NetName[pointer=0], Type=25, Remark[pointer=0], Flags=30 + {"00000000 19000000 00000000 1E000000", null, 25, null}, + // NetName[pointer=2], Type=25, Remark[pointer=4], Flags=30 + {"02000000 19000000 04000000 1E000000", "", 25, ""}, + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, String expectNetName, + int expectType, String expectRemark) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo501 obj = new ShareInfo501(); + obj.unmarshalEntity(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), expectType); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getFlags(), 30); + } + + @DataProvider + public Object[][] data_unmarshalDeferrals() { + return new Object[][] { + // Null + {"", null, null}, + { + // NetName[MaximumCount=9, Offset=0, ActualCount=9, data=testƟ123] + "09000000000000000900000074006500730074009f013100320033000000" + + // Alignment + "0000" + + // Remark[MaximumCount=8, Offset=0, ActualCount=8, data=testƟ12] + "08000000000000000800000074006500730074009f01310032000000", + "testƟ123", "testƟ12" + }, + }; + } + + @Test(dataProvider = "data_unmarshalDeferrals") + public void test_unmarshalDeferrals(String hex, String expectNetName, String expectRemark) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo501 obj = new ShareInfo501(); + if (expectNetName != null) + obj.setNetName(new WChar.NullTerminated()); + obj.setType(25); + if (expectRemark != null) + obj.setRemark(new WChar.NullTerminated()); + obj.setFlags(30); + obj.unmarshalDeferrals(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), 25); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getFlags(), 30); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo502.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo502.java new file mode 100644 index 00000000..aab39e1d --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo502.java @@ -0,0 +1,317 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.bouncycastle.util.encoders.Hex; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.objects.WChar; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_ShareInfo502 { + + @Test + public void test_getters() { + ShareInfo502 obj = new ShareInfo502(); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 0); + assertEquals(obj.getMaxUses(), 0); + assertEquals(obj.getCurrentUses(), 0); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + assertNull(obj.getSecurityDescriptor()); + } + + @Test + public void test_setters() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + WChar.NullTerminated path = WChar.NullTerminated.of("Path"); + WChar.NullTerminated passwd = WChar.NullTerminated.of("Passwd"); + byte[] securityDescriptor = new byte[2]; + ShareInfo502 obj = new ShareInfo502(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + obj.setPath(path); + obj.setPasswd(passwd); + obj.setSecurityDescriptor(securityDescriptor); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertSame(obj.getPath(), path); + assertSame(obj.getPasswd(), passwd); + assertSame(obj.getSecurityDescriptor(), securityDescriptor); + } + + @Test + public void test_hashCode() { + ShareInfo502 obj1 = new ShareInfo502(); + ShareInfo502 obj2 = new ShareInfo502(); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setType(25); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setType(25); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPermissions(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPermissions(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setMaxUses(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setMaxUses(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setCurrentUses(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setCurrentUses(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPath(WChar.NullTerminated.of("Path")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPath(WChar.NullTerminated.of("Path")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPasswd(WChar.NullTerminated.of("Passwd")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPasswd(WChar.NullTerminated.of("Passwd")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setSecurityDescriptor(new byte[]{1, 2}); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setSecurityDescriptor(new byte[]{1, 2}); + assertEquals(obj1.hashCode(), obj2.hashCode()); + } + + @Test + public void test_equals() { + ShareInfo502 obj1 = new ShareInfo502(); + ShareInfo502 obj2 = new ShareInfo502(); + assertEquals(obj1, obj2); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1, obj2); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1, obj2); + obj1.setType(25); + assertNotEquals(obj1, obj2); + obj2.setType(25); + assertEquals(obj1, obj2); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1, obj2); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1, obj2); + obj1.setPermissions(30); + assertNotEquals(obj1, obj2); + obj2.setPermissions(30); + assertEquals(obj1, obj2); + obj1.setMaxUses(30); + assertNotEquals(obj1, obj2); + obj2.setMaxUses(30); + assertEquals(obj1, obj2); + obj1.setCurrentUses(30); + assertNotEquals(obj1, obj2); + obj2.setCurrentUses(30); + assertEquals(obj1, obj2); + obj1.setPath(WChar.NullTerminated.of("Path")); + assertNotEquals(obj1, obj2); + obj2.setPath(WChar.NullTerminated.of("Path")); + assertEquals(obj1, obj2); + obj1.setPasswd(WChar.NullTerminated.of("Passwd")); + assertNotEquals(obj1, obj2); + obj2.setPasswd(WChar.NullTerminated.of("Passwd")); + assertEquals(obj1, obj2); + obj1.setSecurityDescriptor(new byte[]{1, 2}); + assertNotEquals(obj1, obj2); + obj2.setSecurityDescriptor(new byte[]{1, 2}); + assertEquals(obj1, obj2); + } + + @Test + public void test_toString_default() { + assertEquals(new ShareInfo502().toString(), "SHARE_INFO_502{shi502_netname: null, shi502_type: 0, shi502_remark: null, shi502_permissions: 0, shi502_max_uses: 0, shi502_current_uses: 0, shi502_path: null, shi502_passwd: null, size(shi502_security_descriptor): null}"); + } + + @Test + public void test_toString() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + WChar.NullTerminated path = WChar.NullTerminated.of("Path"); + WChar.NullTerminated passwd = WChar.NullTerminated.of("Passwd"); + ShareInfo502 obj = new ShareInfo502(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + obj.setPath(path); + obj.setPasswd(passwd); + obj.setSecurityDescriptor(new byte[2]); + assertEquals(obj.toString(), "SHARE_INFO_502{shi502_netname: \"NetName\", shi502_type: 25, shi502_remark: \"Remark\", shi502_permissions: 30, shi502_max_uses: 35, shi502_current_uses: 40, shi502_path: \"Path\", shi502_passwd: \"Passwd\", size(shi502_security_descriptor): 2}"); + } + + @Test + public void test_unmarshalPreamble() throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + + ShareInfo502 obj = new ShareInfo502(); + obj.unmarshalPreamble(in); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 0); + assertEquals(obj.getMaxUses(), 0); + assertEquals(obj.getCurrentUses(), 0); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + assertNull(obj.getSecurityDescriptor()); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + { + // NetName[pointer=0], Type=25, Remark[pointer=0] + "00000000 19000000 00000000" + + // Permissions=30, MaxUses=35, CurrentUses=40 + "1E000000 23000000 28000000" + + // Path=[pointer=0], Passwd=[pointer=0] + "00000000 00000000" + + // Reserved=2, SecurityDescriptor[pointer=0] + "02000000 00000000", + null, 25, null, 30, 35, 40, null, null, null, + }, + { + // NetName[pointer=2], Type=25, Remark[pointer=4] + "02000000 19000000 04000000" + + // Permissions=30, MaxUses=35, CurrentUses=40 + "1E000000 23000000 28000000" + + // Path=[pointer=6], Passwd=[pointer=8] + "06000000 08000000" + + // Reserved=2, SecurityDescriptor[pointer=10] + "02000000 0A000000", + "", 25, "", 30, 35, 40, "", "", new byte[2] + }, + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, String expectNetName, + int expectType, String expectRemark, int expectPermissions, + int expectMaxUses, int expectCurrentUses, String expectPath, + String expectPasswd, byte[] expectSecurityDescriptor) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo502 obj = new ShareInfo502(); + obj.unmarshalEntity(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), expectType); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getPermissions(), expectPermissions); + assertEquals(obj.getMaxUses(), expectMaxUses); + assertEquals(obj.getCurrentUses(), expectCurrentUses); + assertEquals(obj.getPath(), (expectPath == null ? null : WChar.NullTerminated.of(expectPath))); + assertEquals(obj.getPasswd(), (expectPasswd == null ? null : WChar.NullTerminated.of(expectPasswd))); + assertEquals(obj.getSecurityDescriptor(), expectSecurityDescriptor); + } + + @DataProvider + public Object[][] data_unmarshalDeferrals() { + return new Object[][] { + // Null + {"", null, null, null, null, null}, + { + // NetName[MaximumCount=9, Offset=0, ActualCount=9, data=testƟ123] + "09000000000000000900000074006500730074009f013100320033000000" + + // Alignment + "0000" + + // Remark[MaximumCount=8, Offset=0, ActualCount=8, data=testƟ12] + "08000000000000000800000074006500730074009f01310032000000" + + // Path[MaximumCount=7, Offset=0, ActualCount=7, data=testƟ1] + "07000000000000000700000074006500730074009f0131000000" + + // Alignment + "0000" + + // Passwd[MaximumCount=6, Offset=0, ActualCount=6, data=testƟ] + "06000000000000000600000074006500730074009f010000" + + // SecurityDescriptr[MaxCount=10, data={1, 2}] + "0A0000000102", + "testƟ123", "testƟ12", "testƟ1", "testƟ", new byte[]{1,2} + }, + }; + } + + @Test(dataProvider = "data_unmarshalDeferrals") + public void test_unmarshalDeferrals(String hex, String expectNetName, String expectRemark, + String expectPath, String expectPasswd, byte[] expectSecurityDescriptor) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo502 obj = new ShareInfo502(); + if (expectNetName != null) + obj.setNetName(new WChar.NullTerminated()); + obj.setType(25); + if (expectRemark != null) + obj.setRemark(new WChar.NullTerminated()); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + if (expectPath != null) + obj.setPath(new WChar.NullTerminated()); + if (expectPasswd != null) + obj.setPasswd(new WChar.NullTerminated()); + if (expectSecurityDescriptor != null) + obj.setSecurityDescriptor(new byte[expectSecurityDescriptor.length]); + obj.unmarshalDeferrals(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), 25); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertEquals(obj.getPath(), (expectPath == null ? null : WChar.NullTerminated.of(expectPath))); + assertEquals(obj.getPasswd(), (expectPasswd == null ? null : WChar.NullTerminated.of(expectPasswd))); + assertEquals(obj.getSecurityDescriptor(), expectSecurityDescriptor); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo503.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo503.java new file mode 100644 index 00000000..102eea73 --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfo503.java @@ -0,0 +1,344 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.bouncycastle.util.encoders.Hex; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import com.rapid7.client.dcerpc.io.PacketInput; +import com.rapid7.client.dcerpc.objects.WChar; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; + +public class Test_ShareInfo503 { + + @Test + public void test_getters() { + ShareInfo503 obj = new ShareInfo503(); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 0); + assertEquals(obj.getMaxUses(), 0); + assertEquals(obj.getCurrentUses(), 0); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + assertNull(obj.getServerName()); + assertNull(obj.getSecurityDescriptor()); + } + + @Test + public void test_setters() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + WChar.NullTerminated path = WChar.NullTerminated.of("Path"); + WChar.NullTerminated passwd = WChar.NullTerminated.of("Passwd"); + WChar.NullTerminated serverName = WChar.NullTerminated.of("ServerName"); + byte[] securityDescriptor = new byte[2]; + ShareInfo503 obj = new ShareInfo503(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + obj.setPath(path); + obj.setPasswd(passwd); + obj.setServerName(serverName); + obj.setSecurityDescriptor(securityDescriptor); + assertSame(obj.getNetName(), netName); + assertEquals(obj.getType(), 25); + assertSame(obj.getRemark(), remark); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertSame(obj.getPath(), path); + assertSame(obj.getPasswd(), passwd); + assertSame(obj.getServerName(), serverName); + assertSame(obj.getSecurityDescriptor(), securityDescriptor); + } + + @Test + public void test_hashCode() { + ShareInfo503 obj1 = new ShareInfo503(); + ShareInfo503 obj2 = new ShareInfo503(); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setType(25); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setType(25); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPermissions(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPermissions(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setMaxUses(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setMaxUses(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setCurrentUses(30); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setCurrentUses(30); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPath(WChar.NullTerminated.of("Path")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPath(WChar.NullTerminated.of("Path")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setPasswd(WChar.NullTerminated.of("Passwd")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setPasswd(WChar.NullTerminated.of("Passwd")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setServerName(WChar.NullTerminated.of("ServerName")); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setServerName(WChar.NullTerminated.of("ServerName")); + assertEquals(obj1.hashCode(), obj2.hashCode()); + obj1.setSecurityDescriptor(new byte[]{1, 2}); + assertNotEquals(obj1.hashCode(), obj2.hashCode()); + obj2.setSecurityDescriptor(new byte[]{1, 2}); + assertEquals(obj1.hashCode(), obj2.hashCode()); + } + + @Test + public void test_equals() { + ShareInfo503 obj1 = new ShareInfo503(); + ShareInfo503 obj2 = new ShareInfo503(); + assertEquals(obj1, obj2); + obj1.setNetName(WChar.NullTerminated.of("NetName")); + assertNotEquals(obj1, obj2); + obj2.setNetName(WChar.NullTerminated.of("NetName")); + assertEquals(obj1, obj2); + obj1.setType(25); + assertNotEquals(obj1, obj2); + obj2.setType(25); + assertEquals(obj1, obj2); + obj1.setRemark(WChar.NullTerminated.of("Remark")); + assertNotEquals(obj1, obj2); + obj2.setRemark(WChar.NullTerminated.of("Remark")); + assertEquals(obj1, obj2); + obj1.setPermissions(30); + assertNotEquals(obj1, obj2); + obj2.setPermissions(30); + assertEquals(obj1, obj2); + obj1.setMaxUses(30); + assertNotEquals(obj1, obj2); + obj2.setMaxUses(30); + assertEquals(obj1, obj2); + obj1.setCurrentUses(30); + assertNotEquals(obj1, obj2); + obj2.setCurrentUses(30); + assertEquals(obj1, obj2); + obj1.setPath(WChar.NullTerminated.of("Path")); + assertNotEquals(obj1, obj2); + obj2.setPath(WChar.NullTerminated.of("Path")); + assertEquals(obj1, obj2); + obj1.setPasswd(WChar.NullTerminated.of("Passwd")); + assertNotEquals(obj1, obj2); + obj2.setPasswd(WChar.NullTerminated.of("Passwd")); + assertEquals(obj1, obj2); + obj1.setServerName(WChar.NullTerminated.of("ServerName")); + assertNotEquals(obj1, obj2); + obj2.setServerName(WChar.NullTerminated.of("ServerName")); + assertEquals(obj1, obj2); + obj1.setSecurityDescriptor(new byte[]{1, 2}); + assertNotEquals(obj1, obj2); + obj2.setSecurityDescriptor(new byte[]{1, 2}); + assertEquals(obj1, obj2); + } + + @Test + public void test_toString_default() { + assertEquals(new ShareInfo503().toString(), "SHARE_INFO_503{shi503_netname: null, shi503_type: 0, shi503_remark: null, shi503_permissions: 0, shi503_max_uses: 0, shi503_current_uses: 0, shi503_path: null, shi503_passwd: null, shi503_server_name: null, size(shi503_security_descriptor): null}"); + } + + @Test + public void test_toString() { + WChar.NullTerminated netName = WChar.NullTerminated.of("NetName"); + WChar.NullTerminated remark = WChar.NullTerminated.of("Remark"); + WChar.NullTerminated path = WChar.NullTerminated.of("Path"); + WChar.NullTerminated passwd = WChar.NullTerminated.of("Passwd"); + WChar.NullTerminated serverName = WChar.NullTerminated.of("ServerName"); + ShareInfo503 obj = new ShareInfo503(); + obj.setNetName(netName); + obj.setType(25); + obj.setRemark(remark); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + obj.setPath(path); + obj.setPasswd(passwd); + obj.setServerName(serverName); + obj.setSecurityDescriptor(new byte[2]); + assertEquals(obj.toString(), "SHARE_INFO_503{shi503_netname: \"NetName\", shi503_type: 25, shi503_remark: \"Remark\", shi503_permissions: 30, shi503_max_uses: 35, shi503_current_uses: 40, shi503_path: \"Path\", shi503_passwd: \"Passwd\", shi503_server_name: \"ServerName\", size(shi503_security_descriptor): 2}"); + } + + @Test + public void test_unmarshalPreamble() throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + + ShareInfo503 obj = new ShareInfo503(); + obj.unmarshalPreamble(in); + assertNull(obj.getNetName()); + assertEquals(obj.getType(), 0); + assertNull(obj.getRemark()); + assertEquals(obj.getPermissions(), 0); + assertEquals(obj.getMaxUses(), 0); + assertEquals(obj.getCurrentUses(), 0); + assertNull(obj.getPath()); + assertNull(obj.getPasswd()); + assertNull(obj.getServerName()); + assertNull(obj.getSecurityDescriptor()); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + { + // NetName[pointer=0], Type=25, Remark[pointer=0] + "00000000 19000000 00000000" + + // Permissions=30, MaxUses=35, CurrentUses=40 + "1E000000 23000000 28000000" + + // Path=[pointer=0], Passwd=[pointer=0] + "00000000 00000000" + + // ServerName=[pointer=0] + "00000000" + + // Reserved=2, SecurityDescriptor[pointer=0] + "02000000 00000000", + null, 25, null, 30, 35, 40, null, null, null, null + }, + { + // NetName[pointer=2], Type=25, Remark[pointer=4] + "02000000 19000000 04000000" + + // Permissions=30, MaxUses=35, CurrentUses=40 + "1E000000 23000000 28000000" + + // Path=[pointer=6], Passwd=[pointer=8] + "06000000 08000000" + + // ServerName=[pointer=11] + "0B000000" + + // Reserved=2, SecurityDescriptor[pointer=10] + "02000000 0A000000", + "", 25, "", 30, 35, 40, "", "", "", new byte[2] + }, + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, String expectNetName, + int expectType, String expectRemark, int expectPermissions, + int expectMaxUses, int expectCurrentUses, String expectPath, + String expectPasswd, String expectServerName, byte[] expectSecurityDescriptor) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo503 obj = new ShareInfo503(); + obj.unmarshalEntity(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), expectType); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getPermissions(), expectPermissions); + assertEquals(obj.getMaxUses(), expectMaxUses); + assertEquals(obj.getCurrentUses(), expectCurrentUses); + assertEquals(obj.getPath(), (expectPath == null ? null : WChar.NullTerminated.of(expectPath))); + assertEquals(obj.getPasswd(), (expectPasswd == null ? null : WChar.NullTerminated.of(expectPasswd))); + assertEquals(obj.getServerName(), (expectServerName == null ? null : WChar.NullTerminated.of(expectServerName))); + assertEquals(obj.getSecurityDescriptor(), expectSecurityDescriptor); + } + + @DataProvider + public Object[][] data_unmarshalDeferrals() { + return new Object[][] { + // Null + {"", null, null, null, null, null, null}, + { + // NetName[MaximumCount=9, Offset=0, ActualCount=9, data=testƟ123] + "09000000000000000900000074006500730074009f013100320033000000" + + // Alignment + "0000" + + // Remark[MaximumCount=8, Offset=0, ActualCount=8, data=testƟ12] + "08000000000000000800000074006500730074009f01310032000000" + + // Path[MaximumCount=7, Offset=0, ActualCount=7, data=testƟ1] + "07000000000000000700000074006500730074009f0131000000" + + // Alignment + "0000" + + // Passwd[MaximumCount=6, Offset=0, ActualCount=6, data=testƟ] + "06000000000000000600000074006500730074009f010000" + + // Server[MaximumCount=5, Offset=0, ActualCount=5, data=test] + "05000000000000000500000074006500730074000000" + + // Alignment + "0000" + + // SecurityDescriptr[MaxCount=10, data={1, 2}] + "0A0000000102", + "testƟ123", "testƟ12", "testƟ1", "testƟ", "test", new byte[]{1,2} + }, + }; + } + + @Test(dataProvider = "data_unmarshalDeferrals") + public void test_unmarshalDeferrals(String hex, String expectNetName, String expectRemark, + String expectPath, String expectPasswd, String expectServerName, byte[] expectSecurityDescriptor) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + ShareInfo503 obj = new ShareInfo503(); + if (expectNetName != null) + obj.setNetName(new WChar.NullTerminated()); + obj.setType(25); + if (expectRemark != null) + obj.setRemark(new WChar.NullTerminated()); + obj.setPermissions(30); + obj.setMaxUses(35); + obj.setCurrentUses(40); + if (expectPath != null) + obj.setPath(new WChar.NullTerminated()); + if (expectPasswd != null) + obj.setPasswd(new WChar.NullTerminated()); + if (expectServerName != null) + obj.setServerName(new WChar.NullTerminated()); + if (expectSecurityDescriptor != null) + obj.setSecurityDescriptor(new byte[expectSecurityDescriptor.length]); + obj.unmarshalDeferrals(in); + assertEquals(bin.available(), 0); + assertEquals(obj.getNetName(), (expectNetName == null ? null : WChar.NullTerminated.of(expectNetName))); + assertEquals(obj.getType(), 25); + assertEquals(obj.getRemark(), (expectRemark == null ? null : WChar.NullTerminated.of(expectRemark))); + assertEquals(obj.getPermissions(), 30); + assertEquals(obj.getMaxUses(), 35); + assertEquals(obj.getCurrentUses(), 40); + assertEquals(obj.getPath(), (expectPath == null ? null : WChar.NullTerminated.of(expectPath))); + assertEquals(obj.getPasswd(), (expectPasswd == null ? null : WChar.NullTerminated.of(expectPasswd))); + assertEquals(obj.getServerName(), (expectServerName == null ? null : WChar.NullTerminated.of(expectServerName))); + assertEquals(obj.getSecurityDescriptor(), expectSecurityDescriptor); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfoContainer.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfoContainer.java new file mode 100644 index 00000000..0daf3964 --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfoContainer.java @@ -0,0 +1,84 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.bouncycastle.util.encoders.Hex; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import com.rapid7.client.dcerpc.io.PacketInput; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +public class Test_ShareInfoContainer { + + @DataProvider + public Object[][] data_allInstances() { + return new Object[][] { + {new ShareInfoContainer.ShareInfo0Container()}, + {new ShareInfoContainer.ShareInfo1Container()}, + {new ShareInfoContainer.ShareInfo2Container()}, + {new ShareInfoContainer.ShareInfo501Container()}, + {new ShareInfoContainer.ShareInfo502Container()}, + {new ShareInfoContainer.ShareInfo503Container()}, + }; + } + + @Test(dataProvider = "data_allInstances") + public void test_unmarshalPreamble(ShareInfoContainer container) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(new byte[0]); + PacketInput in = new PacketInput(bin); + container.unmarshalPreamble(in); + assertEquals(bin.available(), 0); + assertNull(container.getBuffer()); + } + + @DataProvider + public Object[][] data_unmarshalEntity() { + return new Object[][] { + {"05000000 02000000", new ShareInfoContainer.ShareInfo0Container(), new ShareInfo0[5]}, + {"05000000 00000000", new ShareInfoContainer.ShareInfo0Container(), null}, + {"05000000 02000000", new ShareInfoContainer.ShareInfo1Container(), new ShareInfo1[5]}, + {"05000000 00000000", new ShareInfoContainer.ShareInfo1Container(), null}, + {"05000000 02000000", new ShareInfoContainer.ShareInfo2Container(), new ShareInfo2[5]}, + {"05000000 00000000", new ShareInfoContainer.ShareInfo2Container(), null}, + {"05000000 02000000", new ShareInfoContainer.ShareInfo501Container(), new ShareInfo501[5]}, + {"05000000 00000000", new ShareInfoContainer.ShareInfo501Container(), null}, + {"05000000 02000000", new ShareInfoContainer.ShareInfo502Container(), new ShareInfo502[5]}, + {"05000000 00000000", new ShareInfoContainer.ShareInfo502Container(), null}, + {"05000000 02000000", new ShareInfoContainer.ShareInfo503Container(), new ShareInfo503[5]}, + {"05000000 00000000", new ShareInfoContainer.ShareInfo503Container(), null}, + }; + } + + @Test(dataProvider = "data_unmarshalEntity") + public void test_unmarshalEntity(String hex, ShareInfoContainer container, ShareInfo[] expectBuffer) throws IOException { + ByteArrayInputStream bin = new ByteArrayInputStream(Hex.decode(hex)); + PacketInput in = new PacketInput(bin); + + container.unmarshalEntity(in); + assertEquals(bin.available(), 0); + assertEquals(container.getBuffer(), expectBuffer); + } +} diff --git a/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfoLevel.java b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfoLevel.java new file mode 100644 index 00000000..7aeedc29 --- /dev/null +++ b/src/test/java/com/rapid7/client/dcerpc/mssrvs/objects/Test_ShareInfoLevel.java @@ -0,0 +1,46 @@ +/* + * Copyright 2017, Rapid7, Inc. + * + * License: BSD-3-clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + */ + +package com.rapid7.client.dcerpc.mssrvs.objects; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +public class Test_ShareInfoLevel { + @DataProvider + public Object[][] data_getInfoLevel() { + return new Object[][] { + {ShareInfoLevel.LPSHARE_INFO_0, 0}, + {ShareInfoLevel.LPSHARE_INFO_1, 1}, + {ShareInfoLevel.LPSHARE_INFO_2, 2}, + {ShareInfoLevel.LPSHARE_INFO_501, 501}, + {ShareInfoLevel.LPSHARE_INFO_502, 502}, + {ShareInfoLevel.LPSHARE_INFO_503, 503}, + }; + } + + @Test(dataProvider = "data_getInfoLevel") + public void test_getInfoLevel(ShareInfoLevel obj, int expected) { + assertEquals(obj.getInfoLevel(), expected); + } +}