[GH-ISSUE #701] bash completion must not call ./john with all the command line parameters... #346

Closed
opened 2026-10-14 03:02:21 +07:00 by bsakaguchi · 13 comments
Owner

Originally created by @frank-dittrich on GitHub (Jul 23, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/701

Bash completion shouldn't reuse all command line parameters when trying to complete --rules= etc.

While testing some --fork issues, I wanted to add --rules and use bash completion for --rules=no[tab].
The completion took longer than usual, and top listed this process running:

./john --nolog --mem-file-size=0 dummy.hashes --wordlist=rockyou.txt --list=rules --fork=2 > stdout.txt

I guess this is the result of bash completion trying to reuse the command line (to find the right config file if there is a --conf= on the command line.

I really need to restrict which parameters and options I use.
And I wonder why "> stdout.txt" is part of the command line as seen in top.

Originally created by @frank-dittrich on GitHub (Jul 23, 2014). Original GitHub issue: https://github.com/openwall/john/issues/701 Bash completion shouldn't reuse all command line parameters when trying to complete --rules= etc. While testing some --fork issues, I wanted to add --rules and use bash completion for --rules=no[tab]. The completion took longer than usual, and top listed this process running: ``` ./john --nolog --mem-file-size=0 dummy.hashes --wordlist=rockyou.txt --list=rules --fork=2 > stdout.txt ``` I guess this is the result of bash completion trying to reuse the command line (to find the right config file if there is a --conf= on the command line. I really need to restrict which parameters and options I use. And I wonder why "> stdout.txt" is part of the command line as seen in top.
bsakaguchi 2026-10-14 03:02:21 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@magnumripper commented on GitHub (Jul 23, 2014):

Yeah that > stdout.txt is even a dangerous bug!

<!-- gh-comment-id:49848702 --> @magnumripper commented on GitHub (Jul 23, 2014): Yeah that `> stdout.txt` is even a dangerous bug!
Author
Owner

@frank-dittrich commented on GitHub (Jul 23, 2014):

I was afraid of the "> stdout.txt" part as well.
But why is it shown in top output? Apparently, it somehow became a part of the command, not an output redirection.
Because, after finishing the completion, there is no file stdout.txt, so nothing got redirected.
While there's still a bug that needs fixing, I don't think it is dangerous.

<!-- gh-comment-id:49852982 --> @frank-dittrich commented on GitHub (Jul 23, 2014): I was afraid of the "> stdout.txt" part as well. But why is it shown in top output? Apparently, it somehow became a part of the command, not an output redirection. Because, after finishing the completion, there is no file stdout.txt, so nothing got redirected. While there's still a bug that needs fixing, I don't think it is dangerous.
Author
Owner

@magnumripper commented on GitHub (Jul 23, 2014):

Maybe it is run in a sandbox, with that redirection.

<!-- gh-comment-id:49866066 --> @magnumripper commented on GitHub (Jul 23, 2014): Maybe it is run in a sandbox, with that redirection.
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

Here's another variant of (probably) same bug. I can't see what introduced this, I'm pretty sure these problems are new:

$ ../run/john test --external=<TAB><TAB>
(dummy    1         Loaded    [N/A])    hash      left      to        
(see      FAQ)      No        crack     hashes    password  

After removing john.pot I get similar output, but mixed with the expected list of external modes.

<!-- gh-comment-id:52859578 --> @magnumripper commented on GitHub (Aug 20, 2014): Here's another variant of (probably) same bug. I can't see what introduced this, I'm pretty sure these problems are new: ``` $ ../run/john test --external=<TAB><TAB> (dummy 1 Loaded [N/A]) hash left to (see FAQ) No crack hashes password ``` After removing john.pot I get similar output, but mixed with the expected list of external modes.
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

Isn't the problem that the enumeration call to john includes the hash file(s) if any were given? It should only include arguments that starts with a - dash.

<!-- gh-comment-id:52859957 --> @magnumripper commented on GitHub (Aug 20, 2014): Isn't the problem that the enumeration call to `john` includes the hash file(s) if any were given? It should only include arguments that starts with a `-` dash.
Author
Owner

@magnumripper commented on GitHub (Aug 21, 2014):

This works, but only if I use sed -r.

diff --git a/run/john.bash_completion b/run/john.bash_completion
index fa787a4..3365607 100644
--- a/run/john.bash_completion
+++ b/run/john.bash_completion
@@ -303,6 +303,9 @@ _john()
        fi
        COMPREPLY=()

+       # Drop any input files from the command to run for enumeration
+       COMP_LINE=`echo ${COMP_LINE}|sed -r "s# [^\-][^ ]+##g"`
+
        # We do not check the token specified on the command line.
        # Instead, we check a modified token (abbreviated option name
        # has already been replaced with the complete option name).
<!-- gh-comment-id:52861938 --> @magnumripper commented on GitHub (Aug 21, 2014): This works, but only if I use `sed -r`. ``` diff --git a/run/john.bash_completion b/run/john.bash_completion index fa787a4..3365607 100644 --- a/run/john.bash_completion +++ b/run/john.bash_completion @@ -303,6 +303,9 @@ _john() fi COMPREPLY=() + # Drop any input files from the command to run for enumeration + COMP_LINE=`echo ${COMP_LINE}|sed -r "s# [^\-][^ ]+##g"` + # We do not check the token specified on the command line. # Instead, we check a modified token (abbreviated option name # has already been replaced with the complete option name). ```
Author
Owner

@magnumripper commented on GitHub (Aug 21, 2014):

Wasn't supposed to be closed yet.

<!-- gh-comment-id:52863484 --> @magnumripper commented on GitHub (Aug 21, 2014): Wasn't supposed to be closed yet.
Author
Owner

@magnumripper commented on GitHub (Aug 21, 2014):

In case that redirection really was a problem, it's actually removed now by the very same regex. It wasn't intended but I realized it now that I was going to add that :-)

I wonder if there can be any ill effects though. Apart from that -r is not guaranteed to work everywhere...

I see you are using similar regexps though, without adding -r. How come?!

<!-- gh-comment-id:52864104 --> @magnumripper commented on GitHub (Aug 21, 2014): In case that redirection really was a problem, it's actually removed now by the very same regex. It wasn't intended but I realized it now that I was going to add that :-) I wonder if there can be any ill effects though. Apart from that `-r` is not guaranteed to work everywhere... I see you are using similar regexps though, without adding `-r`. How come?!
Author
Owner

@magnumripper commented on GitHub (Aug 21, 2014):

Hmm here is the real problem (I think this behavior is new)

$ ../run/john test --list=externals 
Loaded 1 password hash (dummy [N/A])
No password hashes left to crack (see FAQ)

I believe in earlier versions the --list option overrode everything else. Maybe we can revert to that and revert 4dc73c9.

<!-- gh-comment-id:52865213 --> @magnumripper commented on GitHub (Aug 21, 2014): Hmm here is the real problem (I think this behavior is new) ``` $ ../run/john test --list=externals Loaded 1 password hash (dummy [N/A]) No password hashes left to crack (see FAQ) ``` I believe in earlier versions the --list option overrode everything else. Maybe we can revert to that and revert 4dc73c9.
Author
Owner

@frank-dittrich commented on GitHub (Aug 21, 2014):

On 08/21/2014 02:14 AM, magnum wrote:

This works. But is it OK? I now had to add |-r| to sed (why?!). Is
that a bad thing?

I don't think it is a problem. Using GNU extensions would be a problem.

<!-- gh-comment-id:52888084 --> @frank-dittrich commented on GitHub (Aug 21, 2014): On 08/21/2014 02:14 AM, magnum wrote: > This works. But is it OK? I now had to add |-r| to sed (why?!). Is > that a bad thing? I don't think it is a problem. Using GNU extensions would be a problem.
Author
Owner

@frank-dittrich commented on GitHub (Aug 21, 2014):

On 08/21/2014 02:43 AM, magnum wrote:

Hmm here is the real problem (I think this behavior is new)

|$ ../run/john test --list=externals
Loaded 1 password hash (dummy [N/A])
No password hashes left to crack (see FAQ)
|

I believe in earlier versions the --list option overrode everything
else. Maybe we can revert to that and revert 4dc73c9
github.com/magnumripper/JohnTheRipper@4dc73c9247.

Preferably, john should warn about an illegal combination of options here.
It doesn't make sense to use --list together with --test (and many other
options).

<!-- gh-comment-id:52888415 --> @frank-dittrich commented on GitHub (Aug 21, 2014): On 08/21/2014 02:43 AM, magnum wrote: > Hmm here is the real problem (I think this behavior is new) > > |$ ../run/john test --list=externals > Loaded 1 password hash (dummy [N/A]) > No password hashes left to crack (see FAQ) > | > > I believe in earlier versions the --list option overrode everything > else. Maybe we can revert to that and revert 4dc73c9 > https://github.com/magnumripper/JohnTheRipper/commit/4dc73c9247e1d96f560ad5c12a0aba8476860e54. Preferably, john should warn about an illegal combination of options here. It doesn't make sense to use --list together with --test (and many other options).
Author
Owner

@magnumripper commented on GitHub (Aug 21, 2014):

Preferably, john should warn about an illegal combination of options here. It doesn't make sense to use --list together with --test (and many other options).

Normally yes, but for shell completion the "override" behavior turned out to be a feature - without it we'd need a lot more stuff trimmed from $COMP_LINE with some sort of heuristics. I believe we currently have complete override for listconf_parse_early() while listconf_parse_late() is called after loading hashes. I had a quick look today and it's not trivial to change that.

On the other hand we might do fine with a short whitelist and trim anything else. I guess --config= is one of the very few things we need to keep?

<!-- gh-comment-id:52954025 --> @magnumripper commented on GitHub (Aug 21, 2014): > Preferably, john should warn about an illegal combination of options here. It doesn't make sense to use --list together with --test (and many other options). Normally yes, but for shell completion the "override" behavior turned out to be a feature - without it we'd need a lot more stuff trimmed from `$COMP_LINE` with some sort of heuristics. I believe we currently have complete override for listconf_parse_early() while listconf_parse_late() is called after loading hashes. I had a quick look today and it's not trivial to change that. On the other hand we might do fine with a short whitelist and trim anything else. I guess `--config=` is one of the very few things we need to keep?
Author
Owner

@magnumripper commented on GitHub (Aug 28, 2014):

This seems to be fine now

<!-- gh-comment-id:53676364 --> @magnumripper commented on GitHub (Aug 28, 2014): This seems to be fine now
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#346
No description provided.