Jump to content
Sign in to follow this  
prayi

Script to bypass the certificate error - (Moved)

Recommended Posts

Hi All,

I am launching the Internet Explorer as specific user and passing the URL.  Normally it works fine, but for the URL which has certificate issue I need to bypass it. Below is the code I am trying to but unable to bypass the certificate error. Can anyone help on this.

#AutoIt3Wrapper_UseX64=n
Opt("MustDeclareVars", 1)
AutoItSetOption("WinTitleMatchMode", 3) ; EXACT_MATCH!



#include "PSMGenericClientWrapper.au3"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <BlockInputEx.au3>
#include <AutoItConstants.au3>
#include <Clipboard.au3>
#include <IE.au3>
;=======================================
; Consts & Globals
;=======================================

Global $TargetAddress
Global $TargetUsername
Global $TargetPassword
Global $TargetLogonDomain
Global $ConnectionClientPID = 0
Global $PSMRemoteMachine
Global $oIE

Global Const $DISPATCHER_NAME        = "IE RunAs"
Global Const $CLIENT_EXECUTABLE        = "C:\Program Files\Internet Explorer\iexplore.exe"
Global Const $WORKING_DIR            = "C:\Program Files\Internet Explorer"
Global Const $ERROR_MESSAGE_TITLE      = "PSM " & $DISPATCHER_NAME & " Dispatcher error message"
Global Const $LOG_MESSAGE_PREFIX     = $DISPATCHER_NAME & " Dispatcher - "

;=======================================
; Code
;=======================================
Exit Main()

;=======================================
; Main
;=======================================
Func Main()

      Local $title

    ; Init PSM Dispatcher utils wrapper
    ToolTip ("Initializing...")
    if (PSMGenericClient_Init() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("successfully initialized Dispatcher Utils Wrapper")

    ; Get the dispatcher parameters
    FetchSessionProperties()

    LogWrite("mapping local drives")
    if (PSMGenericClient_MapTSDrives() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("starting client application")
    ToolTip ("Starting " & $DISPATCHER_NAME & "...")
    ;$ConnectionClientPID = Run($CLIENT_EXECUTABLE)

    Local $LogonFlag = 1
    ;0 - Interactive logon with no profile.
    ;1 - Interactive logon with profile.
    ;2 - Network credentials only.
    ;4 - Inherit the calling process's environment instead of the user's environment.
    Local $ExePlusURL = StringFormat("%s %s", $CLIENT_EXECUTABLE, $PSMRemoteMachine)
    Local $ConnectionClientPID = RunAs($TargetUsername, $TargetLogonDomain, $TargetPassword, $LogonFlag, $ExePlusURL, $WORKING_DIR, @SW_MAXIMIZE)
    tooltip ("launching iE")

    if ($ConnectionClientPID == 0) Then
        Error(StringFormat("Failed to execute process [%s]", $CLIENT_EXECUTABLE, @error))
    EndIf
tooltip ("Before handle login section")

    ; Send PID to PSM so recording/monitoring can begin
    ; Notice that until we send the PID, PSM blocks all user input.
    LogWrite("sending PID to PSM")
    if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
     EndIf


    ; ------------------
    ; Handle login here! ; CHANGE_ME
    ; ------------------
     Sleep(10000)
          For $i = 1 To 1*2400
            LogWrite("Processing Web Interface - " & $i)
            $title = WinGetTitle("[ACTIVE]")
            LogWrite("Title=" & $title)
            Select
                Case WinWaitActive("Certificate Error")
                    LogWrite("Accept Certificate error warning")
                    _IELinkClickByText($ExePlusURL, "Continue to this website (not recommended).")
                    LogWrite("Accepted Certificate error warning")
         ;Testing IE
               Case WinActive("Internet Explorer")
                sleep(500)
                    
                     Sleep (500)
                     SendCredentials()
               ExitLoop

            EndSelect
            Sleep(25)
        Next
        MouseMove(500, 500)


    ; Terminate PSM Dispatcher utils wrapper
    LogWrite("Terminating Dispatcher Utils Wrapper")
    PSMGenericClient_Term()
    Return $PSM_ERROR_SUCCESS
EndFunc

;==================================
; Functions
;==================================
; #FUNCTION# ====================================================================================================================
; Name...........: Error
; Description ...: An exception handler - displays an error message and terminates the dispatcher
; Parameters ....: $ErrorMessage - Error message to display
;                    $Code          - [Optional] Exit error code
; ===============================================================================================================================
Func Error($ErrorMessage, $Code = -1)

    ; If the dispatcher utils DLL was already initialized, write an error log message and terminate the wrapper
    if (PSMGenericClient_IsInitialized()) Then
        LogWrite($ErrorMessage, True)
        PSMGenericClient_Term()
    EndIf

    Local $MessageFlags = BitOr(0, 16, 262144) ; 0=OK button, 16=Stop-sign icon, 262144=MsgBox has top-most attribute set

    MsgBox($MessageFlags, $ERROR_MESSAGE_TITLE, $ErrorMessage)

    ; If the connection component was already invoked, terminate it
    if ($ConnectionClientPID <> 0) Then
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = 0
    EndIf

    Exit $Code
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: LogWrite
; Description ...: Write a PSMWinSCPDispatcher log message to standard PSM log file
; Parameters ....: $sMessage - [IN] The message to write
;                  $LogLevel - [Optional] [IN] Defined if the message should be handled as an error message or as a trace messge
; Return values .: $PSM_ERROR_SUCCESS - Success, otherwise error - Use PSMGenericClient_PSMGetLastErrorString for details.
; ===============================================================================================================================
Func LogWrite($sMessage, $LogLevel = $LOG_LEVEL_TRACE)
    Return PSMGenericClient_LogWrite($LOG_MESSAGE_PREFIX & $sMessage, $LogLevel)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: PSMGenericClient_GetSessionProperty
; Description ...: Fetches properties required for the session
; Parameters ....: None
; Return values .: None
; ===============================================================================================================================
Func FetchSessionProperties() ; CHANGE_ME
    if (PSMGenericClient_GetSessionProperty("Username", $TargetUsername) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("Password", $TargetPassword) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("Address", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
     EndIf

     if (PSMGenericClient_GetSessionProperty("PSMRemoteMachine", $PSMRemoteMachine) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
     EndIf

      if (PSMGenericClient_GetSessionProperty("LogonDomain", $TargetLogonDomain) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
     EndIf
  EndFunc

  Func SendCredentials()
    MouseClick ($MOUSE_CLICK_LEFT, 500 ,1)
    Sleep(5)
    if (SendUserName()) Then
        if (SendPassword()) Then
            Sleep(100) ;was 500
            Send("{ENTER}")
            return True
        EndIf
    EndIF
        Error("Credentials injection failed")
        return False
EndFunc

Func SendUserName()
    ToolTip("Preparing to inject credentials")
    Local $text
    ToolTip ("Scanning Username filed")
    For $i = 1 to 25 ; try for n minutes
;~         _ClipBoard_SetData("")
;~         Send ("^a")
;~         Sleep(500)
;~         Send("^c")
;~         Sleep(500)
;~         $text = _ClipBoard_GetData($CF_TEXT)
        if (StringInStr($text, "http")) = 0 Then
            Send("Scanning...",1)
            Send("^a")
            Sleep(500)
            Send("^x")
            Sleep(500)
            $text = _ClipBoard_GetData($CF_TEXT)
            if (StringCompare($text, "Scanning...",1))=0 Then
                ToolTip("Sending: " & $TargetUsername)
                Send($TargetUsername,1)
                Send("{TAB}")
                Sleep(500);was 1000
                return True
            EndIf
        Else
            Send("{ESC}{TAB}")
        EndIF
        Send ("{TAB}")
        Sleep(1000)
    Next
    return False
EndFunc

Func SendPassword()
    Local $text
    toolTip("Scanning Password Field")
    For $i = 1 To 25
        _ClipBoard_SetData("")
        Send("^a^x")
        Sleep(500) ;was 500
        $text = _ClipBoard_GetData($CF_TEXT)
        If (StringInStr($text, "https")) = 0 Then
            _ClipBoard_SetData("")
            Send("ScanningP...",1)
            Sleep(100) ;was 100
            Send("^a^x")
            Sleep(100) ;was 100
            $text = _ClipBoard_GetData($CF_TEXT)
            if (StringCompare($text,"ScanningP...",1))<>0 Then
                Send($TargetPassword,1)
                Sleep(100) ;was 1000
                return True
            EndIf
        Else
            Send("{ESC}{TAB}")
        EndIf
        Send("{TAB}")
        Sleep(100)
    Next
    return False
EndFunc


 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...