Skip to content

Commit

Permalink
Code obfuscation bypass and better matches
Browse files Browse the repository at this point in the history
  • Loading branch information
melnary committed Aug 21, 2020
1 parent c97f865 commit 4230775
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-nitro-sniper"
version = "2.4.1"
version = "2.5.0"
authors = ["Mel"]
edition = "2018"

Expand Down
8 changes: 2 additions & 6 deletions src/discord.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::config::Config;
use crate::webhook::Webhook;
use crate::matcher::get_gift_code;
use crate::{log_error_and_exit, pretty_error, pretty_info, pretty_success, pretty_warn};
use colored::*;
use hyper::client::HttpConnector;
use hyper::{Body, Client, Method, Request, StatusCode};
use hyper_tls::HttpsConnector;
use regex::Regex;
use serenity::async_trait;
use serenity::cache::Cache;
use serenity::model::channel::Message;
Expand Down Expand Up @@ -119,12 +119,8 @@ impl Handler {
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
lazy_static! {
static ref GIFT_PATTERN: Regex = Regex::new("(discord.com/gifts/|discordapp.com/gifts/|discord.gift/)([a-zA-Z0-9]{16})([ ,.]|$)").unwrap();
}
if !self.info.config.is_guild_blacklisted(msg.guild_id) {
if let Some(captures) = GIFT_PATTERN.captures(&msg.content) {
let gift_code = captures.get(2).unwrap().as_str().to_string();
if let Some(gift_code) = get_gift_code(&msg) {
let mut seen_codes = self.info.seen_codes.lock().await;
if !seen_codes.contains(&gift_code) {
seen_codes.push(gift_code.clone());
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod config;
mod discord;
mod webhook;
mod matcher;
#[macro_use]
mod logging;

Expand Down
21 changes: 21 additions & 0 deletions src/matcher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use serenity::model::channel::Message;
use regex::Regex;

pub fn get_gift_code(message: &Message) -> Option<String> {
lazy_static! {
static ref GIFT_PATTERN: Regex = Regex::new("(discord.com/gifts/|discordapp.com/gifts/|discord.gift/)[ ]*([a-zA-Z0-9]{16,24})").unwrap();
}
let cleaned_content = sanitize_markdown(&message.content);
if let Some(captures) = GIFT_PATTERN.captures(&cleaned_content) {
Some(captures.get(2).unwrap().as_str().to_string())
} else {
None
}
}

fn sanitize_markdown(dirty_string: &str) -> String {
const MARKDOWN_CHARS: [char; 5] = ['*', '_', '`', '~', '|'];
let mut output = dirty_string.to_string();
output.retain(|c| !MARKDOWN_CHARS.contains(&c));
output
}

0 comments on commit 4230775

Please sign in to comment.