-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlocate.cna
45 lines (37 loc) · 1.35 KB
/
locate.cna
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Author: @nickvourd
#Inspired by @octoberfest73
alias locate {
local('@searchResults $searchTerm $resultCount $maxResults');
# Set maximum results limit
$maxResults = 50;
if(size(@_) != 2) {
berror($1, "Error: No search term provided!");
berror($1, beacon_command_detail("locate"));
return;
}
$searchTerm = $2;
@searchResults = readAll(exec(@("locate", "-i", "--", $searchTerm)));
$resultCount = size(@searchResults);
if($resultCount == 0) {
blog($1, "\c4Unable to find any files with the keyword: \"$searchTerm\"\c0\n");
return;
}
if($resultCount >= $maxResults) {
blog($1, "\c4Warning: Found $resultCount matches - output truncated!\c0");
blog($1, "\cCTip: Use a more specific search term to reduce results\c0\n");
}
else {
blog($1, "\c9Found $resultCount matches for \"$searchTerm\":\c0\n");
blog($1, "\c8==============================================\c0");
foreach $result (@searchResults) {
blog($1, "\c6 $result\c0");
}
blog($1, "\c8==============================================\c0\n");
blog($1, "\c9Search complete - $resultCount results displayed\c0\n");
}
}
beacon_command_register(
"locate",
"Linux locate command implementation",
"Usage: locate <keyword>"
);