Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, I am writing a simple py script which connects to one server on port 25. Then it checks for existence of users from a list of users. The script ...
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    9

    Python Scripting -> Brute Force

    Hello,

    I am writing a simple py script which connects to one server on port 25. Then it checks for existence of users from a list of users.

    The script draft is as follows:
    ..................................................
    Code:
    #!/usr/bin/python
    import socket
    import sys
    
    # Python script to brute force & identify valid usernames on smtp servers
    
    # Step I: create a list of usernames on directory : Done
    
    # Step II: Create a Socket
    s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    # Step III: Connect to the Server
    connect=s.connect(('10.0.0.104',25))
    
    # Step IV: Receive the banner
    banner=s.recv(1024)
    print banner
    
    # Step V: VRFY the user from user file
    # a. Open the file
    # b. Create a loop
    # c. send the VRFY command per user name
    # d. print the result
    # e. close the file once complete
    
    f = open('/home/Victor/users.txt', 'r')
    print f.readlines()
    
    ### This block does not gets executed###
    for i in f.readlines():
    	print 'test'
    	i=i.strip()
    	print i
    	s.send('VRFY ' + i + '\r\n')
    	print 'VRFY ' + i
    	result=s.recv(1024)
    	print result
    	
    f.close()
    
    # Step VI: Close the Socket
    s.close()
    ..................................................

    Could anyone suggest what could be the issue with this code?

    Best Regards,
    Victor

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    In the future, you should always post code inside the code tags, it makes it a lot easier to read, especially with an indentation oriented code such as python. I think your problem lies when you print f.readlines(). You should store it in a variable then use it later. I believe that when you read a file in python even calling readlines() will point the cursor to the end of file, so the subsequent call isn't returning anything.

  3. #3
    Just Joined!
    Join Date
    Aug 2009
    Posts
    9
    Thanks coopstah13. Script code tagged. You were correct. Removing readlines() got it up.

    Best Regards,
    Victor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...