weird issue when trying to read mask option from file
#1
Question 
Hi,

I am trying to perform mask attack with different mask configurations that are predefined in a file. I read each line of that file using shell script and execute hashcat-cli32.bin.

However, some of configs that I read from file, though works if I issue them directly from command line, do not work if I read them from file.

For example this one:
Code:
./hashcat-0.46/hashcat-cli32.bin -m 0 -a 3 --disable-potfile --outfile-format=1 -o cracked.dic hashed.txt --pw-min 4 ?l?l?d?d

When reading from file it says:
Code:
Usage: hashcat [options] hashfile [mask|wordfiles|directories]

Try --help for more help.

Which I think suggesting I used a wrong format. when in terminal it works fine.

What I do in script is to read "--pw-min 4 ?l?l?d?d" part from file and concatenate it with the first part, which is the same all the time. I just want to try different mask strategies.

Any suggestion? thanks!
#2
You are probably not escaping some values properly.
Can you give more details on the actual lines in the script itself?
#3
(11-08-2013, 07:02 PM)unix-ninja Wrote: You are probably not escaping some values properly.
Can you give more details on the actual lines in the script itself?

sure!

heres the full script:
Code:
# read mask per line from the file
old_IFS=$IFS      # save the field separator          
IFS=$'\n'
for line in $(cat $1)
do
    echo "======> mask: $line ..."
    ./hashcat-0.46/hashcat-cli32.bin -m 0 -a 3 --disable-potfile --outfile-format=1 -o cracked.dic $2 $line
done
IFS=$old_IFS

$1 is the mask file and $2 is the hashed file. and the mask file is like:

Code:
?l?l?l?l?l?l
--pw-min=4 ?l?l?d?d
--pw-min=5 ?l?l?l?l?d
--custom-charset1=?d?l ?1?1?1?1

only the first one works.
#4
In cases like this I normally just add a "echo" before the actual command (like echo ./hashcat-0.46 and you will see what is going on)... also I normally prefer the:
while read line
do
// ... something with the line
done < $1

but it depends from case to case
#5
(11-08-2013, 07:16 PM)philsmd Wrote: In cases like this I normally just add a "echo" before the actual command (like echo ./hashcat-0.46 and you will see what is going on)...

do you mean to print the command out to see the problem? When I printed it out, then copy n paste the echoed command to command line, it still works. this is the most confusing part.

(11-08-2013, 07:16 PM)philsmd Wrote: also I normally prefer the:
while read line
do
// ... something with the line
done < $1

but it depends from case to case

The reason I use for loop because while seems not wait each execute before looping the next, thusly I cannot perform my masks one by one (using while loop they seems to be messed with each other and some of them will not get executed).
#6
I don't think that last problem (not wait) has anything to do with for vs while... I think that problem is totally unrelated...
Indeed executing the cmds not one after the other should only happen if you force the process to execute in background ( & )
Try it with the echos to test with while...

Anyway the solution for for is (also see here http://stackoverflow.com/questions/17099...delimiters )

Code:
#!/bin/sh
old_IFS="$IFS"
IFS='
'
for line in $(cat $1)
do
    echo "======> mask: $line ..."
    echo ./hashcat-0.46/hashcat-cli32.bin -m 0 -a 3 --disable-potfile --outfile-format=1 -o cracked.dic $2 $line
done
IFS="$old_IFS"

Basically, you need to enter a newline right into the shell script file... should work...
both while/for work here
#7
The problem here is simple. You are piping multiple arguments to hashcat through the $line variable, and your script is therefore sending them to hashcat as a single parameter.
You think it's saying: hashcat --flag param
But it's actually executing like this: hashcat "--flag param"

Here is a revised version of your script that should work a lot better:

Code:
#!/bin/bash

masks="`cat $1`"
hashfile=$2

IFS=$'\n'
set $(cat $1)

for line in $@; do
  echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
  cmd="./hashcat-0.46/hashcat-cli32.bin -m 0 -a 3 --disable-potfile --outfile-format=1 -o cracked.dic $hashfile $line"
  eval $cmd
done
#8
Yes that makes sense! I got it working, thank you!!!!

one question though, I don't quite understand your code though. are you trying to preload the masks file and then loop the variable in stead of the file? i mean for these 3 lines of code:

(11-08-2013, 08:37 PM)unix-ninja Wrote:
Code:
#!/bin/bash

masks="`cat $1`"
...


set $(cat $1)

for line in $@; do
...

Instead of looping the file, it actually looping the characters in the file path, which is the $1.
#9
thanks for the link! very informative. trying it now.

(11-08-2013, 07:41 PM)philsmd Wrote: I don't think that last problem (not wait) has anything to do with for vs while... I think that problem is totally unrelated...
Indeed executing the cmds not one after the other should only happen if you force the process to execute in background ( & )
Try it with the echos to test with while...

Anyway the solution for for is (also see here http://stackoverflow.com/questions/17099...delimiters )

Code:
#!/bin/sh
old_IFS="$IFS"
IFS='
'
for line in $(cat $1)
do
    echo "======> mask: $line ..."
    echo ./hashcat-0.46/hashcat-cli32.bin -m 0 -a 3 --disable-potfile --outfile-format=1 -o cracked.dic $2 $line
done
IFS="$old_IFS"

Basically, you need to enter a newline right into the shell script file... should work...
both while/for work here