Image 2 is the portion where it is the actual output as stated in image 1. Lab F
ID: 3858971 • Letter: I
Question
Image 2 is the portion where it is the actual output as stated in image 1. Lab Files Download these files for the next script: http//scrivnorcikeys.com/files/labo7tar.gz Ignore the xml and html files. Failed Auth Statistics Script write a python script to generate some interesting statistics from an Ubuntu auth.log file. Mainly we want to find: 1. Total number of login failures for ssh. 2. A histogram of all the user names attempted for logins. a. If the total number is 100, make the username and number RED. b. If it is less than 100, make the username and number YELLOW. 3. A histogram of all the lP Addresses the attempts came from. Note: This sample output will not match yours. SEE BOTTOM OF PAGE FOR ACTUAL OUTPUT Generating statistics. Done! a Total attempts 1234 Usernames attacked: root 723 123 guest ubnt ftp 20 IP Addresses 95.65.31.98 10 43.255.190.147 and so onExplanation / Answer
// please add similar logic to search ip address from the list and print
#!/usr/bin/python2.7
import re
#sfailure="No of failures are: "
count=1;
stringcheck=list()
file1=open("/var/log/auth.log", "r");
print "Generating statistics..."
print "Done!"
print "~~~~~~~~~~~~~"
for line in file1:
if re.search("error: PAM: Authentication failure.*", line):
count += 1
#print line.split("failure for")[1]
stringcheck.append(line.split("failure for")[1])
#print m.start()
#for st1 in stringcheck:
# print(st1)
print "Total attempts: ",count
print "Usernames attacked:"
for x in set(stringcheck):
print x,stringcheck.count(x)