41
41
#pragma comment(lib, "libcrypto-38.lib")
42
42
43
43
#define CHUNKSIZE 262144
44
+ #define BLOCKSIZE 4096
44
45
45
46
using namespace std ;
46
47
@@ -264,7 +265,10 @@ int StealthGetFile(char *filepath, char *outpath, ostringstream *osslog = NULL,
264
265
offset = skipclusters * file->volume ->GetClusterSize ();
265
266
}
266
267
267
- if (!WriteWrapper::isLocal () && !(SparseSkip && strcmp (filepath, " C:\\ $Extend\\ $UsnJrnl:$J" ) == 0 )) { // if using WebDAV and reading file except UsnJrnl
268
+ char journalpath[MAX_PATH + 1 ];
269
+ sprintf (journalpath, " %s\\ $Extend\\ $UsnJrnl:$J" , osvolume);
270
+
271
+ if (!WriteWrapper::isLocal () && !(SparseSkip && strcmp (filepath, journalpath) == 0 )) { // if using WebDAV and reading file except UsnJrnl
268
272
if (wfile.sendheader ()) {
269
273
fprintf (stderr, " failed to send header.\n " );
270
274
return -1 ;
@@ -276,7 +280,7 @@ int StealthGetFile(char *filepath, char *outpath, ostringstream *osslog = NULL,
276
280
int ret;
277
281
278
282
if ((ret = StealthReadFile (file, buf, CHUNKSIZE, offset, &bytesread, &bytesleft, filesize)) != 0 ) {
279
- if (SparseSkip && strcmp (filepath, " C: \\ $Extend \\ $UsnJrnl:$J " ) == 0 ){
283
+ if (SparseSkip && strcmp (filepath, journalpath ) == 0 ){
280
284
filesize -= offset;
281
285
skipclusters = 0 ;
282
286
file->data = (CAttrBase*)file->fileRecord ->FindNextStream (" $J" , atrnum);
@@ -304,7 +308,7 @@ int StealthGetFile(char *filepath, char *outpath, ostringstream *osslog = NULL,
304
308
bytesleft = 1 ; // To continue loop
305
309
continue ;
306
310
}
307
- else if (offset < filesize) {
311
+ else if (ret == 4 && offset < filesize) {
308
312
filesize -= offset;
309
313
file->data = (CAttrBase*)file->fileRecord ->FindNextStream (0 ,atrnum);
310
314
if (file->data == NULL ) {
@@ -317,6 +321,12 @@ int StealthGetFile(char *filepath, char *outpath, ostringstream *osslog = NULL,
317
321
bytesleft = 1 ; // To continue loop
318
322
continue ;
319
323
}
324
+ else if (ret == 3 ) {
325
+ int adjustsize = CHUNKSIZE;
326
+ adjustsize -= BLOCKSIZE;
327
+ while (StealthReadFile (file, buf, adjustsize, offset, &bytesread, &bytesleft, filesize) == 3 )
328
+ adjustsize -= BLOCKSIZE;
329
+ }
320
330
else {
321
331
_perror (" Error reading file" );
322
332
printf (" filename: %s, offset: %lld\n " , filepath, offset);
@@ -345,7 +355,10 @@ int StealthGetFile(char *filepath, char *outpath, ostringstream *osslog = NULL,
345
355
}
346
356
}
347
357
// osfile.write((char*)buf, bytesread);
348
- wfile.write ((char *)buf, bytesread);
358
+ if (wfile.write ((char *)buf, bytesread) < 0 ) {
359
+ fprintf (stderr, " failed to write file.\n " );
360
+ return -1 ;
361
+ }
349
362
offset += bytesread;
350
363
} while (bytesleft > 0 && offset < filesize);
351
364
@@ -356,7 +369,9 @@ int StealthGetFile(char *filepath, char *outpath, ostringstream *osslog = NULL,
356
369
StealthCloseFile (file);
357
370
358
371
if (WriteWrapper::isLocal ()) {
359
- CopyFileTime (filepath, outpath);
372
+ if (CopyFileTime (filepath, outpath)) {
373
+ fprintf (stderr, " failed to copy filetime: %s\n " , filepath);
374
+ }
360
375
}
361
376
362
377
if (osslog) {
@@ -562,6 +577,12 @@ int get_analysisdata(ostringstream *osslog = NULL) {
562
577
cerr << msg (" ジャーナル 取得失敗" , " failed to save journal" ) << endl;
563
578
}
564
579
}
580
+ else {
581
+ cerr << msg (" ジャーナル 取得完了" , " journal is saved" ) << endl;
582
+ }
583
+ }
584
+ else {
585
+ cerr << msg (" ジャーナル 取得完了" , " journal is saved" ) << endl;
565
586
}
566
587
}
567
588
@@ -771,7 +792,7 @@ int main(int argc, char **argv)
771
792
772
793
// chack proces name
773
794
procname = basename (string (argv[0 ]));
774
- cout << msg (" CDIR Collector v1.2 - 初動対応用データ収集ツール" , " CDIR Collector v1.2 - Data Acquisition Tool for First Response" ) << endl;
795
+ cout << msg (" CDIR Collector v1.2.1 - 初動対応用データ収集ツール" , " CDIR Collector v1.2.1 - Data Acquisition Tool for First Response" ) << endl;
775
796
cout << msg (" Cyber Defense Institute, Inc.\n " , " Cyber Defense Institute, Inc.\n " ) << endl;
776
797
777
798
// getting config
@@ -831,7 +852,7 @@ int main(int argc, char **argv)
831
852
_perror (" localtime" );
832
853
__exit (EXIT_FAILURE);
833
854
}
834
- if (!strftime (timestamp, sizeof (timestamp), " %Y%m%d%H%M%S" , t) || !strftime (t_beg, sizeof (t_beg), " %Y %m/%d %H:%M:%S" , t)) {
855
+ if (!strftime (timestamp, sizeof (timestamp), " %Y%m%d%H%M%S" , t) || !strftime (t_beg, sizeof (t_beg), " %Y/ %m/%d %H:%M:%S" , t)) {
835
856
_perror (" strftime" );
836
857
__exit (EXIT_FAILURE);
837
858
}
@@ -888,7 +909,8 @@ int main(int argc, char **argv)
888
909
_perror (" GetCurrentDirectory" );
889
910
__exit (EXIT_FAILURE);
890
911
}
891
- cerr << msg (" 保存先: " , " Output Directory: " ) << outdir << endl;
912
+ if (WriteWrapper::isLocal ())
913
+ cerr << msg (" 保存先: " , " Output Directory: " ) << outdir << endl;
892
914
893
915
// start logging
894
916
ostringstream ossinfo, osslog;
@@ -974,7 +996,7 @@ int main(int argc, char **argv)
974
996
_perror (" localtime" );
975
997
__exit (EXIT_FAILURE);
976
998
}
977
- if (!strftime (t_end, sizeof (t_end), " %Y %m/%d %H:%M:%S" , t)) {
999
+ if (!strftime (t_end, sizeof (t_end), " %Y/ %m/%d %H:%M:%S" , t)) {
978
1000
_perror (" strftime" );
979
1001
__exit (EXIT_FAILURE);
980
1002
}
@@ -1022,7 +1044,9 @@ int main(int argc, char **argv)
1022
1044
1023
1045
string log_str = ossinfo.str ();
1024
1046
WriteWrapper log (" collector-log.txt" , log_str.size ());
1025
- log .sendfile (log_str.c_str ());
1047
+ if (log .sendfile (log_str.c_str ())) {
1048
+ fprintf (stderr, " failed to save log" );
1049
+ }
1026
1050
log .close ();
1027
1051
__exit (EXIT_SUCCESS);
1028
1052
}
0 commit comments