forked from tamuctf/ctfd-shell-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commits converts all of the previous bash scripts to python. This was done to make the handling of usernames and passwords more secure with the use of python's subprocess library. This will also allow the passwords for users to be more secure since the users input does not have to be sanitized now.
- Loading branch information
Showing
12 changed files
with
102 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/python | ||
|
||
import subprocess | ||
from subprocess import Popen, PIPE | ||
import sys | ||
|
||
user = sys.argv[1] | ||
password = sys.argv[2] | ||
|
||
subprocess.call(["useradd", "-G", "ctf-users", "-s", "/usr/local/bin/user-shell", user]) | ||
|
||
#https://stackoverflow.com/questions/4688441/how-can-i-set-a-users-password-in-linux-from-a-python-script | ||
proc=Popen(['passwd', user],stdin=PIPE,stdout=PIPE,stderr=PIPE) | ||
proc.stdin.write(password+'\n') | ||
proc.stdin.write(password) | ||
proc.stdin.flush() | ||
stdout,stderr = proc.communicate() | ||
|
||
if stderr: | ||
print stderr | ||
print stdout | ||
|
||
subprocess.call(["chsh", "-s", "/usr/local/bin/user_shell.py", user]) | ||
|
||
subprocess.call(["docker", "build", "-t", "user-image", "--build-arg", "USER="+user, "-f", "docker/user-docker/Dockerfile", "github.com/tamuctf/CTFd-shell-plugin"]) | ||
|
||
subprocess.call(["docker", "create", "-it", "--name", user, "-w", "/home/"+user, "--read-only", "-e", "TMOUT=86400", "-h", "tamuctf-shell", "-v", "/home/"+user, "user-image", "/bin/bash"]) | ||
|
||
""" | ||
useradd -G ctf-users -s /usr/local/bin/user-shell "$USER" | ||
echo -e "$PASS\n$PASS" | passwd "$USER" | ||
chsh -s /usr/local/bin/user-shell "$USER" | ||
docker build -t user-image --build-arg USER=$USER -f docker/user-docker/Dockerfile github.com/tamuctf/CTFd-shell-plugin | ||
docker create -it --name "$USER" -w /home/"$USER" --read-only -e TMOUT=300 -h tamuctf-shell --cpus=".5" --memory="500M" -v /home/"$USER" user-image /bin/bash | ||
""" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/python | ||
|
||
from subprocess import Popen, PIPE | ||
import sys | ||
|
||
user = sys.argv[1] | ||
password = sys.argv[2] | ||
|
||
#https://stackoverflow.com/questions/4688441/how-can-i-set-a-users-password-in-linux-from-a-python-script | ||
proc=Popen(['passwd', user],stdin=PIPE,stdout=PIPE,stderr=PIPE) | ||
proc.stdin.write(password+'\n') | ||
proc.stdin.write(password) | ||
proc.stdin.flush() | ||
stdout,stderr = proc.communicate() | ||
|
||
if stderr: | ||
print stderr | ||
print stdout | ||
|
||
|
||
""" | ||
echo -e "$PASS\n$PASS" | passwd "$USER" | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/python | ||
|
||
import subprocess | ||
|
||
p = subprocess.Popen("whoami", stdin=subprocess.PIPE,stdout=subprocess.PIPE) | ||
user, err = p.communicate() | ||
|
||
#returns with \n attached | ||
container_name = user[:-1] | ||
|
||
subprocess.call(["docker", "start", container_name]) | ||
|
||
subprocess.call(["docker", "exec", "-it", "-u", container_name, container_name, "/bin/bash"]) | ||
|
||
subprocess.call(["docker", "stop", container_name]) | ||
|
||
""" | ||
#!/bin/bash | ||
container_name=`whoami` | ||
docker start "$container_name" | ||
docker exec -it -u "$container_name" "$container_name" /bin/bash | ||
docker stop "$container_name" | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters