Skip to content

Commit

Permalink
Merge pull request #420 from GDATASoftwareAG/fix-test-hashes-for-new-…
Browse files Browse the repository at this point in the history
…hashlookup

replace test hashes
  • Loading branch information
lennartdohmann authored Apr 8, 2024
2 parents b91d671 + 9d703e5 commit 5914f21
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 218 deletions.
26 changes: 26 additions & 0 deletions dotnet/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Vaas/test/TestFiles/bin/Debug/net8.0/TestFiles.dll",
"args": [],
"cwd": "${workspaceFolder}/Vaas/test/TestFiles",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions dotnet/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Vaas/Vaas.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Vaas/Vaas.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Vaas/Vaas.sln"
],
"problemMatcher": "$msCompile"
}
]
}
29 changes: 29 additions & 0 deletions dotnet/Vaas/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": "C# (.NET)",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm",
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csdevkit"
]
}
}
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5001],
// "portsAttributes": {
// "5001": {
// "protocol": "https"
// }
// }
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "dotnet restore",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions dotnet/Vaas/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<values>
<value name="VS.TelemetryApi.DroppedEventsDuringDisposing" type="int">0</value>
<value name="VS.TelemetryApi.TotalDisposeLatency" type="int">5</value>
<value name="VS.TelemetryApi.ChannelsDisposeLatency" type="int">1</value>
</values>
54 changes: 27 additions & 27 deletions dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ public async void FromSha256SingleMaliciousHash()
{
var vaas = await AuthenticateWithCredentials();
var verdict = await vaas.ForSha256Async(
new ChecksumSha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8"),
new ChecksumSha256("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"),
CancellationToken.None);
Assert.Equal(Verdict.Malicious, verdict.Verdict);
Assert.Equal("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8", verdict.Sha256);
Assert.Equal("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2", verdict.Sha256);
}

[Fact]
public async void FromSha256SingleCleanHash()
{
var vaas = await AuthenticateWithCredentials();
var verdict = await vaas.ForSha256Async(
new ChecksumSha256("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C"),
new ChecksumSha256("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e"),
CancellationToken.None);
Assert.Equal(Verdict.Clean, verdict.Verdict);
Assert.Equal("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C", verdict.Sha256, true);
Assert.Equal("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e", verdict.Sha256, true);
}

[Fact(Skip = "Remove Skip to test keepalive")]
Expand Down Expand Up @@ -98,18 +98,18 @@ public async void From256ListMultipleHashes()
{
var myList = new List<string>
{
"000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8",
"3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C",
"110005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe9"
"ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2",
"cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e",
"1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df"
};
var vaas = await AuthenticateWithCredentials();
var verdictList = await vaas.ForSha256ListAsync(myList, CancellationToken.None);
Assert.Equal(Verdict.Malicious, verdictList[0].Verdict);
Assert.Equal("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8", verdictList[0].Sha256, true);
Assert.Equal("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2", verdictList[0].Sha256, true);
Assert.Equal(Verdict.Clean, verdictList[1].Verdict);
Assert.Equal("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C", verdictList[1].Sha256, true);
Assert.Equal("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e", verdictList[1].Sha256, true);
Assert.Equal(Verdict.Unknown, verdictList[2].Verdict);
Assert.Equal("110005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe9", verdictList[2].Sha256, true);
Assert.Equal("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df", verdictList[2].Sha256, true);
}


Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task ForUrl_WithUrlWithStatusCode4xx_ThrowsVaasClientException()
"Call failed with status code 404 (Not Found): GET https://upload.production.vaas.gdatasecurity.de/nocontenthere",
e.Message);
}

[Fact]
public async Task ForStream_WithEicarString_ReturnsMalicious()
{
Expand All @@ -190,14 +190,14 @@ public async Task ForStream_WithEicarString_ReturnsMalicious()
var eicarBytes = System.Text.Encoding.UTF8.GetBytes("X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");
targetStream.Write(eicarBytes, 0, eicarBytes.Length);
targetStream.Position = 0;

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Malicious, verdict.Verdict);
}

[Fact]
public async Task ForStream_WithCleanString_ReturnsClean()
{
Expand All @@ -207,10 +207,10 @@ public async Task ForStream_WithCleanString_ReturnsClean()
var cleanBytes = System.Text.Encoding.UTF8.GetBytes("This is a clean file");
targetStream.Write(cleanBytes, 0, cleanBytes.Length);
targetStream.Position = 0;

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Clean, verdict.Verdict);
}
Expand All @@ -223,14 +223,14 @@ public async Task ForStream_WithCleanUrl_ReturnsClean()
var url = new Uri("https://raw.githubusercontent.com/GDATASoftwareAG/vaas/main/Readme.md");
var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, url), CancellationToken.None);
var targetStream = await response.Content.ReadAsStreamAsync();

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Clean, verdict.Verdict);
}

[Fact]
public async Task ForStream_WithEicarUrl_ReturnsEicar()
{
Expand All @@ -239,10 +239,10 @@ public async Task ForStream_WithEicarUrl_ReturnsEicar()
var url = new Uri("https://secure.eicar.org/eicar.com.txt");
var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, url), CancellationToken.None);
var targetStream = await response.Content.ReadAsStreamAsync();

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Malicious, verdict.Verdict);
}
Expand Down Expand Up @@ -305,32 +305,32 @@ public async Task Connect_WithResourceOwnerPasswordGrantAuthenticator()
var vaas = provider.GetRequiredService<IVaas>();
await vaas.Connect(CancellationToken.None);
}

[Fact]
public async Task ForStream_WithEicarUrl_ReturnsMaliciousWithDetectionsAndMimeType()
{
var vaas = await AuthenticateWithCredentials();
var url = new Uri("https://secure.eicar.org/eicar.com.txt");
var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, url), CancellationToken.None);
var targetStream = await response.Content.ReadAsStreamAsync();

var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

Assert.Equal(Verdict.Malicious, verdict.Verdict);
Assert.NotNull(verdict.LibMagic);
Assert.NotNull(verdict.Detections);
Assert.Equal("text/plain", verdict.LibMagic.MimeType);
Assert.Contains(verdict.Detections, detection => detection.Virus == "EICAR_TEST_FILE");
}

[Fact]
public async Task ForUrl_WithEicarUrl_ReturnsMaliciousWithDetectionAndMimeType()
{
var vaas = await AuthenticateWithCredentials();
var uri = new Uri("https://secure.eicar.org/eicar.com");

var verdict = await vaas.ForUrlAsync(uri, CancellationToken.None);

Assert.Equal(Verdict.Malicious, verdict.Verdict);
Assert.NotNull(verdict.LibMagic);
Assert.NotNull(verdict.Detections);
Expand Down
12 changes: 6 additions & 6 deletions golang/vaas/pkg/vaas/vaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func (tf *testFixture) tearDown(t *testing.T) {

func TestVaas_ForSha256(t *testing.T) {
const (
cleanSha256 string = "3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C"
maliciousSha256 string = "00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c"
unknownSha256 string = "110005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe9"
cleanSha256 string = "cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e"
maliciousSha256 string = "ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"
unknownSha256 string = "1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df"
)
type fields struct {
testingOptions options.VaasOptions
Expand Down Expand Up @@ -443,9 +443,9 @@ func TestVaas_ForSha256List(t *testing.T) {
vaasClient := fixture.setUp(t)
defer fixture.tearDown(t)

maliciousSha256 := strings.ToLower("00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c")
cleanSha256 := strings.ToLower("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C")
unknownSha256 := strings.ToLower("110005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe9")
maliciousSha256 := strings.ToLower("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2")
cleanSha256 := strings.ToLower("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e")
unknownSha256 := strings.ToLower("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df")

verdicts, err := vaasClient.ForSha256List(context.Background(), []string{maliciousSha256, cleanSha256, unknownSha256})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public void resourceOwnerPasswordAuthenticatorGetToken() throws Exception {
@Test
public void forSha256SingleMaliciousHash() throws Exception {
var vaas = this.getVaasWithCredentials();
var sha256 = new Sha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8");
var sha256 = new Sha256("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2");

var verdict = vaas.forSha256(sha256);
vaas.disconnect();

assertEquals(Verdict.MALICIOUS, verdict.getVerdict());
assertTrue("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8"
assertTrue("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"
.equalsIgnoreCase(verdict.getSha256()));
}

Expand Down Expand Up @@ -134,50 +134,26 @@ public String getToken() throws IOException, InterruptedException {
}

@Test
public void forSha256MultipleMaliciousHash() throws Exception {
public void forSha256MultipleHashes() throws Exception {
var vaas = this.getVaasWithCredentials();
var sha256_1 = new Sha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8");
var sha256_2 = new Sha256("00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c");
var sha256_3 = new Sha256("00000f83e3120f79a21b7b395dd3dd6a9c31ce00857f78d7cf487476ca75fd1a");
var sha256_1 = new Sha256("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2");
var sha256_2 = new Sha256("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e");
var sha256_3 = new Sha256("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df");

var verdict_1 = vaas.forSha256(sha256_1);
var verdict_2 = vaas.forSha256(sha256_2);
var verdict_3 = vaas.forSha256(sha256_3);
vaas.disconnect();

assertEquals(Verdict.MALICIOUS, verdict_1.getVerdict());
assertEquals(Verdict.MALICIOUS, verdict_2.getVerdict());
assertEquals(Verdict.MALICIOUS, verdict_3.getVerdict());

assertTrue("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8"
.equalsIgnoreCase(verdict_1.getSha256()));
assertTrue("00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c"
.equalsIgnoreCase(verdict_2.getSha256()));
assertTrue("00000f83e3120f79a21b7b395dd3dd6a9c31ce00857f78d7cf487476ca75fd1a"
.equalsIgnoreCase(verdict_3.getSha256()));
}

@Test
public void forSha256MultipleCleanHash() throws Exception {
var vaas = this.getVaasWithCredentials();
var sha256_1 = new Sha256("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C");
var sha256_2 = new Sha256("1AFAFE9157FF5670BBEC8CE622F45D1CE51B3EE77B7348D3A237E232F06C5391");
var sha256_3 = new Sha256("4447FAACEFABA8F040822101E2A4103031660DE9139E70ECFF9AA3A89455A783");

var verdict_1 = vaas.forSha256(sha256_1);
var verdict_2 = vaas.forSha256(sha256_2);
var verdict_3 = vaas.forSha256(sha256_3);
vaas.disconnect();

assertEquals(Verdict.CLEAN, verdict_1.getVerdict());
assertEquals(Verdict.CLEAN, verdict_2.getVerdict());
assertEquals(Verdict.CLEAN, verdict_3.getVerdict());
assertEquals(Verdict.UNKNOWN, verdict_3.getVerdict());

assertTrue("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C"
assertTrue("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"
.equalsIgnoreCase(verdict_1.getSha256()));
assertTrue("1AFAFE9157FF5670BBEC8CE622F45D1CE51B3EE77B7348D3A237E232F06C5391"
assertTrue("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e"
.equalsIgnoreCase(verdict_2.getSha256()));
assertTrue("4447FAACEFABA8F040822101E2A4103031660DE9139E70ECFF9AA3A89455A783"
assertTrue("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df"
.equalsIgnoreCase(verdict_3.getSha256()));
}

Expand Down
Loading

0 comments on commit 5914f21

Please sign in to comment.