Skip to content

Commit

Permalink
Shells Materials added
Browse files Browse the repository at this point in the history
  • Loading branch information
aa9863 committed Oct 16, 2023
1 parent 288359e commit a082782
Show file tree
Hide file tree
Showing 28 changed files with 1,074 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Shells/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*#
*~
41 changes: 41 additions & 0 deletions Shells/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Shells_Trainer

Trainers for Shell based activities

All docker compose based.

In the relevant directory

Start with

```
docker-compose up
```

stop with

```
docker-compose down
```

## Shells

Covers SSH and Telnet Etc

Run with

```
cd shells
shells$ docker-compose up
```

## WebShells

Covers WEb Based shells

```
cd WebShellPlayground
docker-compose up
```


7 changes: 7 additions & 0 deletions Shells/Shells/Keys_For_Heuc/heuc_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAOcK0fKKMisVrD6aSuNSMIW+dCa2Ajr3ZuXPJaj8jwrAAAAJi+9CeMvvQn
jAAAAAtzc2gtZWQyNTUxOQAAACAOcK0fKKMisVrD6aSuNSMIW+dCa2Ajr3ZuXPJaj8jwrA
AAAEDckbr2Ilr+q+V/CTKM8vKwGXUGnL/sXnvR7ytdy/sTYQ5wrR8ooyKxWsPppK41Iwhb
50JrYCOvdm5c8lqPyPCsAAAAEGRhbmdAZGFuZy1sYXB0b3ABAgMEBQ==
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions Shells/Shells/Keys_For_Heuc/heuc_key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA5wrR8ooyKxWsPppK41Iwhb50JrYCOvdm5c8lqPyPCs dang@dang-laptop
14 changes: 14 additions & 0 deletions Shells/Shells/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.8"

services:
ssh:
build:
context: ssh
ports:
- "22:22"
# telnet:
# build:
# context: telnet
# ports:
# - 21:21

23 changes: 23 additions & 0 deletions Shells/Shells/ssh/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#SSH

FROM cueh/debian_ctf

#Add a user
RUN useradd -ms /bin/bash cueh && useradd -ms /bin/bash heuc && useradd -ms /bin/bash admin && echo cueh:cueh | chpasswd

#Install Global Programs
RUN apt-get update && apt-get install -y --no-install-recommends openssh-server

#Configure SSH (Cant run as Daemon if this doenst exit
RUN mkdir /var/run/sshd

ADD --chown=heuc:heuc heuc /home/heuc
ADD --chown=admin:admin admin /home/admin

RUN cp /usr/bin/tee /home/cueh/ && chown admin:admin /home/cueh/tee && chmod a+s /home/cueh/tee

# PORTS AND BASIC COMMAND
#RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

Empty file.
1 change: 1 addition & 0 deletions Shells/Shells/ssh/heuc/.ssh/authorized_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA5wrR8ooyKxWsPppK41Iwhb50JrYCOvdm5c8lqPyPCs dang@dang-laptop
7 changes: 7 additions & 0 deletions Shells/Shells/ssh/heuc/.ssh/heuc_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAOcK0fKKMisVrD6aSuNSMIW+dCa2Ajr3ZuXPJaj8jwrAAAAJi+9CeMvvQn
jAAAAAtzc2gtZWQyNTUxOQAAACAOcK0fKKMisVrD6aSuNSMIW+dCa2Ajr3ZuXPJaj8jwrA
AAAEDckbr2Ilr+q+V/CTKM8vKwGXUGnL/sXnvR7ytdy/sTYQ5wrR8ooyKxWsPppK41Iwhb
50JrYCOvdm5c8lqPyPCsAAAAEGRhbmdAZGFuZy1sYXB0b3ABAgMEBQ==
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions Shells/Shells/ssh/heuc/.ssh/heuc_key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA5wrR8ooyKxWsPppK41Iwhb50JrYCOvdm5c8lqPyPCs dang@dang-laptop
5 changes: 5 additions & 0 deletions Shells/Shells/web/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM cueh/php_apache

#RUN apt-get update && apt-get install -y --no-install-recommends netcat

ADD --chown=www-data:www-data html /var/www/html
3 changes: 3 additions & 0 deletions Shells/Shells/web/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>
Tunnelled Connection
</h1>
21 changes: 21 additions & 0 deletions Shells/WebShellPlayground/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3"

services:
web:
#image: cueh/php_apache
build:
context: php
ports:
- 80:80
# volumes:
# - ./php/html/:/var/www/html

flask:
build:
context: flask
ports:
- 5000:5000
# volumes:
# - ./flask/opt:/opt
# environment:
# - FLASK_ENV=development
8 changes: 8 additions & 0 deletions Shells/WebShellPlayground/flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM cueh/flask

USER root
RUN apt-get update && apt-get install -y --no-install-recommends ncat

USER flask
WORKDIR /opt
ADD ./opt /opt
41 changes: 41 additions & 0 deletions Shells/WebShellPlayground/flask/opt/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Very simple Flask App. For Testing
"""

import flask
app = flask.Flask(__name__)

import subprocess

@app.route('/')
def main():

#payload = flask.request.args.get("payload")
return flask.render_template('index.html')

@app.route("/subprocess")
def subproc():

command = flask.request.args.get("payload")
if command:
output = subprocess.check_output(command, shell=True)
output = output.decode()
else:
output = None

return flask.render_template('subprocess.html', command = command, output = output)



@app.route("/eval")
def evalRCE():
error = None
output = None
command = flask.request.args.get("payload")
if command:
try:
output = eval(command)
except Exception as ex:
error = ex

return flask.render_template('evalRce.html', command = command, output = output, error=error)
25 changes: 25 additions & 0 deletions Shells/WebShellPlayground/flask/opt/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>

<html lang="en">
<head>

<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Python Shells</title>
</head>

<body>
<div class="container">
{% include("nav.html") %}

{% block content %}
{% endblock content %}

</div>
</body>
</html>
57 changes: 57 additions & 0 deletions Shells/WebShellPlayground/flask/opt/templates/evalRce.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% extends "base.html" %}


{% block content %}
<h1>Eval based RCE</h1>

<p>
In this challenge we can look at RCE via the Python eval()
</p>
<p>
Eval wont let us execute system commands directly, as the commands are
run within the python interpreter. We need to work around this by using Pythons
internals to build a one liner, that will execute our code.

For example <code>__import__('os').system('whoami')</code>
</p>

<p>
We also have a second problem. While system will run the command for us,
it doesn't give us any output. I am going to leave it up to you to work
this one out.</p>

<p>
<strong>TIP:</strong> You can check the docker-compose logs to get some feedback.
</p>

<div class="row mt-5">
<form>
<div class="form-group">
<label for="payload">Command</label>
<input id="payload" name="payload" placeholder="whoami"></input>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


{% if command %}
<div class="alert alert-info">Command Entered: {{ command }}</div>
{% endif %}

{% if output %}
<pre>
<code>
{{ output }}
</code>
</pre>
{% endif %}

{% if error %}
<div class="alert alert-warning">Error</div>
<pre>
{{ error }}
</pre>
{% endif %}
</div>

{% endblock content %}
16 changes: 16 additions & 0 deletions Shells/WebShellPlayground/flask/opt/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "base.html" %}


{% block content %}
<h1>Python Shells</h1>

<p>This is the playground where you can try working with Python based shells and RCE</p>

<h2>Practice</h2>

<ul>
<li><a href="/subprocess">Subprocess based RCE</a></li>
<li><a href="/eval">Eval Based RCE</a></li>
</ul>

{% endblock content %}
18 changes: 18 additions & 0 deletions Shells/WebShellPlayground/flask/opt/templates/nav.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Shell Playground</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://127.0.0.1/">PHP Shells</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://127.0.0.1:5000/">Python Shells</a>
</li>
</ul>
</nav>
38 changes: 38 additions & 0 deletions Shells/WebShellPlayground/flask/opt/templates/subprocess.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "base.html" %}


{% block content %}
<h1>Subprocess based RCE</h1>

<p>
In this challenge we can look at RCE via the Python Subprocess module.
</p>
<p>
Using Subprocess means that we can call system commands directly,
without having to use any special syntax
</p>

<div class="row mt-5">
<form>
<div class="form-group">
<label for="payload">Command</label>
<input id="payload" name="payload" placeholder="whoami"></input>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


{% if output %}
<div class="alert alert-info">Command Entered: {{ command }}</div>
<pre>
<code>
{{ output }}
</code>
</pre>
{% endif %}
</div>




{% endblock content %}
5 changes: 5 additions & 0 deletions Shells/WebShellPlayground/php/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM cueh/php_apache

RUN apt-get update && apt-get install -y --no-install-recommends netcat

ADD --chown=www-data:www-data html /var/www/html
37 changes: 37 additions & 0 deletions Shells/WebShellPlayground/php/html/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!doctype html>

<html lang="en">
<head>

<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>PHP Shells</title>
</head>

<body>
<div class="container">
<?php include("nav.html") ?>
<h1>PHP Shells</h1>

<p>This is the playground where you can try working with PHP based shells and RCE</p>

<h2>Practice</h2>

<ul>
<li><a href="/shells/pentest-monkey.php">Pen Test Monkey Shell</a></li>
<li><a href="/shells/P0wny.php">P0wny Shell</a></li>
<li><a href="/rce/RCE.php">Remote Code Execution</a></li>
<li><a href="/rce/RCE_Blind.php">Blind RCE</a></li>
<li><a href="/upload.php"> File Uploads</a></li>
</ul>

</div>


</body>
</html>
Loading

0 comments on commit a082782

Please sign in to comment.