<s> '''<STR_LIT>''' <EOL> import rpyc <EOL> import logging <EOL> import platform <EOL> import argparse <EOL> import functools <EOL> import ConfigParser <EOL> from sys import argv <EOL> from threading import Lock <EOL> from os import path , sysconf , _exit <EOL> from multiprocessing import cpu_count <EOL> from rpyc . utils . server import ThreadedServer <EOL> from yapsy . PluginManager import PluginManager <EOL> from plugins . PluginBases import * <EOL> if platform . system ( ) . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> INFO = "<STR_LIT>" <EOL> WARN = "<STR_LIT>" <EOL> else : <EOL> INFO = "<STR_LIT>" <EOL> WARN = "<STR_LIT>" <EOL> logging . basicConfig ( <EOL> format = '<STR_LIT>' , <EOL> level = logging . DEBUG <EOL> ) <EOL> FILTERS = { <EOL> "<STR_LIT>" : MD5Plugin , <EOL> "<STR_LIT>" : SHA1Plugin , <EOL> "<STR_LIT>" : SHA256Plugin , <EOL> "<STR_LIT>" : SHA256Plugin , <EOL> "<STR_LIT>" : LMPlugin , <EOL> "<STR_LIT>" : NTLMPlugin , <EOL> "<STR_LIT>" : PBKDF2Plugin , <EOL> } <EOL> def atomic ( method ) : <EOL> '''<STR_LIT>''' <EOL> @ functools . wraps ( method ) <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> method_exception = None <EOL> results = None <EOL> self . mutex . acquire ( ) <EOL> try : <EOL> results = method ( self , * args , ** kwargs ) <EOL> except Exception as error : <EOL> method_exception = error <EOL> finally : <EOL> self . mutex . release ( ) <EOL> if method_exception is not None : <EOL> raise Exception ( method_exception ) <EOL> return results <EOL> return wrapper <EOL> class WeaponSystem ( rpyc . Service ) : <EOL> '''<STR_LIT>''' <EOL> is_initialized = False <EOL> mutex = Lock ( ) <EOL> is_busy = False <EOL> job_id = None <EOL> def initialize ( self ) : <EOL> '''<STR_LIT>''' <EOL> logging . info ( "<STR_LIT>" ) <EOL> self . plugin_manager = PluginManager ( ) <EOL> self . plugin_manager . setPluginPlaces ( [ "<STR_LIT>" ] ) <EOL> self . plugin_manager . setCategoriesFilter ( FILTERS ) <EOL> self . plugin_manager . collectPlugins ( ) <EOL> self . plugins = { } <EOL> logging . info ( <EOL> "<STR_LIT>" % len ( self . plugin_manager . getAllPlugins ( ) ) <EOL> ) <EOL> self . __cpu__ ( ) <EOL> logging . info ( "<STR_LIT>" ) <EOL> @ atomic <EOL> def on_connect ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not self . is_initialized : <EOL> self . initialize ( ) <EOL> self . is_initialized = True <EOL> logging . info ( "<STR_LIT>" ) <EOL> def on_disconnect ( self ) : <EOL> '''<STR_LIT>''' <EOL> logging . info ( "<STR_LIT>" ) <EOL> def __cpu__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> if cpu_count is not None : <EOL> try : <EOL> self . cpu_cores = cpu_count ( ) <EOL> logging . info ( "<STR_LIT>" % self . cpu_cores ) <EOL> except NotImplementedError : <EOL> logging . error ( "<STR_LIT>" ) <EOL> self . cpu_cores = <NUM_LIT:1> <EOL> else : <EOL> try : <EOL> self . cpu_cores = int ( sysconf ( "<STR_LIT>" ) ) <EOL> logging . info ( "<STR_LIT>" % self . cpu_cores ) <EOL> except ValueError : <EOL> logging . error ( "<STR_LIT>" ) <EOL> self . cpu_cores = <NUM_LIT:1> <EOL> @ atomic <EOL> def exposed_crack ( self , plugin_name , job_id , hashes , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> assert plugin_name in self . plugins <EOL> self . is_busy = True <EOL> self . job_id = job_id <EOL> self . plugin_manager . activatePluginByName ( plugin_name ) <EOL> plugin = self . plugin_manager . getPluginByName ( plugin_name ) <EOL> results = plugin . execute ( hashes , ** kwargs ) <EOL> self . plugin_manager . deactivatePluginByName ( plugin_name ) <EOL> self . job_id = None <EOL> self . is_busy = False <EOL> return results <EOL> def exposed_get_plugin_names ( self ) : <EOL> '''<STR_LIT>''' <EOL> logging . info ( "<STR_LIT>" ) <EOL> plugins = self . plugin_manager . getAllPlugins ( ) <EOL> return [ plugin . name for plugin in plugins ] <EOL> def exposed_get_categories ( self ) : <EOL> '''<STR_LIT>''' <EOL> categories = [ ] <EOL> for category in self . plugin_manager . getCategories ( ) : <EOL> if <NUM_LIT:0> < len ( self . plugin_manager . getPluginsOfCategory ( category ) ) : <EOL> categories . append ( category ) <EOL> return categories <EOL> def exposed_get_category_plugins ( self , category ) : <EOL> '''<STR_LIT>''' <EOL> plugins = self . plugin_manager . getPluginsOfCategory ( category ) <EOL> return [ plugin . name for plugin in plugins ] <EOL> def exposed_get_plugin_details ( self , category , plugin_name ) : <EOL> '''<STR_LIT>''' <EOL> plugin = self . plugin_manager . getPluginByName ( plugin_name , category ) <EOL> info = { '<STR_LIT:name>' : plugin . name } <EOL> info [ '<STR_LIT>' ] = plugin . details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> info [ '<STR_LIT>' ] = plugin . details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> info [ '<STR_LIT:version>' ] = plugin . details . get ( '<STR_LIT>' , '<STR_LIT:version>' ) <EOL> info [ '<STR_LIT:description>' ] = plugin . details . get ( '<STR_LIT>' , '<STR_LIT:description>' ) <EOL> info [ '<STR_LIT>' ] = plugin . details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> info [ '<STR_LIT>' ] = plugin . details . getboolean ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return info <EOL> def exposed_ping ( self ) : <EOL> '''<STR_LIT>''' <EOL> return "<STR_LIT>" <EOL> def exposed_is_busy ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . is_busy <EOL> def exposed_current_job_id ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . job_id <EOL> def exposed_cpu_count ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . cpu_cores <EOL> def start_server ( config_file ) : <EOL> defaults = { <EOL> '<STR_LIT>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> config = ConfigParser . SafeConfigParser ( defaults ) <EOL> config . readfp ( open ( config_file , '<STR_LIT:r>' ) ) <EOL> lport = config . getint ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> host = config . get ( "<STR_LIT>" , '<STR_LIT>' ) . strip ( ) <EOL> agent = ThreadedServer ( WeaponSystem , hostname = host , port = lport ) <EOL> agent . start ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = argparse . ArgumentParser ( <EOL> description = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> action = '<STR_LIT:version>' , <EOL> version = '<STR_LIT>' <EOL> ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT:test>' , <EOL> ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT:-c>' , <EOL> help = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> default = '<STR_LIT>' <EOL> ) <EOL> args = parser . parse_args ( ) <EOL> if not args . test : <EOL> if not path . exists ( args . cfg ) or not path . isfile ( args . cfg ) : <EOL> print ( WARN + "<STR_LIT>" ) <EOL> _exit ( <NUM_LIT:1> ) <EOL> else : <EOL> logging . info ( '<STR_LIT>' % path . abspath ( args . cfg ) ) <EOL> start_server ( args . cfg ) <EOL> _exit ( <NUM_LIT:0> ) <EOL> else : <EOL> print ( INFO + "<STR_LIT>" ) <EOL> wsys = WeaponSystem ( None ) <EOL> wsys . on_connect ( ) <EOL> print wsys . exposed_get_plugin_names ( ) <EOL> print wsys . plugin_manager . getCategories ( ) <EOL> for cat in wsys . plugin_manager . getCategories ( ) : <EOL> print "<STR_LIT>" % cat , <EOL> print [ plug . name for plug in wsys . plugin_manager . getPluginsOfCategory ( cat ) ] </s>
