Your grep
(likely GNU grep
) detects that the file may not be text and instead of printing the matching lines, it only tells you there's a match to avoid printing what may just be garbage.
To bypass that and print it nonetheless, you can add the -a
option (a GNU extension).
Also note that grep
by default matches regular expressions (the re
in grep
), you need -F
to find substrings.
Also, arguments to executed commands are public knowledge on a system, so you shouldn't pass a password or any sensitive data to grep
as argument unless grep
happens to be a built-in of your shell (very few shells have grep
builtin though).
So instead, assuming a shell where printf
is builtin (most these days):
printf '%s\n' "$password" | grep -anFf - /usr/share/wordlists/weakpass_3
Where:
-a
: bypass the heuristic check for binary files
-F
: F
ixed string search instead of regular expression matching
-f -
: takes the list of strings to search for from stdin (one per line)
-n
: report line numbers
file /usr/share/wordlists/weakpass_3
– UndercoverDog Dec 10 '22 at 21:18grep -a 'text' /yourpath
. Related: grep returns "Binary file matches" – Edgar Magallon Dec 10 '22 at 21:38file /usr/share/wordlists/weakpass_3
– Cyrus Dec 10 '22 at 21:57grep
seems to interfere with at least one character in your file and then classifies it as data. A possible workaround might be:strings /usr/share/wordlists/weakpass_3 | grep -n 'text'
– Cyrus Dec 10 '22 at 23:13