Skip to content

Commit

Permalink
TestCpu++
Browse files Browse the repository at this point in the history
  • Loading branch information
Aif4thah committed Jun 7, 2024
1 parent 9072606 commit 3167e7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
if(!string.IsNullOrEmpty(test))
{
Console.WriteLine("Start CPU Testing");
TestCpu.TestAffinity(Secret);
TestCpu.TestAffinity();
}

if (string.IsNullOrEmpty(url))
Expand Down
49 changes: 19 additions & 30 deletions TestCpu/TestCpu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,42 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.Arm;
using System.Security.Cryptography;
using System.Text;
using System.Threading;


namespace VulnerableWebApplication.TestCpu
{
/*
Test de perfs sur un seul proc (compatible Windows et Linux uniquement)
*/
public class TestCpu
{
public static void TestAffinity(string Str)
public static void TestAffinity()
{
string BinStr = ConvertToBinary(Str);
byte[] bytes = File.ReadAllBytes("appsettings.json");
StringBuilder binary = new StringBuilder();
var sha256 = SHA256.Create();
foreach (byte b in bytes) binary.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
string BinStr = binary.ToString();

Console.WriteLine("Total proc: {0}", Environment.ProcessorCount);
foreach (char bit in BinStr)
{
Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)(bit - '0' +1);
CalculateSHA512(Str);
}
Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)5;
}

public static string ConvertToBinary(string input)
{
byte[] bytes = Encoding.UTF8.GetBytes(input);
StringBuilder binary = new StringBuilder();

foreach (byte b in bytes) binary.Append(Convert.ToString(b,2).PadLeft(8,'0'));

return binary.ToString();
}

public static void CalculateSHA512(string input)
{
{
var stopWatch = new Stopwatch();
stopWatch.Start();
while (stopWatch.Elapsed.TotalSeconds < 5)
Thread.Sleep(1000);
if (bit == '0') Thread.Sleep(4000);
else
{
using (var sha256 = SHA256.Create())
{
var bytes = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());
var hash = sha256.ComputeHash(bytes);
}
Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)(bit - '0' + 1);
var stopWatch = new Stopwatch();
stopWatch.Start();
while (stopWatch.Elapsed.TotalSeconds < 4) sha256.ComputeHash(bytes);
stopWatch.Stop();
}
stopWatch.Stop();
}
Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)5;
}

}
Expand Down

0 comments on commit 3167e7c

Please sign in to comment.