Skip to content

Commit

Permalink
feat: implement share functionality with Pastebin API
Browse files Browse the repository at this point in the history
  • Loading branch information
Kremilly committed Dec 12, 2024
1 parent e746a5f commit 1caaea1
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 101 deletions.
18 changes: 18 additions & 0 deletions src/args_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum Commands {

/// Scan the table for xss prevention
Scan(ScanOptions),

/// Share the dump or scan results
Share(ShareOptions),
}

#[derive(Parser)]
Expand Down Expand Up @@ -102,6 +105,21 @@ pub struct ScanOptions {
/// Limit for scan
pub limit: Option<u64>,

#[arg(short, long)]
/// File path for output
pub file: Option<String>,
}

#[derive(Parser)]
pub struct ShareOptions {
#[arg(short, long)]
/// Privacy level for share
pub privacy: Option<String>,

#[arg(short, long)]
/// Name for share
pub name: Option<u64>,

#[arg(short, long)]
/// File path for output
pub file: Option<String>,
Expand Down
3 changes: 2 additions & 1 deletion src/constants/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ impl Global {

pub const APP_ICON: &'static str = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAYAAABxLuKEAAAACXBIWXMAAC4jAAAuIwF4pT92AAADSklEQVR4nO2aP07jQBSHf95si0QQQgihIBJRUAfJgtocAY4ARwhHIFfIEcgRNjXVuqFBCGEkhBBCKC5ow5stHENY/Gb8Z5zYu++Tpkk8+jlfZuyZZztKKQjf+bHoE6gqIoZBxDCIGAYRwyBiGEQMg4hhEDEMIoZBxDCIGAYRwyBiGEQMg4hhSCPGA6AstTGAXwB6Gc+zCeB82jdv7gWAk7SBjqmCp5TypidkGx/AoeM4oSG/O81vWsodOo5zbDrIKOb9/b0sMQDgNxqNPU12G8Bv2JMS0280Gme6A4xTSSlVZutOJhN2eCulekqpZgm5vclk0tb97p8mMURkOqQoXU22V2KuB2DAfVkFMew/R0Taf7Ug2ulZBTGVzDaKSfncaQBgmPB5E9FtMhcpsgMAp7ZzAXsjJlhaWholffH29pb1nLJkl5ILzGEqFem/qL6AvalUSv+CfbXrFEQLTJa6j5jmeDxurqysfFs9Ly8v93MHo/5iugDGr6+vQ0QjYLi6uhrkDpyh7mJijqbt/OXlJQAwitva2pp2L8ZRdTEhsu+T2oh20ScA8Pz8/CFpfX1de12ZpepiRohGQhG8acPT01MA4GxjYyNpzfUF4yaSiFK1Iv01fftEFKY9hxStTUQXj4+P57UWs7m56RPRIREFFuWAiHoPDw/aDaq1skOR/jparZbfarU6SqlTpdRQKRVaKj1oxVT6GjPL1tbWANMywf39fXzd8KApWxjQ9quNmFm2t7fjOw3u7u7a+BR0BEvVvlqKmaXT6QT4LDid3t7exoKyFty/UHsxf7Ozs+MD8G9ubv5dMdfX16Yi/HB3dzexPFn67nrBCzxTzTexFlM0F6i+mIX0BezVY7yrq6ukzwvdIVJkH5WRC9gbMR/7EZukLDvkXcdokacEDFUQw5YCiCiA5rlTWbnAHGq+KWDvLEqpAaK3HOaaCyx+xAxc19XdcgeIVrG2ryPaXMBi2SFH67uum/Sw7APXdUMiOiYif565QLqpFMIw7DIQIprbo4ODg1Rlxv39/QDA3uXlZTxy8oyezLnG92P+V+QdPAYRwyBiGEQMg4hhEDEMIoZBxDCIGAYRwyBiGEQMg4hhEDEMIoZBxDCIGAYRw/AHZ4ENamm/WDkAAAAASUVORK5CYII=";

pub const PASTEBIN_API_URI: &'static str = "https://pastebin.com/api/api_post.php";
pub const CDN_BOOTSTRAP: &'static str = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css";

pub fn app_config() -> String {
format!("{}.yml", Self::APP_NAME)
}
Expand Down
42 changes: 1 addition & 41 deletions src/core/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use std::{
};

use crate::{
plugins::scan_xss::ScanXSS,
handlers::dump_handlers::DumpHandlers,

ui::{
normal_alerts::NormalAlerts,
success_alerts::SuccessAlerts
Expand All @@ -39,12 +38,6 @@ pub struct Dump {
dbname: String,
password: String,
dump_file_path: String,

table: Option<String>,
payload: Option<String>,
offset: Option<u64>,
limit: Option<u64>,
file: Option<String>,
}

static DUMP_COUNT: AtomicUsize = AtomicUsize::new(0);
Expand All @@ -60,12 +53,6 @@ impl Dump {
backup_path: &str,
interval: Option<u64>,
path: &str,

table: Option<&str>,
payload: Option<&str>,
offset: Option<u64>,
limit: Option<u64>,
file: Option<&str>,
) -> Self {
Self {
port,
Expand All @@ -76,12 +63,6 @@ impl Dump {
dump_file_path: backup_path.to_string(),
interval: interval.unwrap_or(3600),
path: path.to_string(),

table: table.map(|s| s.to_string()),
payload: payload.map(|s| s.to_string()),
offset,
limit,
file: file.map(|s| s.to_string()),
}
}

Expand Down Expand Up @@ -139,12 +120,6 @@ impl Dump {
interval: interval_clone,
dump_file_path: dump_file_path_clone.clone(),
path: path_clone.clone(),

table: None,
payload: None,
offset: None,
limit: None,
file: None,
};

let dump_count = DUMP_COUNT.load(Ordering::SeqCst);
Expand Down Expand Up @@ -183,19 +158,4 @@ impl Dump {
).dump().expect("Failed to transfer dump");
}

pub async fn scan_xss(&self) {
ScanXSS::new(
&self.host,
self.port as u16,
&self.user,
&self.password,
&self.dbname,
self.table.as_deref().unwrap_or(""),
self.payload.as_deref(),
self.offset,
self.limit,
self.file.as_deref(),
).scan().await.expect("Failed to scan tables for XSS");
}

}
119 changes: 62 additions & 57 deletions src/dump_sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use clap::Parser;
use std::error::Error;
use std::{
env,
error::Error,
};

use reqwest;

Expand All @@ -12,10 +15,15 @@ use crate::{
args_cli::*,

ui::ui_base::UI,
helpers::env::Env,
core::dump::Dump,
helpers::env::Env,
constants::global::Global,
ui::success_alerts::SuccessAlerts,

plugins::{
share::Share,
scan_xss::ScanXSS,
},
};

pub struct DumpSync;
Expand All @@ -38,17 +46,17 @@ impl DumpSync {
UI::header();

let dbname = options.database.unwrap_or_else(|| {
std::env::var("DB_NAME").or_else(|_| std::env::var("DS_DB_NAME")).unwrap_or_default()
env::var("DB_NAME").or_else(|_| env::var("DS_DB_NAME")).unwrap_or_default()
});

let backup_path = options.file.unwrap_or_else(|| Env::get_var("DS_DUMP_PATH"));

let host = std::env::var("DB_HOST").or_else(|_| std::env::var("DS_DB_HOST")).unwrap_or_default();
let user = std::env::var("DB_USER").or_else(|_| std::env::var("DS_DB_USER")).unwrap_or_default();
let password = std::env::var("DB_PASSWORD").or_else(|_| std::env::var("DS_DB_PASSWORD")).unwrap_or_default();
let host = env::var("DB_HOST").or_else(|_| env::var("DS_DB_HOST")).unwrap_or_default();
let user = env::var("DB_USER").or_else(|_| env::var("DS_DB_USER")).unwrap_or_default();
let password = env::var("DB_PASSWORD").or_else(|_| env::var("DS_DB_PASSWORD")).unwrap_or_default();

let port = std::env::var("DB_PORT")
.or_else(|_| std::env::var("DS_DB_PORT"))
let port = env::var("DB_PORT")
.or_else(|_| env::var("DS_DB_PORT"))
.unwrap_or_default()
.parse::<u64>()
.expect("Invalid port");
Expand All @@ -64,12 +72,6 @@ impl DumpSync {
&backup_path,
None,
&backup_path,

None,
None,
None,
None,
None
).import();
}

Expand All @@ -78,7 +80,7 @@ impl DumpSync {
UI::header();

let dbname = options.database.unwrap_or_else(|| {
std::env::var("DB_NAME").or_else(|_| std::env::var("DS_DB_NAME")).unwrap_or_default()
env::var("DB_NAME").or_else(|_| env::var("DS_DB_NAME")).unwrap_or_default()
});

let interval = options.interval.unwrap_or_else(|| {
Expand All @@ -87,12 +89,12 @@ impl DumpSync {

let backup_path = options.folder.unwrap_or_else(|| Env::get_var("DS_DUMP_PATH"));

let host = std::env::var("DB_HOST").or_else(|_| std::env::var("DS_DB_HOST")).unwrap_or_default();
let user = std::env::var("DB_USER").or_else(|_| std::env::var("DS_DB_USER")).unwrap_or_default();
let password = std::env::var("DB_PASSWORD").or_else(|_| std::env::var("DS_DB_PASSWORD")).unwrap_or_default();
let host = env::var("DB_HOST").or_else(|_| env::var("DS_DB_HOST")).unwrap_or_default();
let user = env::var("DB_USER").or_else(|_| env::var("DS_DB_USER")).unwrap_or_default();
let password = env::var("DB_PASSWORD").or_else(|_| env::var("DS_DB_PASSWORD")).unwrap_or_default();

let port = std::env::var("DB_PORT")
.or_else(|_| std::env::var("DS_DB_PORT"))
let port = env::var("DB_PORT")
.or_else(|_| env::var("DS_DB_PORT"))
.unwrap_or_default()
.parse::<u64>()
.expect("Invalid port");
Expand All @@ -108,13 +110,7 @@ impl DumpSync {
&dbname,
&backup_path,
Some(interval),
&backup_path,

None,
None,
None,
None,
None
&backup_path,
).export();
}

Expand All @@ -130,38 +126,35 @@ impl DumpSync {
let file = options.file;

let dbname = options.database.unwrap_or_else(|| {
std::env::var("DB_NAME").or_else(|_| std::env::var("DS_DB_NAME")).unwrap_or_default()
env::var("DB_NAME").or_else(|_| env::var("DS_DB_NAME")).unwrap_or_default()
});

let host = std::env::var("DB_HOST").or_else(|_| std::env::var("DS_DB_HOST")).unwrap_or_default();
let user = std::env::var("DB_USER").or_else(|_| std::env::var("DS_DB_USER")).unwrap_or_default();
let password = std::env::var("DB_PASSWORD").or_else(|_| std::env::var("DS_DB_PASSWORD")).unwrap_or_default();
let host = env::var("DB_HOST").or_else(|_| env::var("DS_DB_HOST")).unwrap_or_default();
let user = env::var("DB_USER").or_else(|_| env::var("DS_DB_USER")).unwrap_or_default();
let password = env::var("DB_PASSWORD").or_else(|_| env::var("DS_DB_PASSWORD")).unwrap_or_default();

let port = std::env::var("DB_PORT")
.or_else(|_| std::env::var("DS_DB_PORT"))
let port = env::var("DB_PORT")
.or_else(|_| env::var("DS_DB_PORT"))
.unwrap_or_default()
.parse::<u64>()
.expect("Invalid port");

let header = format!("Scaning table: '{}'", table);
UI::section_header(&header, "info");

Dump::new(
&host,
port,
&user,
&password,
&dbname,
"",
None,
"",

Some(table.as_str()),
ScanXSS::new(
&host,
port as u16,
&user,
&password,
&dbname,
&table,
payload.as_deref(),
Some(offset),
Some(limit),
file.as_deref(),
).scan_xss().await;
).scan().await.expect("Failed to scan tables for XSS");

Ok(())
}

Expand All @@ -170,14 +163,14 @@ impl DumpSync {
UI::header();

let backup_path = options.file.unwrap();
let dbname = std::env::var("DS_TRANSFER_DB_NAME").or_else(|_| std::env::var("DS_TRANSFER_DB_NAME")).unwrap_or_default();
let dbname = env::var("DS_TRANSFER_DB_NAME").or_else(|_| env::var("DS_TRANSFER_DB_NAME")).unwrap_or_default();

let host = std::env::var("DS_TRANSFER_HOST").or_else(|_| std::env::var("DS_TRANSFER_HOST")).unwrap_or_default();
let user = std::env::var("DS_TRANSFER_USER").or_else(|_| std::env::var("DS_TRANSFER_USER")).unwrap_or_default();
let password = std::env::var("DS_TRANSFER_PASSWORD").or_else(|_| std::env::var("DS_TRANSFER_PASSWORD")).unwrap_or_default();
let host = env::var("DS_TRANSFER_HOST").or_else(|_| env::var("DS_TRANSFER_HOST")).unwrap_or_default();
let user = env::var("DS_TRANSFER_USER").or_else(|_| env::var("DS_TRANSFER_USER")).unwrap_or_default();
let password = env::var("DS_TRANSFER_PASSWORD").or_else(|_| env::var("DS_TRANSFER_PASSWORD")).unwrap_or_default();

let port = std::env::var("DS_TRANSFER_PORT")
.or_else(|_| std::env::var("DS_TRANSFER_DB_PORT"))
let port = env::var("DS_TRANSFER_PORT")
.or_else(|_| env::var("DS_TRANSFER_DB_PORT"))
.unwrap_or_default()
.parse::<u64>()
.expect("Invalid port");
Expand All @@ -193,15 +186,23 @@ impl DumpSync {
&backup_path,
None,
&backup_path,

None,
None,
None,
None,
None,
).transfer();
}

pub async fn share(&self, options: ShareOptions) -> Result<(), Box<dyn Error>> {
Env::new();
UI::header();

let file = options.file.unwrap();
let api_key = env::var("PASTEBIN_API_KEY").unwrap_or_default();

let header = format!("Sharing file: '{}'", file);
UI::section_header(&header, "info");

Share::new(&file, &api_key).share().await?;
Ok(())
}

pub async fn init(&self) -> Result<(), Box<dyn Error>> {
let cli = Cli::parse();

Expand All @@ -225,6 +226,10 @@ impl DumpSync {
Commands::Scan(options) => {
self.scan_xss(options).await?;
},

Commands::Share(options) => {
self.share(options).await?;
},
}

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod reports_xss;
pub mod scan_xss;
pub mod share;
pub mod scan_xss;
pub mod reports_xss;
Loading

0 comments on commit 1caaea1

Please sign in to comment.