Repository navigation
Expand file tree
/
Copy pathprueba.py
More file actions
92 lines (62 loc) · 1.74 KB
/
Copy pathprueba.py
File metadata and controls
92 lines (62 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
import os
def accepted(path,lines):
word='Accepted'
b=0
ipcont=[]
ip=[]
ipIndex=0
for line in lines:
palabras = line.split(' ')
for p in palabras:
if p==word and (palabras[7]=='password' or palabras[6]=='password') and (palabras[8]=='for' or palabras[7]=='for'):
ipIndex=0
for c in range(len(ip)):
if palabras[11]==ip[c] or palabras[10]==ip[c]:
b=1
ipcont[c]=ipcont[c]+1
if b==0:
#print(palabras[11])
if palabras[7]=='password':
ip.append(palabras[11])
if palabras[6]=='password':
ip.append(palabras[10])
ipcont.append(1)
b=0
for i in range(len(ip)):
print "IP ",ip[i], "has entered",ipcont[i]," times."
def failed(path,lines):
word='Failed'
b=0
ipcont=[]
ip=[]
ipIndex=0;
for line in lines:
palabras = line.split(' ')
for p in palabras:
#print palabras
if p==word and (palabras[6]=='Failed' or palabras[5]=='Failed') and (palabras[6]=='password' or palabras[7]=='password') and (palabras[8]!='invalid' and palabras[9]!='invalid'):
ipIndex=0
for c in range(len(ip)):
if palabras[11]==ip[c] or palabras[10]==ip[c]:
b=1
ipcont[c]=ipcont[c]+1
if b==0:
#print(palabras[11])
if palabras[6]=='Failed':
ip.append(palabras[11])
if palabras[5]=='Failed':
ip.append(palabras[10])
ipcont.append(1)
b=0
num=len(ip)
for i in range(num):
print "IP ",ip[i], "has failed the password ",ipcont[i]," times."
path='/var/log/auth.log'
infile=open(path,'r')
lines=infile.readlines()
function = { '1': failed,'2':accepted}
operation=raw_input("1.- Failed\n2.- Accepted ")
function[operation](path,lines)
# CLosing the file
infile.close()