Skip to content

Commit 06c32a3

Browse files
author
Justin Angel
committed
making browser decodes optional
1 parent c217d34 commit 06c32a3

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

server.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,16 @@ def list_directory(self, path):
124124
linkname = urllib.parse.quote(linkname)
125125
displayname = html.escape(displayname)
126126

127-
# TODO: Handle insertion of JS links
127+
# Handle insertion of JS links
128128
if self.B64_ENCODE_PAYLOAD:
129+
129130
# implenet call to JS via onClick
130-
131131
f.write(
132-
'<li><a href="javascript:decoder(\'{}\')">{}</a>\n'.format(
133-
linkname,
134-
linkname,
135-
displayname).encode('utf8')
132+
self.B64_LINK.format(
133+
linkname,
134+
linkname,
135+
displayname
136+
).encode('utf8')
136137
)
137138

138139
else:
@@ -158,6 +159,11 @@ class CorsHandler(http.server.SimpleHTTPRequestHandler):
158159

159160
B64_ENCODE_PAYLOAD = False
160161
B64_JS_TEMPLATE = None
162+
B64_LINK = None
163+
B64_LINK_TEMPLATE = \
164+
'<li><a href="javascript:downloader(\'{}\',true)">{}</a>\n'
165+
B64_NO_DECODE_LINK_TEMPLATE = \
166+
'<li><a href="javascript:downloader(\'{}\',false)">{}</a>\n'
161167

162168
@property
163169
def client_ip(self):
@@ -473,7 +479,7 @@ def do_basic_POST(self):
473479

474480
def run_server(interface, port, keyfile, certfile,
475481
webroot=None, enable_uploads=False, enable_b64=False,
476-
*args, **kwargs):
482+
disable_browser_decode=False, *args, **kwargs):
477483

478484
# ============================
479485
# CONFIGURE BASE64 OBFUSCATION
@@ -488,6 +494,12 @@ def run_server(interface, port, keyfile, certfile,
488494
'/templates/b64_obfuscation.js','r') as infile:
489495
CorsHandler.B64_JS_TEMPLATE = infile.read()
490496

497+
# Select proper link template based on supplied options
498+
if disable_browser_decode:
499+
CorsHandler.B64_LINK = CorsHandler.B64_NO_DECODE_LINK_TEMPLATE
500+
else:
501+
CorsHandler.B64_LINK = CorsHandler.B64_LINK_TEMPLATE
502+
491503
webroot=webroot or '.'
492504

493505
# Update CorsHandler with upload functionality
@@ -633,8 +645,23 @@ def generate_certificate(certfile, keyfile):
633645
obf_group.add_argument('--enable-b64',
634646
help='Enable double base 64 obfuscation of files.',
635647
action='store_true')
648+
obf_group.add_argument('--disable-browser-decode',
649+
help='Disable decoding at the browser. This may be disirable '
650+
'in situations where browser developers don\'t give a damn ab'
651+
'out your privacy and upload your downloaded files to scanner'
652+
's.',
653+
action='store_true')
636654

637655
args = parser.parse_args()
656+
657+
658+
if not args.enable_b64 and args.disable_browser_decode:
659+
660+
spring('Warning: Browser decoding has been disabled but '
661+
'Base64 encoding has not been enabled. Configuration ign'
662+
'ored.')
663+
664+
args.disable_browser_decode=False
638665

639666
# handle basic auth credentials
640667
if args.basic_username and not args.basic_password or (

templates/b64_obfuscation.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ function encoder(iterations){
6363
}
6464

6565
// For downloads
66-
function decoder(fname){
66+
function downloader(fname,decode){
67+
if(decode == undefined){ decode = false; }
6768
var xhttp = new XMLHttpRequest();
6869
xhttp.open("GET",fname,true);
6970
xhttp.timeout=30000;
7071
xhttp.onreadystatechange = function() {
7172
if(this.readyState == 4 && this.status == 200){
72-
var blob = decode64(this.responseText, 2);
73+
var blob;
74+
if(decode){
75+
blob = decode64(this.responseText, 2);
76+
} else {
77+
blob = new Blob([this.responseText], {type:'text/base64'});
78+
}
7379
var a = document.createElement('a');
7480
var u = window.URL.createObjectURL(blob);
7581
document.body.appendChild(a);

0 commit comments

Comments
 (0)