Author Topic: Crack Firefox passwords with python  (Read 4612 times)

0 Members and 3 Guests are viewing this topic.

Offline fox12345

  • Serf
  • *
  • Posts: 25
  • Cookies: -31
    • View Profile
Crack Firefox passwords with python
« on: September 23, 2013, 11:42:04 am »
I've been keeping a lookout for ffpasscracker.py
I use your script and run it in test mode with my windows 8 pc. I changed some options. but i have not a good result.


I Download "cygwin1.dll","cygwin.dll" and install it my pc. it is give me a error massage.


command > regsvr32 cygwin1.dll


error 1 > "The module "cygwin1.dll" may not compatible with the version of windows that you're running. Check if the module is compatible with an x86 or 64 version of regsvr32.exe"


error 2 > The Module "cygwin1.dll failed to load. Make sure the binary is stored at the specified path or debug it to check for problems with the binary or dependent .DLL files. The specified module could not be found. (But cygwin1.dll is really at the system32 folder)


Same result to cygwin.dl


So how to fix this problem?
How to run this script in my windows 8 pc without any problem?
What to do?
I need serious help with that......


Code: [Select]
#!/usr/bin/env python
# ffpwdcracker - Crack the passwords stored using Firefox browser. The script currently works only on Linux.
# Author : Pradeep Nayak (pradeep1288@gmail.com)
# usage: ffpwdcracker [paths_to_location_of_files]
# Run it with no paramters to extract the standard Passwords from all Profiles of the current
# logged in User.
# Required files:
#    + key3.db
#    + signongs.sqlite
#    + cert8.db
# are used and needed to collect the passwords.
from ctypes import *
import struct
import sys
import os
import glob
import re
import time
import base64


#Password structures
class SECItem(Structure):
   _fields_ = [('type',c_uint),('data',c_void_p),('len',c_uint)]


class secuPWData(Structure):
   _fields_ = [('source',c_ubyte),('data',c_char_p)]


(SECWouldBlock,SECFailure,SECSuccess)=(-2,-1,0)
(PW_NONE,PW_FROMFILE,PW_PLAINTEXT,PW_EXTERNAL)=(0,1,2,3)


def findpath_userdirs():
   appdata = os.getenv('HOME')
   usersdir = appdata+os.sep+".mozilla"+os.sep+'firefox'
   userdir = os.listdir(usersdir)
   res=[]
   for user in userdir:
      if os.path.isdir(usersdir+os.sep+user):
         res.append(usersdir+os.sep+user)
   return res


def errorlog(row,path):
   print "----[-]Error while Decoding! writting error.log:"
   print libnss.PORT_GetError()
   try:
      f=open('error.log','a')
      f.write("-------------------\n")
      f.write("#ERROR in: %s at %s\n" %(path,time.ctime()))
      f.write("Site: %s\n"%row[1])
      f.write("Username: %s\n"%row[6])
      f.write("Password: %s\n"%row[7])
      f.write("-------------------\n")
      f.close()
   except IOError:
      print "Error while writing logfile - No log created!"






#reads the signons.sqlite which is a sqlite3 Database (>Firefox 3)
def readsignonDB(userpath,dbname):
   if libnss.NSS_Init(userpath)!=0:
      print """Error Initalizing NSS_Init,\n
      propably no usefull results"""
   print "Dirname: %s"%os.path.split(userpath)[-1]
   import sqlite3
   conn = sqlite3.connect(userpath+os.sep+dbname)
   c = conn.cursor()
   c.execute("SELECT * FROM moz_logins;")
   for row in c:
      print "--Site(%s):"%row[1]
      uname.data  = cast(c_char_p(base64.b64decode(row[6])),c_void_p)
      uname.len = len(base64.b64decode(row[6]))
      passwd.data = cast(c_char_p(base64.b64decode(row[7])),c_void_p)
      passwd.len=len(base64.b64decode(row[7]))
      if libnss.PK11SDR_Decrypt(byref(uname),byref(dectext),byref(pwdata))==-1:
         errorlog(row,userpath+os.sep+dbname)
      print "----Username %s" % string_at(dectext.data,dectext.len)
      if libnss.PK11SDR_Decrypt(byref(passwd),byref(dectext),byref(pwdata))==-1:
         errorlog(row,userpath+os.sep+dbname)
      print "----Password %s" % string_at(dectext.data,dectext.len)
   c.close()
   conn.close()
   libnss.NSS_Shutdown()




################# MAIN #################
if len(sys.argv)==1:
   ordner = findpath_userdirs()
else:
   ordner=sys.argv[1:]


#Load the libnss3 linked file
libnss = CDLL("libnss3.so")


pwdata = secuPWData()
pwdata.source = PW_NONE
pwdata.data=0


uname = SECItem()
passwd = SECItem()
dectext = SECItem()


for user in ordner:
   signonfiles = glob.glob(user+os.sep+"signons*.*")
   for signonfile in signonfiles:
      (filepath,filename) = os.path.split(signonfile)
      filetype = re.findall('\.(.*)',filename)[0]
      if filetype.lower() == "sqlite":
         readsignonDB(filepath,filename)
      else:
         print "Unhandled Signons File: %s" % filename
         print "Skipping"

It is original source code.....
« Last Edit: September 29, 2013, 10:30:32 am by Kulverstukas »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Crack Firefox passwords with python
« Reply #1 on: September 23, 2013, 12:05:24 pm »
Simply don't use bullshit like Win8. And this most likely will not work with Cygwin either, you need actual linux.
Also the shit that you do with the cygwin dll? what the hell...
You download the cygwin installer and install it that way. Why are you trying to register a dll of some sort? Cygwin doesn't work that way...

Offline fox12345

  • Serf
  • *
  • Posts: 25
  • Cookies: -31
    • View Profile
Re: Crack Firefox passwords with python
« Reply #2 on: September 23, 2013, 12:18:45 pm »
Thank you for your reply. Actually I want modify  this script to windows Pc. I want to use this Decrypt Part. as well as only python. So i use this script to get some idea. Please help me...what to do?
 
Please read this:
" ffpasscracker - I promised you Python, so here's a solution. This uses the libnss.so library as a loaded DLL. To use this on Windows, you can use these cygwin DLL's. "








I do not want to use some DLL downloading software. Only past option or CMD Based installation.
« Last Edit: September 29, 2013, 07:21:15 am by fox12345 »

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Crack Firefox passwords with python
« Reply #3 on: September 23, 2013, 03:16:13 pm »
Well you seem pretty clueless but since you are being really polite and all.
How about rewriting the code.
Forget about the dll's and stuff for just a second.
Code: [Select]

#reads the signons.sqlite which is a sqlite3 Database (>Firefox 3)
def readsignonDB(userpath,dbname):
   if libnss.NSS_Init(userpath)!=0:
      print """Error Initalizing NSS_Init,\n
      propably no usefull results"""
   print "Dirname: %s"%os.path.split(userpath)[-1]
   import sqlite3
   conn = sqlite3.connect(userpath+os.sep+dbname)
   c = conn.cursor()
   c.execute("SELECT * FROM moz_logins;")
   for row in c:
      print "--Site(%s):"%row[1]
      uname.data  = cast(c_char_p(base64.b64decode(row[6])),c_void_p)
      uname.len = len(base64.b64decode(row[6]))
      passwd.data = cast(c_char_p(base64.b64decode(row[7])),c_void_p)
      passwd.len=len(base64.b64decode(row[7]))
      if libnss.PK11SDR_Decrypt(byref(uname),byref(dectext),byref(pwdata))==-1:
         errorlog(row,userpath+os.sep+dbname)
      print "----Username %s" % string_at(dectext.data,dectext.len)
      if libnss.PK11SDR_Decrypt(byref(passwd),byref(dectext),byref(pwdata))==-1:
         errorlog(row,userpath+os.sep+dbname)
      print "----Password %s" % string_at(dectext.data,dectext.len)
   c.close()
   conn.close()
   libnss.NSS_Shutdown()

The rest of the code is not that interesting.
See if you can figure out how it works.
Try an interactive python shell and see if you can access the sqlite database and extract some data.
Later on you could try to find ways of decrypting it.

For reference see ; 'greyhat python' , iirc it has a chapter on this stuff.
Should be in the E-book section.

Bonus hint; learn to help yourself, instead of jumping in to ask for help, pickup  a book like the one I suggested and youll see the awnsers yourself , and btw GUI's arnt all that interesting :P
« Last Edit: September 23, 2013, 03:18:36 pm by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline fox12345

  • Serf
  • *
  • Posts: 25
  • Cookies: -31
    • View Profile
Re: Crack Firefox passwords with python
« Reply #4 on: September 29, 2013, 07:30:08 am »
hi dear  proxx,
Yes i write python script to read "test.db" file and save data to txt file. it is working well. i am really happy about it. it is my first script. then i know how to read ".db" file and extract the data.


so now i want your help to decrypt the key3.db file. how to do it? please help me.
exactly i want decrypt to encrypted "key3.db" with python script. 

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Crack Firefox passwords with python
« Reply #5 on: September 29, 2013, 10:33:59 am »
so now i want your help to decrypt the key3.db file. how to do it? please help me.
exactly i want decrypt to encrypted "key3.db" with python script. 
I hate skiddies like you my friend. I really do. Always want everything served on a plate...

http://evilzone.org/hacking-and-security/how-browsers-store-your-passwords-%28and-why-you-shouldn%27t-let-them%29/
http://evilzone.org/evilzone-releases/mozillarecovery-crack-master-passwords/

and a lot more on google...

Offline DK

  • NULL
  • Posts: 1
  • Cookies: 0
    • View Profile
Re: Crack Firefox passwords with python
« Reply #6 on: October 29, 2013, 10:04:59 pm »
I do apologize for reviving this thread, but I figure I would speak a bit on this and also ask a question.

I agree that you are really not doing an effective job reading through the document.  As per the raidersec article that was linked to by Kulverstukas, it is mentioned that the information stored in key3.db uses Triple DES encryption. (In particular, look for 3DES (DES-EDE-CBC) in the article.)  When a master password is used, that value is used as the salt for it.  When no master password is provided though, a null value is used for the encryption.  With this in mind, Retrieving the necessary information from this file would requre Decrypting the Triple DES encryption with the matching master password as the salt.  What I have seen of the proof of concept in python though is that it is not really the best way to handle this for Windows.

Based on this information and my own experiences of working on a proof of concept for Windows, it may be more worthwhile to handle Triple DES decryption in Python.  In particular, if I am not mistaken, what I have seen of the source for the recovery solution made by evilzone uses similar tactics in Java and may be a good point of reference. (If I am wrong on this please do tell me so that I can correct this post.)

This does bring me to my main question.  Does anybody have any recommendations on libraries for Triple DES decryption in Python?  I wish to get some good insight on this so I can have an effective proof of concept.
« Last Edit: October 29, 2013, 10:11:58 pm by DK »

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: Crack Firefox passwords with python
« Reply #7 on: October 29, 2013, 10:23:34 pm »
There's several cryptographic libraries for Python. Try PyCrypto, I know it has Triple DES.

Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Livebullshit

  • NULL
  • Posts: 4
  • Cookies: 0
    • View Profile
Re: Crack Firefox passwords with python
« Reply #8 on: November 02, 2013, 08:29:00 pm »
This script works fine for windows. There is really not much to change.
Not sure if my contribution is needed anymore or the problem is already solved.

Btw, i'm a bit struggling writing the same kind of stuff for IE 7/8/9 password (still in python), if anyone did it already, would be nice.
« Last Edit: November 02, 2013, 08:32:25 pm by Livebullshit »

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Crack Firefox passwords with python
« Reply #9 on: November 03, 2013, 08:01:42 pm »
This script works fine for windows. There is really not much to change.
Not sure if my contribution is needed anymore or the problem is already solved.

Btw, i'm a bit struggling writing the same kind of stuff for IE 7/8/9 password (still in python), if anyone did it already, would be nice.

Maybe Kulverstukas can help you.