Skip to content

Commit 9354b5a

Browse files
author
Victor MASIAK
committed
new anti-VM features: checks coherence of files dates
1 parent 4dd7d4b commit 9354b5a

File tree

7 files changed

+76
-1
lines changed

7 files changed

+76
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ add_executable(
2828
antiVM/loadedModulesFromLSMOD.c antiVM/loadedModulesFromLSMOD.h
2929

3030
antiFake/firefoxHistory.c antiFake/firefoxHistory.h
31-
antiFake/chromeHistory.c antiFake/chromeHistory.h antiFake/browserHistory.c antiFake/browserHistory.h antiFake/upTime.c antiFake/upTime.h antiVM/screenResolution.c antiVM/screenResolution.h antiVM/userNames.c antiVM/userNames.h antiVM/devicesScsi.c antiVM/devicesScsi.h antiVM/biosVendor.c antiVM/biosVendor.h antiVM/productName.c antiVM/productName.h antiVM/systemVendor.c antiVM/systemVendor.h antiVM/boardVendor.c antiVM/boardVendor.h)
31+
antiFake/chromeHistory.c antiFake/chromeHistory.h antiFake/browserHistory.c antiFake/browserHistory.h antiFake/upTime.c antiFake/upTime.h antiVM/screenResolution.c antiVM/screenResolution.h antiVM/userNames.c antiVM/userNames.h antiVM/devicesScsi.c antiVM/devicesScsi.h antiVM/biosVendor.c antiVM/biosVendor.h antiVM/productName.c antiVM/productName.h antiVM/systemVendor.c antiVM/systemVendor.h antiVM/boardVendor.c antiVM/boardVendor.h antiVM/systemAge.c antiVM/systemAge.h)
3232

3333
find_package(X11 REQUIRED)
3434
include_directories(${X11_INCLUDE_DIR})

antiVM/systemAge.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <time.h>
2+
#include "systemAge.h"
3+
4+
const char* FILES_CHECK_AGE[] = {".", "/"};
5+
const int FILES_CHECK_AGE_SIZE = 2;
6+
7+
int checkSystemAgeCoherence(char* resultDescriptionBuffer){
8+
9+
char tmp[3][128];
10+
strcpy(resultDescriptionBuffer, "");
11+
12+
time_t systemAge, currentDirectory;
13+
int isOlder;
14+
int couldReadFiles = RESULT_SUCCESS;
15+
int result = RESULT_SUCCESS;
16+
17+
if(getLastModification("/var/log/installer", &systemAge)){
18+
strcat(resultDescriptionBuffer, "--> Could not read /var/log/installer metadata.\n");
19+
return RESULT_UNKNOWN;
20+
}
21+
22+
for(int i=0 ; i<FILES_CHECK_AGE_SIZE ; i++){
23+
if(getLastModification(FILES_CHECK_AGE[i], &currentDirectory)){
24+
snprintf(tmp[0], 128, "--> Could not read %s metadata.\n", FILES_CHECK_AGE[i]);
25+
strcat(resultDescriptionBuffer, tmp[0]);
26+
couldReadFiles = RESULT_UNKNOWN;
27+
}
28+
isOlder = difftime(currentDirectory, systemAge) >= 0;//should be true
29+
if(!isOlder){
30+
strftime(tmp[0], 128, "%d-%m-%Y", localtime(&currentDirectory));
31+
strftime(tmp[1], 128, "%d-%m-%Y", localtime(&systemAge));
32+
snprintf(tmp[2], 128, "--> %s is older than /var/log/installer (%s vs %s).\n", FILES_CHECK_AGE[i], tmp[0], tmp[1]);
33+
strcat(resultDescriptionBuffer, tmp[2]);
34+
result = RESULT_FAILURE;
35+
}
36+
}
37+
38+
if(result == RESULT_FAILURE){
39+
return result;
40+
}else if(couldReadFiles == RESULT_UNKNOWN){
41+
return RESULT_UNKNOWN;
42+
}else{
43+
return RESULT_SUCCESS;
44+
}
45+
}

antiVM/systemAge.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef APATE_SYSTEMAGE_H
2+
#define APATE_SYSTEMAGE_H
3+
4+
#include "../constants.h"
5+
#include "../files.h"
6+
7+
int checkSystemAgeCoherence(char* resultDescriptionBuffer);
8+
9+
#endif //APATE_SYSTEMAGE_H

files.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,19 @@ void readFileLine(char* filename, int lineNumber, char* buffer){
8686
}
8787
fclose(file);
8888
}
89+
}
90+
91+
int getLastModification(char* path, time_t* lastModification){
92+
93+
int file=0;
94+
if((file=open(path,O_RDONLY)) < -1)
95+
return 1;
96+
97+
struct stat fileStat;
98+
if(fstat(file,&fileStat) < 0)
99+
return 1;
100+
101+
*lastModification = fileStat.st_mtime;
102+
return 0;
103+
89104
}

files.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
#include <unistd.h>
1010
#include <errno.h>
1111

12+
#include <sys/types.h>
13+
#include <sys/stat.h>
14+
1215
int cp(const char *to, const char *from);
1316
int checkWordInFile(FILE* file, char* str);
1417
void readFileLine(char* filename, int lineNumber, char* buffer);
18+
int getLastModification(char* path, time_t* lastModification);
1519

1620
#endif //APATE_FILES_H

main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int main(int argc, char *argv[]) {
5555
printHeader("ANTI-FAKE");
5656
printResult("Inspects browsers histories", checkBrowserHistory(resultDescriptionBuffer), resultDescriptionBuffer);
5757
printResult("Checks that the system has been running for at least 30 minutes", checkUpTime(resultDescriptionBuffer), resultDescriptionBuffer);
58+
printResult("Checks the coherence of system age", checkSystemAgeCoherence(resultDescriptionBuffer), resultDescriptionBuffer);
5859

5960
return 0;
6061
}

main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ extern int paramCompact;
3838

3939
#include "antiFake/browserHistory.h"
4040
#include "antiFake/upTime.h"
41+
#include "antiVM/systemAge.h"
4142

4243
#endif //APATE_MAIN_H

0 commit comments

Comments
 (0)