Skip to content

Commit

Permalink
Add caesar shellcode example.
Browse files Browse the repository at this point in the history
  • Loading branch information
gogo2464 committed Sep 7, 2023
1 parent e183775 commit 8b85cf9
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ members = [
"cryptatools-gui",
"docs/doc-examples/ethereum-colision-evaluation",
"docs/doc-examples/ethereum-wallet-collision-with-web3js",
"docs/doc-examples/ethereum-wallet-collision-with-web3js-node"
"docs/doc-examples/ethereum-wallet-collision-with-web3js-node",
"docs/doc-examples/caesar_shellcode_statistical_analysis"
]
12 changes: 12 additions & 0 deletions docs/doc-examples/caesar_shellcode_statistical_analysis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "caesar_shellcode_1_statistical_analysis"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cryptatools-core = { git = "https://github.com/gogo2464/cryptatools-rs", package = 'cryptatools-core' }
serde_json = "1.0.91"
r2pipe = { git = "https://github.com/RHL120/r2pipe.rs", branch = "windows_bad" }
itertools = "0.10.5"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�%^1ɱ�>|�.�1�1ҳ��fB*f)ڈF��������8�Woihzooipu6o6666��W��Z��ԇ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�%^1ɱ�>|�.�1�1ҳ��fB*f)ڈF��������8�Woihzooipu6o6666��W��Z��ԇ
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "$(cat shellcode.txt | tr -d 'x' | tr -d '\\' | tr -d '\n')" > opcode.txt
xxd -r -p opcode.txt bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eb255e31c9b11e803e077c05802e07eb1131db31d2b307b2ff66422a1e6629da881646e2e2eb05e8d6ffffff38c7576f69687a6f6f697075366f3636363690ea5790e95a90e8b712d487
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�%^1ɱ�>|�.�1�1ҳ��fB*f)ڈF��������8�Woihzooipu6o6666��W��Z��ԇ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\xeb\x25\x5e\x31\xc9\xb1\x1e\x80\x3e\x07\x7c\x05\x80\x2e\x07\xeb\x11\x31\xdb\x31\xd2\xb3\x07\xb2\xff\x66\x42\x2a\x1e\x66\x29\xda\x88\x16\x46\xe2\xe2\xeb\x05\xe8\xd6\xff\xff\xff\x38\xc7\x57\x6f\x69\x68\x7a\x6f\x6f\x69\x70\x75\x36\x6f\x36\x36\x36\x36\x90\xea\x57\x90\xe9\x5a\x90\xe8\xb7\x12\xd4\x87
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use r2pipe::R2Pipe;
use r2pipe::open_pipe;
use cryptatools_core::utils::alphabets::Alphabet;
use cryptatools_core::cryptanalysis::custom::general_cryptanalysis_methods::frequency_analysis::distribution_algorithms::statistical::Statistical;
use std::u8;

fn read_plain_text(cipher_text: String) -> Vec<u8> {
let mut bytes = Vec::new();
for o in (0..cipher_text.len()).step_by(2) {
let left = cipher_text.chars().nth(o).unwrap();
let right = cipher_text.chars().nth(o+1).unwrap();
let mut opcode = String::from(left);
opcode.push(right);
bytes.push(u8::from_str_radix(&opcode, 16).unwrap());
}

bytes
}

fn main() {
let mut r2p = open_pipe!(Some("bin")).unwrap();
let mut cipher_text = String::from(r2p.cmd("p8 0x1e @ 0x2c ;").unwrap());
cipher_text.remove(cipher_text.len()-1);
cipher_text.remove(cipher_text.len()-1);

println!("cipher text: {:?}", cipher_text);

let unknow_opcode_alphabet = Alphabet::new_empty().unknow_opcodes();

let bytes = read_plain_text(cipher_text);

let stat = Statistical::new(unknow_opcode_alphabet.clone());
let stat_percentage = stat.guess_statistical_distribution(bytes);

for character in stat_percentage {
for opcode in character.0 {
println!("opcode {:x}, statistic: {:?}", opcode, character.1);
}
}

r2p.close();
}

0 comments on commit 8b85cf9

Please sign in to comment.