forked from tabacha/ProSafeLinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psl-cmd.py
executable file
·99 lines (87 loc) · 3.16 KB
/
psl-cmd.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
96
97
98
99
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
import cmd
from psl_class import ProSafeLinux
class NetgearCMD(cmd.Cmd): # {{{
switch = ProSafeLinux()
selectedswitch = {}
discovereddata = {}
def __splitLine(self,argumentcount,line): # {{{
splitline = line.split()
if len(splitline) > argumentcount and argumentcount != 0:
print 'Too many arguments!'
return False
else:
if len(splitline) < argumentcount:
count=len(splitline)
while count < argumentcount:
splitline.append(None)
count += 1
if argumentcount == 1:
return splitline[0]
return splitline
# }}}
def do_discover(self, line): # {{{
'''Discover the switches available.
Arguments: interface'''
iface = self.__splitLine(1,line)
if iface == None:
iface = 'eth0'
self.switch.bind(iface)
data = self.switch.discover()
self.discovereddata = data
for entry in data.keys():
print(entry.get_name() + ': ' + data[entry])
# }}}
def do_selectSwitch(self, line): # {{{
'''Select a switch by IP you wanna use all through the session'''
switchip = self.__splitLine(1,line)
if switchip == None:
print('Please give a IP')
return False
else:
if switchip == self.discovereddata[self.switch.CMD_IP]:
self.selectedswitch = { "ip" : self.discovereddata[self.switch.CMD_IP],
"mac" : self.discovereddata[self.switch.CMD_MAC] }
else:
print('No valid ip given...')
return False
# }}}
def do_query(self, line): # {{{
"""Query Values from Switch.
If no query command is given it prints out the possibilities"""
querycmds = self.switch.get_query_cmds()
query = self.__splitLine(1,line)
if len(query) == 0:
print "you have the following values to query:"
for cmd in list(querycmds):
print "- " + str(cmd.get_name())
return False
else:
querycmd = self.switch.get_cmd_by_name(query)
if querycmd != None:
switchdata = self.switch.query(querycmd, self.selectedswitch['mac'])
for key in switchdata.keys():
print("%s - %s" % (key.get_name(), switchdata[key]))
else:
print 'please give a valid query key'
# }}}
def do_quit(self, line): # {{{
'''Quit the Application'''
return True
do_EOF = do_quit
# }}}
def do_exploitPassword(self, line): # {{{
'''Exploit the switches password and set a new one'''
newpass = self.__splitLine(1,line)
if newpass == None:
print('Please give a new password')
return False
else:
self.switch.passwd_exploit(self.selectedswitch['mac'], newpass, 'transfunc')
# }}}
# }}}
if __name__ == '__main__':
NetgearCMD().cmdloop()
# vim:filetype=python:foldmethod=marker:autoindent:expandtab:tabstop=4