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

admin 2024年8月14日14:39:09评论10 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
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息