Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

TAKEOWN every file subfolder drive and usb port PowerShell script

Enjoy This only works when ran as admin in PowerShell.

Code
# Run this script with elevated privileges (Run as Administrator)

# Specify the drives you want to change ownership for
$targetDrives = @("C:", "E:", "D:", "F:", "I:", "H:")

# Add connected USB drives if any
$usbDrives = Get-WmiObject Win32_DiskDrive | Where-Object { $_.InterfaceType -eq 'USB' } | ForEach-Object {
    $_.Associators("Win32_DiskDriveToDiskPartition") | ForEach-Object {
        $_.Associators("Win32_LogicalDiskToPartition") | ForEach-Object {
            $_.DeviceID
        }
    }
}

$targetDrives += $usbDrives

# Loop through each specified drive and set the owner using takeown command
foreach ($driveLetter in $targetDrives) {
    $drivePath = "$driveLetter\"

    # Set the owner using takeown command
    takeown /F $drivePath /R /A /D Y
}

Write-Host "Ownership changed for specified drives: $($targetDrives -join ', ')"

# Add the code to block all incoming TCP handshakes
New-NetFirewallRule -DisplayName "Block All Incoming TCP" -Direction Inbound -Protocol TCP -Action Block
Hackerone.com/DBMS
Bugcrowd.com/Sleep
[email protected]
Youtube.com/Stripped
Github.com/SleepTheGod
Contact : linkedin.com/in/clumsy/
Contact : T.me/SleepTheGod
Thanks for sharing this. it surely is useful.
[Image: UylCjc.png]
(May 31, 2024 07:45 AM)I ɴ ᴄ ʀ ᴇ ᴅ ɪ ʙ ʟ E Wrote:  Thanks for sharing this. it surely is useful.

Thank you sir glad my scripts are of use to someone :)
Hackerone.com/DBMS
Bugcrowd.com/Sleep
[email protected]
Youtube.com/Stripped
Github.com/SleepTheGod
Contact : linkedin.com/in/clumsy/
Contact : T.me/SleepTheGod
it was fun testing it. Here is an improved version.

PHP Code

<?php 
# Run this script with elevated privileges (Run as Administrator)

# Function to get all connected USB drives
function Get-UsbDrives {
    
$usbDrives = Get-WmiObject Win32_DiskDrive | Where-Object { $_.InterfaceType -eq 'USB' } | ForEach-Object {
        
$_.Associators("Win32_DiskDriveToDiskPartition") | ForEach-Object {
            
$_.Associators("Win32_LogicalDiskToPartition") | ForEach-Object {
                
$_.DeviceID
            
}
        }
    }
    return 
$usbDrives
}

# Function to change ownership of the specified drives
function Change-Ownership {
    
param (
        [
string[]]$drives
    
)

    foreach (
$drive in $drives) {
        
$drivePath = "$drive\"
        Write-Host "
Changing ownership for $drivePath"
        takeown /F 
$drivePath /R /A /D Y
    }
}

# Function to block all incoming TCP handshakes
function Block-IncomingTCP {
    Write-Host "
Blocking all incoming TCP handshakes"
    New-NetFirewallRule -DisplayName "
Block All Incoming TCP" -Direction Inbound -Protocol TCP -Action Block
}

# Main script execution
$targetDrives = @("C:", "E:", "D:", "F:", "I:", "H:")
$targetDrives += Get-UsbDrives

Change-Ownership -drives 
$targetDrives
Write-Host "
Ownership changed for specified drives: $($targetDrives -join ', ')"

Block-IncomingTCP
Write-Host "
Firewall rule added to block all incoming TCP handshakes" 
(Jul 4, 2024 03:07 AM)obtainhigh Wrote:  it was fun testing it. Here is an improved version.

Code
# Run this script with elevated privileges (Run as Administrator)

# Function to get all connected USB drives
function Get-UsbDrives {
    $usbDrives = Get-WmiObject Win32_DiskDrive | Where-Object { $_.InterfaceType -eq 'USB' } | ForEach-Object {
        $_.Associators("Win32_DiskDriveToDiskPartition") | ForEach-Object {
            $_.Associators("Win32_LogicalDiskToPartition") | ForEach-Object {
                $_.DeviceID
            }
        }
    }
    return $usbDrives
}

# Function to change ownership of the specified drives
function Change-Ownership {
    param (
        [string[]]$drives
    )

    foreach ($drive in $drives) {
        $drivePath = "$drive\"
        Write-Host "Changing ownership for $drivePath"
        takeown /F $drivePath /R /A /D Y
    }
}

# Function to block all incoming TCP handshakes
function Block-IncomingTCP {
    Write-Host "Blocking all incoming TCP handshakes"
    New-NetFirewallRule -DisplayName "Block All Incoming TCP" -Direction Inbound -Protocol TCP -Action Block
}

# Main script execution
$targetDrives = @("C:", "E:", "D:", "F:", "I:", "H:")
$targetDrives += Get-UsbDrives

Change-Ownership -drives $targetDrives
Write-Host "Ownership changed for specified drives: $($targetDrives -join ', ')"

Block-IncomingTCP
Write-Host "Firewall rule added to block all incoming TCP handshakes"

You just rewrote the code blocks as functions.
(Jul 4, 2024 06:56 AM)DramaKing Wrote:  You just rewrote the code blocks as functions.

DramaKing clearly posts trash and doesnt know anything about computers. Loser.
Do you have any doubt about that


Possibly Related Threads...
Thread / Author Replies Views Last Post
by aravOct 28, 2024 03:54 PM 15 511 Oct 28, 2024 03:54 PM
Last Post: woo097878781
by Py_DevApr 21, 2024 05:54 AM 3 250 Apr 21, 2024 05:54 AM
Last Post: DramaKing
by Smurfboi007Oct 9, 2022 07:17 AM 4 114 Oct 9, 2022 07:17 AM
Last Post: Smurfboi007