Commit a6c16036 authored by juga's avatar juga
Browse files

Add sybilhunter subcommand

in a similar way to trnnr and sybilhunter, using only router statuses
data.
Also updated arti versions.

Closes #13
parent 3739865e
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -37,11 +37,13 @@ tokio-crate = { package = "tokio", version = "1.7", features = [
# Last versions, increment them as they change:
# https://gitlab.torproject.org/tpo/core/arti/-/tags
arti-client = {version = "0.9", features = ["experimental-api"]}
tor-rtcompat = {version = "0.9", features = ["tokio"]}
tor-chanmgr = {version = "0.9"}
tor-circmgr = {version = "0.8", features = ["experimental-api"] }
tor-circmgr = {version = "0.9", features = ["experimental-api"] }
tor-config = {version = "0.9" }
tor-dirmgr = {version = "0.10" }
tor-linkspec = {version = "0.8"}
tor-llcrypto = {version = "0.5"}
tor-netdir = {version = "0.9", features = ["experimental-api"] }
tor-netdoc = {version = "0.7" }
tor-proto = {version = "0.10" }
tor-netdoc = {version = "0.8" }
tor-proto = {version = "0.11" }
tor-rtcompat = {version = "0.9", features = ["tokio"]}
+15 −0
Original line number Diff line number Diff line
@@ -297,6 +297,21 @@ Note: part of this section should probably be moved into code documentation.
    +-----------+-------------------------------------------+---------------------------------------------+----------+---------------------+
    ```

- `sybilhunter <fingerprint>`: `Discover Sybil relays which are configured in a similar way`

    eg:
    `sybilhunter 501B3DBF250B094A05CA5DBC424AD4C3D46721A2`, output:

    ```bash
    Reference string: CalyxInstitute04162.247.74.20444374840.4.7.13075000
    [+] Computing distances...
    [+] Top 20 closest relays to: 501B3DBF250B094A05CA5DBC424AD4C3D46721A2
    distance: fingerprint, nickname, ip.port, flags bits, tor version, unmeasured measured
    0: 501B3DBF250B094A05CA5DBC424AD4C3D46721A2, CalyxInstitute04, 162.247.74.204443, 7484, 0.4.7.13, 075000
    [...]
    21: 93D3B5088A6813F679A426323AE0125FB4FE7728, RunningOnFumes1, 104.244.75.74443, 7484, 0.4.7.13, 06500
    ```

- `test`: `Run test(s) on one or many relay(s)`
  - `extend <filters>`: Circuit `Extend to a relay`, optionally matching
    some `filter`s.
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ mod err;
mod find;
mod like;
mod sybil;
mod sybilhunter;
mod test;
mod util;

@@ -50,6 +51,11 @@ pub enum SubCommand {
    Sybil(sybil::SybilCommand),
    #[structopt(name = "test", about = "Run test(s) on one or many relay(s)")]
    Test(test::TestCommand),
    #[structopt(
        name = "sybilhunter",
        about = "Discover Sybil relays which are configured in a similar way"
    )]
    SybilHunter(sybilhunter::SybilHunterCommand),
}

impl SubCommand {
@@ -61,6 +67,7 @@ impl SubCommand {
            SubCommand::Like(c) => c,
            SubCommand::Sybil(c) => c,
            SubCommand::Test(c) => c,
            SubCommand::SybilHunter(c) => c,
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -21,4 +21,6 @@ pub enum Error {
    WrongIO(#[from] std::io::Error),
    #[error("Wrong parent: {0}")]
    WrongParent(String),
    #[error("No such relay")]
    NoSuchRelay,
}
+44 −0
Original line number Diff line number Diff line
use anyhow::Result;
use async_trait::async_trait;
use levenshtein::levenshtein;
use std::fmt;
use structopt::StructOpt;
use tor_netdir::NetDir;

use crate::commands::util;
use crate::commands::RunnableOffline;

#[derive(StructOpt)]
pub struct SybilHunterCommand {
    fingerprint: String,
}

impl fmt::Display for SybilHunterCommand {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.fingerprint)
    }
}

#[async_trait]
impl RunnableOffline for SybilHunterCommand {
    fn run(&self, netdir: &NetDir) -> Result<()> {
        let reference = util::id2relay(netdir, &self.fingerprint)?;
        let reference_str = util::relay2string(&reference);
        println!("Reference string: {}", reference_str);
        println!("[+] Computing distances...");
        let mut distances: Vec<_> = netdir
            .relays()
            .map(|relay| {
                (
                    levenshtein(&reference_str, &util::relay2string(&relay)),
                    relay,
                )
            })
            .collect();
        distances.sort_by(|a, b| a.0.cmp(&b.0));

        println!("[+] Top 20 closest relays to: {}", self.fingerprint);
        util::print_distances(distances);
        Ok(())
    }
}
Loading