-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathdsvpwa.py
56 lines (45 loc) · 2.02 KB
/
dsvpwa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import os
import ssl
import argparse
from dsvpwa.server import VulnHTTPServer
from dsvpwa.handlers import VulnHTTPRequestHandler
BUILD_VER = os.getenv('BUILD_VER') or '0.0.1'
BUILD_REV = os.getenv('BUILD_REV') or 'dev'
def main():
parser = argparse.ArgumentParser(prog='DSVPWA',
description='Damn Simple Vulnerable Python Web Application')
parser.add_argument('--host', default='127.0.0.1',
help='set the IP address to bind to (defaults to 127.0.0.1)')
parser.add_argument('--port', type=int, default=os.getenv('DSVPWA_PORT', 65413),
help='set the port number to bind to (defaults to 65413)')
parser.add_argument('--risk', type=int, default=os.getenv('DSVPWA_RISK', 1), choices=range(1,4),
help='set the risk level in the range 1-3')
parser.add_argument('--ssl', action='store_true', default=os.getenv('DSVPWA_SSL', 0),
help='enable encryption (defaults to false)')
parser.add_argument('--version', action='version',
version='%(prog)s v{} ({})'.format(BUILD_VER, BUILD_REV))
args = parser.parse_args()
proto = 'http' if not args.ssl else 'https'
try:
httpd = VulnHTTPServer((args.host, args.port), VulnHTTPRequestHandler)
httpd.RequestHandlerClass.risk = args.risk
if args.ssl:
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.options &= ~ssl.OP_NO_SSLv3
ctx.options &= ~ssl.OP_NO_COMPRESSION
ctx.options &= ~ssl.OP_CIPHER_SERVER_PREFERENCE
ctx.load_cert_chain(certfile='./ssl/cert.pem', keyfile='./ssl/key.pem')
httpd.socket = ctx.wrap_socket(httpd.socket, server_side=True)
print('[*] Navigate to {}://{}:{} to access DSVPWA'.format(proto, args.host, args.port))
httpd.serve_forever()
except KeyboardInterrupt:
print('[*] Quitting...')
pass
except Exception as ex:
print("[!] Exception occurred ('%s')" % ex)
finally:
httpd.server_close()
os._exit(0)
if __name__ == "__main__":
main()