HackMD
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ## Creating a netvm (sys-tor) in Qubes OS that routes all traffic of connected VMs through the Tor network. :::danger **Known issues** * Do not use this guide if you seriously rely on anonymity! * Only Fedora 29 is tested as a template, but it should be possible to apply this guide to other Linux distributions such as Debian with reasonable effort. ::: #### Make sure that required packages are installed in the Fedora 29 template: ``` sudo dnf install tor iptables nyx sudo systemctl disable tor.service ``` #### Append the following line to */etc/tor/torrc* in the Fedora 29 template: `%include /rw/config/torrc` #### Create the *sys-tor* netvm (in dom0) that is based on a Fedora 29 template: ``` qvm-shutdown --wait fedora-29 qvm-create --template fedora-29 --class AppVM --property maxmem=0 --property memory=512 --property netvm=sys-firewall --property provides_network=True --property vcpus=1 -l black sys-tor qvm-start sys-tor ``` #### Create the file */rw/config/torrc* (in sys-tor) with the following content: ``` AutomapHostsOnResolve 1 SOCKSPort 0 VirtualAddrNetwork 10.192.0.0/10 TransPort 0.0.0.0:1080 DNSPort 0.0.0.0:1053 ControlPort 9051 CookieAuthentication 1 ``` #### Modify the file */rw/config/rc.local* (in sys-tor) such that it reads as follows: ``` #!/bin/sh iptables-restore < /rw/config/iptables.conf ip6tables-restore < /rw/config/ip6tables.conf systemctl start tor ``` #### Create the file */rw/config/iptables.conf* (in sys-tor) with the following content: ``` *nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [4:218] :OUTPUT ACCEPT [1:52] -A PREROUTING -i vif+ -p tcp -j REDIRECT --to-ports 1080 -A PREROUTING -i vif+ -p udp -m udp --dport 53 -j REDIRECT --to-ports 1053 -A OUTPUT -p udp -m udp --dport 53 -j REDIRECT --to-ports 1053 -A OUTPUT -o lo -j RETURN -A OUTPUT -m owner --uid-owner toranon -j RETURN -A OUTPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports 1080 COMMIT *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT DROP [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -i vif+ -p tcp -m tcp --dport 1080 -j ACCEPT -A INPUT -i vif+ -p udp -m udp --dport 1053 -j ACCEPT -A OUTPUT -m conntrack --ctstate INVALID -j DROP -A OUTPUT -m state --state INVALID -j DROP -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A OUTPUT -m owner --uid-owner toranon -j ACCEPT -A OUTPUT -o lo -j ACCEPT -A OUTPUT -d 127.0.0.1/32 -j ACCEPT COMMIT ``` #### Create the file /rw/config/ip6tables.conf with the following content (in sys-tor): ``` *nat :PREROUTING DROP [0:0] :INPUT DROP [0:0] :OUTPUT DROP [0:0] :POSTROUTING DROP [0:0] COMMIT *raw :PREROUTING DROP [2:112] :OUTPUT DROP [33:1944] COMMIT *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT DROP [0:0] -A INPUT -j DROP -A FORWARD -j DROP -A OUTPUT -j DROP COMMIT ``` #### Restart sys-tor (in dom0) ``` qvm-shutdown --wait sys-tor qvm-start sys-tor ``` :::success That's it! Now all traffic of VMs is routed through the Tor network as soon as their netvm is set to sys-tor. ::: ### Further information #### Fix clock synchronization issue after suspend/resume cycle (in dom0) tor depends on a somewhat accurately synchronized clock. If you use suspend/resume, the clock in sys-tor may not be synchronized accurately enough for tor to work. To work around that issue, create a file */lib/systemd/system-sleep/99_settorclock.sh* in dom0 with the following content: ``` #!/bin/sh if [ "${1}" == "post" ]; then systemd-run qvm-run -q -n -u root sys-tor "/bin/date -s \"`/bin/date`\"" fi ``` And make that file executable: ``` chown 0:0 /lib/systemd/system-sleep/99_settorclock.sh chmod 700 /lib/systemd/system-sleep/99_settorclock.sh ``` #### Monitoring and interacting with tor (on sys-tor) Run *nyx* to monitor the state of tor and to interact with the tor process: `sudo -u toranon nyx` #### Mitigate traffic correlation attacks Multiple *sys-tor*-like netvms can be used to mitigate traffic correlation attacks. I.e., it should be harder for an adversary, who monitors traffic exiting the Tor network, to correlate that particular applications run on the same host. To this end, clone the sys-tor netvm (in dom0): `qvm-clone sys-tor sys-tor2` Remove tor's state information in sys-tor2: ``` sudo systemctl stop tor sudo rm -f /var/lib/tor/* sudo systemctl start tor ``` Now, it is harder for an adversary, who monitors traffic exiting the Tor network, to correlate that particular applications (connected to *sys-tor* and to *sys-tor2*) actually run on the same host. Just make sure that you add *sys-tor2* to */lib/systemd/system-sleep/99_settorclock.sh* so that its clock is set as well after a suspend/resume cycle (see above).

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully