Skip to content

Commit 16c87f1

Browse files
committed
Merge branch 'main' into release/10.1.x
2 parents bb60937 + 9a02558 commit 16c87f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1510
-506
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# ChangeLog
22

3+
## [10.1.1] - 2022-06-20
4+
### Added
5+
- Toolembed: display a message for missing/broken resource because of bad configuration
6+
- Syslog: display configuration on startup
7+
8+
### Changed
9+
- GetThis: replace from output filenames the possible leading '__' with '_'
10+
- Bits: do not create bits job on 'once' mode if server is unreachable
11+
- Log: set default backtrace log level to debug for commands
12+
13+
### Fixed
14+
- Ntfs: fix parsing for very long paths
15+
- Ntfs: fix parsing for very fragmented mfts
16+
- Ntfs: fix possible crash with nested record resolution
17+
- FastFind: fix matching yara rule display when wildcard is used for rule selection
18+
- Configuration: fix missing log option processing for local configuration
19+
- Fix version string for recents windows releases
20+
- Fix possible crash with GetNetworkAdapters
21+
- Fix possible locking issue when uploading console's log
22+
- Bits: add more detail to failure logs
23+
- Bits: fix some missing error handling
24+
- Outcome: fix possible failure when calculating mothership's hash
25+
- Vcpkg: removed uneeded/broken dependency to libwinpthread
26+
27+
328
## [10.1.0] - 2022-03-25
429
Summary of changes since the 10.0.24. For more details look at rc versions.
530
From 10.1.0 the semantic versioning will be applied.

src/Orc/Mothership_Run.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ HRESULT Main::Launch(const std::wstring& command, const std::wstring& commandArg
185185

186186
std::vector<WCHAR> szCommandLine(MAX_CMDLINE);
187187
std::wstring strCommandLine = cmdLineBuilder.str();
188+
189+
HANDLE hMothership = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, GetCurrentProcessId());
190+
if (hMothership)
191+
{
192+
strCommandLine.append(fmt::format(L" /MothershipHandle={:#x}", reinterpret_cast<size_t>(hMothership)));
193+
}
194+
else
195+
{
196+
Log::Error("Failed to append mothership handle on the cli [{}]", LastWin32Error());
197+
}
198+
188199
wcsncpy_s(szCommandLine.data(), MAX_CMDLINE, strCommandLine.c_str(), strCommandLine.size());
189200

190201
DWORD dwMajor = 0, dwMinor = 0;

src/OrcCommand/Command/GetThis/GetThis_Run.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ CreateSampleFileName(const Main::SampleRef& sample, const PFILE_NAME pFileName,
539539
len = swprintf_s(
540540
name.data(),
541541
name.size(),
542-
L"%llX_%llX_%llX_%x__%.*s_%.*s_%s.%s",
542+
L"%llX_%llX_%llX_%x_%.*s_%.*s_%s.%s",
543543
sample.VolumeSerial,
544544
parentFRN,
545545
FRN,

src/OrcCommand/Command/WolfLauncher/WolfExecution_Execute.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ HRESULT WolfExecution::CompleteExecution()
732732
}
733733
catch (Concurrency::operation_timed_out e)
734734
{
735-
Log::Error("Command agent completion timeout: {} msecs reached", m_CmdTimeOut.count());
735+
Log::Critical("Command agent completion timeout: {} msecs reached", m_CmdTimeOut.count());
736736
return HRESULT_FROM_WIN32(ERROR_TIMEOUT);
737737
}
738738
if (m_pTermination)
@@ -768,7 +768,7 @@ HRESULT WolfExecution::TerminateAllAndComplete()
768768
}
769769
catch (Concurrency::operation_timed_out e)
770770
{
771-
Log::Error(L"Command agent completion timeout: {} msecs reached", m_CmdTimeOut.count());
771+
Log::Critical(L"Command agent completion timeout: {} msecs reached", m_CmdTimeOut.count());
772772
return HRESULT_FROM_WIN32(ERROR_TIMEOUT);
773773
}
774774

@@ -813,7 +813,7 @@ HRESULT WolfExecution::CompleteArchive(UploadMessage::ITarget* pUploadMessageQue
813813
}
814814
catch (Concurrency::operation_timed_out e)
815815
{
816-
Log::Error(
816+
Log::Critical(
817817
"Command archive completion timeout: {} secs reached",
818818
std::chrono::duration_cast<std::chrono::seconds>(m_ArchiveTimeOut).count());
819819
return HRESULT_FROM_WIN32(ERROR_TIMEOUT);

src/OrcCommand/Command/WolfLauncher/WolfLauncher.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class ORCUTILS_API Main : public UtilitiesMain
9494
OutputSpec Outcome;
9595

9696
std::wstring strCompressionLevel;
97+
std::wstring strMothershipHandle;
9798

9899
OutputSpec TempWorkingDir;
99100

@@ -196,6 +197,8 @@ class ORCUTILS_API Main : public UtilitiesMain
196197
HRESULT ExecuteKeyword(WolfExecution& execution);
197198
HRESULT Run_Keywords();
198199

200+
void ReadLogConfiguration(const ConfigItem& configItem, bool hasConsoleConfigItem);
201+
199202
private:
200203
ConsoleConfiguration m_consoleConfiguration;
201204

src/OrcCommand/Command/WolfLauncher/WolfLauncher_Config.cpp

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "Command/WolfLauncher/ConfigFile_WOLFLauncher.h"
2929
#include "Command/WolfLauncher/ConsoleConfiguration.h"
3030
#include "Configuration/Option.h"
31+
#include "Text/Hex.h"
3132

3233
using namespace Orc;
3334
using namespace Orc::Command::Wolf;
@@ -173,6 +174,48 @@ std::shared_ptr<WolfExecution::Recipient> Main::GetRecipientFromItem(const Confi
173174
return retval;
174175
}
175176

177+
void Main::ReadLogConfiguration(const ConfigItem& configItem, bool hasConsoleConfigItem)
178+
{
179+
if (!configItem.empty())
180+
{
181+
//
182+
// DEPRECATED: compatibility with 10.0.x log configuration
183+
//
184+
// Usually configuration is close to '<log ...>ORC_{SystemType}_{FullComputerName}_{TimeStamp}.log</log>'
185+
// instead of '<log><file><output>...</output></file></log>'.
186+
//
187+
// Silently convert any old configuration into new structures.
188+
//
189+
190+
OutputSpec output;
191+
auto hr = output.Configure(configItem);
192+
if (FAILED(hr))
193+
{
194+
Log::Warn(L"Failed to configure DFIR-Orc log file [{}]", SystemError(hr));
195+
}
196+
else if (!hasConsoleConfigItem)
197+
{
198+
m_consoleConfiguration.output.path = output.Path;
199+
m_consoleConfiguration.output.encoding = ToEncoding(output.OutputEncoding);
200+
m_consoleConfiguration.output.disposition = ToFileDisposition(output.disposition);
201+
202+
if (!m_utilitiesConfig.log.level)
203+
{
204+
m_utilitiesConfig.log.level = Log::Level::Info;
205+
UtilitiesLoggerConfiguration::ApplyLogLevel(m_logging, m_utilitiesConfig.log);
206+
}
207+
208+
Log::Warn(
209+
L"This use of the configuration element '<log>' is DEPRECATED, you should use '<console> to capture "
210+
L"console output or keep using 'log' for detailed logging.");
211+
}
212+
}
213+
else if (configItem)
214+
{
215+
UtilitiesLoggerConfiguration::Parse(configItem, m_utilitiesConfig.log);
216+
}
217+
}
218+
176219
HRESULT Main::GetConfigurationFromConfig(const ConfigItem& configitem)
177220
{
178221
using namespace std::string_view_literals;
@@ -227,44 +270,7 @@ HRESULT Main::GetConfigurationFromConfig(const ConfigItem& configitem)
227270
}
228271
}
229272

230-
if (configitem[WOLFLAUNCHER_LOG] && !configitem[WOLFLAUNCHER_LOG].empty())
231-
{
232-
//
233-
// DEPRECATED: compatibility with 10.0.x log configuration
234-
//
235-
// Usually configuration is close to '<log ...>ORC_{SystemType}_{FullComputerName}_{TimeStamp}.log</log>'
236-
// instead of '<log><file><output>...</output></file></log>'.
237-
//
238-
// Silently convert any old configuration into new structures.
239-
//
240-
241-
OutputSpec output;
242-
auto hr = output.Configure(configitem[WOLFLAUNCHER_LOG]);
243-
if (FAILED(hr))
244-
{
245-
Log::Warn(L"Failed to configure DFIR-Orc log file [{}]", SystemError(hr));
246-
}
247-
else if (!configitem[WOLFLAUNCHER_CONSOLE])
248-
{
249-
m_consoleConfiguration.output.path = output.Path;
250-
m_consoleConfiguration.output.encoding = ToEncoding(output.OutputEncoding);
251-
m_consoleConfiguration.output.disposition = ToFileDisposition(output.disposition);
252-
253-
if (!m_utilitiesConfig.log.level)
254-
{
255-
m_utilitiesConfig.log.level = Log::Level::Info;
256-
UtilitiesLoggerConfiguration::ApplyLogLevel(m_logging, m_utilitiesConfig.log);
257-
}
258-
259-
Log::Warn(
260-
L"This use of the configuration element '<log>' is DEPRECATED, you should use '<console> to capture "
261-
L"console output or keep using 'log' for detailed logging.");
262-
}
263-
}
264-
else if (configitem[WOLFLAUNCHER_LOG])
265-
{
266-
UtilitiesLoggerConfiguration::Parse(configitem[WOLFLAUNCHER_LOG], m_utilitiesConfig.log);
267-
}
273+
ReadLogConfiguration(configitem[WOLFLAUNCHER_LOG], configitem[WOLFLAUNCHER_CONSOLE].Status == ConfigItem::PRESENT);
268274

269275
if (configitem[WOLFLAUNCHER_CONSOLE])
270276
{
@@ -533,6 +539,16 @@ HRESULT Main::GetLocalConfigurationFromConfig(const ConfigItem& configitem)
533539
}
534540
}
535541

542+
if (configitem[ORC_LOGGING])
543+
{
544+
ReadLogConfiguration(configitem[ORC_LOGGING], configitem[ORC_CONSOLE].Status == ConfigItem::PRESENT);
545+
}
546+
547+
if (configitem[ORC_CONSOLE])
548+
{
549+
ConsoleConfiguration::Parse(configitem[ORC_CONSOLE], m_consoleConfiguration);
550+
}
551+
536552
return S_OK;
537553
}
538554

@@ -591,6 +607,8 @@ HRESULT Main::GetConfigurationFromArgcArgv(int argc, LPCWSTR argv[])
591607
;
592608
else if (ParameterOption(argv[i] + 1, L"Compression", config.strCompressionLevel))
593609
;
610+
else if (ParameterOption(argv[i] + 1, L"MothershipHandle", config.strMothershipHandle))
611+
;
594612
else if (ParameterOption(argv[i] + 1, L"archive_timeout", config.msArchiveTimeOut))
595613
;
596614
else if (ParameterOption(argv[i] + 1, L"command_timeout", config.msCommandTerminationTimeOut))
@@ -715,6 +733,23 @@ HRESULT Main::CheckConfiguration()
715733
m_utilitiesConfig.log.logFile = logPath;
716734
}
717735

736+
if (!config.strMothershipHandle.empty())
737+
{
738+
auto handle = Text::FromHexToLittleEndian<HANDLE>(std::wstring_view(config.strMothershipHandle));
739+
if (handle)
740+
{
741+
m_hMothership = *handle;
742+
}
743+
else
744+
{
745+
Log::Error("Failed to parse mothership handle [{}]", handle.error());
746+
}
747+
}
748+
else
749+
{
750+
Log::Warn("Missing mothership handle");
751+
}
752+
718753
UtilitiesLoggerConfiguration::Apply(m_logging, m_utilitiesConfig.log);
719754

720755
if ((config.bRepeatCreateNew ? 1 : 0) + (config.bRepeatOnce ? 1 : 0) + (config.bRepeatOverwrite ? 1 : 0) > 1)

src/OrcCommand/Command/WolfLauncher/WolfLauncher_Run.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,16 @@ HRESULT GetRemoteOutputFileInformations(
149149

150150
if (exec.ShouldUpload())
151151
{
152-
DWORD dwFileSize;
153-
hr = uploadAgent.CheckFileUpload(exec.GetOutputFileName(), &dwFileSize);
152+
std::optional<DWORD> fileSize;
153+
hr = uploadAgent.CheckFileUpload(exec.GetOutputFileName(), fileSize);
154154
if (FAILED(hr))
155155
{
156156
return hr;
157157
}
158158

159159
fileInformations.exist = true;
160160
fileInformations.path = uploadAgent.GetRemoteFullPath(exec.GetOutputFileName());
161-
fileInformations.size = dwFileSize;
161+
fileInformations.size = fileSize;
162162
return S_OK;
163163
}
164164

@@ -178,22 +178,32 @@ Result<std::wstring> GetCurrentExecutableHash(CryptoHashStream::Algorithm algori
178178
return Hash(path, algorithm);
179179
}
180180

181+
Result<std::wstring> GetProcessExecutableHash(HANDLE hProcess, CryptoHashStream::Algorithm algorithm)
182+
{
183+
std::error_code ec;
184+
const auto path = GetModuleFileNameExApi(hProcess, NULL, ec);
185+
if (ec)
186+
{
187+
return ec;
188+
}
189+
190+
return Hash(path, algorithm);
191+
}
192+
181193
Result<std::wstring> GetProcessExecutableHash(DWORD dwProcessId, CryptoHashStream::Algorithm algorithm)
182194
{
183195
Guard::Handle hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
184196
if (!hProcess)
185197
{
186-
const auto error = LastWin32Error();
187-
Log::Debug(L"Failed OpenProcess: {} [{}]", dwProcessId, error);
188-
return error;
198+
const auto ec = LastWin32Error();
199+
Log::Debug(L"Failed OpenProcess: {} [{}]", dwProcessId, ec);
200+
return ec;
189201
}
190202

191-
std::error_code ec;
192-
const auto path = GetModuleFileNameExApi(hProcess.value(), NULL, ec);
193-
return Hash(path, algorithm);
203+
return GetProcessExecutableHash(*hProcess, algorithm);
194204
}
195205

196-
void UpdateOutcome(Command::Wolf::Outcome::Outcome& outcome)
206+
void UpdateOutcome(Command::Wolf::Outcome::Outcome& outcome, HANDLE hMothership)
197207
{
198208
auto&& lock = outcome.Lock();
199209

@@ -235,10 +245,13 @@ void UpdateOutcome(Command::Wolf::Outcome::Outcome& outcome)
235245
mothership.SetCommandLineValue(commandLine.value());
236246
}
237247

238-
auto sha1 = GetProcessExecutableHash(mothershipPID.value(), CryptoHashStream::Algorithm::SHA1);
239-
if (sha1)
248+
if (hMothership)
240249
{
241-
mothership.SetSha1(sha1.value());
250+
auto sha1 = GetProcessExecutableHash(hMothership, CryptoHashStream::Algorithm::SHA1);
251+
if (sha1)
252+
{
253+
mothership.SetSha1(sha1.value());
254+
}
242255
}
243256
}
244257

@@ -703,7 +716,7 @@ Orc::Result<void> Main::CreateAndUploadOutcome()
703716
return Success<void>();
704717
}
705718

706-
::UpdateOutcome(m_outcome);
719+
::UpdateOutcome(m_outcome, m_hMothership);
707720
::UpdateOutcome(m_outcome, config.m_Recipients);
708721
::UpdateOutcome(m_outcome, m_standardOutput);
709722
::UpdateOutcome(m_outcome, m_logging);
@@ -930,7 +943,7 @@ HRESULT Main::Run_Execute()
930943
else if (!info.size || *info.size != 0)
931944
{
932945
commandSetNode.Add(
933-
"Skipping set because non-empty remote output file already exists: '{}' ({})",
946+
"Skipping set because non-empty remote output file already exists: '{}' (size: {})",
934947
info.path,
935948
info.size);
936949
commandSetNode.AddEmptyLine();
@@ -984,6 +997,8 @@ HRESULT Main::Run_Execute()
984997
Log::Error("Failed to flush standard output [{}]", ec);
985998
}
986999

1000+
m_standardOutput.FileTee().Close(ec);
1001+
9871002
const std::filesystem::path localPath = *m_standardOutput.FileTee().Path();
9881003
hr = UploadSingleFile(localPath.filename(), localPath);
9891004
if (FAILED(hr))

src/OrcCommand/ConfigFile_OrcConfig.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include "ConfigFile_OrcConfig.h"
1414
#include "Command/WolfLauncher/ConfigFile_WOLFLauncher.h"
15+
#include "Command/WolfLauncher/ConsoleConfiguration.h"
16+
#include "Log/UtilitiesLoggerConfiguration.h"
1517

1618
HRESULT Orc::Config::Wolf::Local::root(ConfigItem& item)
1719
{
@@ -38,13 +40,15 @@ HRESULT Orc::Config::Wolf::Local::root(ConfigItem& item)
3840
return hr;
3941
if (FAILED(hr = item.AddChild(Orc::Config::Wolf::recipient, ORC_RECIPIENT)))
4042
return hr;
41-
if (FAILED(hr = item.AddChild(Orc::Config::Common::logging, ORC_LOGGING)))
43+
if (FAILED(hr = item.AddChild(Orc::Command::UtilitiesLoggerConfiguration::Register, ORC_LOGGING)))
4244
return hr;
4345
if (FAILED(hr = item.AddAttribute(L"priority", ORC_PRIORITY, ConfigItem::OPTION)))
4446
return hr;
4547
if (FAILED(hr = item.AddAttribute(L"powerstate", ORC_POWERSTATE, ConfigItem::OPTION)))
4648
return hr;
4749
if (FAILED(hr = item.AddAttribute(L"altitude", ORC_ALTITUDE, ConfigItem::OPTION)))
4850
return hr;
51+
if (FAILED(hr = item.AddChild(Orc::Command::ConsoleConfiguration::Register, ORC_CONSOLE)))
52+
return hr;
4953
return S_OK;
5054
}

src/OrcCommand/ConfigFile_OrcConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ constexpr auto ORC_LOGGING = 8L;
2525
constexpr auto ORC_PRIORITY = 9L;
2626
constexpr auto ORC_POWERSTATE = 10L;
2727
constexpr auto ORC_ALTITUDE = 11L;
28+
constexpr auto ORC_CONSOLE = 12L;
2829

2930
constexpr auto ORC_ORC = 0L;
3031

0 commit comments

Comments
 (0)