Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.04 KB | None | 0 0
  1. #The MIT License (MIT)
  2.  
  3. # Copyright (c) 2016 klorox
  4.  
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11.  
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14.  
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22.  
  23. from Crypto.Util import randpool
  24. from Crypto.Hash import SHA256
  25. from Crypto.Hash import SHA512
  26. import random
  27. import socket
  28. import sys
  29.  
  30. print(""""
  31.  
  32.            
  33.  
  34.  
  35.               ___                                            ___           ___           ___    
  36.              /\ \                                         /\__\        /\ \        /\ \  
  37.             /::\ \      ___                  ___         /:/ _/_       /::\ \      /::\ \  
  38.            /:/\:\__\    /|  |                /\__\      /:/ /\__\    /:/\:\ \    /:/\:\__\
  39.           /:/ /:/  /    |:|  |               /:/  /      /:/ /:/ _/_   /:/ /::\ \  /:/ /:/  /  
  40.          /:/_/:/  /     |:|  |              /:/__/      /:/_/:/ /\__\ /:/_/:/\:\__\ /:/_/:/__/___
  41.          \:\/:/  /    __|:|__|             /::\ \     \:\/:/ /:/  / \:\/:/  \/__/ \:\/:::::/  /
  42.           \::/__/    /::::\ \           /:/\:\ \     \::/_/:/  /   \::/__/       \::/~~/~~~~
  43.            \:\ \   ~~~~\:\ \          \/__\:\ \     \:\/:/  /     \:\ \       \:\~~\    
  44.             \:\__\       \:\__\              \:\__\     \::/  /       \:\__\       \:\__\  
  45.              \/__/         \/__/                \/__/       \/__/         \/__/         \/__/    
  46.  
  47.  
  48.  
  49.  
  50.  
  51.        
  52.                        written by klorox
  53.                I take no responsibility for how this software is used.
  54.                    DO NOT USE THIS FOR MALICIOUS PURPOSES.
  55.                FOR EDUCATIONAL PURPOSES AND RESEARCH ONLY.
  56.              
  57.              
  58.              
  59.  
  60. """)
  61. host = '127.0.0.1'
  62. port = 443
  63. DIRR = input("                ENTER PASSWORD/KEY LIST NAME: ")
  64. #encryptDirr = input("Enter the directory you want to encrypt(BE CAREFUL): ")
  65.  
  66. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  67. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  68. s.bind((host,port))
  69. s.listen(1)
  70.  
  71.    
  72. def sha512_random_line(line):
  73.     hasher = SHA512.new(line)
  74.     return hasher.digest()    
  75.    
  76. def random_line(afile):
  77.     lines = open(DIRR).read().splitlines()
  78.     myline = random.choice(lines)
  79.     return myline
  80.  
  81. def getKey(password):
  82.     hasher = SHA256.new(password)
  83.     return hasher.digest()
  84.    
  85. def get_connection_keys():
  86.     with open('connection_keys.txt') as txt:
  87.         content = txt.readlines()
  88.         return content
  89.    
  90.  
  91. def generate_random_alpha_string():
  92.     return ''.join(random.choice('0123456789ABCDEF') for i in range(16))
  93.    
  94. print("            Server is running on port %d; press Ctrl-C to terminate." % port)
  95.  
  96. def main():
  97.     while 1:
  98.         clientsock, clientaddr = s.accept()
  99.         data = clientsock.recv(100000)
  100.         data = data.decode("utf-8")
  101.         data = str(data)
  102.         clientAddr = str(clientsock.getpeername())
  103.         set_keys = get_connection_keys()
  104.         falseKey = False
  105.         print("Allowed keys are: ", set_keys)
  106.         print("Recieved da-ta: ", data)
  107.         if data not in set_keys:
  108.             print(clientAddr + " tried to connection with invalid connection key. " + data)
  109.             print("Terminating connection. ")
  110.             terminate = bytes("FalseKey")
  111.             clientsock.send(terminate)
  112.             clientsock.close()
  113.             falseKey = True
  114.         if data in set_keys and falseKey == False:    
  115.             Password = random_line(DIRR)
  116.             with open("clients.txt", "a") as text_file:
  117.                 print("Wrote    " + str(clientAddr)+ " : " + str(Password) + " : " + str(data) + "\n")
  118.                 print("Key:"+ Password)
  119.                 text_file.write("\n" + clientAddr + ":" + Password + ":" + data + "\n")
  120.                 text_file.close()
  121.             print("got connection from ", clientsock.getpeername())
  122.             clientsock.send(bytes(Password, 'utf-8'))
  123. # clientsock.send(encryptDirr)
  124.             print('Sent KEY: ' , Password , ' to: ' , clientaddr)
  125.             clientsock.close()
  126.             print("Client socket closed. ")
  127.            
  128. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement