Added support for apache24 mod_wsgi.

This commit is contained in:
darko-poljak 2015-09-20 08:10:07 +02:00
parent 25e17d32fd
commit 0630e5f841
4 changed files with 77 additions and 47 deletions

View file

@ -14,7 +14,10 @@ below).
Content size can be limited.
It uses lock which allows only one request at a time.
It is implemented with bottle microframework.
It is a hack! :)
This tool was written to deceive/fool proxy which prevented me to
download usefull tools and/or source code files.
Usage
=====
@ -39,19 +42,23 @@ save it to data.tar.xz:
cat DATA.txt | python x.py d > data.tar.xz
Run it in development mode:
Run it in development mode using python wsgiref:
.. code:: bash
python x.py ANY-ARG
python x.py x
Run it in production mode:
Run it in production mode using python wsgiref:
.. code:: bash
python x.py
Run it as apache24 wsig:
see apache-config file for apache configuration
When you use this same tool for prepareing target URL and decrypting
target content on the client then x.py need to be defined with the same AES
KEY and IV values as on the server.
@ -61,6 +68,8 @@ Installation
Copy bottle.py and x.py to the desired server and directory and run it.
For use with apache24 install mod_wsgi and see apache-config file for apache configuration.
Documentation
=============
@ -82,7 +91,5 @@ Further development ideas
* Add configuration file.
* Add apache mod_wsgi support.
* Support defined maximum requests at a time instead of one lock.

13
apache-config Executable file
View file

@ -0,0 +1,13 @@
<VirtualHost _default_:80>
ServerName cloak
ServerAdmin webmaster@localhost
WSGIScriptAlias /x "/home/freebsd/x/wsgi.py"
WSGIDaemonProcess x user=www group=www python-path="/home/freebsd/x"
<Directory "/home/freebsd/x">
WSGIProcessGroup x
WSGIApplicationGroup %{GLOBAL%}
Require all granted
</Directory>
</VirtualHost>

6
wsgi.py Executable file
View file

@ -0,0 +1,6 @@
import os
os.chdir(os.path.dirname(__file__))
import x
application = x.b.default_app()

90
x.py
View file

@ -22,12 +22,15 @@ AES_MODE = AES.MODE_CFB
AES_IV = r'A123B890JKL @%#$'
AES_KEY = r')(*+AKIM 313 321kjah.;klk@sfsd%$'
debug = False
py3k = sys.version_info >= (3, 0, 0)
if py3k:
import urllib.request as urlreq
import urllib.parse as urlpar
stdout_write = sys.stdout.buffer.write
def get_content_length(r):
foo = r.getheader('Content-Length')
if foo:
@ -39,6 +42,7 @@ else:
import urllib as urlpar
stdout_write = sys.stdout.write
def get_content_length(r):
foo = r.info().getheaders('Content-Length')
if foo and len(foo) >= 1:
@ -108,49 +112,49 @@ def x(url):
aes = aes_new()
return base64.b64encode(zlib.compress(aes.encrypt(x)))
argc = len(sys.argv)
if argc > 1:
aes = aes_new()
if sys.argv[1] == '-h':
print("usage: {0} -h print help".format(sys.argv[0]))
print("usage: {0} c TARGET encode TARGET".format(sys.argv[0]))
print("usage: {0} d decode stdin".format(sys.argv[0]))
print("usage: {0} ANY run server in debug mode on 8080".format(
sys.argv[0]))
print("usage: {0} run server on 80".format(sys.argv[0]))
sys.exit(0)
elif sys.argv[1] == 'c':
if argc < 3:
print("missing target")
sys.exit(1)
if __name__ == "__main__":
argc = len(sys.argv)
if argc > 1:
aes = aes_new()
if sys.argv[1] == '-h':
print("usage: {0} -h print help".format(sys.argv[0]))
print("usage: {0} c TARGET encode TARGET".format(sys.argv[0]))
print("usage: {0} d decode stdin".format(sys.argv[0]))
print("usage: {0} ANY run server in debug mode on"
"8080".format(sys.argv[0]))
print("usage: {0} run server on 80".format(sys.argv[0]))
sys.exit(0)
elif sys.argv[1] == 'c':
if argc < 3:
print("missing target")
sys.exit(1)
else:
# encode target url
if sys.argv[1] == 'c':
foo = str.encode(sys.argv[2])
foo = aes.encrypt(foo)
foo = zlib.compress(foo)
foo = base64.b64encode(foo)
stdout_write(foo)
print()
sys.exit(0)
# decode data from stdin
elif sys.argv[1] == 'd':
foo = str.encode(sys.stdin.read())
foo = base64.b64decode(foo)
foo = zlib.decompress(foo)
foo = aes.decrypt(foo)
stdout_write(foo)
sys.exit(0)
else:
# encode target url
if sys.argv[1] == 'c':
foo = str.encode(sys.argv[2])
foo = aes.encrypt(foo)
foo = zlib.compress(foo)
foo = base64.b64encode(foo)
stdout_write(foo)
print()
sys.exit(0)
# decode data from stdin
elif sys.argv[1] == 'd':
foo = str.encode(sys.stdin.read())
foo = base64.b64decode(foo)
foo = zlib.decompress(foo)
foo = aes.decrypt(foo)
stdout_write(foo)
sys.exit(0)
# run dev server
host = DEV_HOST
port = DEV_PORT
debug = True
else:
# run dev server
host = DEV_HOST
port = DEV_PORT
debug = True
else:
# run production server
host = PRODUCTION_HOST
port = PRODUCTION_PORT
debug = False
b.run(host=host, port=port, debug=debug, reloader=True)
# run production server
host = PRODUCTION_HOST
port = PRODUCTION_PORT
debug = False
b.run(host=host, port=port, debug=debug, reloader=True)