Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask server which handles commands using API calls #3

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a9fbea9
samples
snehith57624 May 22, 2023
38cea4c
update
snehith57624 May 22, 2023
63259b3
update
snehith57624 May 22, 2023
2871444
update
snehith57624 May 22, 2023
0257ca9
flask server
snehith57624 May 27, 2023
5d81b6b
Docker
snehith57624 May 27, 2023
79f594f
Docker
snehith57624 May 27, 2023
d590d36
update docker file
snehith57624 May 28, 2023
8052f09
debugging
snehith57624 May 29, 2023
8215e8d
upload api
snehith57624 May 29, 2023
2332c99
ongoing changes
snehith57624 May 30, 2023
2cc2786
upload along with setting data
snehith57624 May 30, 2023
c949e92
Update Dockerfile
snehith57624 Jun 1, 2023
fd792b1
Update target.py
snehith57624 Jun 1, 2023
d417a7f
Update data.py
snehith57624 Jun 1, 2023
d5584e5
Update whitebox.py
snehith57624 Jun 1, 2023
9743203
Update interface.py
snehith57624 Jun 1, 2023
f3e6ce7
Update app.py
snehith57624 Jun 1, 2023
fc0565e
Update app.py
snehith57624 Jun 1, 2023
a7337a7
refactoring
snehith57624 Jun 1, 2023
c605b38
views
snehith57624 Jun 1, 2023
7ba5879
Merge branch 'master' into webserver
snehith57624 Jun 14, 2023
345a12f
Merge pull request #1 from snehith57624/webserver
snehith57624 Jun 14, 2023
d51e061
Rename Untitled-1.txt to curl_commands.txt
snehith57624 Jun 14, 2023
ae8833a
Update curl_commands.txt
snehith57624 Jun 14, 2023
d33ce0f
refactoring
snehith57624 Jun 18, 2023
9dc2088
refactoring
snehith57624 Jun 18, 2023
95ac287
refactoring
snehith57624 Jun 18, 2023
3ef58ec
refactoring
snehith57624 Jun 18, 2023
5ad6d79
refactoring
snehith57624 Jun 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu:latest

# Install necessary dependencies
RUN apt-get update && apt-get install -y python3 python3-pip
RUN apt-get install -y git && apt-get install -y libmagic1

RUN git clone https://github.com/snehith57624/toucanstrike.git

# Expose the port
EXPOSE 5000

# Install Python dependencies
RUN pip install flask colorama && pip install tqdm && pip install -U "ipython>=7.20"

RUN cd toucanstrike && git pull && pip install -r requirements.txt


# Set the entrypoint command
CMD ["python3", "toucanstrike/app.py"]
48 changes: 48 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from flask import Flask, render_template, request, jsonify
from colorama import Fore, Style

from constants import banner
from interface import ToucanStrikeInterface
import os

app = Flask(__name__)
terminal = ToucanStrikeInterface()


@app.route('/')
def index():
return "working"


@app.route('/command', methods=['POST'])
def execute_command():
command = request.form.get('command')
print("input ", command)
output = terminal.onecmd(command)
print("output ", output)
return output


@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return jsonify({'error': 'No file uploaded'})

file = request.files['file']

if file.filename == '':
return jsonify({'error': 'No selected file'})

# Save the file to the static folder
file.save(os.path.join(app.static_folder, file.filename))
command = "data " + str(os.path.join(app.static_folder, file.filename))
output = terminal.onecmd(command)
print("file ", output)

output = terminal.onecmd("run")
print("output ", output)
return output


if __name__ == '__main__':
app.run(debug=True)
14 changes: 14 additions & 0 deletions curl_commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
curl -X POST -d "command=target malconv" http://localhost:5000/command

curl -X POST -d "command=whitebox --type partial_dos" http://localhost:5000/command

curl --location 'http://localhost:5000/upload' \
--form 'file=@"/toucanstrike/malware-samples/Rbot/Rbot-O.7z"' \
--form 'target="\"malconv\""'


docker build -t flask-app . --no-cache --network=host

docker run -d -p 8000:5000 --name webserver flask-app

docker exec -it webserver bash
115 changes: 63 additions & 52 deletions interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import cmd2
from cmd2 import Cmd
import sys
from io import StringIO

from commands.blackbox import get_black_box_parser, blackbox
from commands.clear import clear
Expand All @@ -15,65 +17,74 @@


class ToucanStrikeInterface(Cmd):
def __init__(self):
super().__init__(use_ipython=True)
self.prompt = get_default_prompt()
def __init__(self):
super().__init__()
self.prompt = get_default_prompt()

# setattr(Cmd, "do_set_meta", Cmd.do_set)
# delattr(Cmd, "do_set")
# Override the onecmd method to capture the output
def onecmd(self, line):
stdout_saved = sys.stdout
sys.stdout = StringIO() # Create a StringIO object to capture the output
try:
return super().onecmd(line)
finally:
output = sys.stdout.getvalue() # Get the captured output
sys.stdout.close()
sys.stdout = stdout_saved
return output

@cmd2.with_argparser(get_white_box_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_whitebox(self, args):
"""
Setup a white-box attack.
"""
whitebox(args)
@cmd2.with_argparser(get_white_box_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_whitebox(self, args):
"""
Setup a white-box attack.
"""
whitebox(args)

@cmd2.with_argparser(get_black_box_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_blackbox(self, args):
"""
Setup a black-box attack.
"""
blackbox(args)
@cmd2.with_argparser(get_black_box_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_blackbox(self, args):
"""
Setup a black-box attack.
"""
blackbox(args)

@cmd2.with_argparser(get_target_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_target(self, args):
"""Set attack target"""
target(args)
@cmd2.with_argparser(get_target_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_target(self, args):
"""Set attack target"""
target(args)

@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_status(self, args):
"""Print current set up of the attack"""
status()
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_status(self, args):
"""Print current set up of the attack"""
status()

@cmd2.with_argparser(get_run_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_run(self, args):
"""Run the specified attack against the target, using the specified data"""
run(args)
@cmd2.with_argparser(get_run_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_run(self, args):
"""Run the specified attack against the target, using the specified data"""
run(args)

@cmd2.with_argparser(get_predict_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_predict(self, args):
"""Compute prediction of a sample, using the already set target"""
predict(args)
@cmd2.with_argparser(get_predict_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_predict(self, args):
"""Compute prediction of a sample, using the already set target"""
predict(args)

@cmd2.with_argparser(get_data_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_data(self, args):
"""Set the data for attack and prediction"""
data(args)
@cmd2.with_argparser(get_data_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_data(self, args):
"""Set the data for attack and prediction"""
data(args)

@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_clear(self, args):
"""Clear all the information stored for the attack"""
clear()
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_clear(self, args):
"""Clear all the information stored for the attack"""
clear()

@cmd2.with_argparser(get_set_atk_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_setatk(self, args):
"""Set the parameters for the attack"""
do_set_atk(args)
@cmd2.with_argparser(get_set_atk_parser())
@cmd2.with_category(TOUCAN_STRIKE_COMMANDS)
def do_setatk(self, args):
"""Set the parameters for the attack"""
do_set_atk(args)
11 changes: 11 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>
First Web Page
</title>
</head>
<body>
Hello World!
</body>
</html>