@@ -90,7 +90,7 @@ ConfigParser *config;
90
90
int launchprocess (char *cmdline, DWORD *status) {
91
91
PROCESS_INFORMATION pi = {};
92
92
STARTUPINFO si = {};
93
-
93
+
94
94
if (cmdline == NULL ) {
95
95
return -1 ;
96
96
}
@@ -677,7 +677,106 @@ int get_analysisdata(ostringstream *osslog = NULL) {
677
677
sprintf (srcpath, " %s\\ winevt\\ Logs\\ %s" , sysdir, file.first .c_str ());
678
678
sprintf (dstpath, " Evtx\\ %s" , file.first .c_str ());
679
679
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
+ }
681
780
}
682
781
}
683
782
cerr << msg (" イベントログ 取得完了" , " event log is saved" ) << endl;
@@ -928,7 +1027,7 @@ int main(int argc, char **argv)
928
1027
929
1028
// chack proces name
930
1029
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;
932
1031
cout << msg (" Cyber Defense Institute, Inc.\n " , " Cyber Defense Institute, Inc.\n " ) << endl;
933
1032
934
1033
// set curdir -> exedir
0 commit comments