0

I have small program written for me in Python to help me generate all combinations of passwords from a different sets of numbers and words i know for me to recover a password i forgot, as i know all different words and sets of numbers i used i just wanted to generate all possible combinations, the only problem is that the list seems to go on for hours and hours so eventually i run out of memory and it doesn't finish.

I got told it needs to dump my memory so it can carry on but i'm not sure if this is right. is there any way i can get round this problem?

this is the program i am running:

#!/usr/bin/python
import itertools
gfname = "name"
tendig = "1234567890"
sixteendig = "1111111111111111"
housenum = "99"
Characterset1 = "&&&&"
Characterset2 = "££££"
daughternam = "dname"
daughtyear = "1900"
phonenum1 = "055522233"
phonenum2 = "3333333"





mylist = [gfname, tendig, sixteendig, housenum, Characterset1,
          Characterset2, daughternam, daughtyear, phonenum1, phonenum2]
for length in range(1, len(mylist)+1):
    for item in itertools.permutations(mylist, length):
            print "".join(item)

i have taken out a few sets and changed the numbers and word for obvious reasons but this is roughly the program.

another thing is i may be missing a particular word but didnt want to put it in the list because i know it might go before all the generated passwords, does anyone know how to add a prefix to my program.

sorry for the bad grammar and thanks for any help given.

shaun
  • 1
  • 1
  • 1
  • 2
  • This program does not run out of memory, unless you have *extremely little memory on your machine*. It is quite efficient in fact. – Martijn Pieters Feb 03 '13 at 12:51
  • i have 8 gigs of memory but do bear in mind i have took out a few sets of words and numbers – shaun Feb 03 '13 at 12:53
  • The code shown here will either run out of memory at or before the longest possible combination is shown, or not at all. The longest possible combination takes (on my 64-bit machine) 110 bytes of memory. The whole program will take, at most, kilobytes of memory, not gigabytes. – Martijn Pieters Feb 03 '13 at 12:55
  • It'll take a *very long time* to go through all the possible permutations, sure. You want to find a point where you can stop and at another time continue perhaps, but you don't need a memory dump for that. You need to understand what the program *does* and find ways to partition that instead. – Martijn Pieters Feb 03 '13 at 12:59
  • oh right i see, I'm not familiar with programming you see. I don't understand why i run out of memory, i left it to generate my passwords for several hours but stopped it before it had finished, so i copied and pasted the list into notepad and that created a 49 megabyte file. if i left it over night, which i have done it froze my pc and had messages saying i was low on memory. – shaun Feb 03 '13 at 13:05
  • It may generate a lot of lines, but it does so in very little memory to run itself. It generates over 4 million options. I ran it on my machine just now and it generated all combinations in the time it took you to respond to my last comment, just a few minutes. You could could alter the program to write the combinations to a file for you; the file would be megabytes in size indeed, but your computer memory would easily suffice to run the program. – Martijn Pieters Feb 03 '13 at 13:08

4 Answers4

1

I used guppy to understand the memory usage, I changed the OP code slightly (marked #!!!)

import itertools
gfname = "name"
tendig = "1234567890"
sixteendig = "1111111111111111"
housenum = "99"
Characterset1 = "&&&&"
Characterset2 = u"££££"
daughternam = "dname"
daughtyear = "1900"
phonenum1 = "055522233"
phonenum2 = "3333333"

from guppy import hpy # !!!
h=hpy()               # !!!
mylist = [gfname, tendig, sixteendig, housenum, Characterset1,
          Characterset2, daughternam, daughtyear, phonenum1, phonenum2]
for length in range(1, len(mylist)+1):
    print h.heap() #!!!
    for item in itertools.permutations(mylist, length):
            print item # !!!

Guppy outputs something like this every time h.heap() is called.

Partition of a set of 25914 objects. Total size = 3370200 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  11748  45   985544  29    985544  29 str
     1   5858  23   472376  14   1457920  43 tuple
     2    323   1   253640   8   1711560  51 dict (no owner)
     3     67   0   213064   6   1924624  57 dict of module
     4    199   1   210856   6   2135480  63 dict of type
     5   1630   6   208640   6   2344120  70 types.CodeType
     6   1593   6   191160   6   2535280  75 function
     7    199   1   177008   5   2712288  80 type
     8    124   0   135328   4   2847616  84 dict of class
     9   1045   4    83600   2   2931216  87 __builtin__.wrapper_descriptor

Running python code.py > code.log and the fgrep Partition code.log shows.

Partition of a set of 25914 objects. Total size = 3370200 bytes.
Partition of a set of 25924 objects. Total size = 3355832 bytes.
Partition of a set of 25924 objects. Total size = 3355728 bytes.
Partition of a set of 25924 objects. Total size = 3372568 bytes.
Partition of a set of 25924 objects. Total size = 3372736 bytes.
Partition of a set of 25924 objects. Total size = 3355752 bytes.
Partition of a set of 25924 objects. Total size = 3372592 bytes.
Partition of a set of 25924 objects. Total size = 3372760 bytes.
Partition of a set of 25924 objects. Total size = 3355776 bytes.
Partition of a set of 25924 objects. Total size = 3372616 bytes.

Which I believe shows that the memory footprint stays fairly consistent.

Granted I may be misinterpreting the results from guppy. Although during my tests I deliberately added a new string to a list to see if the object count increased and it did.

For those interested I had to install guppy like so on OSX - Mountain Lion pip install https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy

In summary I don't think that it's a running out of memory issue although granted we're not using the full OP dataset.

sotapme
  • 4,695
  • 2
  • 19
  • 20
  • this is all way past my head, sorry i don't understand what you have done, i know nothing about programming you see :( – shaun Feb 03 '13 at 16:38
  • I was just trying to illustrate that your code wouldn't appear to be running out of memory as I was dumping the memory used each time it went off to do another ``itertools.permutations(...)`` and the memory footprint didn't seem to move much. As suggested doing ``python yourcode.py > youlog.txt`` from a CMD window should run the code without issues. Try that and report back if you do have issues. – sotapme Feb 03 '13 at 19:46
  • i have ran my code through again during the evening and i kept checking on it and it was ok, but then an hour later it had done the same again, which was out of memory. Im going to try something else by disabling a few things and leave it over night and ill let you know. Thanks for your help :) – shaun Feb 03 '13 at 22:24
  • I must say that on your sample above it ran in a couple of minutes - perhaps you should provide your full code and just sanitise the sensitive data but leave the relative lengths and number of fields. – sotapme Feb 03 '13 at 22:37
  • Hi, I ran the code again over night but first disabled a few things, this time it didn't run out of memory but was still going when I woke up this morning. Am I wrong in thinking that there are 10 billion different combinations of my password? And is that why it's taking so long? – shaun Feb 04 '13 at 07:54
  • Well on you set of data above I get 9,864,100 permutations. I've not got the Math to know what it would be knowing just the sizes of the dataset. If we wait long enough someone will be along soon to tell us. It seems to me that if you're trying to rediscover your lost password in such a manner you're not going to have much success. – sotapme Feb 04 '13 at 09:02
  • The reason I came up with 10 billion combinations is if I replaced gfname with the number 1, tendig with number 2 and so on, there would be ten digits and every different combination of a ten digit number is 10 billion, only know this because I googled it, I might be wrong. They are important files but I do enjoy the challenge. The program I am using will check through a notepad list no matter how big, it will usually check around an hundred a second. – shaun Feb 04 '13 at 09:53
  • For `python3` you need to install `guppy3`: `pip3 install guppy3` – gRizzlyGR Mar 17 '21 at 09:43
0

How about using IronPython and Visual Studio for its debug tools (which are pretty good)? You should be able to pause execution and look at the memory (essentially a memory dump).

Bogdan Gavril MSFT
  • 20,615
  • 10
  • 53
  • 74
  • thanks for your suggestion i will look into that but i do think i need to learn a little about programming. – shaun Feb 03 '13 at 13:07
  • plenty of python tutorials around, python is all the rage nowadays :) – Bogdan Gavril MSFT Feb 03 '13 at 13:08
  • it's a lot to take in when i am a complete beginner though, especially understanding my program. would there be a way for my program to paste results in notepad? sorry if its a silly question. – shaun Feb 03 '13 at 13:15
0

To answer the above comment from @shaun if you want the file to output to notepad just run your file like so

Myfile.py >output.txt

If the text file doesn't exist it will be created.

EDIT:

Replace the line in your code at the bottom which reads:

print "" .join(item)

with this:

with open ("output.txt","a") as f:
    f.write('\n'.join(items))
f.close

which will produce a file called output.txt. Should work (haven't tested)

Paul Tricklebank
  • 229
  • 2
  • 3
  • 11
  • sorry I'm confused about where to put that line – shaun Feb 03 '13 at 16:36
  • No problem. You don't add it to the actual code you add the >output.txt when you run the file from the command line. By doing this you are telling windows to push the output to a text file (notepad) rather than the screen. The other way to do this would be to alter your code to replace the line print "" .join(item) with code to open a text file and write to that instead. There are plenty of examples on stack overflow or google. I'm writing this on my mobile so it would be difficult for me to write the code. – Paul Tricklebank Feb 03 '13 at 17:08
  • oh right i see, thanks for explaining that to me, I'm sure I will be able to do that after a bit of research :) – shaun Feb 03 '13 at 18:18
  • No problem Shaun. When I get into the office tomorrow ill amend your code to output to a file without the need for > output.txt – Paul Tricklebank Feb 03 '13 at 19:19
  • Thank you very much Paul, I will give that a try when I get back from work. – shaun Feb 04 '13 at 12:37
  • if that doesn't wprk then replace the line f.write('\n'.join(items)) with f.write("\n"+.join.items)) – Paul Tricklebank Feb 04 '13 at 16:26
  • Thank You Paul for doing that for me, I'm just having trouble running it at the moment, I'm not sure if it's the program I'm using, which is Python 2.7.3 but keeps coming up with something to do with ASCII then i have a syntax error. I'm not sure if I'm doing any of this right to be honest. I installed Python 2.7 but i can only get that up by clicking on IDLE (Python GUI) but then i am confused about how to run the code, I did it a few times but now I can't find how I done it, you must be getting fed up with me by now lol, so sorry :( must go to bed cuz I've got to be up at 5am – shaun Feb 04 '13 at 22:34
0

Your program will run pretty efficiently by itself, as you now know. But make sure you don't just run it in IDLE, for example; that will slow it down to a crawl as IDLE updates the screen with more and more lines. Save the output directly into a file.

Even better: Have you thought about what you'll do when you have the passwords? If you can log on to the lost account from the command line, try doing that immediately instead of storing all the passwords for later use:

for length in range(1, len(mylist)+1):
    for item in itertools.permutations(mylist, length):
        password = "".join(item)
        try_to_logon(command, password)
alexis
  • 48,685
  • 16
  • 101
  • 161
  • wow! I'm overwhelmed by all this info, its just all going well over my head. I'm so sorry for not understanding, I will be checking the passwords in a program, which then checks them against a winrar file but i do have a cryptainer file i have also to check, although I don't have any program to check that file because its not that popular. so with that one i may have to give up because there will be too many passwords to check through. – shaun Feb 03 '13 at 22:16