Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update smbj and bouncy castle to support SMBv3 #182

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
<thirdparty.hamcrest.version>1.3</thirdparty.hamcrest.version>
<thirdparty.junit.version>5.7.2</thirdparty.junit.version>
<thirdparty.mockito.version>1.10.19</thirdparty.mockito.version>
<thirdparty.smbj.version>0.11.1</thirdparty.smbj.version>
<thirdparty.smbj.version>0.12.2</thirdparty.smbj.version>
<thirdparty.testng.version>6.11</thirdparty.testng.version>
<thirdparty.bouncycastle.version>1.68</thirdparty.bouncycastle.version>
<thirdparty.testcontainers.version>1.16.0</thirdparty.testcontainers.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -81,12 +80,6 @@
<artifactId>smbj</artifactId>
<version>${thirdparty.smbj.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${thirdparty.bouncycastle.version}</version>
</dependency>

<!-- Test dependencies. -->
<!-- 3rdparty dependencies. -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rapid7/client/dcerpc/dto/ContextHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

package com.rapid7.client.dcerpc.dto;

import com.google.common.io.BaseEncoding;
import java.util.Arrays;
import java.util.Objects;
import org.bouncycastle.util.encoders.Hex;

/**
* Represents a Windows <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa373605(v=vs.85).aspx">Context Handle</a>
Expand Down Expand Up @@ -76,7 +76,7 @@ public static ContextHandle fromHex(final String hString) {
if (hString == null || hString.length() > (bytes.length * 2)) {
throw new IllegalArgumentException("hString is invalid: " + hString);
}
final byte[] handle = Hex.decode(hString);
final byte[] handle = BaseEncoding.base16().decode(hString.toUpperCase());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it require being upper case to decode then? As we are not obviously uppercasing in the other usages

Copy link
Contributor

@pwatson-r7 pwatson-r7 Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BaseEncoding encodes and decodes using uppercase characters by default.
BaseEncoding.base16().decode

int srcPos = 0;
int index = 0;
while (index < handle.length) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/rapid7/client/dcerpc/dto/SID.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

package com.rapid7.client.dcerpc.dto;

import com.google.common.io.BaseEncoding;
import java.util.Arrays;
import java.util.Objects;
import org.bouncycastle.util.encoders.Hex;

/**
* <a href="https://msdn.microsoft.com/en-us/library/cc230371.aspx">SID</a>
Expand Down Expand Up @@ -126,7 +126,7 @@ public String toString() {
b.append(revision & 0xFF).append("-");
if (identifierAuthority[0] != (byte) 0 || identifierAuthority[1] != (byte) 0) {
b.append("0x");
b.append(Hex.toHexString(identifierAuthority));
b.append(BaseEncoding.base16().encode(identifierAuthority));
} else {
long shift = 0;
long id = 0;
Expand Down Expand Up @@ -169,7 +169,7 @@ public static SID fromString(String sidString) throws MalformedSIDStringExceptio
final byte[] identifierAuthority;
if (identifierAuthorityString.toUpperCase().startsWith("0X")) {
final String bytes = identifierAuthorityString.substring(2, identifierAuthorityString.length());
identifierAuthority = Hex.decode(bytes);
identifierAuthority = BaseEncoding.base16().decode(bytes);
} else {
final long identifierAuthorityValue = Long.parseLong(identifierAuthorityString);
identifierAuthority = new byte[] {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/rapid7/client/dcerpc/io/HexifyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package com.rapid7.client.dcerpc.io;

import com.google.common.io.BaseEncoding;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.bouncycastle.util.encoders.Hex;

public abstract class HexifyImpl implements Hexify {
@Override
Expand All @@ -30,12 +30,12 @@ public String toHexString() throws IOException {
final PacketOutput packetOut = new PacketOutput(packetOutputStream);
marshal(packetOut);
final byte[] packetOutBytes = packetOutputStream.toByteArray();
return Hex.toHexString(packetOutBytes);
return BaseEncoding.base16().lowerCase().encode(packetOutBytes);
}

@Override
public void fromHexString(final String hexIn) throws IOException {
final byte[] packetInBytes = Hex.decode(hexIn);
final byte[] packetInBytes = BaseEncoding.base16().decode(hexIn.replaceAll("\\s", "").toUpperCase());
final ByteArrayInputStream packetInputStream = new ByteArrayInputStream(packetInBytes);
final PacketInput packetIn = new PacketInput(packetInputStream);
unmarshal(packetIn);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright 2017, Rapid7, Inc.
*
* License: BSD-3-clause
Expand All @@ -20,6 +20,7 @@
*/
package com.rapid7.client.dcerpc.msrrp.dto;

import com.google.common.io.BaseEncoding;
import javax.activation.UnsupportedDataTypeException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand All @@ -31,7 +32,6 @@
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.ArrayUtils;
import org.bouncycastle.util.encoders.Hex;

public class RegistryValue {
private final String name;
Expand All @@ -58,20 +58,23 @@ public RegistryValue(final String name, final RegistryValueType type, final byte
case REG_DWORD:
case REG_DWORD_BIG_ENDIAN:
if (data.length != 4) {
throw new IOException(String.format("Data type %s is invalid with length %d: 0x%s,", type, data.length, Hex.toHexString(data).toUpperCase()));
throw new IOException(String.format("Data type %s is invalid with length %d: 0x%s,", type, data.length,
BaseEncoding.base16().encode(data)));
}
break;
case REG_QWORD:
if (data.length != 8) {
throw new IOException(String.format("Data type %s is invalid with length %d: 0x%s,", type, data.length, Hex.toHexString(data).toUpperCase()));
throw new IOException(String.format("Data type %s is invalid with length %d: 0x%s,", type, data.length,
BaseEncoding.base16().encode(data)));
}
break;
case REG_EXPAND_SZ:
case REG_LINK:
case REG_SZ:
case REG_MULTI_SZ:
if ((data.length & 1) != 0) {
throw new IOException(String.format("Data type %s is invalid with length %d: 0x%s,", type, data.length, Hex.toHexString(data).toUpperCase()));
throw new IOException(String.format("Data type %s is invalid with length %d: 0x%s,", type, data.length,
BaseEncoding.base16().encode(data)));
}
default:
}
Expand Down Expand Up @@ -132,7 +135,7 @@ public String getDataAsBinaryStr() {
}

public String getDataAsHexStr() {
return Hex.toHexString(data).toUpperCase();
return BaseEncoding.base16().encode(data);
}

public String[] getDataAsMultiStr() throws UnsupportedEncodingException {
Expand Down
Loading