-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathapp.py
executable file
·155 lines (126 loc) · 6.1 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
import os
import subprocess
import logging
from flask import Flask, request, render_template, redirect, url_for, flash, send_from_directory
from werkzeug.utils import secure_filename
from datetime import datetime
UPLOAD_FOLDER = '/var/www/html/dashboard/dev/pcap/uploads'
SENT_FOLDER = os.path.join(UPLOAD_FOLDER, 'sent')
ALLOWED_EXTENSIONS = {'pcap'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['SENT_FOLDER'] = SENT_FOLDER
app.secret_key = 'supersecretkey'
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
def datetimeformat(value, format='%Y-%m-%d %H:%M:%S'):
return datetime.fromtimestamp(value).strftime(format)
app.jinja_env.filters['datetimeformat'] = datetimeformat
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
files = request.files.getlist('file')
if not files or all(f.filename == '' for f in files):
flash('No selected file')
return redirect(request.url)
for file in files:
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
flash('Files successfully uploaded')
return redirect(url_for('upload_file'))
files = [f for f in os.listdir(app.config['UPLOAD_FOLDER']) if f != 'sent']
file_details = [(f, os.path.getmtime(os.path.join(app.config['UPLOAD_FOLDER'], f))) for f in files]
return render_template('index.html', files=file_details)
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
@app.route('/submit', methods=['POST'])
def submit_files():
email = request.form.get('email')
if not email:
flash('Email address is required')
return redirect(url_for('upload_file'))
files = request.form.getlist('files')
if not files:
flash('No files selected for submission')
return redirect(url_for('upload_file'))
# Ensure the sent directory exists
os.makedirs(app.config['SENT_FOLDER'], exist_ok=True)
for file in files:
filepath = os.path.join(app.config['UPLOAD_FOLDER'], file)
# Log the file path and check if it exists
logger.info(f'Processing file: {filepath}')
if not os.path.exists(filepath):
logger.error(f'File does not exist: {filepath}')
flash(f'File not found: {file}')
continue
# Log before running the command
logger.info(f'Running command: /var/www/html/dashboard/dev/pcap/upload-unix.sh {filepath} {email}')
command = f'/var/www/html/dashboard/dev/pcap/upload-unix.sh {filepath} {email}'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Log the result of the command
logger.info(f'Command result: {result.returncode}')
specific_error_message = "[+] No valid EAPOL handshake or PMKID found in the submitted file.Try another dump or contact us for manual check."
if result.returncode == 0 and "File successfully uploaded" in result.stdout:
sent_path = os.path.join(app.config['SENT_FOLDER'], file)
logger.info(f'File should have been moved to: {sent_path}')
flash(f'File submitted and moved to sent: {file}')
else:
logger.error(f'Failed to process file: {filepath}')
if specific_error_message in result.stdout:
flash(specific_error_message)
else:
flash(f'Failed to process file: {file}')
flash(f'<pre>{result.stdout}</pre>')
return redirect(url_for('upload_file'))
@app.route('/submit_single/<filename>', methods=['POST'])
def submit_single_file(filename):
email = request.form.get('email')
if not email:
flash('Email address is required')
return redirect(url_for('upload_file'))
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
# Log the file path and check if it exists
logger.info(f'Processing file: {filepath}')
if not os.path.exists(filepath):
logger.error(f'File does not exist: {filepath}')
flash(f'File not found: {filename}')
return redirect(url_for('upload_file'))
# Ensure the sent directory exists
os.makedirs(app.config['SENT_FOLDER'], exist_ok=True)
# Log before running the command
logger.info(f'Running command: /var/www/html/dashboard/dev/pcap/upload-unix.sh {filepath} {email}')
command = f'/var/www/html/dashboard/dev/pcap/upload-unix.sh {filepath} {email}'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Log the result of the command
logger.info(f'Command result: {result.returncode}')
specific_error_message = "[+] No valid EAPOL handshake or PMKID found in the submitted file.Try another dump or contact us for manual check."
if result.returncode == 0 and "File successfully uploaded" in result.stdout:
sent_path = os.path.join(app.config['SENT_FOLDER'], filename)
logger.info(f'File should have been moved to: {sent_path}')
flash(f'File submitted and moved to sent: {filename}')
else:
logger.error(f'Failed to process file: {filepath}')
if specific_error_message in result.stdout:
flash(specific_error_message)
else:
flash(f'Failed to process file: {filename}')
flash(f'<pre>{result.stdout}</pre>')
return redirect(url_for('upload_file'))
@app.route('/delete', methods=['POST'])
def delete_file():
file = request.form.get('file')
if file:
filepath = os.path.join(app.config['UPLOAD_FOLDER'], file)
os.remove(filepath)
flash(f'{file} deleted')
return redirect(url_for('upload_file'))
if __name__ == '__main__':
app.run(debug=True)