2024-02-09 20:47:46 +00:00
|
|
|
//! # Server Side
|
|
|
|
//! DNS server component for processing requests and replying with DNS records.
|
|
|
|
//!
|
|
|
|
//! The aim is to have clients exfil to this server and to allow pulling down data from the server.
|
2024-01-30 22:35:22 +00:00
|
|
|
|
2024-01-28 19:30:59 +00:00
|
|
|
use clap::Parser;
|
2024-01-28 22:48:35 +00:00
|
|
|
use std::{thread};
|
2024-01-28 19:30:59 +00:00
|
|
|
|
2024-01-29 00:03:43 +00:00
|
|
|
use log::info;
|
2024-01-28 19:30:59 +00:00
|
|
|
use simplelog::*;
|
2024-02-09 20:47:46 +00:00
|
|
|
use std::fs::OpenOptions;
|
2024-01-29 00:03:43 +00:00
|
|
|
use std::net::SocketAddr;
|
2024-02-08 17:22:06 +00:00
|
|
|
use dnstplib::DomainConfig;
|
2024-01-28 19:30:59 +00:00
|
|
|
|
2024-02-07 17:44:28 +00:00
|
|
|
use dnstplib::net::DNSSocket;
|
2024-01-30 18:36:49 +00:00
|
|
|
use dnstplib::processor::RequestProcesor;
|
2024-01-28 22:48:35 +00:00
|
|
|
|
2024-01-30 22:35:22 +00:00
|
|
|
/// Command-line arguments for configuring the server
|
2024-01-28 19:30:59 +00:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
#[command(author, version, about, long_about = None)]
|
|
|
|
struct Args {
|
|
|
|
/// Addresses to bind server to
|
|
|
|
#[arg(short, long)]
|
|
|
|
address: Vec<String>,
|
2024-02-08 17:22:06 +00:00
|
|
|
/// Base domain to operate on
|
|
|
|
#[arg(long)]
|
|
|
|
base_domain: String,
|
|
|
|
/// Sub-domain to handle key handling when requested
|
|
|
|
#[arg(long, default_value = "static")]
|
|
|
|
key_endpoint: String
|
2024-01-28 19:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
CombinedLogger::init(
|
|
|
|
vec![
|
|
|
|
TermLogger::new(LevelFilter::Info, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
|
2024-02-08 17:22:06 +00:00
|
|
|
WriteLogger::new(LevelFilter::Info, Config::default(), OpenOptions::new()
|
|
|
|
.read(true)
|
|
|
|
.write(true)
|
|
|
|
.append(true)
|
|
|
|
.create(true)
|
|
|
|
.open("dnstp.log").unwrap()),
|
2024-01-28 19:30:59 +00:00
|
|
|
]
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
info!("======================");
|
|
|
|
info!(" dnstp");
|
|
|
|
info!("======================");
|
|
|
|
|
|
|
|
for a in args.address.iter() {
|
|
|
|
info!("Binding to {}", a)
|
|
|
|
}
|
|
|
|
|
|
|
|
let addresses: Vec<SocketAddr> = args.address
|
|
|
|
.iter()
|
|
|
|
.map(|x| x.parse().expect("Couldn't parse address"))
|
|
|
|
.collect();
|
|
|
|
|
2024-01-28 22:48:35 +00:00
|
|
|
let mut socket = DNSSocket::new(addresses);
|
2024-01-29 07:43:16 +00:00
|
|
|
socket.bind();
|
2024-01-29 00:03:43 +00:00
|
|
|
socket.run_tx();
|
|
|
|
|
2024-02-08 17:22:06 +00:00
|
|
|
let mut processor = RequestProcesor::new(DomainConfig {
|
|
|
|
base_domain: args.base_domain,
|
|
|
|
key_endpoint: args.key_endpoint
|
|
|
|
});
|
2024-01-29 00:03:43 +00:00
|
|
|
processor.run(socket.get_tx_message_channel().expect("couldn't get message transmitting channel"));
|
|
|
|
|
|
|
|
socket.run_rx(processor.get_message_channel().expect("couldn't get message processing channel"));
|
2024-01-28 19:30:59 +00:00
|
|
|
|
2024-01-28 22:48:35 +00:00
|
|
|
thread::park();
|
2024-01-28 19:30:59 +00:00
|
|
|
}
|