Skip to content

Commit

Permalink
rename: mitm -> eavesdrop
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op committed Mar 25, 2023
1 parent 196dc4f commit e5398c4
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 95 deletions.
12 changes: 6 additions & 6 deletions boltadm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct CertOptions {
}

#[derive(Debug, StructOpt)]
enum MitmOptions {
enum EavesdropOptions {
/// List all captured data
List,
/// List data ranged from *start* to *end*
Expand All @@ -77,7 +77,7 @@ enum SubCommand {
/// Generate Certificates
Cert(CertOptions),
/// Captured HTTP data
Mitm(MitmOptions),
Eavesdrop(EavesdropOptions),
/// Clean unexpected shutdown
Clean,
/// Reload Configuration
Expand Down Expand Up @@ -128,10 +128,10 @@ async fn main() {
Err(e) => Err(e),
}
}
SubCommand::Mitm(opt) => match opt {
MitmOptions::List => requestor.get_mitm(None).await,
MitmOptions::Range { start, end } => requestor.get_mitm(Some((start, end))).await,
MitmOptions::Get { id } => requestor.get_mitm_payload(id).await,
SubCommand::Eavesdrop(opt) => match opt {
EavesdropOptions::List => requestor.eavesdrop(None).await,
EavesdropOptions::Range { start, end } => requestor.eavesdrop(Some((start, end))).await,
EavesdropOptions::Get { id } => requestor.get_eavesdrop_payload(id).await,
},
SubCommand::Clean => {
if !is_root() {
Expand Down
18 changes: 10 additions & 8 deletions boltadm/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ impl Requester {
Ok(())
}

pub async fn get_mitm(&self, range: Option<(u32, Option<u32>)>) -> Result<()> {
pub async fn eavesdrop(&self, range: Option<(u32, Option<u32>)>) -> Result<()> {
let uri = match range {
None => self.route("/mitm/all"),
Some((s, Some(e))) => self.route(format!("/mitm/range?start={}&end={}", s, e).as_str()),
Some((s, None)) => self.route(format!("/mitm/range?start={}", s).as_str()),
None => self.route("/eavesdrop/all"),
Some((s, Some(e))) => {
self.route(format!("/eavesdrop/range?start={}&end={}", s, e).as_str())
}
Some((s, None)) => self.route(format!("/eavesdrop/range?start={}", s).as_str()),
};
let data = reqwest::get(uri).await?.text().await?;
let result: Vec<boltapi::HttpMitmSchema> = serde_json::from_str(data.as_str())?;
let result: Vec<boltapi::HttpEavesdropSchema> = serde_json::from_str(data.as_str())?;
let mut table = Table::new("{:<} {:<} {:<} {:<} {:<} {:<}");
table.add_row(
Row::new()
Expand All @@ -152,12 +154,12 @@ impl Requester {
Ok(())
}

pub async fn get_mitm_payload(&self, id: u32) -> Result<()> {
let data = reqwest::get(self.route(format!("/mitm/payload/{}", id).as_str()))
pub async fn get_eavesdrop_payload(&self, id: u32) -> Result<()> {
let data = reqwest::get(self.route(format!("/eavesdrop/payload/{}", id).as_str()))
.await?
.text()
.await?;
let result: boltapi::GetMitmDataResp = serde_json::from_str(data.as_str())?;
let result: boltapi::GetEavesdropDataResp = serde_json::from_str(data.as_str())?;
println!("================== Request ===================");
println!("Header:");
result.req_header.iter().for_each(|l| println!("{}", l));
Expand Down
10 changes: 5 additions & 5 deletions boltapi/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct SessionSchema {

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct HttpMitmSchema {
pub mitm_id: u64,
pub struct HttpEavesdropSchema {
pub eavesdrop_id: u64,
pub client: Option<String>,
pub uri: String,
pub method: String,
Expand Down Expand Up @@ -58,20 +58,20 @@ pub struct SetGroupReqSchema {

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct GetMitmRangeReq {
pub struct GetEavesdropRangeReq {
pub start: u32,
pub end: Option<u32>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct GetMitmDataReq {
pub struct GetEavesdropDataReq {
pub id: u32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct GetMitmDataResp {
pub struct GetEavesdropDataResp {
pub req_header: Vec<String>,
#[serde(with = "base64ext")]
pub req_body: Vec<u8>,
Expand Down
4 changes: 2 additions & 2 deletions boltconn/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub struct RawRootCfg {
pub rule_local: Vec<String>,
#[serde(alias = "rule-provider", default = "default_rule_provider")]
pub rule_provider: HashMap<String, RuleProvider>,
#[serde(alias = "mitm-rule")]
pub mitm_rule: Option<Vec<String>>,
#[serde(alias = "eavesdrop-rule")]
pub eavesdrop_rule: Option<Vec<String>>,
#[serde(alias = "rewrite-rule")]
pub rewrite: Option<Vec<String>>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::mitm::url_rewrite::{UrlModManager, UrlModType};
use crate::mitm::{HeaderModManager, Modifier, ModifierContext};
use crate::eavesdrop::url_rewrite::{UrlModManager, UrlModType};
use crate::eavesdrop::{HeaderModManager, Modifier, ModifierContext};
use crate::platform::process::ProcessInfo;
use crate::proxy::{DumpedRequest, DumpedResponse, HttpCapturer, NetworkAddr};
use anyhow::anyhow;
Expand All @@ -11,15 +11,15 @@ use std::str::FromStr;
use std::sync::Arc;
use std::time::Instant;

pub struct MitmModifier {
pub struct EavesdropModifier {
client: Option<ProcessInfo>,
contents: Arc<HttpCapturer>,
url_rewriter: Arc<UrlModManager>,
header_rewriter: Arc<HeaderModManager>,
pending: DashMap<u64, DumpedRequest>,
}

impl MitmModifier {
impl EavesdropModifier {
pub fn new(
contents: Arc<HttpCapturer>,
url_rewriter: Arc<UrlModManager>,
Expand All @@ -37,7 +37,7 @@ impl MitmModifier {
}

#[async_trait]
impl Modifier for MitmModifier {
impl Modifier for EavesdropModifier {
async fn modify_request(
&self,
req: Request<Body>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::mitm::Replacement;
use crate::eavesdrop::Replacement;
use http::header::HeaderName;
use http::{HeaderMap, HeaderValue};
use regex::{Regex, RegexSet};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::adapter::{Connector, TcpOutBound};
use crate::common::duplex_chan::DuplexChan;
use crate::common::id_gen::IdGenerator;
use crate::mitm::modifier::Modifier;
use crate::mitm::ModifierContext;
use crate::eavesdrop::modifier::Modifier;
use crate::eavesdrop::ModifierContext;
use crate::proxy::{ConnAbortHandle, ConnAgent};
use hyper::client::conn;
use hyper::server::conn::Http;
Expand All @@ -12,14 +12,14 @@ use std::io;
use std::sync::Arc;
use tokio::sync::RwLock;

pub struct HttpMitm {
pub struct HttpEavesdrop {
inbound: DuplexChan,
modifier: Arc<dyn Modifier>,
creator: Arc<dyn TcpOutBound>,
conn_info: Arc<RwLock<ConnAgent>>,
}

impl HttpMitm {
impl HttpEavesdrop {
pub fn new(
inbound: DuplexChan,
modifier: Arc<dyn Modifier>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::adapter::{Connector, TcpOutBound};
use crate::common::duplex_chan::DuplexChan;
use crate::common::id_gen::IdGenerator;
use crate::mitm::modifier::Modifier;
use crate::mitm::{sign_site_cert, ModifierContext};
use crate::eavesdrop::modifier::Modifier;
use crate::eavesdrop::{sign_site_cert, ModifierContext};
use crate::proxy::{ConnAbortHandle, ConnAgent};
use hyper::client::conn;
use hyper::server::conn::Http;
Expand All @@ -18,7 +18,7 @@ use tokio_rustls::rustls::{
};
use tokio_rustls::{TlsAcceptor, TlsConnector};

pub struct HttpsMitm {
pub struct HttpsEavesdrop {
cert: Vec<Certificate>,
priv_key: PrivateKey,
server_name: String,
Expand All @@ -28,7 +28,7 @@ pub struct HttpsMitm {
conn_info: Arc<RwLock<ConnAgent>>,
}

impl HttpsMitm {
impl HttpsEavesdrop {
pub fn new(
ca_cert: &CaCertificate,
server_name: String,
Expand Down
12 changes: 6 additions & 6 deletions boltconn/src/mitm/mod.rs → boltconn/src/eavesdrop/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
mod eavesdrop_modifier;
mod header_rewrite;
mod http_mitm;
mod https_mitm;
mod mitm_modifier;
mod http_eavesdrop;
mod https_eavesdrop;
mod modifier;
mod url_rewrite;

pub use eavesdrop_modifier::*;
pub use header_rewrite::*;
pub use http_mitm::HttpMitm;
pub use https_mitm::HttpsMitm;
pub use mitm_modifier::*;
pub use http_eavesdrop::HttpEavesdrop;
pub use https_eavesdrop::HttpsEavesdrop;
pub use modifier::*;
use rcgen::{
date_time_ymd, Certificate, CertificateParams, DistinguishedName, DnType, IsCa, KeyUsagePurpose,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::mitm::ReplacedChunk;
use crate::eavesdrop::ReplacedChunk;
use regex::{Regex, RegexSet};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
23 changes: 12 additions & 11 deletions boltconn/src/external/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use axum::response::IntoResponse;
use axum::routing::{delete, get, post};
use axum::{Json, Router};
use boltapi::{
GetGroupRespSchema, GetMitmDataResp, GetMitmRangeReq, ProxyData, SetGroupReqSchema, TrafficResp,
GetEavesdropDataResp, GetEavesdropRangeReq, GetGroupRespSchema, ProxyData, SetGroupReqSchema,
TrafficResp,
};
use serde_json::json;
use std::collections::HashMap;
Expand Down Expand Up @@ -75,9 +76,9 @@ impl ApiServer {
)
.route("/connections/:id", delete(Self::stop_conn))
.route("/sessions", get(Self::get_sessions))
.route("/mitm/all", get(Self::get_mitm))
.route("/mitm/range", get(Self::get_mitm_range))
.route("/mitm/payload/:id", get(Self::get_mitm_payload))
.route("/eavesdrop/all", get(Self::get_eavesdrop))
.route("/eavesdrop/range", get(Self::get_eavesdrop_range))
.route("/eavesdrop/payload/:id", get(Self::get_eavesdrop_payload))
.route("/proxies", get(Self::get_all_proxies))
.route(
"/proxies/:group",
Expand Down Expand Up @@ -252,8 +253,8 @@ impl ApiServer {
) -> Json<serde_json::Value> {
let mut result = Vec::new();
for (idx, (host, proc, req, resp)) in list.into_iter().enumerate() {
let item = boltapi::HttpMitmSchema {
mitm_id: idx as u64,
let item = boltapi::HttpEavesdropSchema {
eavesdrop_id: idx as u64,
client: proc.map(|proc| proc.name),
uri: {
let s = req.uri.to_string();
Expand All @@ -275,7 +276,7 @@ impl ApiServer {
Json(json!(result))
}

async fn get_mitm(State(server): State<Self>) -> Json<serde_json::Value> {
async fn get_eavesdrop(State(server): State<Self>) -> Json<serde_json::Value> {
if let Some(capturer) = &server.http_capturer {
let list = capturer.get_copy();
Self::collect_captured(list)
Expand All @@ -284,9 +285,9 @@ impl ApiServer {
}
}

async fn get_mitm_range(
async fn get_eavesdrop_range(
State(server): State<Self>,
Query(params): Query<GetMitmRangeReq>,
Query(params): Query<GetEavesdropRangeReq>,
) -> Json<serde_json::Value> {
if let Some(capturer) = &server.http_capturer {
if let Some(list) =
Expand All @@ -298,7 +299,7 @@ impl ApiServer {
Json(serde_json::Value::Null)
}

async fn get_mitm_payload(
async fn get_eavesdrop_payload(
State(server): State<Self>,
Path(params): Path<HashMap<String, String>>,
) -> Json<serde_json::Value> {
Expand All @@ -314,7 +315,7 @@ impl ApiServer {
if let Some(list) = capturer.get_range_copy(id, Some(id + 1)) {
if list.len() == 1 {
let (_, _, req, resp) = list.get(0).unwrap();
let result = GetMitmDataResp {
let result = GetEavesdropDataResp {
req_header: req
.headers
.iter()
Expand Down
Loading

0 comments on commit e5398c4

Please sign in to comment.