예제 #1
0
파일: human.py 프로젝트: kevoreilly/CAPEv2
def get_office_window_click_around(hwnd, lparm):
    global OFFICE_CLICK_AROUND
    if USER32.IsWindowVisible(hwnd):
        text = create_unicode_buffer(1024)
        USER32.GetWindowTextW(hwnd, text, 1024)
        if any(value in text.value
               for value in ("Microsoft Word", "Microsoft Excel",
                             "Microsoft PowerPoint")):
            USER32.SetForegroundWindow(hwnd)
            # first click the middle
            USER32.SetCursorPos(RESOLUTION["x"] // 2, RESOLUTION["y"] // 2)
            click_mouse()
            KERNEL32.Sleep(50)
            click_mouse()
            KERNEL32.Sleep(500)
            # click through the middle with offset for cell position on side and scroll bar
            x = 80
            while x < RESOLUTION["x"] - 40:
                # make sure the window still exists
                if USER32.IsWindowVisible(hwnd):
                    USER32.SetForegroundWindow(hwnd)
                    USER32.SetCursorPos(x, RESOLUTION["y"] // 2)
                    click_mouse()
                    KERNEL32.Sleep(50)
                    click_mouse()
                    KERNEL32.Sleep(50)
                    if not USER32.IsWindowVisible(hwnd):
                        break
                    USER32.SetForegroundWindow(hwnd)
                    USER32.SetCursorPos(
                        x, RESOLUTION["y"] // 2 + random.randint(80, 200))
                    click_mouse()
                    KERNEL32.Sleep(50)
                    click_mouse()
                    KERNEL32.Sleep(50)
                    if not USER32.IsWindowVisible(hwnd):
                        break
                    USER32.SetForegroundWindow(hwnd)
                    USER32.SetCursorPos(
                        x, RESOLUTION["y"] // 2 - random.randint(80, 200))
                    click_mouse()
                    KERNEL32.Sleep(50)
                    click_mouse()
                    KERNEL32.Sleep(50)
                    x += random.randint(150, 200)
                    KERNEL32.Sleep(50)
                else:
                    log.info(
                        "Breaking out of office click loop as our window went away"
                    )
                    break
            KERNEL32.Sleep(20000)
            OFFICE_CLICK_AROUND = True
    return True
예제 #2
0
def foreach_window(hwnd, lparam):
    # If the window is visible, enumerate its child objects, looking
    # for buttons.

    if USER32.IsWindowVisible(hwnd):
        classname = create_unicode_buffer(50)
        USER32.GetClassNameW(hwnd, classname, 50)

        # If the window is one of the known class types that are inaccessible by User32, send Enter
        # This may proceed if there is a default action
        for win in default_action_win:
            if win in classname.value.lower():
                log.info(
                    "Found inaccessible window of class %s. Sending Enter" %
                    classname.value.lower())
                USER32.SetActiveWindow(hwnd)
                USER32.SetForegroundWindow(hwnd)
                type_keyboard(0x09, 0x8F)
                type_keyboard(0x0D, 0x9C)

        USER32.EnumChildWindows(hwnd, EnumChildProc(foreach_child), 0)

#Turning off the ability of pressing objects in PDF, URL is good enough
#try:
#Get PID of current window
#	win_pid = c_ulong(0)
#	USER32.GetWindowThreadProcessId(hwnd,byref(win_pid))

#Get application name from PID
#	procname = psutil.Process(win_pid.value)
#	applicname = procname.name()

#	tabVal = get_tab_val(win_pid.value)

#If this is PDF
#	if "AcroRd" in applicname:
#		log.info("App Name %s",applicname)
#		log.info("TabValue: %s",str(tabVal))
#		USER32.SetActiveWindow(hwnd)
#	        USER32.SetForegroundWindow(hwnd)
#		log.info("Sending Tab and Enter")
#We are sending Tab different number of times
# to cover different URLs
#for y in range(0,tabVal):
#	#Sending Tab
#	type_keyboard(0x09,0x0F)
#	time.sleep(0.1)
#Sending Enter
#type_keyboard(0x0D,0x1C)
#time.sleep(10)
#update_tab_val(win_pid.value)

#except:
#	log.info("Raised exception")
#	e = sys.exc_info()[0]
#       log.info(str(e))
#        e1 = sys.exc_info()[1]
#        log.info(str(e1))

    return True
예제 #3
0
def foreach_window(hwnd, lparam):
    # If the window is visible, enumerate its child objects, looking
    # for buttons.
    if USER32.IsWindowVisible(hwnd):
        # we also want to inspect the "parent" windows, not just the children
        foreach_child(hwnd, lparam)
        USER32.EnumChildWindows(hwnd, EnumChildProc(foreach_child), 0)
    return True
예제 #4
0
def get_office_window(hwnd, lparam):
    if USER32.IsWindowVisible(hwnd):
        text = create_unicode_buffer(1024)
        USER32.GetWindowTextW(hwnd, text, 1024)
        if "- Microsoft" in text:
            # send ALT+F4 equivalent
            USER32.SendMessageW(hwnd, WM_CLOSE, None, None)
    return True
예제 #5
0
파일: human.py 프로젝트: obert01/cuckoo
def get_office_window(hwnd, lparam):
    if USER32.IsWindowVisible(hwnd):
        text = create_unicode_buffer(1024)
        USER32.GetWindowTextW(hwnd, text, 1024)
        # TODO Would " - Microsoft (Word|Excel|PowerPoint)$" be better?
        if re.search("- (Microsoft|Word|Excel|PowerPoint)", text.value):
            USER32.SendNotifyMessageW(hwnd, WM_CLOSE, None, None)
            log.info("Closed Office window.")
    return True
예제 #6
0
def foreach_window(hwnd, lparam):
    '''Callback procedure invoked for every enumerated window. 
    '''

    # If the window is visible, enumerate its child objects, looking
    # for buttons.
    if USER32.IsWindowVisible(hwnd):
        USER32.EnumChildWindows(hwnd, EnumChildProc(foreach_child), 0)
    return True
예제 #7
0
def get_office_window(hwnd, lparam):
    global CLOSED_OFFICE
    if USER32.IsWindowVisible(hwnd):
        text = create_unicode_buffer(1024)
        USER32.GetWindowTextW(hwnd, text, 1024)
        if "- Microsoft" in text.value or "- Word" in text.value or "- Excel" in text.value or "- PowerPoint" in text.value:
            # send ALT+F4 equivalent
            log.info("Closing Office window.")
            USER32.SendNotifyMessageW(hwnd, WM_CLOSE, None, None)
            CLOSED_OFFICE = True
    return True
예제 #8
0
def get_office_window(hwnd, lparam):
    '''
    Callback procedure invoked for every enumerated window.
    Purpose is to close any office window.
    '''
    if USER32.IsWindowVisible(hwnd):
        text = get_window_text(hwnd)
        if re.search("(Microsoft|Word|Excel|PowerPoint)", text):
            USER32.SendNotifyMessageW(hwnd, WM_CLOSE, None, None)
            KERNEL32.Sleep(1000)
            log.info("Closed Office window: %s", text)
    return True
예제 #9
0
def foreach_window(hwnd, lparam):
    # If the window is visible, enumerate its child objects, looking
    # for buttons.
    if USER32.IsWindowVisible(hwnd):
        USER32.EnumChildWindows(hwnd, EnumChildProc(foreach_child), 0)
    return True
예제 #10
0
def foreach_child(hwnd, lparam):
    # List of buttons labels to click.
    buttons = [
        # english
        "yes",
        "ok",
        "accept",
        "next",
        "install",
        "run",
        "agree",
        "enable",
        "don't send",
        "don't save",
        "continue",
        "unzip",
        "open",
        "close the program",
        "save",
        "later",
        "finish",
        "end",
        "allow access",
        "remind me later",
        # german
        "ja",
        "weiter",
        "akzeptieren",
        "ende",
        "starten",
        "jetzt starten",
        "neustarten",
        "neu starten",
        "jetzt neu starten",
        "beenden",
        "oeffnen",
        "schliessen",
        "installation weiterfuhren",
        "fertig",
        "beenden",
        "fortsetzen",
        "fortfahren",
        "stimme zu",
        "zustimmen",
        "senden",
        "nicht senden",
        "speichern",
        "nicht speichern",
        "ausfuehren",
        "spaeter",
        "einverstanden"
    ]

    # List of buttons labels to not click.
    dontclick = [
        # english
        "check online for a solution",
        "don't run",
        "do not ask again until the next update is available",
        "cancel",
        "do not accept the agreement",
        "i would like to help make reader even better",
        # german
        "abbrechen",
        "online nach losung suchen",
        "abbruch",
        "nicht ausfuehren",
        "hilfe",
        "stimme nicht zu"
    ]

    classname = create_unicode_buffer(128)
    USER32.GetClassNameW(hwnd, classname, 128)

    # Check if the class of the child is button.
    if "button" in classname.value.lower(
    ) or classname.value == "NUIDialog" or classname.value == "bosa_sdm_msword":
        # Get the text of the button.
        length = USER32.SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0)
        if not length:
            return True
        text = create_unicode_buffer(length + 1)
        USER32.SendMessageW(hwnd, WM_GETTEXT, length + 1, text)
        textval = text.value.replace('&', '')
        if "Microsoft" in textval and (classname.value == "NUIDialog" or
                                       classname.value == "bosa_sdm_msword"):
            log.info("Issuing keypress on Office dialog")
            USER32.SetForegroundWindow(hwnd)
            # enter key down/up
            USER32.keybd_event(0x0d, 0x1c, 0, 0)
            USER32.keybd_event(0x0d, 0x1c, 2, 0)
            return False

        # we don't want to bother clicking any non-visible child elements, as they
        # generally won't respond and will cause us to fixate on them for the
        # rest of the analysis, preventing progress with visible elements

        if not USER32.IsWindowVisible(hwnd):
            return True

        # Check if the button is set as "clickable" and click it.
        for button in buttons:
            if button in textval.lower():
                dontclickb = False
                for btn in dontclick:
                    if btn in textval.lower():
                        dontclickb = True
                if not dontclickb:
                    log.info("Found button \"%s\", clicking it" % text.value)
                    USER32.SetForegroundWindow(hwnd)
                    KERNEL32.Sleep(1000)
                    USER32.SendMessageW(hwnd, BM_CLICK, 0, 0)
                    # only stop searching when we click a button
                    return False
    return True
예제 #11
0
def getwindowlist(hwnd, lparam):
    global INITIAL_HWNDS
    if USER32.IsWindowVisible(hwnd):
        INITIAL_HWNDS.append(hwnd)
    return True
예제 #12
0
def foreach_child(hwnd, lparam):
    # List of buttons labels to click.
    buttons = [
        "yes",
        "ok",
        "accept",
        "next",
        "install",
        "run",
        "agree",
        "enable",
        "don't send",
        "don't save",
        "continue",
        "unzip",
        "open",
        "close the program",
        "save",
        "later",
        "finish",
        "end",
        "allow access",
    ]

    # List of buttons labels to not click.
    dontclick = [
        "check online for a solution",
        "don't run",
        "do not ask again until the next update is available",
        "cancel",
    ]

    classname = create_unicode_buffer(128)
    USER32.GetClassNameW(hwnd, classname, 128)

    # Check if the class of the child is button.
    if "button" in classname.value.lower() or classname.value == "NUIDialog":
        # Get the text of the button.
        length = USER32.SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0)
        if not length:
            return True
        text = create_unicode_buffer(length + 1)
        USER32.SendMessageW(hwnd, WM_GETTEXT, length + 1, text)
        textval = text.value.replace('&', '')
        if classname.value == "NUIDialog" and "Microsoft" in textval:
            log.info("Issuing keypress on Office dialog")
            USER32.SetForegroundWindow(hwnd)
            # enter key down/up
            USER32.keybd_event(0x0d, 0x1c, 0, 0)
            USER32.keybd_event(0x0d, 0x1c, 2, 0)
            return False

        # we don't want to bother clicking any non-visible child elements, as they
        # generally won't respond and will cause us to fixate on them for the
        # rest of the analysis, preventing progress with visible elements

        if not USER32.IsWindowVisible(hwnd):
            return True

        # Check if the button is set as "clickable" and click it.
        for button in buttons:
            if button in textval.lower():
                dontclickb = False
                for btn in dontclick:
                    if btn in textval.lower():
                        dontclickb = True
                if not dontclickb:
                    log.info("Found button \"%s\", clicking it" % text.value)
                    USER32.SetForegroundWindow(hwnd)
                    KERNEL32.Sleep(1000)
                    USER32.SendMessageW(hwnd, BM_CLICK, 0, 0)
                    # only stop searching when we click a button
                    return False
    return True