-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
docs/doc-examples/caesar_shellcode_statistical_analysis/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�%^1ɱ�>|�.�1�1ҳ��fB*f)ڈF��������8�Woihzooipu6o6666��W��Z��ԇ |
1 change: 1 addition & 0 deletions
1
docs/doc-examples/caesar_shellcode_statistical_analysis/data/bin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�%^1ɱ�>|�.�1�1ҳ��fB*f)ڈF��������8�Woihzooipu6o6666��W��Z��ԇ |
2 changes: 2 additions & 0 deletions
2
docs/doc-examples/caesar_shellcode_statistical_analysis/data/how-to-compile-opcode.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
docs/doc-examples/caesar_shellcode_statistical_analysis/data/opcode.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
eb255e31c9b11e803e077c05802e07eb1131db31d2b307b2ff66422a1e6629da881646e2e2eb05e8d6ffffff38c7576f69687a6f6f697075366f3636363690ea5790e95a90e8b712d487 |
1 change: 1 addition & 0 deletions
1
docs/doc-examples/caesar_shellcode_statistical_analysis/data/out.bin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�%^1ɱ�>|�.�1�1ҳ��fB*f)ڈF��������8�Woihzooipu6o6666��W��Z��ԇ |
1 change: 1 addition & 0 deletions
1
docs/doc-examples/caesar_shellcode_statistical_analysis/data/shellcode.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
42 changes: 42 additions & 0 deletions
42
docs/doc-examples/caesar_shellcode_statistical_analysis/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |