File tree Expand file tree Collapse file tree 9 files changed +340
-116
lines changed
tencentcloud/cvm/cvm_security_group_open_all_port Expand file tree Collapse file tree 9 files changed +340
-116
lines changed Load Diff Large diffs are not rendered by default.
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1+ # Tencent Cloud CVM security group open all port
2+
3+ English | [ 中文] ( ./README_CN.md )
4+
5+ ## Description
6+
7+ This is a scenario used to build the Tencent Cloud CVM security group open all port.
8+
9+ ## Deployment Environment
10+
11+ Execute the following command in the container
12+
13+ ``` shell
14+ cd /TerraformGoat/tencentcloud/cvm/cvm_security_group_open_all_port
15+ ```
16+
17+ Edit the ` terraform.tfvars ` file and write your ` tencentcloud_secret_id ` and ` tencentcloud_secret_key ` in the file
18+
19+ ``` shell
20+ vim terraform.tfvars
21+ ```
22+
23+ > You can create and view your SecretKey on the [ API Key Management] ( https://console.cloud.tencent.com/cam/capi ) of the Tencent Cloud console
24+
25+ Deploy Vulnerable Environment
26+
27+ ``` shell
28+ terraform init
29+ terraform apply
30+ ```
31+
32+ > When the terminal prompts ` Enter a value: ` , enter ` yes `
33+
34+ After the environment is set up, you can see the instance and security group IDs at Outputs
35+
36+ ## Steps
37+
38+ Use the Tencent Cloud command line tool to view the rules of the security group.
39+
40+ ``` bash
41+ > tccli vpc DescribeSecurityGroupPolicies --SecurityGroupId sg-bitg1oeb
42+
43+ {
44+ " SecurityGroupPolicySet" : {
45+ " Version" : " 1" ,
46+ " Egress" : [],
47+ " Ingress" : [
48+ {
49+ " PolicyIndex" : 0,
50+ " Protocol" : " tcp" ,
51+ " Port" : " 1-65535" ,
52+ " ServiceTemplate" : {
53+ " ServiceId" : " " ,
54+ " ServiceGroupId" : " "
55+ },
56+ " CidrBlock" : " 0.0.0.0/0" ,
57+ " Ipv6CidrBlock" : " " ,
58+ " SecurityGroupId" : " " ,
59+ " AddressTemplate" : {
60+ " AddressId" : " " ,
61+ " AddressGroupId" : " "
62+ },
63+ " Action" : " ACCEPT" ,
64+ " PolicyDescription" : " " ,
65+ " ModifyTime" : " 2022-06-09 17:18:02"
66+ }
67+ ]
68+ },
69+ " RequestId" : " 41986b77-47e5-46be-980e-1b93c874d5ff"
70+ }
71+ ```
72+
73+ ## Destroy the environment
74+
75+ ``` shell
76+ terraform destroy
77+ ```
Original file line number Diff line number Diff line change 1+ # 腾讯云 CVM 安全组允许所有端口访问
2+
3+ [ English] ( ./README.md ) | 中文
4+
5+ ## 描述信息
6+
7+ 这是一个用于构建腾讯云 CVM 安全组允许所有端口访问的场景。
8+
9+ ## 环境搭建
10+
11+ 在容器中执行以下命令
12+
13+ ``` shell
14+ cd /TerraformGoat/tencentcloud/cvm/cvm_security_group_open_all_port
15+ ```
16+
17+ 编辑 ` terraform.tfvars ` 文件,在文件中填入你的 ` tencentcloud_secret_id ` 和 ` tencentcloud_secret_key `
18+
19+ ``` shell
20+ vim terraform.tfvars
21+ ```
22+
23+ > 在腾讯云控制台的 [ API 密钥管理] ( https://console.cloud.tencent.com/cam/capi ) 可以创建和查看您的 SecretKey
24+
25+ 部署靶场
26+
27+ ``` shell
28+ terraform init
29+ terraform apply
30+ ```
31+
32+ > 在终端提示 ` Enter a value: ` 时,输入 ` yes ` 即可
33+
34+ 环境搭建完后,在 Outputs 处可以看到实例和安全组的 ID
35+
36+ ## 步骤
37+
38+ 使用腾讯云命令行工具查看安全组的规则。
39+
40+ ``` bash
41+ > tccli vpc DescribeSecurityGroupPolicies --SecurityGroupId sg-bitg1oeb
42+
43+ {
44+ " SecurityGroupPolicySet" : {
45+ " Version" : " 1" ,
46+ " Egress" : [],
47+ " Ingress" : [
48+ {
49+ " PolicyIndex" : 0,
50+ " Protocol" : " tcp" ,
51+ " Port" : " 1-65535" ,
52+ " ServiceTemplate" : {
53+ " ServiceId" : " " ,
54+ " ServiceGroupId" : " "
55+ },
56+ " CidrBlock" : " 0.0.0.0/0" ,
57+ " Ipv6CidrBlock" : " " ,
58+ " SecurityGroupId" : " " ,
59+ " AddressTemplate" : {
60+ " AddressId" : " " ,
61+ " AddressGroupId" : " "
62+ },
63+ " Action" : " ACCEPT" ,
64+ " PolicyDescription" : " " ,
65+ " ModifyTime" : " 2022-06-09 17:18:02"
66+ }
67+ ]
68+ },
69+ " RequestId" : " 41986b77-47e5-46be-980e-1b93c874d5ff"
70+ }
71+ ```
72+
73+ 通过返回的内容可以看到当前安全组允许所有端口访问。
74+
75+ ## 销毁环境
76+
77+ ``` shell
78+ terraform destroy
79+ ```
Original file line number Diff line number Diff line change 1+ resource "tencentcloud_instance" "instance" {
2+ instance_name = " huocorp_terraform_goat_instance"
3+ availability_zone = " ap-guangzhou-7"
4+ image_id = " img-pi0ii46r"
5+ security_groups = [tencentcloud_security_group . default . id ]
6+ instance_type = data. tencentcloud_instance_types . instance_types . instance_types . 0 . instance_type
7+ }
8+
9+ resource "tencentcloud_security_group" "default" {
10+ name = " huocorp_terraform_goat_security_group"
11+ description = " make it accessible for both production and stage ports"
12+ project_id = 0
13+ }
14+
15+ resource "tencentcloud_security_group_rule" "ingress" {
16+ security_group_id = tencentcloud_security_group. default . id
17+ type = " ingress"
18+ cidr_ip = " 0.0.0.0/0"
19+ ip_protocol = " tcp"
20+ port_range = " 1-65535"
21+ policy = " accept"
22+ depends_on = [
23+ tencentcloud_security_group . default
24+ ]
25+ }
26+
27+ data "tencentcloud_instance_types" "instance_types" {
28+ cpu_core_count = 1
29+ memory_size = 1
30+ }
Original file line number Diff line number Diff line change 1+ output "tencentcloud_instance_id" {
2+ value = tencentcloud_instance. instance . id
3+ }
4+
5+ output "tencentcloud_security_group_id" {
6+ value = tencentcloud_security_group. default . id
7+ }
Original file line number Diff line number Diff line change 1+ tencentcloud_secret_id = " xxx"
2+ tencentcloud_secret_key = " xxx"
Original file line number Diff line number Diff line change 1+ variable "tencentcloud_secret_id" {
2+ type = string
3+ description = " Set TencentCloud secret id."
4+ sensitive = true
5+ nullable = false
6+ }
7+
8+ variable "tencentcloud_secret_key" {
9+ type = string
10+ description = " Set TencentCloud secret key."
11+ sensitive = true
12+ nullable = false
13+ }
Original file line number Diff line number Diff line change 1+ terraform {
2+ required_providers {
3+ tencentcloud = {
4+ source = " tencentcloudstack/tencentcloud"
5+ version = " 1.70.2"
6+ }
7+ }
8+ }
9+
10+ provider "tencentcloud" {
11+ secret_id = var. tencentcloud_secret_id
12+ secret_key = var. tencentcloud_secret_key
13+ region = " ap-guangzhou"
14+ }
You can’t perform that action at this time.
0 commit comments