Created
October 20, 2013 17:42
-
-
Save boxmein/7072788 to your computer and use it in GitHub Desktop.
A script to run a HTTP server that responds with different data when an Authorization header has been sent. Will not tell the end user about needing an Authorization header.
This file contains hidden or 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
# A secret HTTP server that only serves some content of a page | |
# when a decent Authorization header has been sent with the | |
# correct data. | |
# By itself will not tell the client that there needs to be an Authorization | |
# header. | |
# woo, secret spy networks! | |
# boxmein 2013 - free to use - idk | |
import http.server | |
import base64 | |
HTTPPORT = 3000 | |
# transparent logging: returns the same string that was passed to it | |
def tlog(s): | |
print(s) | |
return s | |
class SecretAuthTypeServer (http.server.BaseHTTPRequestHandler): | |
def do_GET (self): | |
print('GET '+ self.path) | |
self.send_header('Content-Type', 'text/html') | |
responded = False | |
if 'Authorization' in self.headers: | |
b64 = self.headers['Authorization'].split(' ')[1] | |
auths = base64.b64decode(b64).decode(encoding='UTF-8').split(':') | |
if auths[0] == 'Bosch' and auths[1] == 'sun': | |
responded = True | |
self.wfile.write("""<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>magic document with secret data</title> | |
</head> | |
<body> | |
<pre> | |
[00:11.55] <\m> sounds like | |
[00:12.05] <\m> An into-solid turner | |
[01:13.34] <mniip> jacob1, don't you see it | |
[01:13.41] <mniip> the penis | |
[01:13.41] <@jacob1> ? | |
[01:13.52] <@jacob1> ... | |
[02:26.00] <Ristovski> mozzarella filofax fadget | |
[02:28.21] <Ristovski> Doxin: shadap | |
[02:28.30] <Ristovski> Doxin: birch | |
</pre> | |
</body> | |
</html> | |
""".encode(encoding='UTF-8')) | |
if not responded: | |
self.wfile.write("""<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>magic document</title> | |
</head> | |
<body> | |
[02:26.47] <cracker64> lets play terrwormscrafttoy | |
[02:27.06] <Delta_unit> What does it do? | |
[02:27.29] <Delta_unit> What is it in first place anyway | |
[02:27.31] <boxmein> >_> | |
[22:17.53] <boxmein> Triclops256 | |
[22:18.00] <boxmein> you have fueled my summer nights with activity | |
[22:18.18] <Nibble> ... is this about your gay experience boxmein? | |
[22:18.20] <Triclops256> boxmein: xD, yes, that site kept me busy for weeks a few months ago | |
[22:18.24] <boxmein> Nibble: yes | |
[22:19.32] <Triclops256> I would say something about being boxmein's gay lover, but my fiancée is in #powder :p | |
[00:22.37] * You are now known as there | |
[00:22.43] * You are now known as boxmein | |
[00:29.40] <TheBombBaker> boxmein: There you are | |
[00:30.33] <boxmein> >_> | |
</body> | |
</html> | |
""".encode(encoding='UTF-8')) | |
def do_HEAD(self): | |
self.send_header('Content-Type', 'text/html') | |
def runhttpserver(server_class=http.server.HTTPServer, | |
handler_class=http.server.BaseHTTPRequestHandler): | |
print("running httpd at localhost with port",HTTPPORT) | |
server_address = ('', HTTPPORT) | |
httpd = server_class(server_address, handler_class) | |
httpd.serve_forever() | |
if __name__=='__main__': | |
runhttpserver(handler_class=SecretAuthTypeServer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment