github.com/iDigitalFlame/xmt@v0.5.4/c2/task/task_test.go (about)

     1  //go:build !implant
     2  // +build !implant
     3  
     4  // Copyright (C) 2020 - 2023 iDigitalFlame
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    18  //
    19  
    20  package task
    21  
    22  import (
    23  	"context"
    24  	"testing"
    25  	"time"
    26  
    27  	"github.com/iDigitalFlame/xmt/com"
    28  )
    29  
    30  func TestDLL(t *testing.T) {
    31  	p, err := DLL{Data: []byte("hello"), Timeout: time.Hour}.Packet()
    32  	if err != nil {
    33  		t.Fatalf("TestDLL(): Packet returned error: %s!", err.Error())
    34  	}
    35  	if n := p.Size(); n <= com.PacketHeaderSize {
    36  		t.Fatalf("TestDLL(): Packet result was empty!")
    37  	}
    38  }
    39  func TestTasks(t *testing.T) {
    40  	v := [...]struct {
    41  		Packet *com.Packet
    42  		Size   int
    43  		ID     uint8
    44  	}{
    45  		{FuncUnmapAll(), 1, TvFuncMap},
    46  		{Evade(0), 1, TvEvade},
    47  		{FuncRemapList(), 0, TvFuncMapList},
    48  		{FuncUnmap("test"), 5, TvFuncMap},
    49  		{CheckDLLFile("file"), 12, TvCheck},
    50  		{PatchDLLFile("file"), 12, TvPatch},
    51  		{FuncRemap("test", []byte("test")), 11, TvFuncMap},
    52  		{CheckFunction("test", "test", []byte("test")), 22, TvCheck},
    53  		{PatchFunction("test", "test", []byte("test")), 22, TvPatch},
    54  		{CheckDLL("test", 0x1234, []byte("test")), 17, TvCheck},
    55  		{PatchDLL("test", 0x1234, []byte("test")), 17, TvPatch},
    56  		{CheckFunctionFile("test", "test", []byte("test")), 22, TvCheck},
    57  		{ProcessList(), 0, MvProcList},
    58  		{Kill(0x2345), 5, TvSystemIO},
    59  		{Touch("test"), 7, TvSystemIO},
    60  		{KillName("test"), 7, TvSystemIO},
    61  		{Download("test"), 6, TvDownload},
    62  		{Move("test", "test"), 13, TvSystemIO},
    63  		{Copy("test", "test"), 13, TvSystemIO},
    64  		{Pull("test", "test"), 13, TvPull},
    65  		{Upload("test", []byte("test")), 10, TvUpload},
    66  		{Delete("test", true), 7, TvSystemIO},
    67  		{PullAgent("test", "test", "test"), 18, TvPull},
    68  		{Restart("test", 0, true, 0x5), 15, TvPower},
    69  		{Shutdown("test", 0, true, 0x5), 15, TvPower},
    70  		{Netcat("test", 0, 0, false, []byte("test")), 15, TvNetcat},
    71  		{RegLs("test"), 7, TvRegistry},
    72  		{RegMakeKey("test"), 7, TvRegistry},
    73  		{RegGet("test", "test"), 13, TvRegistry},
    74  		{RegSetString("test", "test", "test"), 19, TvRegistry},
    75  		{RegDeleteKey("test", true), 8, TvRegistry},
    76  		{RegDelete("test", "test", false), 13, TvRegistry},
    77  		{RegSetDword("test", "test", 0xBEEF), 17, TvRegistry},
    78  		{RegSetQword("test", "test", 0xDEADBEEF), 21, TvRegistry},
    79  		{RegSetBytes("test", "test", []byte("test")), 19, TvRegistry},
    80  		{RegSetExpandString("test", "test", "test"), 19, TvRegistry},
    81  		{RegSet("test", "test", 0, []byte("test")), 23, TvRegistry},
    82  		{RegSetStringList("test", "test", []string{"test"}), 21, TvRegistry},
    83  		{Pwd(), 0, MvPwd},
    84  		{Mounts(), 0, MvMounts},
    85  		{Refresh(), 0, MvRefresh},
    86  		{RevToSelf(), 0, TvRevSelf},
    87  		{UserLogins(), 0, TvLogins},
    88  		{ScreenShot(), 0, TvScreenShot},
    89  		{Ls("test"), 6, MvList},
    90  		{IsDebugged(), 0, MvCheckDebug},
    91  		{Jitter(10), 10, MvTime},
    92  		{Cwd("test"), 6, MvCwd},
    93  		{Profile([]byte("test")), 6, MvProfile},
    94  		{KillDate(time.Time{}), 9, MvTime},
    95  		{ProcessName("test"), 6, TvRename},
    96  		{Wait(time.Hour), 8, TvWait},
    97  		{UserLogoff(0), 5, TvLoginsAct},
    98  		{Sleep(time.Minute), 10, MvTime},
    99  		{ProxyRemove("test"), 7, MvProxy},
   100  		{UserProcesses(1), 4, TvLoginsProc},
   101  		{UserDisconnect(2), 5, TvLoginsAct},
   102  		{Duration(time.Hour, 10), 10, MvTime},
   103  		{Proxy("test", "test", []byte("test")), 19, MvProxy},
   104  		{ProxyReplace("test", "test", []byte("test")), 19, MvProxy},
   105  		{LoginUser(false, "test", "test", "test"), 19, TvLoginUser},
   106  		{WorkHours(1, 2, 3, 4, 5), 6, MvTime},
   107  		{WindowList(), 0, TvWindowList},
   108  		{SwapMouse(false), 1, TvTroll},
   109  		{BlockInput(true), 1, TvTroll},
   110  		{Wallpaper("test"), 7, TvTroll},
   111  		{HighContrast(true), 1, TvTroll},
   112  		{WindowFocus(0xBEEF), 9, TvUI},
   113  		{WindowClose(0xBEEF), 9, TvUI},
   114  		{WallpaperBytes([]byte("test")), 5, TvTroll},
   115  		{WindowWTF(time.Hour), 9, TvTroll},
   116  		{WindowShow(0xBEEF, 0), 10, TvUI},
   117  		{WindowEnable(0xBEEF, true), 9, TvUI},
   118  		{WindowSendInput(0xBEEF, "test"), 15, TvUI},
   119  		{WindowTransparency(0xBEEF, 127), 10, TvUI},
   120  		{WindowMove(0xBEEF, 1, 2, 3, 4), 25, TvUI},
   121  		{WindowMessageBox(0xBEEF, "test", "test", 123), 25, TvUI},
   122  		{UserMessageBox(0, "test", "test", 1, 2, true), 26, TvLoginsAct},
   123  	}
   124  	for i := range v {
   125  		if v[i].Packet == nil {
   126  			t.Fatalf(`TestPacket(): Packet index "%d" was nil!`, i)
   127  		}
   128  		if v[i].ID != v[i].Packet.ID {
   129  			t.Fatalf(`TestPacket(): Packet ID "%d" does not match expected ID "%d"!`, v[i].Packet.ID, v[i].ID)
   130  		}
   131  		if n := v[i].Packet.Size(); n < v[i].Size+com.PacketHeaderSize {
   132  			t.Fatalf(`TestPacket(): Packet size "%d" does not match the expected size "%d"!`, n, v[i].Size+com.PacketHeaderSize)
   133  		}
   134  	}
   135  }
   136  func TestZombie(t *testing.T) {
   137  	p, err := Zombie{Data: []byte("hello"), Timeout: time.Hour}.Packet()
   138  	if err != nil {
   139  		t.Fatalf("TestZombie(): Packet returned error: %s!", err.Error())
   140  	}
   141  	if n := p.Size(); n <= com.PacketHeaderSize {
   142  		t.Fatalf("TestZombie(): Packet result was empty!")
   143  	}
   144  }
   145  func TestProcess(t *testing.T) {
   146  	p, err := Process{Args: []string{"test1", "test2"}, User: "bob", Pass: "password", Timeout: time.Hour}.Packet()
   147  	if err != nil {
   148  		t.Fatalf("TestProcess(): Packet returned error: %s!", err.Error())
   149  	}
   150  	if n := p.Size(); n <= com.PacketHeaderSize {
   151  		t.Fatalf("TestProcess(): Packet result was empty!")
   152  	}
   153  	p.Seek(0, 0)
   154  	a, _, err := ProcessUnmarshal(context.Background(), p)
   155  	if err != nil {
   156  		t.Fatalf("TestProcess(): AssemblyUnmarshal() returned error: %s!", err.Error())
   157  	}
   158  	if a.Args[0] != "test1" || a.Args[1] != "test2" {
   159  		t.Fatalf(`TestProcess(): Args "%s" did not equal "[test1, test2]"!`, a.Args)
   160  	}
   161  	if a.Timeout != time.Hour {
   162  		t.Fatalf(`TestProcess(): Timeout "%s" did not equal "1h"!`, a.Timeout.String())
   163  	}
   164  }
   165  func TestAssembly(t *testing.T) {
   166  	p, err := Assembly{Data: []byte("hello"), Timeout: time.Hour}.Packet()
   167  	if err != nil {
   168  		t.Fatalf("TestAssembly(): Packet returned error: %s!", err.Error())
   169  	}
   170  	if n := p.Size(); n <= com.PacketHeaderSize {
   171  		t.Fatalf("TestAssembly(): Packet result was empty!")
   172  	}
   173  	p.Seek(0, 0)
   174  	a, _, err := AssemblyUnmarshal(context.Background(), p)
   175  	if err != nil {
   176  		t.Fatalf("TestAssembly(): AssemblyUnmarshal() returned error: %s!", err.Error())
   177  	}
   178  	if string(a.Data) != "hello" {
   179  		t.Fatalf(`TestAssembly(): Data "%s" did not equal "hello"!`, a.Data)
   180  	}
   181  	if a.Timeout != time.Hour {
   182  		t.Fatalf(`TestAssembly(): Timeout "%s" did not equal "1h"!`, a.Timeout.String())
   183  	}
   184  }