Added Callback return types.
This commit is contained in:
parent
32d5555004
commit
953ff1fda5
4 changed files with 82 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use sslrelay::{self, ConfigType, RelayConfig, HandlerCallbacks};
|
use sslrelay::{self, ConfigType, RelayConfig, HandlerCallbacks, CallbackRet};
|
||||||
|
|
||||||
// Handler object
|
// Handler object
|
||||||
#[derive(Clone)] // Must have Clone trait implemented.
|
#[derive(Clone)] // Must have Clone trait implemented.
|
||||||
|
|
@ -16,8 +16,9 @@ impl HandlerCallbacks for Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownStream blocking callback
|
// DownStream blocking callback
|
||||||
fn ds_b_callback(&self, _in_data: &mut Vec<u8>) {
|
fn ds_b_callback(&self, _in_data: Vec<u8>) {
|
||||||
println!("[CALLBACK] Down Stream Blocking CallBack!");
|
println!("[CALLBACK] Down Stream Blocking CallBack!");
|
||||||
|
CallbackRet::Relay(_in_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpStream non blocking callback
|
// UpStream non blocking callback
|
||||||
|
|
@ -26,8 +27,9 @@ impl HandlerCallbacks for Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpStream blocking callback
|
// UpStream blocking callback
|
||||||
fn us_b_callback(&self, _in_data: &mut Vec<u8>) {
|
fn us_b_callback(&self, _in_data: Vec<u8>) {
|
||||||
println!("[CALLBACK] Up Stream Blocking CallBack!");
|
println!("[CALLBACK] Up Stream Blocking CallBack!");
|
||||||
|
CallbackRet::Relay(_in_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,10 @@ impl HandlerCallbacks for Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownStream blocking callback
|
// DownStream blocking callback
|
||||||
fn ds_b_callback(&self, _in_data: &mut Vec<u8>) {
|
fn ds_b_callback(&self, _in_data: Vec<u8>) {
|
||||||
_in_data.reverse();
|
_in_data.reverse();
|
||||||
println!("[+] Data rewritten to:\n{:#04X?}", _in_data);
|
println!("[+] Data rewritten to:\n{:#04X?}", _in_data);
|
||||||
|
CallbackRet::Relay(_in_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpStream non blocking callback
|
// UpStream non blocking callback
|
||||||
|
|
@ -27,9 +28,10 @@ impl HandlerCallbacks for Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpStream blocking callback
|
// UpStream blocking callback
|
||||||
fn us_b_callback(&self, _in_data: &mut Vec<u8>) {
|
fn us_b_callback(&self, _in_data: Vec<u8>) {
|
||||||
_in_data.reverse();
|
_in_data.reverse();
|
||||||
println!("[+] Data rewritten to:\n{:#04X?}", _in_data);
|
println!("[+] Data rewritten to:\n{:#04X?}", _in_data);
|
||||||
|
CallbackRet::Relay(_in_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
76
src/data.rs
76
src/data.rs
|
|
@ -6,7 +6,7 @@ use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crate::{HandlerCallbacks, InnerHandlers};
|
use crate::{HandlerCallbacks, CallbackRet, InnerHandlers};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum FullDuplexTcpState {
|
enum FullDuplexTcpState {
|
||||||
|
|
@ -378,10 +378,15 @@ impl<H: HandlerCallbacks + std::marker::Sync + std::marker::Send + Clone + 'stat
|
||||||
match state_request {
|
match state_request {
|
||||||
|
|
||||||
// DownStream Write Request
|
// DownStream Write Request
|
||||||
FullDuplexTcpState::DownStreamWrite(mut data) => {
|
FullDuplexTcpState::DownStreamWrite(data) => {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Callbacks that work with data from UpStream go here
|
Callbacks that work with data from UpStream go here
|
||||||
|
Add callback return types for blocking callback subroutines
|
||||||
|
Shutdown - Shutdown TCP connection
|
||||||
|
Relay - Relay TCP stream
|
||||||
|
Spoof - Spoof back to received stream direction
|
||||||
|
Freeze - Freeze data (dont relay and destroy data)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let inner_handlers_clone = self.inner_handlers.clone();
|
let inner_handlers_clone = self.inner_handlers.clone();
|
||||||
|
|
@ -391,17 +396,40 @@ impl<H: HandlerCallbacks + std::marker::Sync + std::marker::Send + Clone + 'stat
|
||||||
inner_handlers_clone.cb.us_nb_callback(in_data);
|
inner_handlers_clone.cb.us_nb_callback(in_data);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.inner_handlers.cb.us_b_callback(&mut data);
|
match self.inner_handlers.cb.us_b_callback(data) {
|
||||||
match ds_data_pipe_sender.send(DataPipe::DataWrite(data)) {
|
CallbackRet::Relay(retdata) => {
|
||||||
Ok(()) => {},
|
match ds_data_pipe_sender.send(DataPipe::DataWrite(retdata)) {
|
||||||
Err(e) => {
|
Ok(()) => {},
|
||||||
println!("[SSLRelay Error]: Failed to send data write to DownStream thread: {}", e);
|
Err(e) => {
|
||||||
|
println!("[SSLRelay Error]: Failed to send data write to DownStream thread: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CallbackRet::Spoof(retdata) => {
|
||||||
|
match us_data_pipe_sender.send(DataPipe::DataWrite(retdata)) {
|
||||||
|
Ok(()) => {},
|
||||||
|
Err(e) => {
|
||||||
|
println!("[SSLRelay Error]: Failed to send data write to DownStream thread: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CallbackRet::Freeze => {},
|
||||||
|
CallbackRet::Shutdown => {
|
||||||
|
if let Err(e) = us_data_pipe_sender.send(DataPipe::Shutdown) {
|
||||||
|
println!("[SSLRelay Error]: Failed to send Shutdown signal to UpStream thread: {}", e);
|
||||||
|
}
|
||||||
|
if let Err(e) = ds_data_pipe_sender.send(DataPipe::Shutdown) {
|
||||||
|
println!("[SSLRelay Error]: Failed to send Shutdown signal to DownStream thread: {}", e);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
// UpStream Write Request
|
// UpStream Write Request
|
||||||
FullDuplexTcpState::UpStreamWrite(mut data) => {
|
FullDuplexTcpState::UpStreamWrite(data) => {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Callbacks that work with data from DownStream go here
|
Callbacks that work with data from DownStream go here
|
||||||
|
|
@ -414,12 +442,34 @@ impl<H: HandlerCallbacks + std::marker::Sync + std::marker::Send + Clone + 'stat
|
||||||
inner_handlers_clone.cb.ds_nb_callback(in_data);
|
inner_handlers_clone.cb.ds_nb_callback(in_data);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.inner_handlers.cb.ds_b_callback(&mut data);
|
match self.inner_handlers.cb.ds_b_callback(data) {
|
||||||
|
CallbackRet::Relay(retdata) => {
|
||||||
|
match us_data_pipe_sender.send(DataPipe::DataWrite(retdata)) {
|
||||||
|
Ok(()) => {},
|
||||||
|
Err(e) => {
|
||||||
|
println!("[SSLRelay Error]: Failed to send data write to UpStream thread: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CallbackRet::Spoof(retdata) => {
|
||||||
|
match ds_data_pipe_sender.send(DataPipe::DataWrite(retdata)) {
|
||||||
|
Ok(()) => {},
|
||||||
|
Err(e) => {
|
||||||
|
println!("[SSLRelay Error]: Failed to send data write to DownStream thread: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CallbackRet::Freeze => {},
|
||||||
|
CallbackRet::Shutdown => {
|
||||||
|
if let Err(e) = ds_data_pipe_sender.send(DataPipe::Shutdown) {
|
||||||
|
println!("[SSLRelay Error]: Failed to send Shutdown signal to DownStream thread: {}", e);
|
||||||
|
|
||||||
match us_data_pipe_sender.send(DataPipe::DataWrite(data)) {
|
}
|
||||||
Ok(()) => {},
|
if let Err(e) = us_data_pipe_sender.send(DataPipe::Shutdown) {
|
||||||
Err(e) => {
|
println!("[SSLRelay Error]: Failed to send Shutdown signal to UpStream thread: {}", e);
|
||||||
println!("[SSLRelay Error]: Failed to send data write to UpStream thread: {}", e);
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/lib.rs
12
src/lib.rs
|
|
@ -22,9 +22,9 @@ pub struct RelayConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HandlerCallbacks {
|
pub trait HandlerCallbacks {
|
||||||
fn ds_b_callback(&self, _in_data: &mut Vec<u8>){}
|
fn ds_b_callback(&self, _in_data: Vec<u8>) -> CallbackRet {CallbackRet::Relay(_in_data)}
|
||||||
fn ds_nb_callback(&self, _in_data: Vec<u8>){}
|
fn ds_nb_callback(&self, _in_data: Vec<u8>){}
|
||||||
fn us_b_callback(&self, _in_data: &mut Vec<u8>){}
|
fn us_b_callback(&self, _in_data: Vec<u8>) -> CallbackRet {CallbackRet::Relay(_in_data)}
|
||||||
fn us_nb_callback(&self, _in_data: Vec<u8>){}
|
fn us_nb_callback(&self, _in_data: Vec<u8>){}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,6 +35,14 @@ pub enum ConfigType<T> {
|
||||||
Default,
|
Default,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum CallbackRet {
|
||||||
|
Relay(Vec<u8>),// Relay data
|
||||||
|
Spoof(Vec<u8>),// Skip relaying and send data back
|
||||||
|
Shutdown,// Shutdown TCP connection
|
||||||
|
Freeze,// Dont send data (pretend as if stream never was recieved)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SSLRelay<H>
|
pub struct SSLRelay<H>
|
||||||
where
|
where
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue