版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
pascustomizationIntroductiontoCPMTerminalPluginsBytheendofthissessionyouwillbeableto:DescribethebasicfunctionalityofastatemachineDescribeastatemachinecompiledasProcessandPromptsfilesReverseEngineeranexistingCPMTerminalpluginLessonObjectives2reviewPMTerminalandTPCarethetwopluginenginesresponsibleformanagingcredentialsinTerminalbasedDevices.PMTerminalandTPCexecutethelogicinpluginsthatarecompiledastwofiles:TheProcessfileThePromptsfilePMTerminalandTPCREVIEWANewPMTerminalorTPCprocessisspawnedbytheCPMwhenitneedstoperformanActionCPMprovidestheenginewiththefollowing:CPMActionNon-SensitiveInformationSensitiveInformationTheinformationprovidedbyCPMtothepluginenginecanbeusedasparametersintheflowPMTerminal.exe/TPCCPMIPAddressUsernameLogonReconcilePortProcessPromptsNon-SensitiveInformation<VerifyPass><Logon><ChangePass><PreReconcoilePass><ReconcilePass>CPMAction<pmpass><pmnewpass><pmextrapass1><pmextrapass3>SensitiveInformationManagingterminalbaseddevicesreviewThestatemachinePMTerminalandTPCrunasastatemachine,simulatinghumanbehavior(usingamodulecalledExpect).Astatemachinestartsataninitialstate,andmovesfromstatetostateaccordingtoconditionsthataremetuntilitreachesafinalstate.ThePromptsandProcess
files
describetheStateMachine,whichisusedtodescribetheprocessofchanging,verifyingandreconcilingapasswordonaspecificdeviceDevelopingCPMTerminalpluginsmanuallyrequiresmanuallycreatingthestatemachine,i.e.–manuallycreatingtheProcessandPrompts
filesStateMachineTheProcessFiledefinesStatesandTransitions.Statesdefinetheactionsperformedtoenterastate.TransitionsdefinewheretomoveinthestatemachineonceaConditionhasbeenmet.ThePromptsFiledefinestheConditions.Whenthepluginruns,theenginematchestheconditionstotheoutput(prompts)
itreceivedfromthetargetmachine.Processfile:[states]Login=(spawn)telnet.exe<address>SendUsername=<username>SendPassword=<pmpass>InvalidLogon=FAIL(badusernameorpassword,8001).END[transitions]#CurrentState Condition NextStateLogin, Username, SendUsernameSendUsername, Password, SendPasswordSendPassword, StandardPrompt, ENDSendPassword, AccessDenied, InvalidLogonPromptsfile:[conditions]Username=username:Password=password:StandardPrompt=#AccessDenied=AccessdeniedProcessandpromptsfilesProcessandPromptsFiles(Flow)LoginSendUsernameUsernameSendPasswordPasswordInvalidLogonAccessDeniedStandardPromptEND(spawn)telnet.exe<address><username><pmpass>Processfile:[states]Login=(spawn)telnet.exe<address>SendUsername=<username>SendPassword=<pmpass>InvalidLogon=FAIL(badusernameorpassword,8001).END[transitions]#CurrentState Condition NextStateLogin, Username, SendUsernameSendUsername, Password, SendPasswordSendPassword, StandardPrompt, ENDSendPassword, AccessDenied, InvalidLogonPromptsfile:[conditions]Username=username:Password=password:StandardPrompt=#AccessDenied=Accessdenied[Conditions]PlinkStoreKey=Storekeyincache|AreyousureyouwantLogin=loginas:|login[States]StartSSH=(spawn)bin\\Plink.exe<address>-ssh-P<port>StoreKeyInCache=yLogonUser=<username>[Transitions]StartSSH, PlinkStoreKey, StoreKeyInCacheStartSSH, Login, LogonUserStoreKeyInCache, Login, LogonUserBranchLogin(If…Then…Else)If$prompt="Login:"Then sendkeys($password)ElseIf$prompt="Storekeyincache" sendkeys("y")EndIf[Conditions]IsRoot=(expression)[stringequal-nocase"<username>""root"]IsAdmin=(expression)[stringequal-nocase"<username>""admin"]IsSupport=(expression)[stringequal-nocase"<username>""support"][States]CheckUserTypeSendAdminUID=<username>SendSupportUID=<username>SendExtra1UID=<extrapass1\username>[Transitions]CheckUserType, IsAdmin, SendAdminUIDCheckUserType, IsSupport, SendSupportUIDCheckUserType, IsRoot, SendExtra1UIDBranchLogic(Select…Case)SELECTCASE$type="Admin" sendkeys(<username>) …CASE$type="Support" sendkeys(<username>) …CASE$type="Root" sendkeys(<extrapass1/username>) …ENDSELECT[Conditions]GetOutput=(.*)(.*)[States]Command=uname–n-oSetOutput=(script)set$hostname“$output_match(1,string)”;set$osname“$output_match(2,string)”;[Transitions]Command, GetOutput,SetOutputCaptureOutputandSetaVariable$hostname=“Blackhole”$osname=“GNU/Linux”CommandsyntaxInthissectionwewillcoverthecommandsyntaxforusingthefollowinginCPMTerminalplugins:ParametersVariablesExpressionsTCLCommandsparametersCredentialsandotherpropertiesfromthetargetandlinkedaccountscanbeusedasparametersintheflow.Propertiescanbebroughtfromthefollowinglocation:TargetAccountLinkedAccountTargetAccountPlatform(AdditionalPolicySettings)ChangePass=passwd<username>
Inthisexample,thecommand"passwd"issenttothetargetmachinewiththeusernametakenfromthetargetaccount.SendPass=<pmpass>
Inthisexample,thecurrentpasswordofthetargetaccountissenttothetargetmachine.LoginExtraUser=<extrapass1\username>
Inthisexample,theusernameofthefirstlinkedaccount(commonlyusedasalogonaccount)issenttothetargetmachine.StartSession=(spawn)bin\\plink.exe<address>-SSH-P<port>
Inthisexample,anSSHconnectionisestablishedusingtheaddressandporttakenfromthetargetaccount.Iftheportisnotsetinthetargetaccount,itistakenfromtheplatform.variablesYoucanuselocalvariablesduringtherunofthepluginTosetavariableuseSET.ToupdateavariableuseSETorAPPENDTouseavariable,Referencethevariablebyappendingthe
$
charactertothenameofthevariableInit=(script)setcurr_pass"<pmpass>";
InitVerifyLogon=(script)setcurr_pass"<pmnewpass>";
Inthisexample,thevariablecurr_passissetintwodifferentways:Whenreachingthe
Init
state,itissettothecurrentpasswordofthetargetaccountWhenreachingthe
InitVerifyLogon
state,itissettothenewpasswordofthetargetaccountLoginPass=$curr_pass
Inthisexample,thevariablecurr_passissenttothetargetmachine.Whilethepluginisrunning,thispasswordcanbesettothetargetaccount’scurrentornewpasswordoreventooneofthelinkedaccount’spasswords,dependingontheuserthatisusedtologontothetarget.Theseexamplesareusefulforreusingtheloginflow.Oncefortheinitiallogon,andasecondforrunningaverifyafterthepasswordwaschanged.expressionsBooleanexpressionscanalsobeusedasconditionswithintheplugincode.Expressionscaninclude:StringcomparisonIntegercomparisonBooleanconstantsBooleanoperations:ActionIsVerify=(expression)[stringequal-nocase"<action>""verifypass"]ThisexpressionchecksthattheactioncurrentlyrunningisVerify,bycomparingthebuilt-inparameter<action>andtheconstantstringverifypassIsVerifyLogon=(expression)$VerifyLogon==1Thisexpressionusesintegercomparisontovalidatethatthevariable$VerifyLogon,whichispreviouslysettoavalueusingasetcommand,isnowset1.TRUE=(expression)true
Thisexpressionsetsaconditionthatisalwaystrueusingthekeywordtrue.Inthesameway,youcancreateaconditionthatisalwaysfalseusingthekeywordfalse.!(Expression)Not(ExpressionA)&&(ExpressionB)And(ExpressionA)||(ExpressionB)OrActionIsNotVerify=!(expression)[stringequal-nocase"<action>""verifypass"]Thisexpressionchecksthattheactioncurrentlyrunningisnot
Verify.Usingastringcompressionofthebuiltinparameter<action>andtheconstantstring"verifypass"andtheoperator"!"TclcommandsTCLisaDynamicProgrammingLanguage.TCLcommandscanbeusedintheplugintoworkwithvariables,manipulatestrings,performarithmeticoperationsandmore.AsPMTerminalwaswritteninTCL,itsupportsTCLcommandsnatively.Althoughwrittenin.NET,TPCalsosupportsallTCLcommandsforbackwardcompatibility(fromv11).SomeexamplesofcommonlyusedTCLcommandsSyntaxFunctionCommandSet<Variable><Value>ReadandwritevariablesSetappend<Variable><Value>AppendtovariableAppendstringlength<input>ReturnsthenumberofcharactersinastringStringlengthlogout=(script)closeClosetheconnectiontothetargetCloseYoucanfindallsupportedTCLcommandsinthislocation:ProcessFileInthissectionwewillcovertheProcessFilewhichcontainsfivesections:StatesTransitionsCPMParametersValidationParametersDebugInformationStatesareactionsthatparticipateintheprocess:sendtoremote(default)spawnscriptsendtoremote-Thisactiondefinestheinformationtosendtotheremotemachine.Itisthemostcommonaction,soitdoesnotrequireakeyword.spawn-Thisactiondefinestheclientapplicationwhichwillbeusedtoconnecttotheremotemachine(plink,telnet,python)script-ThisactiondefinesavalidTCLscriptthatisevaluatedduringruntimewhentheactionisperformed.Multipleactionscanbeperformedinasinglestateusingthe
;
(semicolon)separator
[states]#InitializationInit=(script)setVerifyLogon0;setcurr_pass"<pmpass>";#LoginsequenceCheckProtocol=StartSessionSSH=(spawn)bin\\plink.exe<address>-ssh-P<port>StartSessionTelnet=(spawn)telnet<address><port>StoreKeyInCache=yCheckExtraPass=LoginExtraUser=<extrapass1\username>LoginExtraPass=<pmextrapass1>SwitchUser=su-<username>SwitchPass=$curr_pass...#FinalstateEND#FailurestatesFailUnableToConnect=FAIL(Firstlogin-Unabletoconnecttomachine.Checkmachineaddressandport,8000)FailTARGETInvalidUsernameOrPassword=FAIL(Invalidusernameorbadpassword,2114)StatesTherearetwospecialstatesthatwillendtheplugin:ENDFailureScenariosEND-Thisstatesetsthesuccessfulreturnfromtheplugin.Whenreachingthisstate,thepluginreturnsareturncode0(success)tothe
CPM
andtheenduser.Youmustnamethisstate“END”.FAIL–ThisactionsetsthereturncodeandmessagethatarereturnedtotheCPMandtheenduserThefailuremessagewillbewrittentothescreenandlog.Theerrorcodewillbeusedasthereturnedcode(allowingCPMtotakenecessaryaction,e.g.–reconcile).
[states]#InitializationInit=(script)setVerifyLogon0;setcurr_pass"<pmpass>";#LoginsequenceCheckProtocol=StartSessionSSH=(spawn)bin\\plink.exe<address>-ssh-P<port>StartSessionTelnet=(spawn)telnet<address><port>StoreKeyInCache=yCheckExtraPass=LoginExtraUser=<extrapass1\username>LoginExtraPass=<pmextrapass1>SwitchUser=su-<username>SwitchPass=$curr_pass...#FinalstateEND#FailurestatesFailUnableToConnect=FAIL(Firstlogin-Unabletoconnecttomachine.Checkmachineaddressandport,8000)FailTARGETInvalidUsernameOrPassword=FAIL(Invalidusernameorbadpassword,2114)EndstateandfailurescenariosTransitionsdefinetheflowoftheprocess.Eachtransitionismadeupofthreeparameterscalleda
triple,whichareseparatedbycommasThefirstelementisthelogicalnameofthecurrentstate,thesecondelementisthecondition,andthethirdelementisthenextstate.
[transitions]#CurrentState Condition NextStateLogin, Username, SendUsernameSendUsername, Password, SendPasswordSendPassword, StandardPrompt,ENDSendPassword, AccessDenied, InvalidLogonTransitionsPMTerminalandTPCcanbeinstructedtovalidatetheexistenceofmandatoryparametersintheplatformbeforethepluginisexecuted.Inthisexample,theusernameofthelogonaccount(extrapass1)isrequiredonlyifalogonaccountisattached.Thisischeckedbymakingsurethatthelogonaccount’spasswordisnotempty
[CPMParametersValidation]username,source=FILE,Mandatory=yesaddress, source=FILE,Mandatory=yesprotocol,source=FILE,Mandatory=yesport,source=FILE,Mandatory=yesextrapass1\username,source=FILE,Mandatory=![stringequal-nocase"<pmextrapass1>"""]CPMParametersValidationPromptTimeout-Thetimeoutinsecondstowaitforaprompt.Whenthistimeoutexpires,theplug-inwillfail.SendSlow/SendHuman-Therateatwhichinformationissenttotheremotemachine.Stty-enableordisablepropertiesoftheterminal.Note:whenTPCisperformingtheaction,onlythePromptTimeoutparameterisparsed(astheconnectionismadebytheNET.SSHlibraryandnotplink). [parameters]PromptTimeout=60#SendSlow=1.001#SendHuman=.1.31.052#Stty-validvaluesareoneormoreof:echo,raw,cooked,-echo,-raw,-cooked#Stty=ParametersDebugInformation(PMTerminal)Userscansetavarietyofparameterstocontroldifferentaspectsofdebuggingtheplugin.Logswillbewrittento<cpmfolder>/logs/thirdparty
[DebugInformation]DebugLogFullParsingInfo=noDebugLogFullExecutionInfo=noDebugLogDetailBuiltInActions=noExpectLog=yesConsoleOutput=no*****************************************************************2017/07/0216:26:40(58414670)STATE:StartSessionSSH*****************************************************************FATALERROR:expect:does"FATALERROR:"(spawn_idexp4)matchregularexpression"FATALERROR:|Unabletoopenconnection:|Couldnotopenconnectiontothehost"?yesexpect:setexpect_out(0,string)"FATALERROR:"expect:setexpect_out(spawn_id)"exp4"expect:setexpect_out(buffer)"FATALER*****************************************************************2017/07/0216:27:03(58436840)STATE:FailUnableToConnect**************************************************************ExpectLogexample:DebugInformation(TPC)TPCcreatesonlyonedebuglogwhichwillbewrittento<cpmfolder>/logs/thirdpartySwitchinganyoftheparametersinthissectiontoyeswillturnondebug.Alternative–inthePVWA,turnonDebug
parameterfromthefollowinglocation:TargetAccountPlatform
>
AutomaticPasswordManagement
>
AdditionalPolicySettings[DebugInformation]DebugLogFullParsingInfo=noDebugLogFullExecutionInfo=noDebugLogDetailBuiltInActions=noExpectLog=yesConsoleOutput=no13/11/201902:34:29.011|Info->a7::c->*****************************************************************13/11/201902:34:29.011|Info->a7::c-> CheckAction13/11/201902:34:29.011|Info->a7::c->*****************************************************************13/11/201902:34:29.011|Info->bp::c->START13/11/201902:34:29.011|Info->bp::c->AnalyzingnextstatecandidateIsVerifyLogon13/11/201902:34:29.026|Info->bp::c->AnalyzingnextstatecandidateActionIsRecOrPreRec13/11/201902:34:29.026|Info->bp::c->AnalyzingnextstatecandidateActionIsVerify13/11/201902:34:29.026|Info->bp::c->Expression(expression)[stringequal-nocase"<action>""verifypass"]isTRUE,continuingtonextstateCheckExtraPass113/11/201902:34:29.026|Info->bp::c->END13/11/201902:34:29.026|Info->a7::c->*****************************************************************13/11/201902:34:29.026|Info->a7::c-> CheckExtraPass113/11/201902:34:29.026|Info->a7::c->*******************************************************************************************************************************TPCdebugLogexample:InthissectionwewillcoverthePromptsFilewhich
containsthreetypesofconditions:SimplePrompts(complex)PromptsExpressions
PromptsFileSimplepromptsareconditionswherethevalueofthereturnedpromptsiscomparedtotext.Regularexpressionscannotbeused.Simplepromptshavethefollowingformat:Name=(simpleprompt)Prompt
Simpleprompts[conditions]#StandardpromptsStandardPrompt=\n.*\$?$|.*\#?$|.*\>?$|.*\%?$|.*\]?$#LoginsequenceLogin=loginas:|login:Password=Password:|Enterthepasswordfor.*PasswordExpired=Passwordfor<username>expired.|ChooseanewpasswordInvalidLogin=Youenteredaninvalidloginnameorpassword|password:PlinkStoreKey=Storekeyincache#CheckprotocolProtocolIsSSH=(expression)[stringequal-nocase"<protocol>"ssh]ProtocolIsTelnet=(expression)[stringequal-nocase"<protocol>"telnet]ExtraPassExists=(expression)<pmmaxextrapassindex>==1ExtraPassNotExists=(expression)<pmmaxextrapassindex>==0EOF=(simpleprompt)eofTRUE=(expression)trueComplexPromptsarepromptsthatincluderegularexpressions.Astheyaremostcommonlyused,nokeywordisrequired.Alistofregularexpressionscanbecomparedinasingleconditionsusing'|'betweentheregexexpressionsUseabackslash(‘\’)beforespecialcharacters.Regularexpressionscanbetestedonline:
(Complex)Prompts[conditions]#StandardpromptsStandardPrompt=\n.*\$?$|.*\#?$|.*\>?$|.*\%?$|.*\]?$#LoginsequenceLogin=loginas:|login:Password=Password:|Enterthepasswordfor.*PasswordExpired=Passwordfor<username>expired.|ChooseanewpasswordInvalidLogin=Youenteredaninvalidloginnameorpassword|password:PlinkStoreKey=Storekeyincache#CheckprotocolProtocolIsSSH=(expression)[stringequal-nocase"<protocol>"ssh]ProtocolIsTelnet=(expression)[stringequal-nocase"<protocol>"telnet]ExtraPassExists=(expression)<pmmaxextrapassindex>==1ExtraPassNotExists=(expression)<pmmaxextrapassindex>==0EOF=(simpleprompt)eofTRUE=(expression)trueExpressionsareconditional(Boolean)expressions.Expressionshavethefollowingformat:Name=(expression)expression
Canbeusedtocomparestringsornumbers
expressions[conditions]#StandardpromptsStandardPrompt=\n.*\$?$|.*\#?$|.*\>?$|.*\%?$|.*\]?$#LoginsequenceLogin=loginas:|login:Password=Password:|Enterthepasswordfor.*PasswordExpired=Passwordfor<username>expired.|ChooseanewpasswordInvalidLogin=Youenteredaninvalidloginnameorpassword|password:PlinkStoreKey=Storekeyincache#CheckprotocolProtocolIsSSH=(expression)[stringequal-nocase"<protocol>"ssh]ProtocolIsTelnet=(expression)[stringequal-nocase"<protocol>"telnet]ExtraPassExists=(expression)<pmmaxextrapassindex>==1ExtraPassNotExists=(expression)<pmmaxextrapassindex>==0EOF=(simpleprompt)eofTRUE=(expression)trueReverseengineeraplugin
(os390)CheckProtocolInitsetVerifyLogon0;setcurr_pass"<pmpass>";ProtocolIsSSHStartSessionSSHConnectionFailedFailUnableToConnect(spawn)bin\\plink.exe<address>-ssh-P<port>(expression)[stringequal-nocase"<protocol>"ssh]LoginLogin=loginas:|login:CheckExtraPassStoreKeyInCache=yPlinkStoreKeyLoginTRUE=(expression)trueExistsDoesNotExistLoginExtraUserLoginUser<username><extrapass1\username>PasswordLoginExtraPass<pmextrapass1>PasswordExpiredFAILExpiredExtraPasswordFAILInvalidCurrPassword1InvalidLoginStandardPromptSwitchUsersu-<username>PasswordSwitchPass$curr_passStandardPromptVerifySwitchEcho\$LOGNAMEFailInvalidCurrPassword3SuWrongPasswordCheckAction2StandardPromptPasswordExpiredCheckIDCheckAction1C
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年行政車輛租賃合規(guī)合同樣本
- 2024年度健康養(yǎng)生產(chǎn)品銷售結(jié)算與市場拓展合同3篇
- 2024年特許經(jīng)營合同詳細(xì)條款與標(biāo)的
- 2024年版:房屋買賣違約金索賠協(xié)議
- 2024年貨車租賃合同(帶維修責(zé)任規(guī)定)
- 2024年紀(jì)錄片創(chuàng)作與制作服務(wù)合同版B版
- 2024年綠化工程苗木種植養(yǎng)護(hù)合同2篇
- 2025年度環(huán)保倉儲倉單質(zhì)押反擔(dān)保服務(wù)協(xié)議3篇
- 2024年離婚合同書:女方放棄財產(chǎn)分割版版
- 運(yùn)維服務(wù)能力指標(biāo)體系
- 生豬屠宰獸醫(yī)衛(wèi)生檢驗人員理論考試題及答案
- 物流園保安服務(wù)投標(biāo)方案(技術(shù)方案)
- GB/T 44038-2024車輛倒車提示音要求及試驗方法
- 2024年咸陽職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫及答案解析
- 農(nóng)村生態(tài)環(huán)境保護(hù)培訓(xùn)
- 科學(xué)精神與科學(xué)研究方法智慧樹知到期末考試答案2024年
- 《中國心力衰竭診斷和治療指南(2024)》解讀
- 高速公路機(jī)電工程標(biāo)準(zhǔn)化施工管理質(zhì)量控制
- 頭條號策劃方案
- 維護(hù)社會穩(wěn)定規(guī)定
- 《牙髓血運(yùn)重建術(shù)》課件
評論
0/150
提交評論