Created
December 25, 2018 11:04
-
-
Save angeloped/49c88bf4f20283de9a0491105215fae6 to your computer and use it in GitHub Desktop.
This authentication is messing me up! I know that the logic is correct but it's stupid. xD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import pyaes | |
import random | |
from hashlib import md5 | |
import base64 | |
import urllib | |
key="ruoski" | |
class ENCRYPTION: | |
def __init__(self,key): | |
# the salty sea salt made from the sea water on the seashore | |
self.salt256 = "theseaissaltyb8ecbaacbd68de040cd78eb2ed5889130cceb4c49268ea4d506" | |
self.aes = pyaes.AESModeOfOperationCTR(md5((self.salt256+key).encode()).hexdigest().encode("ascii")) | |
def encrypt(self,data): | |
return base64.b64encode(self.aes.encrypt(data)) | |
def decrypt(self,data): | |
return self.aes.decrypt(base64.b64decode(data.encode())) | |
def pong(raw_data): | |
data = urllib.quote(ENCRYPTION(key).encrypt(raw_data).decode()) | |
return ENCRYPTION(key).decrypt(urllib.urlopen("http://localhost:92/" + data).read()).decode() | |
while 1: | |
raw_data = raw_input("Enter something cool >>> ") | |
ping = pong(raw_data) | |
#syn-ack | |
if ping == raw_data: | |
print("syn-ack") | |
print(pong("Ok")) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#usage: python srvr 92 | |
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer | |
import ssl | |
import sys | |
# ----------------------- | |
import pyaes | |
import random | |
from hashlib import md5 | |
import base64 | |
import urllib | |
class ENCRYPTION: | |
def __init__(self,key): | |
# the salty sea salt made from the sea water on the seashore | |
self.salt256 = "theseaissaltyb8ecbaacbd68de040cd78eb2ed5889130cceb4c49268ea4d506" | |
self.aes = pyaes.AESModeOfOperationCTR(md5((self.salt256+key).encode()).hexdigest().encode("ascii")) | |
def encrypt(self,data): | |
return base64.b64encode(self.aes.encrypt(data)) | |
def decrypt(self,data): | |
return self.aes.decrypt(base64.b64decode(data.encode())) | |
PORT_NUMBER = int(sys.argv[1]) | |
#This class will handles any incoming request | |
class myHandler(BaseHTTPRequestHandler): | |
#Handler for the GET requests | |
def do_GET(self): | |
key="barbie123" | |
data = ENCRYPTION(key).decrypt(urllib.unquote(self.requestline.split()[1][1:])) | |
print(data) | |
self.send_response(200) | |
self.end_headers() | |
if data == "Ok": | |
#connection established | |
print("connection established") | |
self.wfile.write(ENCRYPTION(key).encrypt("connection established").decode()) | |
else: | |
print("Forward: " + ENCRYPTION(key).encrypt(data).decode()) | |
self.wfile.write(ENCRYPTION(key).encrypt(data).decode()) | |
return | |
try: | |
#Create a web server and define the handler to manage the | |
#incoming request | |
server = HTTPServer(('', PORT_NUMBER), myHandler) | |
#server.socket = ssl.wrap_socket(server.socket, certfile='cert.pem',keyfile='key.pem', server_side=True) | |
print('Started httpserver on port ' , PORT_NUMBER) | |
#Wait forever for incoming htto requests | |
server.serve_forever() | |
except: | |
pass | |
finally: | |
print '^C received, shutting down the web server' | |
server.socket.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment