forked from sec4us-training/web-api-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_bank.yml
350 lines (281 loc) · 10.2 KB
/
setup_bank.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
---
- hosts: all
become: yes
vars_files:
- vars.yml
tasks:
- include_tasks: 'user_details.yml'
- name: Getting NGINX user
ignore_errors: yes
shell: |
cat /etc/nginx/nginx.conf | grep -E '\buser\b' | sed 's/user//g;s/\;//g' | tr -d ' '
register: nginx_output
- name: Setting NGINX user
set_fact:
nginx_user: "{{ nginx_output.stdout }}"
- name: Nginx user
debug:
msg: "Nginx user is {{ nginx_user }}"
- name: Adding local user
user:
name: bank
groups: "{{ nginx_user }}"
append: yes
state: present
createhome: yes
shell: /bin/bash
#- name: Adding local user
# ignore_errors: yes
# shell: |
# adduser --disabled-password --ingroup {{ nginx_user }} --gecos "" bank
- name: Create data structure
shell: |
mkdir -p /u01/www/bank/
mkdir -p /u01/www/cathub/
mkdir -p /u01/www/facebuquison/
rsync -av /tmp/web_api/bank/src/* /u01/www/bank/
rsync -av /tmp/web_api/cathub/src/* /u01/www/cathub/
rsync -av /tmp/web_api/facebuquison/src/* /u01/www/facebuquison/
chown -R bank:{{ nginx_user }} /u01/www/bank/
chown -R bank:{{ nginx_user }} /u01/www/cathub/
chown -R bank:{{ nginx_user }} /u01/www/facebuquison/
chown -R bank:{{ nginx_user }} /tmp/web_api/oauthlib*
- name: Install Bank Python environment
shell: |
cat << EOF > /tmp/instala.sh
cd /u01/www/
python3.8 -m venv bank
source bank/bin/activate
pip install -U pip
pip install wheel uWSGI
cd /tmp/web_api/oauthlib
pip install .
pip install -r /tmp/web_api/bank/requirements.txt
EOF
chmod 777 /tmp/instala.sh
sudo -u bank bash -c "/tmp/instala.sh"
- name: Install Cathub Python environment
shell: |
cat << EOF > /tmp/instala.sh
cd /u01/www/
python3.8 -m venv cathub
source cathub/bin/activate
pip install -U pip
pip install wheel uWSGI
cd /tmp/web_api/oauthlib
pip install .
pip install -r /tmp/web_api/cathub/requirements.txt
EOF
chmod 777 /tmp/instala.sh
sudo -u bank bash -c "/tmp/instala.sh"
- name: Install Facebuquison Python environment
shell: |
cat << EOF > /tmp/instala.sh
cd /u01/www/
python3.8 -m venv facebuquison
source facebuquison/bin/activate
pip install -U pip
pip install wheel uWSGI
cd /tmp/web_api/oauthlib
pip install .
pip install -r /tmp/web_api/facebuquison/requirements.txt
EOF
chmod 777 /tmp/instala.sh
sudo -u bank bash -c "/tmp/instala.sh"
- name: Creating a Nginx Bank config file
copy:
dest: "/etc/nginx/conf.d/bank.conf"
content: |
server {
#listen 80;
listen 443 ssl;
server_name sec4usbank.webapiexploitation.com.br;
ssl_certificate /etc/nginx/certs/webapiexploitation.com.br.cer;
ssl_certificate_key /etc/nginx/certs/webapiexploitation.com.br.key;
location / {
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
proxy_read_timeout 600;
proxy_connect_timeout 1d;
proxy_max_temp_file_size 5024m;
proxy_send_timeout 600;
uwsgi_read_timeout 600;
uwsgi_send_timeout 600;
include uwsgi_params;
uwsgi_pass unix:/tmp/bank.sock;
}
}
- name: Creating a Nginx cathub config file
copy:
dest: "/etc/nginx/conf.d/cathub.conf"
content: |
server {
#listen 80;
listen 443 ssl;
server_name cathub.webapiexploitation.com.br;
ssl_certificate /etc/nginx/certs/webapiexploitation.com.br.cer;
ssl_certificate_key /etc/nginx/certs/webapiexploitation.com.br.key;
location / {
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
proxy_read_timeout 600;
proxy_connect_timeout 1d;
proxy_max_temp_file_size 5024m;
proxy_send_timeout 600;
uwsgi_read_timeout 600;
uwsgi_send_timeout 600;
include uwsgi_params;
uwsgi_pass unix:/tmp/cathub.sock;
}
}
- name: Creating a Nginx facebuquison config file
copy:
dest: "/etc/nginx/conf.d/facebuquison.conf"
content: |
server {
#listen 80;
listen 443 ssl;
server_name facebuquison.webapiexploitation.com.br;
ssl_certificate /etc/nginx/certs/webapiexploitation.com.br.cer;
ssl_certificate_key /etc/nginx/certs/webapiexploitation.com.br.key;
location / {
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
proxy_read_timeout 600;
proxy_connect_timeout 1d;
proxy_max_temp_file_size 5024m;
proxy_send_timeout 600;
uwsgi_read_timeout 600;
uwsgi_send_timeout 600;
include uwsgi_params;
uwsgi_pass unix:/tmp/facebuquison.sock;
}
}
- name: Creating a bank service file
copy:
dest: "/etc/systemd/system/bank.service"
owner: root
group: root
mode: 0644
force: yes
content: |
[Unit]
Description=Sec4US Bank Service
After=network.target
[Service]
User = bank
Group = {{ nginx_user }}
WorkingDirectory=/u01/www/bank/
Environment="PATH=/u01/www/bank/bin"
ExecStart=/u01/www/bank/bin/uwsgi --socket /tmp/bank.sock --chmod-socket=666 -w wsgi:app --processes=1 --reload-mercy=1 --worker-reload-mercy=1 --req-logger file:/dev/nul --touch-reload /u01/www/bank/bank/config.py
[Install]
WantedBy=multi-user.target
- name: Creating a cathub service file
copy:
dest: "/etc/systemd/system/cathub.service"
owner: root
group: root
mode: 0644
force: yes
content: |
[Unit]
Description=Sec4US Cathub Service
After=network.target
[Service]
User = bank
Group = {{ nginx_user }}
WorkingDirectory=/u01/www/cathub/
Environment="PATH=/u01/www/cathub/bin;AUTHLIB_INSECURE_TRANSPORT=1"
ExecStart=/u01/www/cathub/bin/uwsgi --socket /tmp/cathub.sock --chmod-socket=666 -w wsgi:app --processes=1 --reload-mercy=1 --worker-reload-mercy=1 --req-logger file:/dev/nul --touch-reload /u01/www/cathub/website/settings.py
[Install]
WantedBy=multi-user.target
- name: Creating a facebuquison service file
copy:
dest: "/etc/systemd/system/facebuquison.service"
owner: root
group: root
mode: 0644
force: yes
content: |
[Unit]
Description=Sec4US Facebuquison Service
After=network.target
[Service]
User = bank
Group = {{ nginx_user }}
WorkingDirectory=/u01/www/facebuquison/
Environment="PATH=/u01/www/facebuquison/bin;AUTHLIB_INSECURE_TRANSPORT=1"
ExecStart=/u01/www/facebuquison/bin/uwsgi --socket /tmp/facebuquison.sock --chmod-socket=666 -w wsgi:app --processes=1 --reload-mercy=1 --worker-reload-mercy=1 --req-logger file:/dev/nul --touch-reload /u01/www/facebuquison/website/settings.py
[Install]
WantedBy=multi-user.target
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: yes
- name: Enable service Bank
ansible.builtin.systemd:
name: bank
enabled: yes
masked: no
- name: Enable service Cathub
ansible.builtin.systemd:
name: cathub
enabled: yes
masked: no
- name: Enable service Facebuquison
ansible.builtin.systemd:
name: facebuquison
enabled: yes
masked: no
- name: Creatting Bank config file
copy:
dest: "/u01/www/bank/bank/config.ini"
owner: bank
group: "{{ nginx_user }}"
mode: 0644
force: yes
content: |
[GENERAL]
debug=True
[DATABASE]
user = bank
passwd = 123456
db = bank
host = localhost
port = 3306
charset = utf8
autocommit = False
- name: Creating a database structure script
copy:
dest: "/tmp/db2.sql"
content: |
DROP DATABASE IF EXISTS `bank`;
CREATE DATABASE `bank`;
DROP USER IF EXISTS 'bank'@'localhost';
CREATE USER 'bank'@'localhost' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON `bank`.* TO 'bank'@'localhost';
FLUSH PRIVILEGES;
- name: Create database structure
shell: |
mysql -u root < /tmp/db2.sql
mysql -u root bank < /tmp/web_api/bank/database/mysql.sql
- name: Restart Bank service
service:
name: bank
state: restarted
- name: Restart Cathub service
service:
name: cathub
state: restarted
- name: Restart Facebuquison service
service:
name: facebuquison
state: restarted
- name: Reload nginx config
shell: |
nginx -s reload