Skip to content

Commit 5b2ebb7

Browse files
author
4n6ist
committed
v1.3.2
1 parent 0ea2de0 commit 5b2ebb7

File tree

4 files changed

+104
-5
lines changed

4 files changed

+104
-5
lines changed

CDIR/CDIR.cpp

+102-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ConfigParser *config;
9090
int launchprocess(char *cmdline, DWORD *status) {
9191
PROCESS_INFORMATION pi = {};
9292
STARTUPINFO si = {};
93-
93+
9494
if (cmdline == NULL) {
9595
return -1;
9696
}
@@ -677,7 +677,106 @@ int get_analysisdata(ostringstream *osslog = NULL) {
677677
sprintf(srcpath, "%s\\winevt\\Logs\\%s", sysdir, file.first.c_str());
678678
sprintf(dstpath, "Evtx\\%s", file.first.c_str());
679679
if (StealthGetFile(srcpath, dstpath, osslog, false)) {
680-
cerr << msg("取得失敗", "failed to save") << ": " << srcpath << endl;
680+
if (!WriteWrapper::isLocal())
681+
continue;
682+
// If SltealthGetFile failed and isLocal, then tried wevtutil - workaround
683+
char cmdline[1024];
684+
DWORD status;
685+
sprintf(cmdline, "wevtutil epl \"%s\" \"%s\" /lf", srcpath, dstpath);
686+
if (launchprocess(cmdline, &status))
687+
cerr << msg("取得失敗", "failed to save") << ": " << srcpath << endl;
688+
else { // hashing & logging
689+
if (!osslog)
690+
continue;
691+
FILE *stream;
692+
BYTE *buf = (BYTE*)malloc(sizeof(BYTE)*CHUNKSIZE);
693+
694+
if (buf == NULL) {
695+
_perror("malloc");
696+
return -1;
697+
}
698+
699+
SHA256_CTX sha256;
700+
SHA_CTX sha1;
701+
MD5_CTX md5;
702+
703+
if (!(SHA256_Init(&sha256) && SHA1_Init(&sha1) && MD5_Init(&md5))) {
704+
fprintf(stderr, "failed to initialize hash context.\n");
705+
return -1;
706+
}
707+
708+
if (fopen_s(&stream, dstpath, "rb") == 0) {
709+
while(fread(buf, 1, CHUNKSIZE, stream) == CHUNKSIZE) {
710+
if (!(SHA256_Update(&sha256, buf, CHUNKSIZE)
711+
&& SHA1_Update(&sha1, buf, CHUNKSIZE)
712+
&& MD5_Update(&md5, buf, CHUNKSIZE))) {
713+
fprintf(stderr, "failed to update hash context.\n");
714+
return -1;
715+
}
716+
}
717+
int remain_bytes = size_t(get_filesize(dstpath)) % CHUNKSIZE;
718+
if (remain_bytes > 0) {
719+
fread(buf, 1, remain_bytes, stream);
720+
if (!(SHA256_Update(&sha256, buf, remain_bytes)
721+
&& SHA1_Update(&sha1, buf, remain_bytes)
722+
&& MD5_Update(&md5, buf, remain_bytes))) {
723+
fprintf(stderr, "failed to update hash context.\n");
724+
return -1;
725+
}
726+
}
727+
free(buf);
728+
fclose(stream);
729+
} else {
730+
fprintf(stderr, "failed to open file.\n");
731+
return -1;
732+
}
733+
734+
if (WriteWrapper::isLocal()) {
735+
if (CopyFileTime(srcpath, dstpath)) {
736+
fprintf(stderr, "failed to copy filetime: %s\n", srcpath);
737+
}
738+
}
739+
740+
WIN32_FILE_ATTRIBUTE_DATA w32ad;
741+
FILETIME ft_c, ft_a, ft_w;
742+
SYSTEMTIME st_c, st_a, st_w;
743+
char str_c[32], str_a[32], str_w[32];
744+
745+
if (!GetFileAttributesEx(srcpath, GetFileExInfoStandard, &w32ad)) {
746+
_perror("GetFileAttributesEx");
747+
}
748+
else {
749+
ft_c = w32ad.ftCreationTime;
750+
ft_a = w32ad.ftLastAccessTime;
751+
ft_w = w32ad.ftLastWriteTime;
752+
753+
FileTimeToSystemTime(&ft_c, &st_c);
754+
FileTimeToSystemTime(&ft_a, &st_a);
755+
FileTimeToSystemTime(&ft_w, &st_w);
756+
757+
sprintf(str_c, "%d/%02d/%02d %02d:%02d:%02d", st_c.wYear, st_c.wMonth, st_c.wDay, st_c.wHour, st_c.wMinute, st_c.wSecond);
758+
sprintf(str_a, "%d/%02d/%02d %02d:%02d:%02d", st_a.wYear, st_a.wMonth, st_a.wDay, st_a.wHour, st_a.wMinute, st_a.wSecond);
759+
sprintf(str_w, "%d/%02d/%02d %02d:%02d:%02d", st_w.wYear, st_w.wMonth, st_w.wDay, st_w.wHour, st_w.wMinute, st_w.wSecond);
760+
761+
*osslog << str_c << string(22 - string(str_c).size(), ' ');
762+
*osslog << str_a << string(22 - string(str_a).size(), ' ');
763+
*osslog << str_w << string(22 - string(str_w).size(), ' ');
764+
}
765+
unsigned char md5hash[MD5_DIGEST_LENGTH];
766+
unsigned char sha1hash[SHA_DIGEST_LENGTH];
767+
unsigned char sha256hash[SHA256_DIGEST_LENGTH];
768+
769+
if (!(SHA256_Final(sha256hash, &sha256) && SHA1_Final(sha1hash, &sha1) && MD5_Final(md5hash, &md5))) {
770+
fprintf(stderr, "failed to finalize hash context.\n");
771+
return -1;
772+
}
773+
774+
*osslog << hexdump(md5hash, MD5_DIGEST_LENGTH) << " ";
775+
*osslog << hexdump(sha1hash, SHA_DIGEST_LENGTH) << " ";
776+
*osslog << hexdump(sha256hash, SHA256_DIGEST_LENGTH) << " ";
777+
*osslog << srcpath << " (wevtutil)";
778+
*osslog << "\r\n";
779+
}
681780
}
682781
}
683782
cerr << msg("イベントログ 取得完了", "event log is saved") << endl;
@@ -928,7 +1027,7 @@ int main(int argc, char **argv)
9281027

9291028
// chack proces name
9301029
procname = basename(string(argv[0]));
931-
cout << msg("CDIR Collector v1.3.1 - 初動対応用データ収集ツール", "CDIR Collector v1.3.1 - Data Acquisition Tool for First Response") << endl;
1030+
cout << msg("CDIR Collector v1.3.2 - 初動対応用データ収集ツール", "CDIR Collector v1.3.2 - Data Acquisition Tool for First Response") << endl;
9321031
cout << msg("Cyber Defense Institute, Inc.\n", "Cyber Defense Institute, Inc.\n") << endl;
9331032

9341033
// set curdir -> exedir

CDIR/CDIR.rc

0 Bytes
Binary file not shown.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# cdir-collector
1+
# cdir-collector (CDIR-C)
22

33
[English](README_en.md)
44

README_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# cdir-collector
1+
# cdir-collector (CDIR-C)
22

33
[Japanese](README.md)
44

0 commit comments

Comments
 (0)