mirror of
https://github.com/nmap/nmap.git
synced 2025-12-13 11:19:02 +00:00
Improve fingermatch/fingerdiff in deciding which tests to use when there are multiple instances of the same test line
This commit is contained in:
@@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {
|
|||||||
char observedFPString[8192];
|
char observedFPString[8192];
|
||||||
char line[512];
|
char line[512];
|
||||||
char *p, *endptr;
|
char *p, *endptr;
|
||||||
int i;
|
int i, rc;
|
||||||
int done=0;
|
int done=0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
@@ -182,9 +182,14 @@ int main(int argc, char *argv[]) {
|
|||||||
if (readFP(stdin, observedFPString, sizeof(observedFPString)) == -1)
|
if (readFP(stdin, observedFPString, sizeof(observedFPString)) == -1)
|
||||||
usage("Failed to read in supposed observed fingerprint from stdin\n");
|
usage("Failed to read in supposed observed fingerprint from stdin\n");
|
||||||
|
|
||||||
|
|
||||||
observedFP = parse_single_fingerprint(observedFPString);
|
observedFP = parse_single_fingerprint(observedFPString);
|
||||||
if (!observedFP) fatal("Sorry -- failed to parse the so-called reference fingerprint you entered");
|
if (!observedFP) fatal("Sorry -- failed to parse the so-called reference fingerprint you entered");
|
||||||
|
|
||||||
|
if ((rc = remove_duplicate_tests(observedFP))) {
|
||||||
|
printf("[WARN] Adjusted fingerprint due to %d duplicated tests (we only look at the first).\n", rc);
|
||||||
|
}
|
||||||
|
|
||||||
/* OK, now I've got the fingerprints -- I just need to compare them ... */
|
/* OK, now I've got the fingerprints -- I just need to compare them ... */
|
||||||
accuracy = compare_fingerprints(referenceFP, observedFP, 1);
|
accuracy = compare_fingerprints(referenceFP, observedFP, 1);
|
||||||
if (accuracy == 1)
|
if (accuracy == 1)
|
||||||
|
|||||||
@@ -290,6 +290,15 @@ int readFP(FILE *filep, char *FP, int FPsz ) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int count_attributes(struct AVal *res) {
|
||||||
|
int count = 0;
|
||||||
|
while(res) {
|
||||||
|
count++;
|
||||||
|
res = res->next;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
/* When Nmap prints a fingerprint for submission, it sometimes
|
/* When Nmap prints a fingerprint for submission, it sometimes
|
||||||
includes duplicates of tests because 1 or more elements of that
|
includes duplicates of tests because 1 or more elements of that
|
||||||
test differ. While this is important for things like fingerfix
|
test differ. While this is important for things like fingerfix
|
||||||
@@ -308,15 +317,18 @@ int remove_duplicate_tests(FingerPrint *FP) {
|
|||||||
and if so, remove them */
|
and if so, remove them */
|
||||||
for(inner = outer; inner->next; inner = inner->next) {
|
for(inner = outer; inner->next; inner = inner->next) {
|
||||||
if (strcmp(outer->name, inner->next->name) == 0) {
|
if (strcmp(outer->name, inner->next->name) == 0) {
|
||||||
/* DUPLICATE FOUND! REMOVE IT */
|
/* DUPLICATE FOUND! REMOVE THE ONE W/THE FEWEST ATTRIBUTES */
|
||||||
|
int outeratts = count_attributes(outer->results);
|
||||||
|
int inneratts = count_attributes(inner->next->results);
|
||||||
|
if (inneratts > outeratts) {
|
||||||
|
/* We do a swap of members because we can't change the address of 'FP' */
|
||||||
|
outer->results = inner->next->results; /* MEMORY LEAK BUT THATS OK */
|
||||||
|
}
|
||||||
dupsfound++;
|
dupsfound++;
|
||||||
tmp = inner->next;
|
inner->next = inner->next->next; /* MEMORY LEAK, BUT THATS OK */
|
||||||
inner->next = inner->next->next;
|
|
||||||
free(tmp);
|
|
||||||
}
|
}
|
||||||
if (!inner->next) break;
|
if (!inner->next) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dupsfound;
|
return dupsfound;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user