Skip to content

Commit

Permalink
Merge pull request #15 from VerisimilitudeX/GPU-MD5-Crack
Browse files Browse the repository at this point in the history
Adds time to crack passcode based on system hardware [Feature]
  • Loading branch information
LimesKey authored Oct 3, 2023
2 parents d773aeb + 5c17e23 commit c33a47e
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 64 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/analyze-powershell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PSScriptAnalyzer

on:
push:
branches: [ "main", "GPU-MD5-Crack" ]
pull_request:
branches: [ "main", "GPU-MD5-Crack" ]

permissions:
contents: write

jobs:
build:
permissions:
contents: write # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: write # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: PSScriptAnalyzer
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Run PSScriptAnalyzer
uses: microsoft/psscriptanalyzer-action@6b2948b1944407914a58661c49941824d149734f
with:
path: .\
recurse: true
includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"'
output: results.sarif

- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif
58 changes: 11 additions & 47 deletions .github/workflows/powershell.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,13 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
#
# https://github.com/microsoft/action-psscriptanalyzer
# For more information on PSScriptAnalyzer in general, see
# https://github.com/PowerShell/PSScriptAnalyzer

name: PSScriptAnalyzer

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '29 8 * * 0'

permissions:
contents: read

name: Run powershell script for PasswordLLM
on: [push]
jobs:
build:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: PSScriptAnalyzer
runs-on: ubuntu-latest
Download_and_Run:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Run PSScriptAnalyzer
uses: microsoft/psscriptanalyzer-action@6b2948b1944407914a58661c49941824d149734f
with:
# Check https://github.com/microsoft/action-psscriptanalyzer for more info about the options.
# The below set up runs PSScriptAnalyzer to your entire repository and runs some basic security rules.
path: .\
recurse: true
# Include your own basic security rules. Removing this option will run all the rules
includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"'
output: results.sarif

# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif
- name: Check out code
uses: actions/checkout@v2


- name: Run the program
shell: pwsh
run: .\PasswordLLM-Installer.ps1 $True
37 changes: 30 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,50 @@ name: Rust

on:
push:
branches: [ "main" ]
branches: [ "main", "master", "GPU-MD5-Crack" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "master", "GPU-MD5-Crack" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: windows-latest

runs-on: ubuntu-latest

steps:
- name: Load OpenCL
run: |
wget -qO - https://repositories.intel.com/graphics/intel-graphics.key |
sudo apt-key add -
sudo add-apt-repository \
'deb [arch=amd64] https://repositories.intel.com/graphics/ubuntu focal main'
sudo apt-get update
sudo apt-get install \
intel-opencl-icd \
intel-level-zero-gpu level-zero \
intel-media-va-driver-non-free libmfx1
sudo apt-get install ocl-icd-opencl-dev
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose

test:
runs-on: ubuntu-latest

steps:
- name: Load OpenCL
run: |
wget -qO - https://repositories.intel.com/graphics/intel-graphics.key |
sudo apt-key add -
sudo add-apt-repository \
'deb [arch=amd64] https://repositories.intel.com/graphics/ubuntu focal main'
sudo apt-get update
sudo apt-get install \
intel-opencl-icd \
intel-level-zero-gpu level-zero \
intel-media-va-driver-non-free libmfx1
sudo apt-get install ocl-icd-opencl-dev
- uses: actions/checkout@v3
- name: Run tests
run: cargo test --verbose
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

#vscode stuff
settings.json

Rockyou.*
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ rpassword = "7.2"
tokio = { version = "1.28.2", features = ["full"] }
pwned = { git = "https://github.com/wisespace-io/pwned-rs.git" }
parselnk = "0.1.1"
regex = "1.9.5"
regex = "1.9.5"
opencl3 = "0.9.3"
thousands = "0.2.0"
Binary file modified PasswordLLM-64x.exe
Binary file not shown.
23 changes: 21 additions & 2 deletions PasswordLLM-Installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ $downloads_folder = (New-Object -ComObject Shell.Application).NameSpace('shell:D
$dir_path = "$downloads_folder/PasswordLLM"
# Creates a temporary windows progam file
$TempFile = New-TemporaryFile
# Accepts parameters for Github Workflow
$GHW = $args[0]

$repo = "VerisimilitudeX/PasswordLLM"
$file = "PasswordLLM-64x.exe"
Expand Down Expand Up @@ -53,14 +55,31 @@ $Shortcut.Save()
if (Test-Path "$dir_path\$file") {
Write-Host "Installed sucessfully, running program now!" -ForegroundColor Green
Set-Location -Path $dir_path
Start-Process -FilePath "$file" -Wait
$processTimer = [System.Diagnostics.Stopwatch]::StartNew()
if ($GHW) {
Write-Host "Running in a Github Workflow Windows machine" -ForegroundColor Cyan
$PasswordLLM_Program = Start-Process -FilePath "$file" -ArgumentList "TestFrog" -PassThru -RedirectStandardOutput output.txt
Start-Sleep -Seconds 50
Stop-Process $PasswordLLM_Program

Write-Output $PasswordLLM_Program
$output = get-content "output.txt"
Write-Output $output
Write-Host "This took $($processTimer.Elapsed.TotalSeconds) seconds to run"
$processTimer.Stop()
}
else {
$program_output = Start-Process -FilePath "$file" -Wait
Write-Host "This took $($processTimer.Elapsed.TotalSeconds) seconds to run"
$processTimer.Stop()
}

Write-Host "Cleaning up... Deleting temp files"
try {
Remove-Item $TempFile.FullName
Remove-Item $ShortcutPath
} catch [System.Exception] {
Write-Host "Something went wrong..." -ForegroundColor Red
Write-Host "Something went wrong..." -ForegroundColor Cyan
Write-Error $_.Exception.Message
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/cal_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pub mod cal_time {
use round::{round, round_up};
use thousands::Separable;

pub fn cal_time(GFLOP_64: u64, Entropy: f64) -> u64 {
let MD5_Hashrate: u64 = (GFLOP_64 * 124) * 1000000;
let combinations = round(f64::powf(2.0, Entropy), 0);

println!("Possible Combinations {}", combinations.separate_with_commas());
let time_sec = round_up((combinations / MD5_Hashrate as f64) / 2.0, 0);
println!("Time: {} seconds", time_sec.separate_with_commas());
return time_sec as u64
// 29,586,412,362,451 / 51584000000 = 573 seconds to crack
}
}
pub mod test {
#[test]
pub fn check_time() {
let GFLOP_64: u64 = 416;
let Entropy = 44.75;

use crate::cal_time;
let result = cal_time(GFLOP_64, Entropy);

assert_eq!(result, 287)
}
}
54 changes: 54 additions & 0 deletions src/gpu/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#[allow(non_snake_case)]

pub mod gpu {
use opencl3::device::{get_all_devices, CL_DEVICE_TYPE_GPU};
use std::io;
pub fn obtainGPU() -> Result<u32, ()> {
let devices: Vec<*mut std::ffi::c_void> = get_all_devices(CL_DEVICE_TYPE_GPU).expect("Cannot detect a GPU!");
let mut gpu_choice: u32 = 0;

if devices.len() > 1 {
loop {
println!("You have multiple ({}) GPUs, please select one!", devices.len());
for gpu in 0..devices.len() {
let device = devices[gpu];
let device = opencl3::device::Device::new(device);
println!("\tGPU Device {}: {}", gpu, device.name().unwrap());
}
print!("Selection: ");

let mut tree = String::new();
io::stdin().read_line(&mut tree).expect("Failed to read line");
let water = tree.trim();

match water.parse::<u32>() {
Ok(_) => {
gpu_choice = water.parse().unwrap();
if gpu_choice > devices.len() as u32 {
panic!("Please select a valid GPU!")
}
break;
}
Err(_) => {
println!("Please type a number!");
}
}
}
}
println!("You have selected GPU Device {}", gpu_choice);
let gpu = opencl3::device::Device::new(devices[gpu_choice as usize]);
let gpu_clock = gpu.max_clock_frequency().unwrap();
let gpu_cores = gpu.max_compute_units();
let gpu_cores = gpu_cores.unwrap(); // use ?
let gpu_cores = gpu_cores * 8;

let gpu_gflops_FP32: u32 = (gpu_clock * gpu_cores * 2) / 1000;
let gpu_gflops_FP64 = ((gpu_clock * gpu_cores * 2) / 4) / 1000;

println!("Your GPU has a clock speed of {} MHz", gpu_clock);
println!("Your {} has {} CUDA cores or {} stream multiprocessors", gpu.name().unwrap(), gpu.max_compute_units().unwrap(), (gpu.max_compute_units().unwrap() * 8));
println!("This GPU has {} GFLOPS for FP32!", gpu_gflops_FP32.to_string()); // todo format properly
println!("Or {} GFLOPS for FP64!", gpu_gflops_FP64);
Ok(gpu_gflops_FP64)
}
}
16 changes: 12 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

mod tests;
mod utils;
mod gpu;
mod cal_time;

use utils::pwned_api::pass_check;
use gpu::gpu::obtainGPU;
use cal_time::cal_time::cal_time;

use std::env;
use std::fs::File;
use std::path::Path;
use utils::pwned_api::pass_check;
use round::round;
use std::fs;
use std::io::{BufRead, BufReader};
Expand All @@ -28,6 +34,8 @@ pub async fn main() {
let pool_size = get_pool_size(password.clone());
let entropy = calculate_entropy(pool_size); // calls functions
let alphabet_match = regex_match(password.clone());
let statistics = obtainGPU(); // todo
cal_time(statistics.unwrap().into(), entropy);

check_if_pwned(password.clone()).await;

Expand Down Expand Up @@ -162,7 +170,7 @@ async fn password_list(password: String) -> Result<bool, ()> {
if passwords == password {
return Ok(true);
}
else if counter % 1000 == 0 { // maybe increase it not sure
else if counter % 4000 == 0 {
println!("Searching...");
counter = 0;
}
Expand All @@ -172,7 +180,7 @@ async fn password_list(password: String) -> Result<bool, ()> {
tokio::time::sleep(Duration::from_secs(1)).await;
}
}
if line >= 2459760 {
if line >= 2459760 { // if it's at the end of the file, stop the search and return password not found
return Ok(false);
}
}
Expand All @@ -185,7 +193,7 @@ async fn password_list(password: String) -> Result<bool, ()> {
println!("{:?}", file.file_name());
}
}
println!("Error 2");
println!("File not found, skipping!");
Err(())
}

Expand Down
9 changes: 6 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ mod test {
}
}
#[tokio::test]
#[cfg(target_os = "windows")]
#[cfg(target_os = "windows")] // I don't have it setup for github runs checks thingy
async fn test_password_list() {
use crate::password_list;

for &(passcode, _, _, _, detected) in TEST_CASES {
let result = password_list(passcode.to_string()).await;
let result = result.ok().unwrap();
assert_eq!(result, detected);
match result {
Ok(worked) => assert_eq!(worked, detected),
Err(error) => panic!("Ah something went wrong! This error is probably not a big issue, you may need to place your rockyou shortcut inside the directory your running cargo test from. the error is : {:?}", error)
}

}
}

Expand Down

0 comments on commit c33a47e

Please sign in to comment.