1- #!/usr/bin/env python2
1+ #!/usr/bin/env python3
22import cmd
33import sqlite3
44import sys
77from time import sleep
88from terminaltables import AsciiTable
99from cme .msfrpc import Msfrpc , MsfAuthError
10- from ConfigParser import ConfigParser
10+ import configparser
1111from cme .loaders .protocol_loader import protocol_loader
1212from requests import ConnectionError
1313
@@ -38,23 +38,23 @@ def do_exit(self, line):
3838 sys .exit (0 )
3939
4040 def print_table (self , data , title = None ):
41- print ""
41+ print ( "" )
4242 table = AsciiTable (data )
4343 if title :
4444 table .title = title
45- print table .table
46- print ""
45+ print ( table .table )
46+ print ( "" )
4747
4848 def do_export (self , line ):
4949 if not line :
50- print "[-] not enough arguments"
50+ print ( "[-] not enough arguments" )
5151 return
5252
5353 line = line .split ()
5454
5555 if line [0 ].lower () == 'creds' :
5656 if len (line ) < 3 :
57- print "[-] invalid arguments, export creds <plaintext|hashes|both|csv> <filename>"
57+ print ( "[-] invalid arguments, export creds <plaintext|hashes|both|csv> <filename>" )
5858 return
5959 if line [1 ].lower () == 'plaintext' :
6060 creds = self .db .get_credentials (credtype = "plaintext" )
@@ -70,21 +70,21 @@ def do_export(self, line):
7070 export_file .write ('{},{},{},{},{},{}\n ' .format (credid ,domain ,user ,password ,credtype ,fromhost ))
7171 else :
7272 export_file .write ('{}\n ' .format (password ))
73- print '[+] creds exported'
73+ print ( '[+] creds exported' )
7474
7575 elif line [0 ].lower () == 'hosts' :
7676 if len (line ) < 2 :
77- print "[-] invalid arguments, export hosts <filename>"
77+ print ( "[-] invalid arguments, export hosts <filename>" )
7878 return
7979 hosts = self .db .get_computers ()
8080 with open (os .path .expanduser (line [1 ]), 'w' ) as export_file :
8181 for host in hosts :
8282 hostid ,ipaddress ,hostname ,domain ,opsys ,dc = host
8383 export_file .write ('{},{},{},{},{},{}\n ' .format (hostid ,ipaddress ,hostname ,domain ,opsys ,dc ))
84- print '[+] hosts exported'
84+ print ( '[+] hosts exported' )
8585
8686 else :
87- print '[-] invalid argument, specify creds or hosts'
87+ print ( '[-] invalid argument, specify creds or hosts' )
8888
8989
9090 def do_import (self , line ):
@@ -116,12 +116,12 @@ def do_import(self, line):
116116
117117 self .db .add_credential (cred ['credtype' ], cred ['domain' ], cred ['username' ], cred ['password' ])
118118
119- print "[+] Empire credential import successful"
119+ print ( "[+] Empire credential import successful" )
120120 else :
121- print "[-] Error authenticating to Empire's RESTful API server!"
121+ print ( "[-] Error authenticating to Empire's RESTful API server!" )
122122
123123 except ConnectionError as e :
124- print "[-] Unable to connect to Empire's RESTful API server: {}" .format (e )
124+ print ( "[-] Unable to connect to Empire's RESTful API server: {}" .format (e ) )
125125
126126 elif line == 'metasploit' :
127127 msf = Msfrpc ({'host' : self .config .get ('Metasploit' , 'rpc_host' ),
@@ -130,7 +130,7 @@ def do_import(self, line):
130130 try :
131131 msf .login ('msf' , self .config .get ('Metasploit' , 'password' ))
132132 except MsfAuthError :
133- print "[-] Error authenticating to Metasploit's MSGRPC server!"
133+ print ( "[-] Error authenticating to Metasploit's MSGRPC server!" )
134134 return
135135
136136 console_id = str (msf .call ('console.create' )['id' ])
@@ -159,7 +159,7 @@ def do_import(self, line):
159159
160160 msf .call ('console.destroy' , [console_id ])
161161
162- print "[+] Metasploit credential import successful"
162+ print ( "[+] Metasploit credential import successful" )
163163
164164 def complete_import (self , text , line , begidx , endidx ):
165165 "Tab-complete 'import' commands."
@@ -188,10 +188,10 @@ def __init__(self, config_path):
188188 self .config_path = config_path
189189
190190 try :
191- self .config = ConfigParser ()
191+ self .config = configparser . ConfigParser ()
192192 self .config .read (self .config_path )
193193 except Exception as e :
194- print "[-] Error reading cme.conf: {}" .format (e )
194+ print ( "[-] Error reading cme.conf: {}" .format (e ) )
195195 sys .exit (1 )
196196
197197 self .workspace_dir = os .path .expanduser ('~/.cme/workspaces' )
@@ -213,7 +213,7 @@ def open_proto_db(self, db_path):
213213 self .conn .isolation_level = None
214214
215215 def write_configfile (self ):
216- with open (self .config_path , 'wb ' ) as configfile :
216+ with open (self .config_path , 'w ' ) as configfile :
217217 self .config .write (configfile )
218218
219219 def do_proto (self , proto ):
@@ -243,7 +243,7 @@ def do_workspace(self, line):
243243 if line .split ()[0 ] == 'create' :
244244 new_workspace = line .split ()[1 ].strip ()
245245
246- print "[*] Creating workspace '{}'" .format (new_workspace )
246+ print ( "[*] Creating workspace '{}'" .format (new_workspace ) )
247247 os .mkdir (os .path .join (self .workspace_dir , new_workspace ))
248248
249249 for protocol in self .protocols .keys ():
@@ -255,7 +255,7 @@ def do_workspace(self, line):
255255 proto_db_path = os .path .join (self .workspace_dir , new_workspace , protocol + '.db' )
256256
257257 if not os .path .exists (proto_db_path ):
258- print '[*] Initializing {} protocol database' .format (protocol .upper ())
258+ print ( '[*] Initializing {} protocol database' .format (protocol .upper () ))
259259 conn = sqlite3 .connect (proto_db_path )
260260 c = conn .cursor ()
261261
@@ -286,7 +286,7 @@ def main():
286286 config_path = os .path .expanduser ('~/.cme/cme.conf' )
287287
288288 if not os .path .exists (config_path ):
289- print "[-] Unable to find config file"
289+ print ( "[-] Unable to find config file" )
290290 sys .exit (1 )
291291
292292 try :
0 commit comments