Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60465 > unrolled thread

Cracking hashes with Python

Started byTheRandomPast <wishingforsam@gmail.com>
First post2013-11-25 15:32 -0800
Last post2013-11-27 17:44 +0000
Articles 5 on this page of 25 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  Cracking hashes with Python TheRandomPast <wishingforsam@gmail.com> - 2013-11-25 15:32 -0800
    Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-26 10:47 +1100
      Re: Cracking hashes with Python TheRandomPast <wishingforsam@gmail.com> - 2013-11-25 16:01 -0800
        Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-26 11:19 +1100
    Re: Cracking hashes with Python Steven D'Aprano <steve@pearwood.info> - 2013-11-26 02:55 +0000
      RE: Cracking hashes with Python Frank Cui <ycui@outlook.com> - 2013-11-25 23:46 -0300
        Re: Cracking hashes with Python TheRandomPast <wishingforsam@gmail.com> - 2013-11-26 02:30 -0800
          Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-26 21:39 +1100
          Re: Cracking hashes with Python "TheRandomPast ." <wishingforsam@gmail.com> - 2013-11-26 11:46 +0000
          Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-26 23:48 +1100
          Re: Cracking hashes with Python Robert Kern <robert.kern@gmail.com> - 2013-11-26 13:00 +0000
          Re: Cracking hashes with Python "TheRandomPast ." <wishingforsam@gmail.com> - 2013-11-26 14:18 +0000
            Re: Cracking hashes with Python Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-26 18:33 +0000
          Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-27 01:46 +1100
          Re: Cracking hashes with Python "TheRandomPast ." <wishingforsam@gmail.com> - 2013-11-26 15:13 +0000
          Re: Cracking hashes with Python Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-26 18:17 +0000
            Re: Cracking hashes with Python "TheRandomPast ." <wishingforsam@gmail.com> - 2013-11-26 23:06 +0000
            Re: Cracking hashes with Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-27 01:04 +0000
            Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-27 13:28 +1100
            Re: Cracking hashes with Python Tim Delaney <timothy.c.delaney@gmail.com> - 2013-11-27 13:55 +1100
            Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-27 13:58 +1100
            Re: Cracking hashes with Python "TheRandomPast ." <wishingforsam@gmail.com> - 2013-11-27 12:40 +0000
              Re: Cracking hashes with Python Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-27 21:18 +0000
            Re: Cracking hashes with Python Chris Angelico <rosuav@gmail.com> - 2013-11-28 00:27 +1100
            Re: Cracking hashes with Python MRAB <python@mrabarnett.plus.com> - 2013-11-27 17:44 +0000

Page 2 of 2 — ← Prev page 1 [2]


#60569

FromChris Angelico <rosuav@gmail.com>
Date2013-11-27 13:58 +1100
Message-ID<mailman.3274.1385521086.18130.python-list@python.org>
In reply to#60532
On Wed, Nov 27, 2013 at 1:55 PM, Tim Delaney
<timothy.c.delaney@gmail.com> wrote:
> Before I go look it up, I'm guessing that the etymology of "stumped" is
> actually coming from the problem of a plough getting stuck on a stump (i.e.
> can't progress any further). Not much of an issue anymore since the
> invention of the stump-jump plough:
> https://en.wikipedia.org/wiki/Stump-jump_plough
>

Australian inventiveness! We were too lazy to dig out the stumps
before ploughing, so we came up with a solution.

ChrisA

[toc] | [prev] | [next] | [standalone]


#60603

From"TheRandomPast ." <wishingforsam@gmail.com>
Date2013-11-27 12:40 +0000
Message-ID<mailman.3296.1385558675.18130.python-list@python.org>
In reply to#60532

[Multipart message — attachments visible in raw view] — view raw

Hi,

So apparently when I've been staring at code all day and tired my brain
doesn't tell my hands to type half of what I want it to. I apologise for my
last post.

This is my code;

import md5
import sys

characters=range(48,57)+range(65,90)+range(97,122)

def chklength(hash):
    if len(hash) != 32:
        print '[-] Improper length for md5 hash.'
        sys.exit(1)

def checkPassword(password):
    #print password
    m = md5.new(password)
    if (m.hexdigest() == hash):
        print "match [" + password + "]"
        sys.exit()

def recurse(width, position, baseString):
    for char in characters:
        if (position < width - 1):
            recurse(width, position + 1, baseString + "%c" % char)
        checkPassword(baseString + "%c" % char)
        print "Target Hash [" + hash+ " string: "+ baseString

def brute_force():
    maxChars = 32
    for baseWidth in range(1, maxChars + 1):
        print "checking passwords width [" + `baseWidth` + "]"
        recurse(baseWidth, 0, "")

def dictionary():
    for line in File.readlines():
        checkPassword(line.strip('\n'))
hash =raw_input("Input MD5 hash:")
option=raw_input("Choose method:1=Brute Force; 0=Dictionary")
if(option==1):
    chklength()
    brute_force()
else:
    if(option==0):
        File=open("C:\dictionary.txt")
        chklength()
        dictionary()
    else:
        print "Wrong method!"

And dictionary is working, as is the brute force however the issue I have
having is with my chklength() as no matter how many characters I input it
skips the !=32 and goes straight to asking the user to chose either Brute
Force or Dictionary. I want an error to be shown if the hash is less than
or more than 32 characters but at present this chklength() doesn't work as
I thought it would.

Can anyone point out an obvious error that I am missing?


On Wed, Nov 27, 2013 at 2:58 AM, Chris Angelico <rosuav@gmail.com> wrote:

> On Wed, Nov 27, 2013 at 1:55 PM, Tim Delaney
> <timothy.c.delaney@gmail.com> wrote:
> > Before I go look it up, I'm guessing that the etymology of "stumped" is
> > actually coming from the problem of a plough getting stuck on a stump
> (i.e.
> > can't progress any further). Not much of an issue anymore since the
> > invention of the stump-jump plough:
> > https://en.wikipedia.org/wiki/Stump-jump_plough
> >
>
> Australian inventiveness! We were too lazy to dig out the stumps
> before ploughing, so we came up with a solution.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [next] | [standalone]


#60638

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-11-27 21:18 +0000
Message-ID<l75njn$hgk$1@dont-email.me>
In reply to#60603
On Wed, 27 Nov 2013 12:40:41 +0000, TheRandomPast . wrote:

> And dictionary is working, as is the brute force however the issue I
> have having is with my chklength() as no matter how many characters I
> input it skips the !=32 and goes straight to asking the user to chose
> either Brute Force or Dictionary. I want an error to be shown if the
> hash is less than or more than 32 characters but at present this
> chklength() doesn't work as I thought it would.
> 
> Can anyone point out an obvious error that I am missing?

Yes - you don't need to type in the hashes by hand at all.

You have code to read the hashes from a web page as strings.

Read the hashes from the web into a list of hashes.
Read the dictionary file into a list of words.
for each word in the dictionary compare the hashed word with the list of 
hashes, and if you get a match, output the word and the hash.

If you have code to get the hash strings from the web url, it is nuts to 
output them to the screen and then type them back in to the cracking 
program when you can just add the code to get them from the web to the 
cracking program.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#60604

FromChris Angelico <rosuav@gmail.com>
Date2013-11-28 00:27 +1100
Message-ID<mailman.3298.1385558870.18130.python-list@python.org>
In reply to#60532
On Wed, Nov 27, 2013 at 11:40 PM, TheRandomPast .
<wishingforsam@gmail.com> wrote:
> And dictionary is working, as is the brute force however the issue I have
> having is with my chklength() as no matter how many characters I input it
> skips the !=32 and goes straight to asking the user to chose either Brute
> Force or Dictionary. I want an error to be shown if the hash is less than or
> more than 32 characters but at present this chklength() doesn't work as I
> thought it would.

You never pass it any argument. I don't know why it isn't throwing
TypeError at you.

ChrisA

[toc] | [prev] | [next] | [standalone]


#60625

FromMRAB <python@mrabarnett.plus.com>
Date2013-11-27 17:44 +0000
Message-ID<mailman.3311.1385574233.18130.python-list@python.org>
In reply to#60532
On 27/11/2013 12:40, TheRandomPast . wrote:
> Hi,
>
> So apparently when I've been staring at code all day and tired my brain
> doesn't tell my hands to type half of what I want it to. I apologise for
> my last post.
>
> This is my code;
>
> import md5
> import sys
>
> characters=range(48,57)+range(65,90)+range(97,122)
>
> def chklength(hash):
>      if len(hash) != 32:
>          print '[-] Improper length for md5 hash.'
>          sys.exit(1)
>
> def checkPassword(password):
>      #print password
>      m = md5.new(password)
>      if (m.hexdigest() == hash):
>          print "match [" + password + "]"
>          sys.exit()
> def recurse(width, position, baseString):
>      for char in characters:
>          if (position < width - 1):
>              recurse(width, position + 1, baseString + "%c" % char)
>          checkPassword(baseString + "%c" % char)
>          print "Target Hash [" + hash+ " string: "+ baseString
>
> def brute_force():
>      maxChars = 32
>      for baseWidth in range(1, maxChars + 1):
>          print "checking passwords width [" + `baseWidth` + "]"
>          recurse(baseWidth, 0, "")
>
> def dictionary():
>      for line in File.readlines():
>          checkPassword(line.strip('\n'))
> hash =raw_input("Input MD5 hash:")
> option=raw_input("Choose method:1=Brute Force; 0=Dictionary")
> if(option==1):
>      chklength()
>      brute_force()
> else:
>      if(option==0):
>          File=open("C:\dictionary.txt")
>          chklength()
>          dictionary()
>      else:
>          print "Wrong method!"
>
> And dictionary is working, as is the brute force however the issue I
> have having is with my chklength() as no matter how many characters I
> input it skips the !=32 and goes straight to asking the user to chose
> either Brute Force or Dictionary. I want an error to be shown if the
> hash is less than or more than 32 characters but at present this
> chklength() doesn't work as I thought it would.
>
> Can anyone point out an obvious error that I am missing?
>
[snip]

You're asking for the hash, then you're asking for the method. You're
not checking the length of the hash between the two.

BTW, 'raw_input' returns a string and a string != a number, e.g. "1" !=
1.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web