Allow to search for multiple functions

This commit is contained in:
Andrea Cardaci 2018-09-15 16:06:56 +02:00
parent 45b926300f
commit 339f87a077

View File

@ -1,4 +1,4 @@
<input id="bin-search" type="text" placeholder="Search among {{ site.gtfobins | size }} binaries by name (e.g., 'ftp') or by function (e.g., '/shell')"/> <input id="bin-search" type="text" placeholder="Search among {{ site.gtfobins | size }} binaries: <binary> +<function> ..."/>
<div id="bin-table-wrapper"> <div id="bin-table-wrapper">
<table id="bin-table"> <table id="bin-table">
@ -24,25 +24,29 @@
<script> <script>
function filter(query) { function filter(query) {
var queryArray = query.toLowerCase().trim().split(/ *\+/);
var binPattern = queryArray[0];
var functionPatterns = queryArray.splice(1);
// consistently update the URL // consistently update the URL
location.hash = query; location.hash = query;
// determine the query type
var queryType = query[0];
if (queryType === '/') {
query = query.slice(1);
}
// filter rows // filter rows
var noResults = true; var noResults = true;
document.querySelectorAll('#bin-table tbody tr').forEach(function (row) { document.querySelectorAll('#bin-table tbody tr').forEach(function (row) {
var binName = row.children[0].firstElementChild.innerText.toLowerCase(); var binName = row.children[0].firstElementChild.innerText.toLowerCase();
var functions = Array.from(row.children[1].firstElementChild.children) var functions = Array.from(row.children[1].firstElementChild.children)
.map(function (x) { return x.innerText }) .map(function (x) { return x.innerText })
.join('\n').toLowerCase(); .join('\x00').toLowerCase(); // separator
var against = (queryType === '/' ? functions : binName); var show = (
if (against.indexOf(query) !== -1) { binName.indexOf(binPattern) !== -1 &&
functionPatterns.every(function (pattern) {
return functions.indexOf(pattern) !== -1;
})
);
if (show) {
row.style.display = ''; row.style.display = '';
noResults = false; noResults = false;
} else { } else {
@ -64,14 +68,14 @@
// handle user input // handle user input
searchBox.addEventListener('input', function () { searchBox.addEventListener('input', function () {
var query = searchBox.value.toLowerCase().trim(); var query = searchBox.value;
filter(query); filter(query);
}); });
// handle shortcuts // handle shortcuts
addEventListener('keydown', function (event) { addEventListener('keydown', function (event) {
// focus search box on valid keydown // focus search box on valid keydown
if (event.key.toLowerCase().match(/^[\/a-z]$/) && if (event.key.toLowerCase().match(/^[+a-z]$/) &&
!(event.ctrlKey || event.altKey || event.metaKey)) { !(event.ctrlKey || event.altKey || event.metaKey)) {
searchBox.focus(); searchBox.focus();
} }