Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor permutations module #58

Merged
merged 3 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions examples/twistrs-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use colored::*;

use tokio::sync::mpsc;
use twistrs::enrich::DomainMetadata;
use twistrs::permutate::Domain;
use twistrs::permutate::{Domain, Permutation};

use anyhow::Result;
use std::collections::HashSet;
Expand All @@ -21,15 +21,13 @@ async fn main() -> Result<()> {

let domain = Domain::new(matches.value_of("domain").unwrap()).unwrap();

let mut domain_permutations = domain.all()?.collect::<HashSet<String>>();
let domain_permutations = domain.all()?.collect::<HashSet<Permutation>>();
let domain_permutation_count = domain_permutations.len();

domain_permutations.insert(String::from(domain.fqdn));

let (tx, mut rx) = mpsc::channel(5000);

for (i, v) in domain_permutations.into_iter().enumerate() {
let domain_metadata = DomainMetadata::new(v.clone());
let domain_metadata = DomainMetadata::new(v.domain.fqdn.clone());
let mut tx = tx.clone();

tokio::spawn(async move {
Expand Down
21 changes: 8 additions & 13 deletions examples/twistrs-grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ use domain_enumeration::Fqdn;

mod domain_enumeration;


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let channel = tonic::transport::Channel::from_static("http://127.0.0.1:8080")
.connect()
.await?;

let mut client = DomainEnumerationClient::new(channel);

println!("[+] Starting DNS resolutions...");

let request = tonic::Request::new(
Fqdn {
fqdn:String::from("google.com")
},
);
let request = tonic::Request::new(Fqdn {
fqdn: String::from("google.com"),
});

let mut response = client.send_dns_resolution(request).await?.into_inner();

Expand All @@ -28,11 +25,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

println!("[+] Starting MX Checks...");

let request = tonic::Request::new(
Fqdn {
fqdn:String::from("google.com")
},
);
let request = tonic::Request::new(Fqdn {
fqdn: String::from("google.com"),
});

let mut response = client.send_mx_check(request).await?.into_inner();

Expand All @@ -41,4 +36,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}

Ok(())
}
}
8 changes: 4 additions & 4 deletions examples/twistrs-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl DomainEnumeration for DomainEnumerationService {
let (tx, rx) = mpsc::channel(64);

for permutation in Domain::new(&request.get_ref().fqdn).unwrap().all().unwrap() {
let domain_metadata = DomainMetadata::new(permutation.clone());
let domain_metadata = DomainMetadata::new(permutation.domain.fqdn.clone());
let mut tx = tx.clone();

// Spawn DNS Resolution check
Expand All @@ -34,7 +34,7 @@ impl DomainEnumeration for DomainEnumerationService {
if let Some(ips) = metadata.ips {
if tx
.send(Ok(DomainEnumerationResponse {
fqdn: permutation.clone().to_string(),
fqdn: permutation.domain.fqdn.to_string(),
ips: ips.into_iter().map(|x| format!("{}", x)).collect(),
}))
.await
Expand Down Expand Up @@ -62,7 +62,7 @@ impl DomainEnumeration for DomainEnumerationService {
let (tx, rx) = mpsc::channel(64);

for permutation in Domain::new(&request.get_ref().fqdn).unwrap().all().unwrap() {
let domain_metadata = DomainMetadata::new(permutation.clone());
let domain_metadata = DomainMetadata::new(permutation.domain.fqdn.clone());
let mut tx = tx.clone();

// Spawn DNS Resolution check
Expand All @@ -71,7 +71,7 @@ impl DomainEnumeration for DomainEnumerationService {
if let Some(smtp) = metadata.smtp {
if tx
.send(Ok(MxCheckResponse {
fqdn: permutation.clone().to_string(),
fqdn: permutation.domain.fqdn.to_string(),
is_positive: smtp.is_positive,
message: smtp.message,
}))
Expand Down
7 changes: 3 additions & 4 deletions examples/twistrs-ws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use warp::ws::{Message, WebSocket};
use warp::Filter;

use twistrs::enrich::DomainMetadata;
use twistrs::permutate::Domain;
use twistrs::permutate::{Domain, Permutation};

/// Our global unique user id counter.
static NEXT_USER_ID: AtomicUsize = AtomicUsize::new(1);
Expand Down Expand Up @@ -93,11 +93,10 @@ async fn user_message(my_id: usize, msg: Message, users: &Users) {
eprintln!("initiating dns resolution checks for user: {}", my_id);

let domain = Domain::new(msg).unwrap();
let mut domain_permutations = domain.all().unwrap().collect::<HashSet<String>>();
domain_permutations.insert(String::from(domain.fqdn));
let domain_permutations = domain.all().unwrap().collect::<HashSet<Permutation>>();

for v in domain_permutations.into_iter() {
let domain_metadata = DomainMetadata::new(v.clone());
let domain_metadata = DomainMetadata::new(v.domain.fqdn.clone());
let tx = tx.clone();

tokio::spawn(async move {
Expand Down
2 changes: 1 addition & 1 deletion twistrs/src/enrich.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl DomainMetadata {
);

let stream = BufStream::new(
TcpStream::connect(&format!("{}:25", self.fqdn.to_string()))
TcpStream::connect(&format!("{}:25", self.fqdn))
.await
.map_err(|e| EnrichmentError::SmtpLookupError {
domain: self.fqdn.clone(),
Expand Down
Loading
Loading