




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2031年中国渔抄网行业投资前景及策略咨询研究报告
- 2025至2031年中国模具图文成像机行业投资前景及策略咨询研究报告
- 2025至2031年中国有轴单边纸架行业投资前景及策略咨询研究报告
- 电商直播内容策划行业跨境出海项目商业计划书
- 2025至2031年中国撑鞋机行业投资前景及策略咨询研究报告
- 学前教育AI应用企业制定与实施新质生产力项目商业计划书
- 2025至2031年中国干洗助剂行业投资前景及策略咨询研究报告
- 2025至2031年中国女式短袖睡衣套行业投资前景及策略咨询研究报告
- 2025至2031年中国基本型球形摄像机行业投资前景及策略咨询研究报告
- 校园科技节活动行业深度调研及发展项目商业计划书
- (完整版)非计划性拔管鱼骨图
- 如何落实“三管三必须”完整ppt
- 2022年《明码标价和禁止价格欺诈规定》重点解读
- LED台灯及亮度调节电路设计
- 公路线形设计外文文献中英对照
- 现场质量管理
- 结核分枝杆菌实验活动风险评估报告
- 电力电子第三版习题及解答
- 钢结构管廊安装施工方案-zshj
- 人教版九年级化学教材分析(共20页)
- 2MCL457离心压缩机结构设计说明书
评论
0/150
提交评论