neoslab / torbridge

Script to redirect all traffic through Tor network including DNS queries for anonymizing entire system
GNU General Public License v3.0
1 stars 0 forks source link

There appears to be an issue starting / stopping torbridge `TorBridge already started` #2

Open ozymandiaslone opened 4 weeks ago

ozymandiaslone commented 4 weeks ago
(base) exeo@exeo:~$ sudo torbridge --status
[sudo] password for exeo:
[+] TorBridge is started                                                  [OK]
[*] Tor service is inactive                                                [!!]
[+] Remote IP [MY IP]                                                    [OK]
(base) exeo@exeo:~$ sudo torbridge --stop
[+] Remote IP [MY IP (UNCHANGED)]                         [OK]
[+] Traffic is not redirected through Tor                          [OK]
(base) exeo@exeo:~$ sudo torbridge --start
[*] TorBridge already started                                          [!!]
(base) exeo@exeo:~$ sudo torbridge --status
[+] TorBridge is started                                                  [OK]
[*] Tor service is inactive                                                [!!]
[+] Remote IP [MY IP]                                                   [OK]
(base) exeo@exeo:~$ sudo torbridge --restart
[+] Remote IP [MY IP]                                                   [OK]
[+] Traffic is not redirected through Tor                         [OK]
[*] TorBridge already started                                         [!!]
(base) exeo@exeo:~$

It could be some form of user error, but I don't see anything in the --help options that would help me troubleshoot

ozymandiaslone commented 4 weeks ago

I think that in the torstart() fn, whenever it makes a call to checkstatus, it always returns true. Even if I manually sudo rm /etc/torbridge/status, the torstart() checkstatus call still returns true

ozymandiaslone commented 4 weeks ago
function torstart()
{
    if ! [ -z "$(ls -A $torbridgepath)" ];
    then
        if ! [ -e "$torbridgepath/started" ];
        then
            touch "$torbridgepath/started"
        fi
    fi

    if checkstatus;
    then
        loadstatus "[*] TorBridge already started" "!!" "issue"
    else
    <...>
 }

Actually it looks like the torstart() fn first creates the /etc/torbridge/started path, if none exists (and if /etc/torbridge is not empty - which it isn't, due to resolv.conf.bak@) . Thus, when it calls checkstatus - which just checks for the existence of that path - it finds that the path exists, and errs that torbridge is already started.

ozymandiaslone commented 4 weeks ago
function torstart()
{
    if checkstatus;
    then
        loadstatus "[*] TorBridge already started" "!!" "issue"
    else
        # Display IP Address
        ## ------------------
        showipaddr

        ## Backup Tor Config
        ## -----------------
        backuptorrc

        ## Backup Resolv Config
        ## --------------------
        backupresolv

        ## Backup Iptables Rules
        ## ---------------------
        backupiptables

        ## Backup Sysctl Rules
        ## -------------------
        backupsysctl

        ## Flush Iptables
        ## --------------
        flushiptables

        ## Build Tor Config
        ## ----------------
        configtorrc

        ## Build Rsolv Config
        ## ------------------
        configresolv

        ## Start Services
        ## --------------
        servicestart tor

        ## Apply Rules
        ## -----------
        rulesiptables
        rulessysctl

        ## Display IP Address
        ## ------------------
        showipaddr

        ## Return Notice
        ## -------------
        loadstatus "[+] All traffic is being redirected through Tor" "OK" "valid"
        touch $torbridgepath/started
    fi
    if ! [ -z "$(ls -A $torbridgepath)" ];
    then
        if ! [ -e "$torbridgepath/started" ];
        then
            touch "$torbridgepath/started"
        fi
    fi

}

Moving that if block to the end of the fn seems to have fixed all of the issues on my end. I haven't spent the time to really dive into understanding this script, so I do not know if this breaks the script elsewhere; if it seems alright id be happy to open a pull request.

neoslab commented 4 weeks ago

Actually there is absolutely no issue with the script. I believe that you started TorBridge and shutdown your PC without stop TorBridge or something like this. Actually just have a look into /etc/torbridge and check if there is a file named "started" in such case, just delete it and try to restart

ozymandiaslone commented 4 weeks ago

Yeah you're right that the issue stems from my laptop entering hibernation or something while torbridge was still active. I had tried deleting the started file manually in /etc/torbridge, but the issue was that the file called resolv.conf.bak@ was still in the /etc/torbridge directory.

So then when this conditional:

if ! [ -z "$(ls -A $torbridgepath)" ];
    then
        if ! [ -e "$torbridgepath/started" ];
        then
            touch "$torbridgepath/started"
        fi
    fi

is checked at the beginning of the torstart() function, it leads to errors. (and --stop or --restart do not recover functionality)

I think I could have solved the problem entirely just by manually deleting the whole /etc/torbridge directory, or everything in it - but there is still no way for the script to recover once it finds itself in a state where it failed to empty the /etc/torbridge directory properly

neoslab commented 4 weeks ago

Well actually to solve the issue at the time it happened to you, you just needed to stop torbridge for the script to revert the initial config and delete the started file present in the torbridge directory.

Or another would be to recover the config manually and after that delete the started file. In which OS are you using Torbridge for me to know ?

ozymandiaslone commented 4 weeks ago

Oh I'm on linux mint. I think I did try stopping torbridge, and it would successfully delete the 'started' file, but not the 'resolv.conf.bak@' file, which was causing the broken state.

(base) exeo@exeo:~$ sudo torbridge --stop
[+] Remote IP [MY IP]                         [OK]
[+] Traffic is not redirected through Tor                          [OK]
(base) exeo@exeo:~$ sudo torbridge --start
[*] TorBridge already started                                          [!!]
neoslab commented 4 weeks ago

I just check more deeply and yes you are right, there is an issue to restore the resolv.conf file since the last Kernel update. Temporary in order to recover your resolv.conf what you can do is :

sudo mv /etc/resolv.conf /etc/resolv.conf.bak
sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
sudo rm -rf /etc/torbridge