-1

I want test to open a winrar password protected file, testing with dictionay of words. This is my code, but it don't work can any help me ? thanks

import subprocess
def extractFile(rFile, password):
try:
    subprocess.call(['c:\\mio\\unrar\\unrar.exe -p'+password+'x C:\\mio\\unrar\\'+rFile,'shell=True'])
    return password
except:
    return
def main():    
rFile = "c:\\mio\\unrar\msploit.rar"
passFile = open("C:\\mio\\unrar\\dic.txt")
for line in passFile.readlines():
    password = line.strip('\n')

    guess = extractFile(rFile, password)
    print(password)
    if guess:
       print '[+] Password = ' + password + '\n'
       break
if __name__ == '__main__':
main()
CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • you have to indent the `main()` line (the last one) – CharlesB Jan 10 '14 at 08:53
  • 2
    Can you please explain wha tdo you mean by `doesn't work`? Please be more specific when asking about a problem with your code. – aIKid Jan 10 '14 at 08:55
  • @CharlesB and other lines as well. – glglgl Jan 10 '14 at 09:19
  • What do you want to achieve by putting `, 'shell=True'` into the array instead of giving it properly as an argument to the function? – glglgl Jan 10 '14 at 09:20
  • In my response you will see that `call()` has wrong arguments, but I think that even when `call()` succeeds you may not guess password correctly and then probably `unrar` will display some error and will not create output file. – Michał Niklas Jan 10 '14 at 11:13

1 Answers1

1

First argument to call() is an array but you use full command. Try something like:

subprocess.call(['unrar.exe', 'x', '-p'+password, rarfn], shell=True)

EDIT:

I think you will also have to check if output file is created. Maybe unrar with incorrect password will not create output file. Check if it is created (for example use os.path.isfile()). You can also examine unrar output to see where is the problem.

EDIT2:

It seems that there was no x rar command to Extract files with full path.

This is working example where I rar-ed with password file Order.htm into Order.rar and then I deleted Order.htm:

rarfn = 'Order.rar'
outfn = 'Order.htm'
if os.path.isfile(outfn):
    print('%s already exists!!!' % (outfn))
else:
    for password in ('ala', 'ma', 'kota', 'zorro', 'rudy'):
        print('testing %s...' % (password))
        subprocess.call(['unrar.exe', 'x', '-p'+password, rarfn], shell=True)
        if os.path.isfile(outfn):
            print('guessed: [%s]' % (password))
            break
Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
  • Thanks, unrar in dos mode works ok with unrar -ppassword xfile.rar, but in subprocess call, putting this:subprocess.call(['c:\\mio\\unrar\\unrar.exe ', '-p',password,' xC:\\mio\\unrar\\',rFile]) opens a dos windows but waiting a password manually – user3180949 Jan 10 '14 at 11:39