Exemple #1
0
 def __init__(self, agent_main):
     self._agent_main=agent_main
     self._osnative = None
     if agent.is_windows():
         self._osnative = NativeWindows(self._agent_main)
     elif agent.is_linux():
         self._osnative = NativeLinux()
     elif agent.is_mac():
         self._osnative = NativeMac()
Exemple #2
0
 def keyboard(self, dm, tp, code, ctrl, alt, shift) :
     sid=self.get_id(dm)
     bok = True;
     if agent.is_windows() and tp=="CTRLALTCANC":
         if self._get_osmodule().sas():
             bok = False
     if bok:
         apps=u"KEYBOARD:"+str(sid)+";"+str(tp)+";"+str(code)+";"+str(ctrl)+";"+str(alt)+";"+str(shift)
         #print(apps)
         self._request_async(apps)
Exemple #3
0
def get_supported(agt):
    arSupportedApplications=[]
    arSupportedApplications.append("filesystem")
    arSupportedApplications.append("texteditor")
    arSupportedApplications.append("logwatch")
    arSupportedApplications.append("resource")
    arSupportedApplications.append("desktop")
    if agent.is_linux() or agent.is_mac() or (agent.is_windows() and platform.release() == '10'):
        arSupportedApplications.append("shell")
    return arSupportedApplications
        
Exemple #4
0
 def _on_data(self, websocket, tpdata, data):
     self._semaphore.acquire()
     try:
         if not self._bclose:
             try:
                 self._timeout_cnt = 0
                 self._last_timeout = long(time.time() * 1000)
                 prprequest = json.loads(data.to_str("utf8"))
                 if prprequest["type"] == ShellManager.REQ_TYPE_INITIALIZE:
                     sid = prprequest["id"]
                     if agent.is_windows():
                         shl = Windows(self, sid, prprequest["cols"],
                                       prprequest["rows"])
                     else:
                         shl = Linux(self, sid, prprequest["cols"],
                                     prprequest["rows"])
                     shl.initialize()
                     self._shell_list[sid] = shl
                     self._semaphore.notifyAll()
                 elif prprequest["type"] == ShellManager.REQ_TYPE_TERMINATE:
                     sid = prprequest["id"]
                     if sid in self._shell_list:
                         shl = self._shell_list[sid]
                         shl.terminate()
                         del self._shell_list[sid]
                         self._semaphore.notifyAll()
                 elif prprequest["type"] == ShellManager.REQ_TYPE_INPUTS:
                     sid = prprequest["id"]
                     if sid in self._shell_list:
                         shl = self._shell_list[sid]
                         sdata = prprequest["data"]
                         shl.write_inputs(sdata)
                         self._semaphore.notifyAll()
                 elif prprequest[
                         "type"] == ShellManager.REQ_TYPE_CHANGE_ROWS_COLS:
                     sid = prprequest["id"]
                     if sid in self._shell_list:
                         shl = self._shell_list[sid]
                         rows = prprequest["rows"]
                         cols = prprequest["cols"]
                         shl.change_rows_cols(rows, cols)
                         self._semaphore.notifyAll()
                 elif prprequest["type"] == "alive":
                     None
             except Exception as ex:
                 self._bclose = True
                 self._shlmain._agent_main.write_except(
                     ex, "AppShell:: shell manager " + self._id + ":")
     finally:
         self._semaphore.release()
Exemple #5
0
def get_supported(agt):
    arSupportedApplications=[]
    arSupportedApplications.append("filesystem")
    arSupportedApplications.append("texteditor")
    arSupportedApplications.append("logwatch")
    arSupportedApplications.append("resource")
    #Desktop
    if agent.is_windows() or agent.is_mac():
        arSupportedApplications.append("desktop")
    elif agent.is_linux():
        if agt.get_osmodule().is_gui():
            arSupportedApplications.append("desktop")
    #Shell
    if agent.is_linux() or agent.is_mac():
        arSupportedApplications.append("shell")
    return arSupportedApplications
        
Exemple #6
0
 def _init_process(self):
     if self._bdestroy:
         raise Exception("Process destroyed.")
     iretry=0;
     while True:
         try:
             self._appconsoleid=None
             iretry+=1
             if agent.is_windows():
                 self._appconsoleid=self._get_osmodule().consoleSessionId();
                 if (self._get_osmodule().isWinXP()==1 or self._get_osmodule().isWin2003Server()==1) and self._appconsoleid>0:
                     self._get_osmodule().winStationConnectW()
                     time.sleep(1)
                     self._destroy_internal()
                 elif self._currentconsoleid!=None and self._appconsoleid!=self._currentconsoleid:
                     self._destroy_internal()
             elif agent.is_mac():
                 self._appconsoleid=self._get_osmodule().consoleUserId();
                 if self._currentconsoleid!=None and self._appconsoleid!=self._currentconsoleid:
                     self._destroy_internal()
                     time.sleep(1)
             
             if self._sharedmem==None:
                 self._sharedmem=sharedmem.Stream()
                 def fix_perm(fn):
                     if agent.is_mac() and self._appconsoleid!=None:
                         utils.path_change_owner(fn, self._appconsoleid, -1)
                         utils.path_change_permissions(fn, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
                 fname = self._sharedmem.create(fixperm=fix_perm)
                 #RUN PROCESS
                 #if utils.path_exists("apps" + utils.path_sep + "desktop.py"): ##MI SERVE IN SVILUPPO
                 #    import compileall
                 #    compileall.compile_file("apps" + utils.path_sep + "desktop.py")
                 if agent.is_windows():
                     runaselevatore=u"False"
                     if self._get_osmodule().isUserInAdminGroup()==1:
                         if self._get_osmodule().isRunAsAdmin()==1:
                             if self._get_osmodule().isProcessElevated()==1:
                                 runaselevatore=u"True"
                     #Gestito cosi perche' sys.executable creave problemi con percorsi unicode
                     exep=sys.executable
                     pyhome=u""
                     appth="native\\service.properties"
                     if (utils.path_exists(appth)):
                         f = utils.file_open(appth, 'r', encoding='utf-8')
                         sprop = f.read()
                         f.close()
                         lns = sprop.splitlines()
                         for line in lns:
                             if line.startswith("pythonPath="):
                                 exep=line[11:]
                             elif line.startswith("pythonHome="):
                                 pyhome=line[11:]
                       
                     appcmd=u"\"" + exep + u"\" -S -m agent app=desktop " + unicode(fname) + u" " + unicode(str(self._agent_main._agent_debug_mode)) + u" windows " + runaselevatore
                     self._ppid = self._get_osmodule().startProcessAsUser(appcmd,pyhome)
                     self._currentconsoleid=self._get_osmodule().consoleSessionId();                        
                 elif agent.is_linux():
                     libenv = os.environ
                     if utils.path_exists("runtime"):
                         libenv["LD_LIBRARY_PATH"]=utils.path_absname("runtime/lib")
                     #for some distro linux command below don't works because missing runpy
                     #self._process=subprocess.Popen([sys.executable, u'-S', u'-m', u'agent' , u'app=desktop', unicode(fname), unicode(str(self._agent_main._agent_debug_mode)),u'linux'], env=libenv)
                     self._process=subprocess.Popen([sys.executable, u'agent.pyc', u'app=desktop', fname, str(self._agent_main._agent_debug_mode),u'linux'], env=libenv)
                     '''
                     stat -c%U /dev/tty2                        
                     if my_args is None: my_args = sys.argv[1:]
                     user_name, cwd = my_args[:2]
                     args = my_args[2:]
                     pw_record = pwd.getpwnam(user_name)
                     user_name      = pw_record.pw_name
                     user_home_dir  = pw_record.pw_dir
                     user_uid       = pw_record.pw_uid
                     user_gid       = pw_record.pw_gid
                     env = os.environ.copy()
                     env[ 'HOME'     ]  = user_home_dir
                     env[ 'LOGNAME'  ]  = user_name
                     env[ 'PWD'      ]  = cwd
                     env[ 'USER'     ]  = user_name
                     self._process=subprocess.Popen([sys.executable, u'agent.pyc', u'app=desktop', fname, str(self._agent_main._agent_debug_mode),u'linux'], env=libenv, preexec_fn=self._init_process_demote(1000, 1000))
                     '''
                     #GESTIRE IL RENICE
                 elif agent.is_mac():
                     self._ppid = self._agent_main.get_osmodule().exec_guilnc(self._appconsoleid,"desktop",[fname, str(self._agent_main._agent_debug_mode),u'mac'])
                     if self._ppid is not None:
                         self._currentconsoleid=self._appconsoleid
                         self._process = None
                     else:
                         self._currentconsoleid=None
                         libenv = os.environ
                         if utils.path_exists("runtime"):
                             libenv["DYLD_LIBRARY_PATH"]=utils.path_absname("runtime/lib")
                         #self._process=subprocess.Popen([sys.executable, u'agent.pyc', u'app=desktop', fname, str(self._agent_main._agent_debug_mode),u'mac'], env=libenv)
                         self._process=subprocess.Popen([sys.executable, u'-S', u'-m', u'agent' , u'app=desktop', unicode(fname), unicode(str(self._agent_main._agent_debug_mode)),u'mac'], env=libenv)
                         #GESTIRE IL RENICE
                 self._appconsoleid=None
                    
                 #Attende che il processo si attiva
                 bok=False
                 for i in range(10):
                     time.sleep(0.5)
                     if self._process!=None:
                         if self._process.poll() == None:
                             bok=True
                             break
                     elif self._ppid!=None:
                         if self._agent_main.get_osmodule().is_task_running(self._ppid):
                             bok=True
                             break
                     else:
                         break
                 if bok:
                     break
                 else:
                     raise Exception("Process not started.")
             else:
                 break
          
         except Exception as e:
             time.sleep(1)
             self._destroy_internal()
             if iretry>=3:
                 raise e