Last change
on this file since 12 was
3,
checked in by tim, 9 years ago
|
.
|
-
Property svn:executable set to
*
|
File size:
1.5 KB
|
Rev | Line | |
---|
[3] | 1 | #!/usr/bin/env python3 |
---|
| 2 | # |
---|
| 3 | # Copyright (C) 2015 Blindspot Security LLC |
---|
| 4 | # by Timothy D. Morgan |
---|
| 5 | # twits: @ecbftw |
---|
| 6 | |
---|
| 7 | import sys |
---|
| 8 | import time |
---|
| 9 | import hashlib |
---|
| 10 | import socketserver |
---|
| 11 | import http.server |
---|
| 12 | import sqlite3 |
---|
| 13 | |
---|
| 14 | mem = sqlite3.connect(':memory:') |
---|
| 15 | disk = sqlite3.connect('/var/tmp/x.db') |
---|
| 16 | memc = mem.cursor() |
---|
| 17 | diskc = disk.cursor() |
---|
| 18 | |
---|
| 19 | q='''CREATE TABLE user |
---|
| 20 | (username text, pwdhash text, other text, data real, stuff real)''' |
---|
| 21 | memc.execute(q) |
---|
| 22 | diskc.execute(q) |
---|
| 23 | q="INSERT INTO user VALUES ('jack','010203040506070809000A0B0C0D0E0F','hello',42,3.1415926535)" |
---|
| 24 | memc.execute(q) |
---|
| 25 | diskc.execute(q) |
---|
| 26 | mem.commit() |
---|
| 27 | disk.commit() |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | class HashHandler(http.server.BaseHTTPRequestHandler): |
---|
| 32 | """ |
---|
| 33 | """ |
---|
| 34 | |
---|
| 35 | def do_GET(self): |
---|
| 36 | resolution = time.clock_getres(time.CLOCK_MONOTONIC) |
---|
| 37 | |
---|
| 38 | conn = None |
---|
| 39 | if 't=' in self.path: |
---|
| 40 | t = self.path.split('t=', 1)[1] |
---|
| 41 | if t == '1': |
---|
| 42 | conn = memc |
---|
| 43 | elif t == '2': |
---|
| 44 | conn = diskc |
---|
| 45 | |
---|
| 46 | received = int(time.monotonic()/resolution) |
---|
| 47 | if conn != None: |
---|
| 48 | x = conn.execute("SELECT * FROM user WHERE username='jack'") |
---|
| 49 | now = int(time.monotonic()/resolution) |
---|
| 50 | |
---|
| 51 | self.send_response(200) |
---|
| 52 | self.send_header('Content-Type','text/plain; charset=UTF-8') |
---|
| 53 | self.end_headers() |
---|
| 54 | |
---|
| 55 | content = "waited: %d\n" % (now - received) |
---|
| 56 | self.wfile.write(content.encode('utf-8')) |
---|
| 57 | self.wfile.flush() |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | if __name__ == "__main__": |
---|
| 61 | HOST, PORT = "0.0.0.0", 3240 |
---|
| 62 | server = socketserver.TCPServer((HOST, PORT), HashHandler) |
---|
| 63 | server.serve_forever() |
---|
Note: See
TracBrowser
for help on using the repository browser.