Re: [Tails-dev] Tails control port filter proxy in Whonix?

Poista viesti

Vastaa
Lähettäjä: Patrick Schleizer
Päiväys:  
Vastaanottaja: The Tails public development discussion list
Aihe: Re: [Tails-dev] Tails control port filter proxy in Whonix?
anonym:
> Patrick Schleizer:
>> Where I need to correct myself. The injected IP is probably difficult to
>> add to a config file since IPs in Qubes will remain dynamic for some
>> quite some time until Qubes 4.0. We'd need something like this.
>>
>>     ADD_ONION:
>>       - pattern: 'NEW:BEST Port=80,(176[0-5][0-9])'
>>         replacement: 'NEW:BEST Port=80,<client i.e. workstation IP>:{}'

>>
>> (Where <workstation IP> is just used to illustrate. Not a syntax
>> suggestion. Could be expressed with any other special chars.)
>>
>> Could you implement that please?
>
> I hacked something together so that the following should work for you:
>
>     ADD_ONION:
>       - pattern:     'NEW:BEST Port=80,(176[0-5][0-9])'
>         replacement: 'NEW:BEST Port=80,{client-address}:{}'

>
> See attached patch, but note that I haven't tested it (and not pushed
> it, since the branch is up for review, and I won't have time to test it
> for that). If there's some silly syntax error, I bet you can fix it
> yourself. :)


Fixed some minor issues indeed. Patch attached.

However, there is an offending line, I am stuck with.

return r['replacement'].format(*match.groups()) + terminator

  File "./tor-controlport-filter", line 334, in rewrite_line
    return r['replacement'].format(*match.groups()) + terminator
KeyError: 'client-address'


Could you fix that please?

Cheers,
Patrick

>From cf1a7c9033d4b06763c71f166ced2892b82f8a5b Mon Sep 17 00:00:00 2001
From: Your Name <you@???>
Date: Sat, 12 Nov 2016 23:17:54 +0000
Subject: [PATCH] syntax

---
tor-controlport-filter | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/tor-controlport-filter b/tor-controlport-filter
index 95be1e5..face56e 100755
--- a/tor-controlport-filter
+++ b/tor-controlport-filter
@@ -316,10 +316,10 @@ def handle_controlport_session(controller, readh, writeh, client_desc, client_pi

     def rewrite_line(replacers, line):
         builtin_replacers = (
-            ('{client-address}', client_address[0]),
-            ('{client-port}',    client_address[1]),
-            ('{server-address}', server_address[0]),
-            ('{server-port}',    server_address[1]),
+            ('{client-address}', str(client_address[0])),
+            ('{client-port}',    str(client_address[1])),
+            ('{server-address}', str(server_address[0])),
+            ('{server-port}',    str(server_address[1])),
         )
         for pattern, replacement in builtin_replacers:
             line = line.replace(pattern, replacement)
@@ -560,7 +560,7 @@ class FilteredControlPortProxyHandler(socketserver.StreamRequestHandler):
         try:
             handle_controlport_session(controller, self.rfile, self.wfile,
                                        client_desc, client_pid,
-                                       self.client_address, self.server_address,
+                                       self.client_address, server_address,
                                        allowed_commands, allowed_events,
                                        restrict_stream_events
             )
@@ -631,9 +631,10 @@ def main():
     global_args.__dict__['print_requests'] = global_args.complain or \
                                              global_args.debug
     global_args.__dict__['print_responses'] = global_args.debug
-    address = (global_args.listen_address, global_args.listen_port)
-    server = FilteredControlPortProxy(address, FilteredControlPortProxyHandler)
-    log("Tor control port filter started, listening on {}:{}".format(*address))
+    global server_address
+    server_address = (global_args.listen_address, global_args.listen_port)
+    server = FilteredControlPortProxy(server_address, FilteredControlPortProxyHandler)
+    log("Tor control port filter started, listening on {}:{}".format(*server_address))
     try:
         server.serve_forever()
     except KeyboardInterrupt:
-- 
2.1.4