-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfig-sshhost.py
69 lines (56 loc) · 1.82 KB
/
config-sshhost.py
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
################################################################################
# Configure a box for the general ssh example challenge.
################################################################################
import sys
import subprocess
def main():
try:
# Grab password from file =========================================
password = ""
with open("/tmp/password.txt", "r") as f:
password = f.read()
password = password.strip()
subprocess.run(
["/bin/sh", "-c", "rm /tmp/password.txt"], check=True
)
# =====================================================================
# Create ctf-player user
subprocess.run(
[
"/usr/sbin/useradd",
"-U",
"ctf-player",
"-d",
"/home/ctf-player",
"-s",
"/bin/bash",
],
check=True,
)
# Pipe the output of echo into chpasswd to change password of
# ctf-user
pEcho = subprocess.Popen(
(
'echo',
f'ctf-player:{password}'
),
stdout=subprocess.PIPE
)
output = subprocess.check_output(('chpasswd'), stdin=pEcho.stdout)
pEcho.wait()
# Make sure ownership is changed to ctf-player
subprocess.run(
[
"/usr/bin/chown",
"-R",
"ctf-player:ctf-player",
"/home/ctf-player/",
],
check=True,
)
except subprocess.CalledProcessError:
print("A subprocess has returned an error code")
sys.exit(1)
# =============================================================================
if __name__ == "__main__":
main()