Skip to content

Commit

Permalink
Adds support for NetrShareEnum and NetrShareGetInfo for all levels (#111
Browse files Browse the repository at this point in the history
)

Adds support for all levels of NetrShareEnum and NetrShareGetInfo requests.

* Adding NetrShareGetInfo request for all info levels
* Adding missing NetrShareEnum info levels
* Refactoring existing NetrShareEnum to use common classes when possible. Also conforming to new marshalling strategy
* Adding proper DTO layer for ServerService
  • Loading branch information
tosmun-r7 authored Dec 7, 2017
1 parent 50b1b16 commit 0e115ee
Show file tree
Hide file tree
Showing 48 changed files with 5,330 additions and 1,131 deletions.
348 changes: 311 additions & 37 deletions src/main/java/com/rapid7/client/dcerpc/mssrvs/ServerService.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading

0 comments on commit 0e115ee

Please sign in to comment.