Use AWS SSM(Systems Manager) execute remote script file at EC2 instance

admin 2024年8月14日14:39:09评论8 views字数 1338阅读4分27秒阅读模式

0x00 TL;DR

This article documents how to use AWS SSM to execute remote script files at EC2 instances.There are two general methods:1.Running Scripts from GitHub and Amazon S32.First upload the file to EC2 through SSM, and then use SSM to execute the command to run the uploaded script.

0x01 Running Scripts from GitHub

Use the following AWS Cli command

1
aws ssm send-command --document-name "AWS-RunRemoteScript" --instance-ids "i-0d781805630c8edc0" --parameters '{"sourceType":["GitHub"],"sourceInfo":["{\"owner\":\"omg2hei\", \"repository\":\"PowerShellDemo\", \"path\": \"/\"}"],"commandLine":["get-process.ps1"]}'

Then EC2 instance(Windows Server 2016) will be execute get-process.ps1.

0x02 First upload the file to EC2 through SSM, and then use SSM to execute the command to run the uploaded script

Step 1.Upload file to EC2 use SSM

1
aws ssm send-command --document-name "AWS-RunPowerShellScript" --parameters commands="Invoke-WebRequest http://52.80.67.123:8000/get-process.ps1 -OutFile c:\get-process.ps1" --instance-ids i-0d781805630c8edc0 --document-version "\$DEFAULT"

Step 2.use SSM to execute the command to run the uploaded script

1
aws ssm send-command --document-name "AWS-RunPowerShellScript" --parameters commands="c:\get-process.ps1" --instance-ids i-0d781805630c8edc0 --document-version "\$DEFAULT"

0x03 Reference

[1] Running Scripts from GitHub and Amazon S3 - https://docs.aws.amazon.com/systems-manager/latest/userguide/integration-remote-scripts.html

- source:tonghuaroot.com

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年8月14日14:39:09
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Use AWS SSM(Systems Manager) execute remote script file at EC2 instancehttps://cn-sec.com/archives/3067260.html

发表评论

匿名网友 填写信息