Author Topic: How do I PIPE Python script to aircrack  (Read 1537 times)

0 Members and 1 Guest are viewing this topic.

Offline Shad0w

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
How do I PIPE Python script to aircrack
« on: December 12, 2014, 10:28:30 pm »
I've written a small script tha generates 8 chars, I want it to pipe through to aircrack (Like Crunch does).

Here is the code....

     
Code: [Select]
#!/usr/bin/env python
import os,string,random,sys
length = 8
chars = string.ascii_letters.upper()+string.digits
random.seed = (os.urandom(1024))

keep=[]
keep1=[]
while len(keep)<100000:
     keep.append(''.join(random.choice(chars) for i in range(length)))

#print '\n',keep[::-1]

for x in keep:
    keep1.append(x[::-1])

while len(keep1) < 1000:
       
   
    sys.stdout()   [\code]


I can save them to a file and run them..But I want it to run with aircrack as it generates the 'default router passwords'

Here is the code that saves it to file...
Code: [Select]
#!/usr/bin/env python

import os,   random,   string

length = 8
chars = string.ascii_letters.upper()+string.digits
random.seed = (os.urandom(1024))


file_out = open('newRa.txt','w') # Create a 'FILE' to save Generated Passwords
list1=[]
while len(list1) < 100000:
    list1.append(''.join(random.choice(chars) for i in range(length)))

for item in list1:
  file_out.write('%s\n' % item)
file_out.close()
 
   
file_out1=open('test.txt','w')

for x in list1:
    file_out1.write('%s\n' %x[::-1])  [\code]


I want it to work like     "./My_Python_Code stdout | aircrack-ng ....."

It does run with aircrack but it does not look correct.
Any ideas??
« Last Edit: December 12, 2014, 10:33:51 pm by Shad0w »

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: How do I PIPE Python script to aircrack
« Reply #1 on: December 12, 2014, 10:54:02 pm »
Code: [Select]
random.py | aircrack -  etc
Quote
  Path to a dictionary file for wpa cracking. Specify "-" to use stdin. Here is  a  list  of  wordlists:
^ rtfm

Don't random generate like that , it's silly and counterproductive.
« Last Edit: December 12, 2014, 10:55:59 pm by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline madf0x

  • Knight
  • **
  • Posts: 172
  • Cookies: 50
    • View Profile
Re: How do I PIPE Python script to aircrack
« Reply #2 on: December 12, 2014, 11:14:54 pm »
Proxx gave you the correct answer, not sure why you couldn't have figured that one out?

That aside, you have a lot of cruft in your python code, and simply is quite unpythonic. You're reversing strings for no reason, using while loops when theres no need to, and going out of your way to preform output. Hell your non-file one doesn't even run sys.stdout() isn't a function, sys.stdout is a file object...

heres a slightly better reworked version:
Code: [Select]
#!/usr/bin/env python
import os,string,random
length = 8
#might not always want 100000 results, keep it in a variable for easy changing
results = 100000
chars = string.ascii_letters.upper()+string.digits
random.seed = (os.urandom(1024))
keep = []

#I prefer xrange, cause it returns results as requested, instead of the
#upfront memory and computation costs. Not required here, but just personal
#preference
for i in xrange(results):
    #we don't even need a keep[] if we wanted to simply print to stdout
    #this simply lets us work with a list if we wanted to add functionality
    #but be careful cause this can eat up a large amount of memory to store it
    #all at once. Better way memory wise would be process each result as it is built
    string = ''.join(random.choice(chars) for i in xrange(length))
   
    #need to check for any unlikely duplicates ;)
    if string not in keep:
        keep[i] = string
#output easy as:
for i in keep:
    print i

Offline Shad0w

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Re: How do I PIPE Python script to aircrack
« Reply #3 on: December 13, 2014, 02:33:33 pm »
madf0x, Your code throwed up a error.


File "/root/test.py", line 22, in <module>
    keep = string
IndexError: list assignment index out of range


I stripped my code down as it was very slow.
Here is what I have now..

Code: [Select]
#!/usr/bin/env python
 import os,string,random,sys
 length = 8
chars = string.ascii_letters.upper()+string.digits random.seed = (os.urandom(1024))
 keep=[]
while len(keep)<1000:
    keep = (''.join(random.choice(chars) for i in range(length)))
    print '\n'
    print sys.stdout.write(keep)
sys.stdout.flush()





Quote



Don't random generate like that , it's silly and counterproductive.


As in "Going round in circles"?

I'm random Generating Because it is a talktalk router Default Password.
It was just something to do , to learn programming .

Thanks for the input :)

Quote
Proxx gave you the correct answer, not sure why you couldn't have figured that one out?


I knew what command to use to pipe..lol
It was the correct codeing I was missing..

I'm very new to programming and Python is my first language..

« Last Edit: December 13, 2014, 03:10:10 pm by Shad0w »

Offline madf0x

  • Knight
  • **
  • Posts: 172
  • Cookies: 50
    • View Profile
Re: How do I PIPE Python script to aircrack
« Reply #4 on: December 13, 2014, 03:14:54 pm »
Your output is adding None cause you are managing output on your own when you REALLY have no reason to.

Also my bad, I was cutting out some stuff before I posted it and created that embarrassing error. Simply change line 22 to :

keep.append(string)


but really, learn the print statement. The print statement is almost always what youll need and when it's not, you'lll know. This isn't C, you don't need to manage file descriptors and newline characters every time you want to print something.

Offline Shad0w

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Re: How do I PIPE Python script to aircrack
« Reply #5 on: December 13, 2014, 03:47:29 pm »
Thanks madf0x.

I've got it working now. After reading your last post..
I removed

print '\n'
sys.stdout.write(keep)

And just used

print keep


Offline madf0x

  • Knight
  • **
  • Posts: 172
  • Cookies: 50
    • View Profile
Re: How do I PIPE Python script to aircrack
« Reply #6 on: December 13, 2014, 03:54:24 pm »
No problem, also I recommend reading some of my comments closely, they will help you in the future while you learn. Esp stuff like checking for duplicates. You just waste cycles trying a value that already hasn't worked no? And theres nothing in random.choice() to avoid duplicate string building, its random after all. Things like that are small but important to consider in the future.

Also it may well be worth it to simply sequentially save all possible output to a file. All uppers with mixed numbers isn't even half the charset of all lower and uppercase, so its entirely feasible. It would also be a small challenge in its own way to correctly produce all possible combinations without repeating in an efficient manner. Just a suggestion.

Offline Shad0w

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Re: How do I PIPE Python script to aircrack
« Reply #7 on: December 13, 2014, 04:31:29 pm »
No problem, also I recommend reading some of my comments closely, they will help you in the future while you learn. Esp stuff like checking for duplicates. You just waste cycles trying a value that already hasn't worked no? And theres nothing in random.choice() to avoid duplicate string building, its random after all. Things like that are small but important to consider in the future.

Also it may well be worth it to simply sequentially save all possible output to a file. All uppers with mixed numbers isn't even half the charset of all lower and uppercase, so its entirely feasible. It would also be a small challenge in its own way to correctly produce all possible combinations without repeating in an efficient manner. Just a suggestion.

I was aware of it producing duplicates. Now I have the output piping correctly with aircrack,  I will try and make a better
code.
Like the one you suggested that outputs all the possible combinations.
Not sure how I check all combinations are created..
as people say " Google is your friend"