Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 08dee660f5 |
@@ -39,7 +39,6 @@ script=/tmp/install_script.sh && curl -s https://git.thecoven.info/PrincessPi/ge
|
||||
* `large_file_search_for_hash`
|
||||
* `randomtoken`
|
||||
* `alfa_install_kali.sh`
|
||||
* `torsilly.sh`
|
||||
|
||||
#### monitoring
|
||||
* `mon-watch`
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+138
-227
@@ -5,40 +5,30 @@ param(
|
||||
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
|
||||
[string[]]$FilePath,
|
||||
|
||||
# Output file switch (-o) - auto generates file based on rules
|
||||
# Output file to save generated checksums (-o mode)
|
||||
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
||||
[Alias('o', 'out')]
|
||||
[switch]$SaveToFile,
|
||||
|
||||
# Custom Output file name (-f)
|
||||
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
||||
[Alias('f', 'outfile')]
|
||||
[Alias('o')]
|
||||
[string]$OutFile,
|
||||
|
||||
# File containing checksums to verify (-c mode)
|
||||
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
|
||||
[Alias('c', 'check')]
|
||||
[Alias('c')]
|
||||
[string]$Check,
|
||||
|
||||
# Direct checksum hash string to match against (-m mode)
|
||||
[Parameter(Mandatory = $true, ParameterSetName = 'Match')]
|
||||
[Alias('m', 'match')]
|
||||
[Alias('m')]
|
||||
[string]$Match,
|
||||
|
||||
# Hashing algorithm to use (Defaults to SHA256)
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias('a', 'algo', 'algorithm')]
|
||||
[Alias('a')]
|
||||
[ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5')]
|
||||
[string]$Algorithm,
|
||||
|
||||
# Recursive flag (-r)
|
||||
# Help flag (-h, -Help)
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias('r', 'recursive')]
|
||||
[switch]$Recursive,
|
||||
|
||||
# Help flag (-h)
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias('h', 'help')]
|
||||
[Alias('h')]
|
||||
[switch]$Help
|
||||
)
|
||||
|
||||
@@ -49,60 +39,53 @@ NAME
|
||||
checksum - Compute and verify message digests / file checksums
|
||||
|
||||
SYNOPSIS
|
||||
.\checksum.ps1 [-FilePath] <string[]> [-o] [-OutFile <string>] [-Algorithm <string>] [-r]
|
||||
.\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>] [-r]
|
||||
.\checksum.ps1 -Check <string> [-Algorithm <string>] [-r]
|
||||
.\checksum.ps1 [-FilePath] <string[]> [-OutFile <string>] [-Algorithm <string>]
|
||||
.\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>]
|
||||
.\checksum.ps1 -Check <string> [-Algorithm <string>]
|
||||
.\checksum.ps1 -Help
|
||||
|
||||
DESCRIPTION
|
||||
Computes or verifies checksums using various cryptographic algorithms.
|
||||
Outputs hash values in standard Linux utility format (<hash> <filename>).
|
||||
Ignores checksum files (.md5, .sha1, .sha256, .sha384, .sha512) unless explicitly passed.
|
||||
|
||||
PARAMETERS
|
||||
-FilePath <string[]>
|
||||
Specifies the path to one or more files to hash. Accepts wildcards (*).
|
||||
|
||||
-o, -Out, --Out <switch>
|
||||
Enables writing checksum results to an auto-named file.
|
||||
- If input has a wildcard (*), outputs to 'checksums.<algo>'
|
||||
- If no wildcard is used, outputs to '<filename>.<algo>' per file.
|
||||
When combined with -r and *, it auto-generates checksum files
|
||||
inside the current working directory and each subdirectory recursively.
|
||||
-o, -OutFile <string>
|
||||
Specifies an output file to save the checksum results to, while still
|
||||
displaying the output on screen.
|
||||
|
||||
-f, -OutFile, --OutFile <string>
|
||||
Specifies an explicit output file name to save results to.
|
||||
|
||||
-r, -Recursive, --Recursive <switch>
|
||||
Recursively generate or verify checksums in subdirectories.
|
||||
|
||||
-c, -Check, --Check <string>
|
||||
-c, -Check <string>
|
||||
Read checksums from the specified file and verify them against files on disk.
|
||||
If -r is used, searches for the specified filename recursively in subdirectories.
|
||||
|
||||
-m, -Match, --Match <string>
|
||||
-m, -Match <string>
|
||||
Compare the computed hash of the target file(s) against a specific hash string.
|
||||
|
||||
-a, -Algorithm, --Algorithm <string>
|
||||
-a, -Algorithm <string>
|
||||
Specifies the cryptographic hash algorithm to use.
|
||||
Supported values: SHA1, SHA256 (default), SHA384, SHA512, MD5.
|
||||
If omitted in -c or -m mode, the algorithm is auto-detected by hash length.
|
||||
|
||||
-h, -Help, --Help <switch>
|
||||
-h, -Help
|
||||
Display this help message.
|
||||
|
||||
EXAMPLES
|
||||
1. Compute SHA256 checksum for a single file:
|
||||
.\checksum.ps1 myfile.iso
|
||||
|
||||
2. Compute checksums for all files and auto-write to files (-o flag):
|
||||
.\checksum.ps1 * -r -o
|
||||
2. Compute checksums for all files and write to a file while showing output:
|
||||
.\checksum.ps1 * -o checksums.sha256
|
||||
|
||||
3. Verify checksums from verification files recursively:
|
||||
.\checksum.ps1 -c checksums.sha256 -r
|
||||
3. Verify a file against a explicit hash string:
|
||||
.\checksum.ps1 myfile.iso -m "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
|
||||
4. Verify checksums from a verification file (auto-detects algorithm):
|
||||
.\checksum.ps1 -c checksums.sha256
|
||||
'@
|
||||
}
|
||||
|
||||
# Helper function to auto-detect hash algorithm based on string character length
|
||||
function Get-AlgorithmFromHashLength {
|
||||
param([string]$HashString)
|
||||
|
||||
@@ -121,244 +104,172 @@ EXAMPLES
|
||||
}
|
||||
|
||||
process {
|
||||
# Bulletproof help check (catches --help passed positionally)
|
||||
$helpInPath =$false
|
||||
if ($FilePath) {
|
||||
foreach ($p in ($FilePath)) {
|
||||
if ($p -match '^(?i)[-/]{1,2}(h\vert{}help)$') {
|
||||
$helpInPath =$true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
# Match help arguments passed either as switch (-h, -Help) or positional string ('help', 'h', '--help', etc.)
|
||||
$isHelpRequested = $Help.IsPresent -or (
|
||||
$FilePath -and $FilePath.Count -eq 1 -and (
|
||||
$FilePath[0] -match '^(?i)[-/]{0,2}(h|help)$'
|
||||
)
|
||||
)
|
||||
|
||||
if ($Help.IsPresent -or$helpInPath) {
|
||||
if ($isHelpRequested) {
|
||||
Show-Help
|
||||
return
|
||||
}
|
||||
|
||||
# Normalize explicit algorithm input if provided
|
||||
if (-not [string]::IsNullOrWhiteSpace($Algorithm)) {
|
||||
$Algorithm =$Algorithm.ToUpper()
|
||||
}
|
||||
|
||||
# --- ITEM GATHERING (Generate & Match Modes) ---
|
||||
if ($PSCmdlet.ParameterSetName -in @('Generate', 'Match')) {
|
||||
if (-not $FilePath -or$FilePath.Count -eq 0) {
|
||||
Write-Error "checksum: Missing file path parameter. Use -Help for usage."
|
||||
return
|
||||
}
|
||||
|
||||
$allItems = @();
|
||||
$isWildcardGlobal =$false;
|
||||
$skipExtensions = @('.md5', '.sha1', '.sha256', '.sha384', '.sha512');
|
||||
|
||||
foreach ($pathEntry in ($FilePath)) {
|
||||
$isWildcard = ($pathEntry -match '\*');
|
||||
if ($isWildcard) { $isWildcardGlobal =$true }
|
||||
|
||||
$resolvedItems = @();
|
||||
if ($Recursive) {
|
||||
# Parens around variables prevent space-stripping crashes
|
||||
$resolvedItems = Get-ChildItem -Path ($pathEntry) -Recurse -File -ErrorAction 'SilentlyContinue'
|
||||
} else {
|
||||
if ($isWildcard -or ($pathEntry -match '\?')) {
|
||||
$resolvedItems = Get-ChildItem -Path ($pathEntry) -File -ErrorAction 'SilentlyContinue'
|
||||
} else {
|
||||
$resolvedItems = Get-Item -Path ($pathEntry) -ErrorAction 'SilentlyContinue'
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $resolvedItems) {
|
||||
Write-Error "checksum: $($pathEntry)`: No such file or directory"
|
||||
continue
|
||||
}
|
||||
|
||||
$explicitFileFound = $false;
|
||||
if ((-not $isWildcard) -and (Test-Path -Path ($pathEntry) -PathType 'Leaf')) {
|
||||
$explicitFileFound = $true
|
||||
}
|
||||
|
||||
foreach ($item in ($resolvedItems)) {
|
||||
if ($item.PSIsContainer) { continue }
|
||||
|
||||
if (-not $explicitFileFound) {
|
||||
if ($skipExtensions -contains $item.Extension.ToLower()) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
$allItems += $item
|
||||
}
|
||||
}
|
||||
$Algorithm = $Algorithm.ToUpper()
|
||||
}
|
||||
|
||||
# --- DIRECT MATCH MODE (-m / -Match) ---
|
||||
if ($PSCmdlet.ParameterSetName -eq 'Match') {
|
||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
|
||||
$Algorithm = Get-AlgorithmFromHashLength -HashString ($Match)
|
||||
if (-not $Algorithm) { return }
|
||||
if (-not $FilePath -or $FilePath.Count -eq 0) {
|
||||
Write-Error "checksum: Missing file path parameter for matching. Use -Help for usage."
|
||||
return
|
||||
}
|
||||
|
||||
$expectedHash = $Match.Trim().ToLower();
|
||||
# Auto-detect algorithm from provided -Match hash string if not explicitly given
|
||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
|
||||
$Algorithm = Get-AlgorithmFromHashLength -HashString $Match
|
||||
if (-not $Algorithm) { return }
|
||||
Write-Verbose "Auto-detected algorithm: $Algorithm"
|
||||
}
|
||||
|
||||
foreach ($item in ($allItems)) {
|
||||
$actualHash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower()
|
||||
$targetFile = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue'
|
||||
if (-not $targetFile) { $targetFile = $item.Name }
|
||||
if ($targetFile.StartsWith(".\")) { $targetFile = $targetFile.Substring(2) }
|
||||
$expectedHash = $Match.Trim().ToLower()
|
||||
|
||||
if ($actualHash -eq $expectedHash) {
|
||||
Write-Host "${targetFile}: " -NoNewline
|
||||
Write-Host "OK" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "${targetFile}: " -NoNewline
|
||||
Write-Host "FAILED" -ForegroundColor Red
|
||||
foreach ($pathEntry in $FilePath) {
|
||||
$resolvedItems = Get-Item -Path $pathEntry -ErrorAction SilentlyContinue
|
||||
|
||||
if (-not $resolvedItems) {
|
||||
Write-Error "checksum: $pathEntry`: No such file or directory"
|
||||
continue
|
||||
}
|
||||
|
||||
foreach ($item in $resolvedItems) {
|
||||
if ($item.PSIsContainer) {
|
||||
Write-Error "checksum: $($item.Name)`: Is a directory"
|
||||
} else {
|
||||
$actualHash = (Get-FileHash -Path $item.FullName -Algorithm $Algorithm).Hash.ToLower()
|
||||
$targetFile = Resolve-Path -Path $item.FullName -Relative
|
||||
if ($targetFile.StartsWith(".\")) { $targetFile = $targetFile.Substring(2) }
|
||||
|
||||
if ($actualHash -eq $expectedHash) {
|
||||
Write-Host "${targetFile}: " -NoNewline
|
||||
Write-Host "OK" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "${targetFile}: " -NoNewline
|
||||
Write-Host "FAILED" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# --- VERIFICATION MODE (-c / -Check) ---
|
||||
elseif ($PSCmdlet.ParameterSetName -eq 'Verify') {
|
||||
$checkFiles = @();
|
||||
if ($Recursive) {
|
||||
$checkFileName = Split-Path -Path ($Check) -Leaf
|
||||
$checkFiles = Get-ChildItem -Path '.\' -Filter ($checkFileName) -Recurse -File -ErrorAction 'SilentlyContinue'
|
||||
} else {
|
||||
if (Test-Path -Path ($Check) -PathType 'Leaf') {
|
||||
$checkFiles = @(Get-Item -Path ($Check))
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $checkFiles -or $checkFiles.Count -eq 0) {
|
||||
Write-Error "checksum: $($Check)`: No such file or directory"
|
||||
if (-not (Test-Path -Path $Check -PathType Leaf)) {
|
||||
Write-Error "checksum: $Check`: No such file or directory"
|
||||
return
|
||||
}
|
||||
|
||||
foreach ($cf in ($checkFiles)) {
|
||||
$lines = Get-Content -Path ($cf.FullName)
|
||||
$baseDir =$cf.DirectoryName
|
||||
|
||||
$fileAlgo =$Algorithm
|
||||
if ([string]::IsNullOrWhiteSpace($fileAlgo)) {
|
||||
foreach ($line in ($lines)) {
|
||||
if ([string]::IsNullOrWhiteSpace($line) -or$line.StartsWith("#")) { continue }
|
||||
if ($line -match '^([a-fA-F0-9]+)\s+') {
|
||||
$fileAlgo = Get-AlgorithmFromHashLength -HashString ($Matches[1])
|
||||
break
|
||||
}
|
||||
$lines = Get-Content -Path $Check
|
||||
|
||||
# Auto-detect algorithm based on hash length if not explicitly provided
|
||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
|
||||
foreach ($line in $lines) {
|
||||
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith("#")) { continue }
|
||||
if ($line -match '^([a-fA-F0-9]+)\s+') {
|
||||
$Algorithm = Get-AlgorithmFromHashLength -HashString $Matches[1]
|
||||
if (-not $Algorithm) { return }
|
||||
Write-Verbose "Auto-detected algorithm: $Algorithm"
|
||||
break
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($fileAlgo)) {$fileAlgo = 'SHA256' }
|
||||
}
|
||||
|
||||
# Fallback if file contained no parsable hashes
|
||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
|
||||
$Algorithm = 'SHA256'
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($line in ($lines)) {
|
||||
if ([string]::IsNullOrWhiteSpace($line) -or$line.StartsWith("#")) { continue }
|
||||
foreach ($line in $lines) {
|
||||
# Skip empty lines or comments
|
||||
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith("#")) { continue }
|
||||
|
||||
if ($line -match '^([a-fA-F0-9]+)\s+[* ]?(.*)$') {$expectedHash = $Matches[1].ToLower()$targetFile = $Matches[2].Trim().TrimStart('*')$targetFullPath = Join-Path -Path ($baseDir) -ChildPath ($targetFile)
|
||||
# Match standard checksum output format: "<hash> [* ]<filename>"
|
||||
if ($line -match '^([a-fA-F0-9]+)\s+[* ]?(.*)$') {
|
||||
$expectedHash = $Matches[1].ToLower()
|
||||
# Strip leading whitespace and any leftover leading asterisk
|
||||
$targetFile = $Matches[2].Trim().TrimStart('*')
|
||||
|
||||
if (Test-Path -Path ($targetFullPath) -PathType 'Leaf') {$actualHash = (Get-FileHash -Path ($targetFullPath) -Algorithm ($fileAlgo)).Hash.ToLower()
|
||||
|
||||
$displayPath = Resolve-Path -Path ($targetFullPath) -Relative -ErrorAction 'SilentlyContinue'
|
||||
if (-not $displayPath) { $displayPath =$targetFile }
|
||||
if ($displayPath.StartsWith(".\")) { $displayPath =$displayPath.Substring(2) }
|
||||
if (Test-Path -Path $targetFile -PathType Leaf) {
|
||||
$actualHash = (Get-FileHash -Path $targetFile -Algorithm $Algorithm).Hash.ToLower()
|
||||
|
||||
if ($actualHash -eq$expectedHash) {
|
||||
Write-Host "${displayPath}: " -NoNewline
|
||||
Write-Host "OK" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "${displayPath}: " -NoNewline
|
||||
Write-Host "FAILED" -ForegroundColor Red
|
||||
}
|
||||
if ($actualHash -eq $expectedHash) {
|
||||
Write-Host "${targetFile}: " -NoNewline
|
||||
Write-Host "OK" -ForegroundColor Green
|
||||
} else {
|
||||
$displayPath =$targetFile
|
||||
if ($baseDir -ne (Get-Location).Path) {$displayPath = Join-Path -Path (Resolve-Path -Path ($baseDir) -Relative -ErrorAction 'SilentlyContinue') -ChildPath ($targetFile)
|
||||
if ($displayPath.StartsWith(".\")) { $displayPath =$displayPath.Substring(2) }
|
||||
}
|
||||
Write-Host "${displayPath}: " -NoNewline
|
||||
Write-Host "FAILED open or read" -ForegroundColor Red
|
||||
Write-Host "${targetFile}: " -NoNewline
|
||||
Write-Host "FAILED" -ForegroundColor Red
|
||||
}
|
||||
} else {
|
||||
Write-Host "${targetFile}: " -NoNewline
|
||||
Write-Host "FAILED open or read" -ForegroundColor Red
|
||||
}
|
||||
} else {
|
||||
Write-Warning "checksum: improperly formatted line: $line"
|
||||
}
|
||||
}
|
||||
}
|
||||
# --- GENERATION MODE ---
|
||||
else {
|
||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256'
|
||||
# Default to SHA256 if no algorithm was specified in generation mode
|
||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
|
||||
$Algorithm = 'SHA256'
|
||||
}
|
||||
|
||||
# Enable output if the switch is used OR an explicit file is provided
|
||||
$wantOutFile = $SaveToFile.IsPresent -or (-not [string]::IsNullOrWhiteSpace($OutFile));
|
||||
if (-not $FilePath -or $FilePath.Count -eq 0) {
|
||||
Write-Error "checksum: Missing file path parameter. Use -Help for usage."
|
||||
return
|
||||
}
|
||||
|
||||
if ($wantOutFile) {
|
||||
if ($Recursive -and$isWildcardGlobal) {
|
||||
$groupedItems =$allItems | Group-Object DirectoryName
|
||||
# Clear/initialize output file if specified before writing hashes
|
||||
if (-not [string]::IsNullOrWhiteSpace($OutFile)) {
|
||||
$null = New-Item -Path $OutFile -ItemType File -Force
|
||||
}
|
||||
|
||||
foreach ($group in ($groupedItems)) {
|
||||
$dirPath =$group.Name
|
||||
$filesInDir =$group.Group
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($OutFile)) {
|
||||
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())"
|
||||
} else {
|
||||
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile)
|
||||
}
|
||||
foreach ($pathEntry in $FilePath) {
|
||||
# Resolve wildcards and single file inputs
|
||||
$resolvedItems = Get-Item -Path $pathEntry -ErrorAction SilentlyContinue
|
||||
|
||||
$null = New-Item -Path ($currentOutFile) -ItemType 'File' -Force
|
||||
if (-not $resolvedItems) {
|
||||
Write-Error "checksum: $pathEntry`: No such file or directory"
|
||||
continue
|
||||
}
|
||||
|
||||
foreach ($item in ($filesInDir)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower()
|
||||
$relativePath =$item.Name
|
||||
|
||||
$outputLine = "$hash$relativePath"
|
||||
Add-Content -Path ($currentOutFile) -Value ($outputLine)
|
||||
Write-Output $outputLine
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$singleOutFile =$null;
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($OutFile)) {
|
||||
if ($isWildcardGlobal) {$singleOutFile = "checksums.$($Algorithm.ToLower())"
|
||||
}
|
||||
foreach ($item in $resolvedItems) {
|
||||
# Handle directories like Linux sha256sum does
|
||||
if ($item.PSIsContainer) {
|
||||
Write-Error "checksum: $($item.Name)`: Is a directory"
|
||||
} else {
|
||||
$singleOutFile =$OutFile
|
||||
}
|
||||
|
||||
if ($singleOutFile) {
|
||||
$null = New-Item -Path ($singleOutFile) -ItemType 'File' -Force
|
||||
}
|
||||
|
||||
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower()
|
||||
$hash = (Get-FileHash -Path $item.FullName -Algorithm $Algorithm).Hash.ToLower()
|
||||
|
||||
$relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue'
|
||||
if (-not $relativePath) { $relativePath =$item.Name }
|
||||
# Format standard relative path (stripping leading '.\')
|
||||
$relativePath = Resolve-Path -Path $item.FullName -Relative
|
||||
if ($relativePath.StartsWith(".\")) {
|
||||
$relativePath =$relativePath.Substring(2)
|
||||
$relativePath = $relativePath.Substring(2)
|
||||
}
|
||||
|
||||
$outputLine = "$hash$relativePath"
|
||||
$outputLine = "$hash $relativePath"
|
||||
|
||||
if ($singleOutFile) {
|
||||
Add-Content -Path ($singleOutFile) -Value ($outputLine)
|
||||
} else {
|
||||
$currentOutFile = "$($item.FullName).$($Algorithm.ToLower())"
|
||||
$null = New-Item -Path ($currentOutFile) -ItemType 'File' -Force
|
||||
Add-Content -Path ($currentOutFile) -Value ($outputLine)
|
||||
# If -OutFile is provided, write line to file
|
||||
if (-not [string]::IsNullOrWhiteSpace($OutFile)) {
|
||||
Add-Content -Path $OutFile -Value $outputLine
|
||||
}
|
||||
|
||||
# Output to stdout
|
||||
Write-Output $outputLine
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower()
|
||||
|
||||
$relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue'
|
||||
if (-not $relativePath) { $relativePath =$item.Name }
|
||||
if ($relativePath.StartsWith(".\")) {
|
||||
$relativePath =$relativePath.Substring(2)
|
||||
}
|
||||
|
||||
$outputLine = "$hash$relativePath"
|
||||
Write-Output $outputLine
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
if ($args[0]) { $commit_message=($args -join " ") } # if arg0 exists, join all passed args with spaces
|
||||
else { $commit_message="waypoint" } # or default to "waypoint"
|
||||
# waypoint.ps1
|
||||
|
||||
Write-Host "WAYPOINT!`n`tCommit Message: $commit_message`n"
|
||||
# add and commit
|
||||
if (-not (Test-Path -Path ".\.git" -PathType Container)) {
|
||||
Write-Host "No .git folder detected. Initializing new Git repository..." -ForegroundColor Yellow
|
||||
git init
|
||||
} else {
|
||||
Write-Host "Git repository detected. Creating waypoint..." -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
# Stage all changes
|
||||
git add .
|
||||
git commit -m "$commit_message"
|
||||
|
||||
Write-Host "`nDone :`"3"
|
||||
# Format the timestamp with timezone offset/ID string
|
||||
$timestamp = (Get-Date).ToString("yyyy-MM-dd-HHmm") + "-" + ((Get-TimeZone).Id -creplace '[a-z\s]', '')
|
||||
|
||||
# Capture current git status output
|
||||
$statusOutput = (git status | Out-String).Trim()
|
||||
|
||||
# Construct the commit message
|
||||
$commitMessage = "WAYPOINT $timestamp`n`n$statusOutput"
|
||||
|
||||
# Execute commit
|
||||
git commit -m "$commitMessage"
|
||||
@@ -1,58 +0,0 @@
|
||||
#!/bin/bash
|
||||
domain=kasm.h.acker.is
|
||||
local_port=8443
|
||||
swap_size_gib=6
|
||||
sudo apt update
|
||||
sudo apt dist-upgrade -y
|
||||
sudo fallocate -l ${swap_size_gib}g /mnt/${swap_size_gib}GiB.swap
|
||||
sudo chmod 600 /mnt/${swap_size_gib}GiB.swap
|
||||
sudo mkswap /mnt/${swap_size_gib}GiB.swap
|
||||
sudo swapon /mnt/${swap_size_gib}GiB.swap
|
||||
echo "/mnt/${swap_size_gib}GiB.swap swap swap defaults 0 0" | sudo tee -a /etc/fstab
|
||||
cd /tmp
|
||||
curl -O https://kasm-static-content.s3.amazonaws.com/kasm_release_1.19.0-latest.tar.gz
|
||||
tar -xf kasm_release*.tar.gz
|
||||
sudo bash kasm_release/install.sh -L $local_port
|
||||
sudo apt update
|
||||
sudo apt install nginx certbot python3-certbot-nginx -y
|
||||
sudo certbot certonly --nginx -d $domain
|
||||
sudo cat << 'EOF' > /etc/nginx/sites-available/$domain
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name $domain;
|
||||
ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;
|
||||
location / {
|
||||
# WebSocket Support
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# Host and X headers
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Should match the listening port of this proxy
|
||||
proxy_set_header X-Forwarded-Port 443;
|
||||
|
||||
# Connectivity Options
|
||||
proxy_http_version 1.1;
|
||||
proxy_read_timeout 1800s;
|
||||
proxy_send_timeout 1800s;
|
||||
proxy_connect_timeout 1800s;
|
||||
proxy_buffering off;
|
||||
|
||||
# Allow large requests to support file uploads to sessions
|
||||
client_max_body_size 10M;
|
||||
|
||||
# Proxy to Kasm Workspaces running locally on $local_port using ssl
|
||||
proxy_pass https://127.0.0.1:$local_port;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
sudo ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/$domain
|
||||
sudo nginx -t
|
||||
sudo systemctl restart nginx
|
||||
sudo docker restart kasm_api
|
||||
sudo shutdown -r +7
|
||||
@@ -12,6 +12,7 @@ tmpDir='/tmp/generalssss'
|
||||
tmp_customscripts_dir="$tmpDir/customscripts"
|
||||
finalDir='/usr/share/customscripts'
|
||||
packages="7zip apache2 argon2 avahi-daemon btop build-essential byobu cargo cifs-utils clamav cmake cowsay cracklib-runtime detox docker.io exiftool fdupes ffuf gcc-arm-none-eabi grc gzip iotop iptraf-ng jq kpartx libnss-mdns libnewlib-arm-none-eabi librust-git2+openssl-probe-dev libstdc++-arm-none-eabi-newlib locales lynx net-tools nginx openssl php polygen polygen-data procps python3 python3-scapy resolvconf restic ripgrep samba screen seclists snapd thefuck unzip wget xrdp xxd xz-utils zip kali-linux-default"
|
||||
# packages="grc kpartx openssl cracklib-runtime argon2 jq polygen polygen-data apache2 seclists cmake locales python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib librust-git2+openssl-probe-dev cargo nginx build-essential cowsay iotop iptraf-ng btop screen byobu thefuck wget lynx zip unzip 7zip xz-utils gzip net-tools clamav php restic cifs-utils detox fdupes ripgrep avahi-daemon libnss-mdns xxd xrdp libimage-exiftool-perl kali-tools-hardware kali-tools-crypto-stego kali-tools-fuzzing kali-tools-bluetooth kali-tools-rfid kali-tools-sdr kali-tools-voip kali-tools-802-11 kali-tools-forensics samba procps snapd"
|
||||
|
||||
echo -e "\nSTARTING!\n\tUsing Shell $SHELL\n"
|
||||
|
||||
@@ -72,48 +73,49 @@ if [ ! -z "$1" ]; then
|
||||
# echo -e "\nhaveibeenpwned-downloader installed, skipping install\n"
|
||||
# fi
|
||||
# homebrew
|
||||
if [ ! $(which brew) ]; then
|
||||
## install homebrew
|
||||
echo -e "\nlinuxbrew not found, installing\n"
|
||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
||||
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
||||
### add to rcfile
|
||||
if ! grep -q 'linuxbrew' $rcfile; then
|
||||
echo "adding linuxbrew to $rcfile"
|
||||
echo "# linuxbrew (homebrew/brew)" >> $rcfile
|
||||
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> $rcfile
|
||||
else
|
||||
echo "linuxbrew already in $rcfile skipping"
|
||||
fi
|
||||
|
||||
else
|
||||
echo -e "\nlinuxbrew installed, skipping install\n"
|
||||
fi
|
||||
### install ponysay
|
||||
if [ ! $(which ponysay) ]; then
|
||||
echo -e "\nponysay not fonud, installiing\n"
|
||||
brew install ponysay
|
||||
if ! grep 'ponysay fix' $rcfile; then
|
||||
echo "adding ponysay fix to $rcfile"
|
||||
echo -e "# ponysay fix\nexport PYTHONWARNINGS=ignore::SyntaxWarning" >> $rcfile
|
||||
source $rcfile
|
||||
else
|
||||
echo "ponysay fix already in $rcfile skipping"
|
||||
source $rcfile
|
||||
fi
|
||||
else
|
||||
echo -e "\nponysay already installed, skipping\n"
|
||||
fi
|
||||
# if [ ! $(which brew) ]; then
|
||||
# ## install homebrew
|
||||
# echo -e "\nlinuxbrew not found, installing\n"
|
||||
# bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
# test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
||||
# test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
||||
# ### add to rcfile
|
||||
# if ! grep -q 'linuxbrew' $rcfile; then
|
||||
# # echo "adding linuxbrew to $rcfile"
|
||||
# # echo "# linuxbrew (homebrew/brew)" >> $rcfile
|
||||
# # echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> $rcfile
|
||||
# else
|
||||
# echo "linuxbrew already in $rcfile skipping"
|
||||
# fi
|
||||
#
|
||||
# # source $rcfile
|
||||
# else
|
||||
# echo -e "\nlinuxbrew installed, skipping install\n"
|
||||
# # source $rcfile
|
||||
# fi
|
||||
# ### install ponysay
|
||||
# if [ ! $(which ponysay) ]; then
|
||||
# echo -e "\nponysay not fonud, installiing\n"
|
||||
# brew install ponysay
|
||||
# if ! grep 'ponysay fix' $rcfile; then
|
||||
# # echo "adding ponysay fix to $rcfile"
|
||||
# # echo -e "# ponysay fix\nexport PYTHONWARNINGS=ignore::SyntaxWarning" >> $rcfile
|
||||
# # source $rcfile
|
||||
# else
|
||||
# # echo "ponysay fix already in $rcfile skipping"
|
||||
# # source $rcfile
|
||||
# fi
|
||||
# else
|
||||
# echo -e "\nponysay already installed, skipping\n"
|
||||
# fi
|
||||
# cargo
|
||||
|
||||
## oniux
|
||||
echo -e "\nINSTALLIN TOR ONIUX\n"
|
||||
if [ -f /usr/local/bin/oniux ]; then
|
||||
echo -e "\nexisting oniux found, skipping\n"
|
||||
else
|
||||
echo -e "\nexisting oniux not found, installing\n"
|
||||
cd /tmp && cargo install --git https://gitlab.torproject.org/tpo/core/oniux && cd - && echo -e '## Oniux/Cargo Shit\nPATH=$PATH:$HOME/.cargo/bin' >> ~/.bashrc && source ~/.bashrc && oniux curl https://canhazip.com
|
||||
cargo install --git https://gitlab.torproject.org/tpo/core/oniux --tag v0.6.1 oniux
|
||||
fi
|
||||
|
||||
else
|
||||
@@ -158,7 +160,7 @@ git clone $gitRepo $tmpDir --single-branch --depth 1
|
||||
|
||||
# donut
|
||||
echo -e "\nCompiling donut\n"
|
||||
gcc -o "$tmp_customscripts_dir/donut" "$tmp_customscripts_dir/donut.c" -lm 2>/dev/null
|
||||
gcc -o "$tmp_customscripts_dir/donut" "$tmp_customscripts_dir/donut.c" -lm # 2>/dev/null
|
||||
|
||||
# put the customscripts dir into place
|
||||
echo -e "\nPlacing in $finalDir\n"
|
||||
@@ -179,10 +181,10 @@ pathgrep=$?
|
||||
if [ $pathgrep -eq 0 ]; then
|
||||
echo -e "\n$finalDir Already in \$PATH Skipping Append\n"
|
||||
fi
|
||||
else
|
||||
# echo -e "\nAdding $finalDir to $username's \$PATH by Appending to $rcfile\n"
|
||||
# echo -e "\n\n# automatically added by customscripts installer\nexport PATH=\"\$PATH:$finalDir\"" >> "$rcfile"
|
||||
fi
|
||||
# else
|
||||
# echo -e "\nAdding $finalDir to $username's \$PATH by Appending to $rcfile\n"
|
||||
# echo -e "\n\n# automatically added by customscripts installer\nexport PATH=\"\$PATH:$finalDir\"" >> "$rcfile"
|
||||
# fi
|
||||
|
||||
# install pishrink if not there
|
||||
if [ ! -f /usr/local/bin/pishrink ]; then
|
||||
@@ -202,11 +204,15 @@ if [ ! -d $userhome/.local/share/blesh ]; then
|
||||
cd /tmp
|
||||
git clone --recursive --depth 1 --shallow-submodules --single-branch -b master https://github.com/akinomyoga/ble.sh.git
|
||||
make -C ble.sh install PREFIX=~/.local
|
||||
echo '# ble.sh' >> $rcfile
|
||||
echo "source -- ~/.local/share/blesh/ble.sh" >> $rcfile
|
||||
else
|
||||
echo -e "\nble.sh already installed, skippping\n"
|
||||
# echo '# ble.sh' >> $rcfile
|
||||
# echo "source -- ~/.local/share/blesh/ble.sh" >> $rcfile
|
||||
# source $rcfile
|
||||
# exec "$SHELL"
|
||||
fi
|
||||
# else
|
||||
# echo -e "\nble.sh already installed, skippping\n"
|
||||
# source $rcfile
|
||||
# fi
|
||||
|
||||
$SHELL -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> "$rcfile"
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
# usage
|
||||
## curl -s https://raw.githubusercontent.com/PrincessPi3/general-scripts-and-system-ssssssetup/refs/heads/main/customscripts/python_pyenv_setup.sh | sudo "$SHELL" && source ~/.zshrc && exec "$SHELL" && pyenv install 3:latest && pyenv global 3:latest
|
||||
# set -e
|
||||
|
||||
# set rcfile
|
||||
rcfile="$HOME/.zshrc" # zsh
|
||||
# rcfile="$USER/.bashrc" # bash
|
||||
package_log="/home/princesspi/python_packages_removed.txt"
|
||||
|
||||
# check if a command exists, and if so, purge that package
|
||||
# usage: check_purge_package <package_name>
|
||||
check_purge_package () {
|
||||
package_name=$1
|
||||
|
||||
# which -s $package_name 2>/dev/null 1>/dev/null # silently test for command
|
||||
# package_check=$? # get return code. 0 for found, any other for not found
|
||||
|
||||
# if [ $package_check -eq 0 ]; then # if package is found, purge it
|
||||
echo "purging $package_name"
|
||||
sudo apt purge $package_name -y 2>>"$package_log" 1>>"$package_log"
|
||||
echo "finished purging $package_name"
|
||||
# else # otherwise skip
|
||||
# echo "no $package_name installation found, skipping uninstall"
|
||||
#fi
|
||||
}
|
||||
|
||||
# cleanup previous python installs
|
||||
# check_purge_package pyenv*
|
||||
# check_purge_package python3*
|
||||
# check_purge_package python2*
|
||||
# check_purge_package python*
|
||||
# check_purge_package pip*
|
||||
# check_purge_package pip3*
|
||||
# check_purge_package pip2*
|
||||
|
||||
|
||||
# cleanup
|
||||
# echo "Autoremoving packages"
|
||||
# sudo apt autoremove -y 2>>"$package_log" 1>>"$package_log"
|
||||
# echo -e "DONE CLEARING OLD PACKAGES!\n\tRemoved packages logged to $package_log"
|
||||
|
||||
if [ -d $HOME/.pyenv ]; then
|
||||
echo "Removing existing pyenv installation"
|
||||
rm -rf $HOME/.pyenv
|
||||
else
|
||||
echo "No existing pyenv installation found, skipping removal"
|
||||
fi
|
||||
|
||||
# install pyenv
|
||||
curl -fsSL https://pyenv.run | bash
|
||||
## setup shell
|
||||
### check for pyenv in rcfile
|
||||
grep -q .pyenv $rcfile
|
||||
rc_pyenv_check=$? # get retcode, 0 for found not 0 for not found
|
||||
|
||||
if [ $rc_pyenv_check -eq 0 ]; then # if pyenv found
|
||||
echo "pyenv already set up in $rcfile, skipping add init"
|
||||
else # if pyenv not found
|
||||
echo "Setting up pyenv in $rcfile"
|
||||
echo -e "\n# pyenv setup" >> $rcfile
|
||||
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> $rcfile
|
||||
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> $rcfile
|
||||
echo 'eval "$(pyenv init - zsh)"' >> $rcfile
|
||||
fi
|
||||
## add aliases
|
||||
### check for aliases in rcfile
|
||||
grep -q '## python aliases' $rcfile
|
||||
rc_pyalias_check=$? # get retcode, 0 for found not 0 for not found
|
||||
|
||||
if [ $rc_pyalias_check -eq 0 ]; then # if aliases found
|
||||
echo "pyenv aliases already set up in $rcfile, skipping"
|
||||
else # if aliases not found, add python shit
|
||||
echo "Setting up pyenv aliases in $rcfile"
|
||||
echo "## python aliases" >> $rcfile
|
||||
echo 'alias py=python' >> $rcfile
|
||||
echo 'alias py3=python' >> $rcfile
|
||||
echo 'alias py2=python' >> $rcfile
|
||||
echo 'alias python3=python' >> $rcfile
|
||||
echo 'alias python2=python' >> $rcfile
|
||||
echo 'alias pip3=pip' >> $rcfile
|
||||
echo -e "alias pip2=pip\n" >> $rcfile
|
||||
fi
|
||||
|
||||
echo -e "\n\ndone~ :3~\n\treset shell with exec \"\$SHELL\"\n"
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Usage:
|
||||
## Install Tor
|
||||
### sudo apt update; sudo apt install tor -y
|
||||
## Edit /etc/tor/torrc
|
||||
### sudo nano /etc/tor/torrc
|
||||
#### Uncomment or add
|
||||
##### ControlPort 9051
|
||||
#### Ucomment and change to (default value is 1, change to 0)
|
||||
##### CookieAuthentication 0
|
||||
## Enable, Start, and Restart Tor
|
||||
### sudo systemctl enable tor; sudo systemctl start tor; sleep 20; sudo systemctl restart tor
|
||||
|
||||
# Configuration
|
||||
TARGET_URL="https://canhazip.com"
|
||||
TOR_PROXY="socks5h://127.0.0.1:9050"
|
||||
TOR_CONTROL_PORT=9051
|
||||
DELAY=2 # Delay in seconds between requests
|
||||
|
||||
# Ensure you respect HIBP's API rate limits and terms of service
|
||||
while true; do
|
||||
echo "[+] Requesting new Tor identity..."
|
||||
|
||||
# Send NEWNYM signal to Tor Control Port to switch IP
|
||||
echo -e 'AUTHENTICATE ""\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051 > /dev/null
|
||||
|
||||
# Give Tor a brief moment to establish the new circuit
|
||||
sleep "$DELAY"
|
||||
|
||||
echo "[+] Verifying current IP..."
|
||||
CURRENT_IP=$(curl -s --proxy "$TOR_PROXY" https://canhazip.com)
|
||||
echo "[+] Current Tor IP: $CURRENT_IP"
|
||||
|
||||
echo "[+] Sending request to Have I Been Pwned..."
|
||||
# 'socks5h://' ensures DNS resolution happens through Tor, preventing leaks
|
||||
curl -s --proxy "$TOR_PROXY" -H "hibp-api-key: YOUR_API_KEY" "$TARGET_URL"
|
||||
|
||||
echo -e "\n[+] Waiting for next iteration...\n"
|
||||
sleep "$DELAY"
|
||||
done
|
||||
Reference in New Issue
Block a user