Archived. Attack mode 12 does this directly. You write one mask and put ?w where the word goes, so there is no rule file to generate. This page is kept for reference and is listed in the Archive.
Outdated. This page describes how to build a brute-force rule file because there used to be no other way to put a mask somewhere other than the start or the end of a word. Attack mode 12 does that directly now, so you no longer need to generate a rule file for it:
$ hashcat -a 12 -m 0 hash.txt ?d?w?d?d example.dict
The rest of this page is kept because the technique still works, and because generating rules with maskprocessor is useful for other things.
All you need to do is to generate a so called brute-force rule. This is just all possible rules required to generate all possible combinations. This can be done with maskprocessor.
The generated rule file can be used to perform Hybrid attacks with hashcat. All you need is to pass the rule file to hashcat via -r bf.rule.
This appends 0000 - 9999 to each words from your dictionary:
$ ./mp64.bin -o bf.rule '$?d $?d $?d $?d'
This prepends aa - zz to each words from your dictionary:
$ ./mp64.bin -o bf.rule '^?l ^?l'