Skip to content

Commit c5a6815

Browse files
authored
Merge pull request #2 from qsecure-labs/dev-new-tf
Migration from terraform v11 to v12
2 parents d913dab + 7cf8342 commit c5a6815

File tree

217 files changed

+3674
-5361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+3674
-5361
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__pycache__
1+
redbaron/data/plugins/

README.md

Lines changed: 19 additions & 272 deletions
Large diffs are not rendered by default.

config/config.json

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
{
22
"mod_redirector": {
33
"module": "redirector",
4-
"type" : "http",
4+
"type": "http",
55
"region": "LON1",
6-
"redirector_id":"",
6+
"redirector_id": "",
77
"provider": "digitalocean",
88
"size": "s-1vcpu-1gb",
99
"id": ""
1010
},
1111
"mod_c2": {
1212
"module": "c2",
13-
"type" : "http",
13+
"type": "http",
1414
"redirectors": 1,
1515
"tools": [],
1616
"region": "LON1",
1717
"provider": "digitalocean",
1818
"size": "s-1vcpu-1gb",
19-
"id": ""
19+
"id": "",
20+
"distro": "debian"
2021
},
2122
"mod_dns_record": {
2223
"module": "dns_record",
@@ -39,8 +40,8 @@
3940
"mod_letsencrypt": {
4041
"module": "letsencrypt",
4142
"id": "",
42-
"domain_name" : "",
43-
"mod_id" : "",
43+
"domain_name": "",
44+
"mod_id": "",
4445
"email": "[email protected]"
4546
},
4647
"mod_mail": {
@@ -67,27 +68,78 @@
6768
"domain": "",
6869
"id": ""
6970
},
71+
"mod_ansible": {
72+
"module": "ansible",
73+
"hosts": [],
74+
"playbook": "",
75+
"id": ""
76+
},
7077
"mod_firewall": {
7178
"module": "firewall",
7279
"provider": "digitalocean",
7380
"protocol": "tcp",
7481
"port": "",
7582
"address": "0.0.0.0/0",
7683
"rule": "inbound",
77-
"mod_id":""
84+
"mod_id": ""
7885
},
79-
"aws" :{
80-
"regions" : ["us-east-2", "us-east-1", "us-west-1", "us-west-2", "ap-east-1", "ap-south-1", "ap-northeast-3", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "eu-north-1", "me-south-1", "sa-east-1", "us-gov-east-1", "us-gov-west-1"],
81-
"size" : ["t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "t2.xlarge", "t2.2xlarge", "a1.medium", "a1.large", "a1.xlarge", "a1.2xlarge", "a1.4xlarge", "t3.nano", "t3.micro", "t3.small", "t3.medium", "t3.large", "t3.xlarge", "t3.2xlarge", "t3a.nano", "t3a.micro", "t3a.small", "t3a.medium", "t3a.large", "t3a.xlarge", "t3a.2xlarge"],
86+
"aws": {
87+
"regions": ["us-east-2", "us-east-1", "us-west-1", "us-west-2", "ap-east-1", "ap-south-1", "ap-northeast-3", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "eu-north-1", "me-south-1", "sa-east-1", "us-gov-east-1", "us-gov-west-1"],
88+
"size": ["t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "t2.xlarge", "t2.2xlarge", "a1.medium", "a1.large", "a1.xlarge", "a1.2xlarge", "a1.4xlarge", "t3.nano", "t3.micro", "t3.small", "t3.medium", "t3.large", "t3.xlarge", "t3.2xlarge", "t3a.nano", "t3a.micro", "t3a.small", "t3a.medium", "t3a.large", "t3a.xlarge", "t3a.2xlarge"],
8289
"default_region": "eu-west-1",
83-
"default_size": "t2.micro"
84-
},
85-
"digitalocean" :{
86-
"regions" : ["NYC1","NYC2","NYC2", "SFO1", "SFO2", "AMS2", "AMS1", "LON1","FRA1","TOR1","BLR1"],
87-
"size" : ["s-1vcpu-1gb"],
88-
"default_region" : "LON1",
89-
"default_size" : "s-1vcpu-1gb"
90-
},
91-
"providers_list" : ["digitalocean","aws"]
92-
}
93-
90+
"default_size": "t2.micro",
91+
"supported_distros": ["debian","kali","ubuntu"],
92+
"amis": {
93+
"ap-northeast-1-debian": "ami-b6b568d0",
94+
"ap-northeast-2-debian": "ami-b7479dd9",
95+
"ap-south-1-debian": "ami-02aded6d",
96+
"ap-southeast-1-debian": "ami-d76019b4",
97+
"ap-southeast-2-debian": "ami-8359bae1",
98+
"ca-central-1-debian": "ami-3709b053",
99+
"eu-central-1-debian": "ami-8bb70be4",
100+
"eu-west-1-debian": "ami-ce76a7b7",
101+
"eu-west-2-debian": "ami-a6f9ebc2",
102+
"sa-east-1-debian": "ami-f5c7b899",
103+
"us-east-1-debian": "ami-71b7750b",
104+
"us-east-2-debian": "ami-dab895bf",
105+
"us-west-1-debian": "ami-58eedd38",
106+
"us-west-2-debian": "ami-c032f6b8",
107+
"ap-northeast-1-kali": "ami-0d701fcae946c61ed",
108+
"ap-northeast-2-kali": "ami-0fbd27bb0a724c459",
109+
"ap-south-1-kali": "ami-055e6bebd7c5e24c2",
110+
"ap-southeast-1-kali": "ami-01027fa676ff2da3d",
111+
"ap-southeast-2-kali": "ami-02811a36e6f758099",
112+
"ca-central-1-kali": "ami-0f394074fe16decd6",
113+
"eu-central-1-kali": "ami-0b61a044e0ae0d17d",
114+
"eu-west-1-kali": "ami-0ac0bf7b0683eb820",
115+
"eu-west-2-kali": "ami-071d0c011e7ab12f5",
116+
"sa-east-1-kali": "ami-00c9b2d0ec9e3835c",
117+
"us-east-1-kali": "ami-0c11557d0e4e9c896",
118+
"us-east-2-kali": "ami-00f7390b60c41a3c0",
119+
"us-west-1-kali": "ami-09aa8451f267643a9",
120+
"us-west-2-kali": "ami-0a967289406d51ad4",
121+
"ap-northeast-1-ubuntu": "ami-0f29c17df60493658",
122+
"ap-northeast-2-ubuntu": "ami-065a2f32a35b7c52f",
123+
"ap-south-1-ubuntu": "ami-05a3a2a452701c0ff",
124+
"ap-southeast-1-ubuntu": "ami-05405da5795c2f2e7",
125+
"ap-southeast-2-ubuntu": "ami-0243fb2a9c789bb43",
126+
"ca-central-1-ubuntu": "ami-07d2c94058f3ca045",
127+
"eu-central-1-ubuntu": "ami-07d14b5d47292e022",
128+
"eu-west-1-ubuntu": "ami-014aff0119d738e34",
129+
"eu-west-2-ubuntu": "ami-0339455b66e82a8ca",
130+
"sa-east-1-ubuntu": "ami-0a32099c90454cc7a",
131+
"us-east-1-ubuntu": "ami-07d1c0a30a7814597",
132+
"us-east-2-ubuntu": "ami-083af2bfea9e15579",
133+
"us-west-1-ubuntu": "ami-0b3f68410f4d4fed6",
134+
"us-west-2-ubuntu": "ami-0652b0a864db01553"}
135+
},
136+
"digitalocean": {
137+
"regions": ["NYC1", "NYC2", "NYC2", "SFO1", "SFO2", "AMS2", "AMS1", "LON1", "FRA1", "TOR1", "BLR1"],
138+
"size": ["s-1vcpu-1gb"],
139+
"default_region": "LON1",
140+
"default_size": "s-1vcpu-1gb",
141+
"supported_distros": ["debian","ubuntu"]
142+
},
143+
"providers_list": ["digitalocean", "aws"],
144+
"distros": ["debian","kali","ubuntu"]
145+
}

config/install.sh

100644100755
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#!/bin/bash
22

3-
apt install python3
4-
apt install python3-pip
3+
# install all the packages required
4+
sudo apt install python3
5+
sudo apt install python3-pip
6+
sudo apt install wget
7+
sudo apt install unzip
8+
sudo apt install curl
9+
sudo apt install autossh
10+
11+
# install the python requirements from the txt
512
pip3 install -r requirements.txt
613

7-
pip install ansible
8-
wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip
9-
unzip terraform_0.11.14_linux_amd64.zip
10-
mv terraform /opt/terraform
11-
rm terraform_0.11.14_linux_amd64.zip
12-
echo 'export PATH="$PATH:/opt"' >> ~/.profile
14+
# download terraform binary
15+
wget https://releases.hashicorp.com/terraform/0.12.26/terraform_0.12.26_linux_amd64.zip
16+
unzip terraform_0.12.26_linux_amd64.zip
17+
sudo mv terraform /opt/terraform
18+
rm terraform_0.12.26_linux_amd64.zip
1319

14-
wget https://github.com/n3integration/terraform-godaddy/releases/download/v1.6.4/terraform-godaddy_linux_amd64.tgz
20+
# download godaddy plugin for terraform
21+
wget https://github.com/n3integration/terraform-godaddy/releases/download/v1.7.3/terraform-godaddy_linux_amd64.tgz
1522
tar -xvzf terraform-godaddy_linux_amd64.tgz
1623
rm terraform-godaddy_linux_amd64.tgz
17-
mv terraform-godaddy_linux_amd64 ../redbaron/data/plugins/terraform-provider-godaddy_v1.6.4_x4
24+
sudo mv terraform-godaddy_linux_amd64 ../redbaron/data/plugins/terraform-provider-godaddy_v1.7.3_x4

config/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cmd2
22
prettytable
3-
PTable
3+
PTable
4+
ansible

modules/ansible.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import cmd2
2+
import os
3+
import argparse
4+
from prettytable import PrettyTable
5+
from prettytable import MSWORD_FRIENDLY
6+
import random
7+
import string
8+
import json
9+
10+
module = {}
11+
campaign_list = []
12+
13+
class main(list):
14+
"""Main function to initialize variables and calls the cmd2 package for the godaddy module """
15+
def __init__(self,campaign,mod,project_id):
16+
global campaign_list
17+
campaign_list = campaign
18+
19+
if mod is not None:
20+
global module
21+
module = mod
22+
23+
# Call cmd_main class
24+
i = cmd_main()
25+
i.prompt = "(" + cmd2.ansi.style("Overlord", fg='red', bg='',bold=True, underline=False) + " : " + cmd2.ansi.style( project_id, fg='bright_black', bg='',bold=True, underline=False) + cmd2.ansi.style("/ansible", fg='blue', bg='',bold=True, underline=False) +")" +"$> "
26+
i.cmdloop()
27+
28+
def hide_cmd2_modules(self):
29+
# Remove most of the functionalities of the cmd2 package
30+
self.hidden_commands.append('py')
31+
self.hidden_commands.append('alias')
32+
self.hidden_commands.append('macro')
33+
self.hidden_commands.append('script')
34+
self.hidden_commands.append('shortcuts')
35+
self.hidden_commands.append('pyscript')
36+
self.hidden_commands.append('run_pyscript')
37+
self.hidden_commands.append('edit')
38+
self.hidden_commands.append('run_script')
39+
self.hidden_commands.append('quit')
40+
self.hidden_commands.append('load')
41+
42+
class cmd_main(cmd2.Cmd):
43+
"""cmd2 instance for firewall module"""
44+
# The mod dictionary for the firewall module
45+
mod = {}
46+
playbooks_list = []
47+
providers_list = []
48+
49+
def __init__(self):
50+
super().__init__()
51+
global module
52+
global campaign_list
53+
# Hide the Quit funcitionality
54+
hide_cmd2_modules(self)
55+
56+
dir_path = "config"
57+
if os.path.exists(dir_path+"/config.json"):
58+
with open(dir_path+'/config.json', 'r') as filehandle:
59+
config = json.load(filehandle)
60+
self.mod = config["mod_ansible"]
61+
else:
62+
print("The config/config.json file does not exists! Exiting...")
63+
return True
64+
65+
# Check if the editmodule functionality was used
66+
if module:
67+
self.mod = dict(module)
68+
else:
69+
self.mod["id"] = randomString()
70+
71+
# Create list with modules id
72+
modules_ids=[]
73+
for c in campaign_list:
74+
if c["module"] != "dns_record" and c["module"] != "letsencrypt" and c["module"] != "godaddy" and c["module"] != "ansible":
75+
modules_ids.insert(len(modules_ids),(c["id"]+"/"+c["module"]))
76+
if c["module"] != "redirector":
77+
for i in range(c["redirectors"]):
78+
modules_ids.insert(len(modules_ids),(c["id"]+"-"+str(i+1)+"/"+c["module"]))
79+
modules_ids.insert(len(modules_ids),"all")
80+
self.module_hosts_parser.choices = modules_ids
81+
82+
# Load the playbooks
83+
dir_path = "redbaron/data/playbooks"
84+
for pb in os.listdir(dir_path):
85+
self.playbooks_list.append(pb)
86+
87+
def do_back(self, arg):
88+
"""Return to main menu"""
89+
return True
90+
91+
def do_clear(self, arg):
92+
"""Clears screen"""
93+
os.system('clear')
94+
95+
def do_info(self,mod):
96+
"""Prints variable table"""
97+
if mod:
98+
x = PrettyTable()
99+
x.title = mod["module"] + "/"+ mod["id"]
100+
x.field_names = ["VARIABLE", "VALUE", "REQUIRED", "DESCRITPION"]
101+
x.add_row(["id", mod["id"], "N/A", "Module ID"])
102+
x.add_row(["hosts", mod["hosts"], "yes", "Module to be used"])
103+
x.add_row(["playbook", mod["playbook"], "yes", "Playbook to be used"])
104+
x.align["DESCRITPION"] = "l"
105+
else:
106+
x = PrettyTable()
107+
x.title = 'Ansible module'
108+
x.field_names = ["VARIABLE", "VALUE", "REQUIRED", "DESCRITPION"]
109+
x.add_row(["id", self.mod["id"], "N/A", "Module ID"])
110+
x.add_row(["hosts", self.mod["hosts"], "yes", "Module to be used"])
111+
x.add_row(["playbook", self.mod["playbook"], "yes", "Playbook to be used"])
112+
x.align["DESCRITPION"] = "l"
113+
print(x)
114+
115+
# set command
116+
# create the top-level parser for the set command
117+
set_parser = argparse.ArgumentParser(prog='set')
118+
set_subparsers = set_parser.add_subparsers(title='set-commands', help='Sets the variables of the module')
119+
120+
# create the parser for the "hosts" sub-command
121+
parser_hosts = set_subparsers.add_parser('hosts', help='hosts to be used')
122+
module_hosts_parser = parser_hosts.add_argument('hosts',nargs="+", type=str, help='example : [set hosts <id> ]')
123+
124+
parser_playbook = set_subparsers.add_parser('playbook', help='playbook to be used')
125+
parser_playbook.add_argument('playbook', type=str,choices=playbooks_list, help='example : [set playbook <playbook name> ]')
126+
127+
def set_mod(self, arg):
128+
"""Sets the hosts variable"""
129+
if 'all' in arg.hosts:
130+
for c in campaign_list:
131+
if c["module"] != "dns_record" and c["module"] != "letsencrypt" and c["module"] != "godaddy" and c["module"] != "ansible":
132+
self.mod["hosts"].insert(len(self.mod["hosts"]),(c["id"]+"/"+c["module"]))
133+
for i in range(c["redirectors"]):
134+
self.mod["hosts"].insert(len(self.mod["hosts"]),(c["id"]+"-"+str(i+1)+"/"+c["module"]))
135+
else:
136+
self.mod["hosts"]= arg.hosts
137+
138+
def set_playbook(self, arg):
139+
"""Sets the =playbook variable"""
140+
self.mod["playbook"]= arg.playbook
141+
142+
#Set handler functions for the sub-commands
143+
parser_hosts.set_defaults(func=set_mod)
144+
parser_playbook.set_defaults(func=set_playbook)
145+
146+
@cmd2.with_argparser(set_parser)
147+
def do_set(self, args):
148+
"""Set the variables for the module"""
149+
func = getattr(args, 'func', None)
150+
if func is not None:
151+
# Call whatever sub-command function was selected
152+
func(self, args)
153+
else:
154+
# No sub-command was provided, so call help
155+
self.do_help('help')
156+
157+
def do_add(self,args):
158+
"""Adds c2 module to the project """
159+
global module
160+
module = self.mod
161+
if self.mod["hosts"]:
162+
module = self.mod
163+
return True
164+
else:
165+
print("The hosts can not be None!")
166+
if self.mod["playbook"]:
167+
module = self.mod
168+
return True
169+
else:
170+
print("The playbook can not be None!")
171+
172+
# Command categories
173+
CMD_CAT_GENERAL = 'General (type help <command>)'
174+
CMD_CAT_MODULE = 'Module (type help <command>)'
175+
176+
cmd2.categorize((do_add,do_set), CMD_CAT_MODULE)
177+
cmd2.categorize(do_info, CMD_CAT_GENERAL)
178+
179+
def randomString(stringLength=6):
180+
"""Generate a random string of fixed length """
181+
letters = string.ascii_uppercase
182+
return ''.join(random.choice(letters) for i in range(stringLength))

0 commit comments

Comments
 (0)