-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Use AMSI for archive malware scanning #4910
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
#include "pch.h" | ||
#include "TestCommon.h" | ||
#include <winget/Archive.h> | ||
|
||
using namespace AppInstaller::Archive; | ||
using namespace TestCommon; | ||
|
||
constexpr std::string_view s_ZipFile = "TestZip.zip"; | ||
|
||
TEST_CASE("Extract_ZipArchive", "[archive]") | ||
{ | ||
TestCommon::TempDirectory tempDirectory("TempDirectory"); | ||
TestDataFile testZip(s_ZipFile); | ||
|
||
const auto& testZipPath = testZip.GetPath(); | ||
const auto& tempDirectoryPath = tempDirectory.GetPath(); | ||
|
||
HRESULT hr = TryExtractArchive(testZipPath, tempDirectoryPath); | ||
|
||
std::filesystem::path expectedPath = tempDirectoryPath / "test.txt"; | ||
REQUIRE(SUCCEEDED(hr)); | ||
REQUIRE(std::filesystem::exists(expectedPath)); | ||
} | ||
|
||
TEST_CASE("Scan_ZipArchive", "[archive]") | ||
{ | ||
TestDataFile testZip(s_ZipFile); | ||
|
||
const auto& testZipPath = testZip.GetPath(); | ||
bool result = ScanZipFile(testZipPath); | ||
REQUIRE(result); | ||
} | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
#include "pch.h" | ||
#include "TestCommon.h" | ||
#include "WorkflowCommon.h" | ||
#include <winget/Archive.h> | ||
#include <Workflows/ShellExecuteInstallerHandler.h> | ||
|
||
using namespace AppInstaller::Archive; | ||
using namespace AppInstaller::CLI::Workflow; | ||
using namespace AppInstaller::Settings; | ||
using namespace TestCommon; | ||
|
||
constexpr std::string_view s_ZipFile = "TestZip.zip"; | ||
constexpr std::string_view s_TarGzFile = "TestTarGz.tar.gz"; | ||
constexpr std::string_view s_Large7zFile = "TestLarge7z.7z"; | ||
|
||
TEST_CASE("Extract_ZipArchive", "[archive]") | ||
{ | ||
TestCommon::TempDirectory tempDirectory("TempDirectory"); | ||
TestDataFile testZip(s_ZipFile); | ||
|
||
const auto& testZipPath = testZip.GetPath(); | ||
const auto& tempDirectoryPath = tempDirectory.GetPath(); | ||
|
||
HRESULT hr = TryExtractArchive(testZipPath, tempDirectoryPath); | ||
|
||
std::filesystem::path expectedPath = tempDirectoryPath / "test.txt"; | ||
REQUIRE(SUCCEEDED(hr)); | ||
REQUIRE(std::filesystem::exists(expectedPath)); | ||
} | ||
|
||
TEST_CASE("Scan_ZipArchive", "[archive]") | ||
{ | ||
TestDataFile testZip(s_ZipFile); | ||
|
||
const auto& testZipPath = testZip.GetPath(); | ||
bool result = ScanZipFile(testZipPath); | ||
REQUIRE(result); | ||
} | ||
|
||
TEST_CASE("Extract_TarGzArchive", "[archive]") | ||
{ | ||
TestCommon::TempDirectory tempDirectory("TempDirectory"); | ||
TestDataFile testTarGz(s_TarGzFile); | ||
|
||
TestCommon::TestUserSettings testSettings; | ||
testSettings.Set<Setting::ArchiveExtractionMethod>(AppInstaller::Archive::ExtractionMethod::Tar); | ||
|
||
const auto& testTarGzPath = testTarGz.GetPath(); | ||
const auto& tempDirectoryPath = tempDirectory.GetPath(); | ||
|
||
ShellExecuteExtractArchive(testTarGzPath, tempDirectoryPath); | ||
|
||
std::ostringstream extractOutput; | ||
TestContext context{ extractOutput, std::cin }; | ||
context << ShellExecuteExtractArchive(testTarGzPath, tempDirectoryPath); | ||
|
||
std::filesystem::path expectedPath = tempDirectoryPath / "test.txt"; | ||
REQUIRE(SUCCEEDED(context.GetTerminationHR())); | ||
REQUIRE(std::filesystem::exists(expectedPath)); | ||
INFO(extractOutput.str()); | ||
} | ||
|
||
TEST_CASE("Scan_TarGzArchive", "[archive]") | ||
{ | ||
TestDataFile testTarGz(s_TarGzFile); | ||
|
||
const auto& testTarGzPath = testTarGz.GetPath(); | ||
bool result = ScanZipFile(testTarGzPath); | ||
REQUIRE(result); | ||
} | ||
|
||
//TEST_CASE("Scan_Large7zArchive", "[archive]") | ||
//{ | ||
// TestDataFile testLarge7z(s_Large7zFile); | ||
// | ||
// const auto& testTarGzPath = testLarge7z.GetPath(); | ||
// bool result = ScanZipFile(testTarGzPath); | ||
// REQUIRE(result); | ||
//} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be me being paranoid but I would be slightly concerned about having a binary checked without knowing what it is. Would be great if you could share how it gas generated so that we can validate that it's that (assuming it's a deterministic process) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,21 @@ | |
<SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Windows</SubSystem> | ||
<SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Windows</SubSystem> | ||
</Link> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, I wonder why we don't have the other dependencies here. I think they are listed in the projects that produce the final binaries, like |
||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> | ||
<ClCompile> | ||
|
@@ -287,6 +302,9 @@ | |
<Link> | ||
<SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Windows</SubSystem> | ||
</Link> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'"> | ||
<ClCompile> | ||
|
@@ -324,6 +342,18 @@ | |
<SubSystem Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Windows</SubSystem> | ||
<SubSystem Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Windows</SubSystem> | ||
</Link> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)'=='ReleaseStatic'"> | ||
<ClCompile> | ||
|
@@ -365,6 +395,18 @@ | |
<SubSystem Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">Windows</SubSystem> | ||
<SubSystem Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">Windows</SubSystem> | ||
</Link> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|ARM'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|ARM64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Fuzzing'"> | ||
<ClCompile> | ||
|
@@ -385,6 +427,12 @@ | |
<GenerateWindowsMetadata>false</GenerateWindowsMetadata> | ||
<SubSystem>Windows</SubSystem> | ||
</Link> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Fuzzing|Win32'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
<Lib> | ||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Fuzzing|x64'">amsi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Lib> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(WingetDisableTestHooks)'=='true'"> | ||
<ClCompile> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing