Git Product home page Git Product logo

freshycalls's People

Contributors

elephantse4l avatar mariobartolome avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

freshycalls's Issues

NtCreateThreadEx Not Working with Error Code 0xc0000005

Enviroment:
OS Name: Microsoft Windows 11 Home
OS Version: 10.0.22000 N/A Build 22000
Toolchain: Visual Studio 2019 MSVC with c++20 standard and x64 MT runtime

It's not working with following code to invoke NtCreateThreadEx .
But it works fine With HellsGate technique.
I want to learn deeply here Why it doesn't work just like HellsGate.

int FreshyCall(void *buffer, size_t size) {
	using namespace  std;
	NTSTATUS status = 0x00000000;

	// buffer is some sort of  shellcode complied by nasm with x64 bin mode , which will pop up a messagebox.
        // Its size is around  400 Bytes.
        // size is the size of  buffer.
	// char buffer [] = "\x90\x90\x90\x90\xcc\xcc\xcc\xcc\xc3 .... ";

	// Allocate memory for the shellcode
	PVOID lpAddress = NULL;
	size_t sDataSize = size;


	HANDLE ProcessHandle = (HANDLE)-1 ;
	//HANDLE ProcessHandle = GetCurrentProcess();


	try {

		auto &syscall = freshycalls::Syscall::get_instance();
		syscall
			.CallSyscall("NtAllocateVirtualMemory", ProcessHandle, &lpAddress,
						 0,
						 &sDataSize, MEM_COMMIT, PAGE_READWRITE)
			.OrDie("[NtAllocateVirtualMemory] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");

		VxMoveMemory(lpAddress, buffer, size);

		ULONG ulOldProtect = 0;
		syscall
			.CallSyscall("NtProtectVirtualMemory", ProcessHandle, &lpAddress,
						 &sDataSize, PAGE_EXECUTE_READ, &ulOldProtect)
			.OrDie("[NtProtectVirtualMemory] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");




                 //it works fine here to invoke the shellcode in place
                 // using func_t = void(*)();
		// auto func = (func_t)(lpAddress);
      
		// func(); 
		HANDLE hHostThread = INVALID_HANDLE_VALUE;

		
	
		syscall
			.CallSyscall("NtCreateThreadEx", &hHostThread, THREAD_ALL_ACCESS,
						 NULL, ProcessHandle, (LPTHREAD_START_ROUTINE)lpAddress,
						 NULL, FALSE, NULL, NULL, NULL, NULL)
			.OrDie("[NtCreateThreadEx] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");

		syscall.CallSyscall("NtWaitForSingleObject", hHostThread, TRUE, NULL)
			.OrDie("[NtWaitForSingleObject] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");
	} catch (std::exception &e) {
	
		cout << e.what() << endl;
	        return -1;
	
	}
	return 0;
}

Thanks.

VirtualWriteMemory Address Issue when greater than 27352

Hey,

I'm trying to use FreshyCalls to do Process Injection and when the size of data I am trying to write with NtWriteVirtualMemory is greater than 27,352 the syscall returns AccessDenied. I've confirmed it allocates enough memory for this to fit (and double checked via ProcesHacker), so am assuming its an issue within the call trampoline and am not sure how to debug it.

Below is code that can be placed in the POC to replicate the issue.

int main(int argc, char *argv[]) {
  HANDLE process_handle;
  HANDLE file_handle;
  //const uint32_t process_id = GetPID(argc, argv);
  PVOID* mem = NULL;

  std::cout << "FreshyCalls' PoC dumper" << std::endl << std::endl;

  try {
    HANDLE hProcess;
    const char* sc = "\xc0\xd3";
    // Used in NtAllocateVirtualMemory
    SIZE_T fSize = ((sizeof(sc) + 780000 + 0x1000 - 1) & ~(0x1000 - 1));
    // Used in NtWriteVirtualMemory, when greater than 27,352 - fails to write
    SIZE_T wtf = 27353;

    std::cout << "[+] Grabbing handle to process...";
    hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION |
      PROCESS_VM_OPERATION | PROCESS_VM_WRITE |
      PROCESS_VM_READ, FALSE, 11368);
    if (hProcess)
        std::cout << " OK!" << std::endl;

    std::cout << "[+] Trying NtAllocateVirtualMemory...";
    syscall.CallSyscall("NtAllocateVirtualMemory", hProcess, &mem, 0, (PULONG)&fSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)
        .OrDie("NtAllocateVirtualMemory: {{result_as_hex}}");
    std::cout << " OK!" << std::endl;
    
    std::cout << "[+] Trying NtWriteVirtualMemory...";

    syscall.CallSyscall("NtWriteVirtualMemory", hProcess, mem, sc, wtf, NULL)
        .OrDie("NtWriteVirtualMemory: {{result_as_hex}}");

    std::cout << " OK!" << std::endl;

  }
  catch (const std::runtime_error &e) {
    std::cerr << std::endl << e.what() << std::endl;
    exit(-1);
  }

  return 0;
}

NtCreateThreadEx Not Working with Error Code 0xc0000005

Enviroment:
OS Name: Microsoft Windows 11 Home
OS Version: 10.0.22000 N/A Build 22000
Toolchain: Visual Studio 2019 MSVC with c++20 standard and x64 MT runtime

It's not working with following code to invoke NtCreateThreadEx .
But it works fine With HellsGate technique.
I want to learn deeply here Why it doesn't work just like HellsGate.

int FreshyCall(void *buffer, size_t size) {
	using namespace  std;
	NTSTATUS status = 0x00000000;

	// buffer is some sort of  shellcode complied by nasm with x64 bin mode , which will pop up a messagebox.
        // Its size is around  400 Bytes.
        // size is the size of  buffer.
	// char buffer [] = "\x90\x90\x90\x90\xcc\xcc\xcc\xcc\xc3 .... ";

	// Allocate memory for the shellcode
	PVOID lpAddress = NULL;
	size_t sDataSize = size;


	HANDLE ProcessHandle = (HANDLE)-1 ;
	//HANDLE ProcessHandle = GetCurrentProcess();


	try {

		auto &syscall = freshycalls::Syscall::get_instance();
		syscall
			.CallSyscall("NtAllocateVirtualMemory", ProcessHandle, &lpAddress,
						 0,
						 &sDataSize, MEM_COMMIT, PAGE_READWRITE)
			.OrDie("[NtAllocateVirtualMemory] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");

		VxMoveMemory(lpAddress, buffer, size);

		ULONG ulOldProtect = 0;
		syscall
			.CallSyscall("NtProtectVirtualMemory", ProcessHandle, &lpAddress,
						 &sDataSize, PAGE_EXECUTE_READ, &ulOldProtect)
			.OrDie("[NtProtectVirtualMemory] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");




                 //it works fine here to invoke the shellcode in place
                 // using func_t = void(*)();
		// auto func = (func_t)(lpAddress);
      
		// func(); 
		HANDLE hHostThread = INVALID_HANDLE_VALUE;

		
	
		syscall
			.CallSyscall("NtCreateThreadEx", &hHostThread, THREAD_ALL_ACCESS,
						 NULL, ProcessHandle, (LPTHREAD_START_ROUTINE)lpAddress,
						 NULL, FALSE, NULL, NULL, NULL, NULL)
			.OrDie("[NtCreateThreadEx] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");

		syscall.CallSyscall("NtWaitForSingleObject", hHostThread, TRUE, NULL)
			.OrDie("[NtWaitForSingleObject] Error:"
				   "Msg: \"{{result_msg}}\" (Error Code: "
				   "{{result_as_hex}})");
	} catch (std::exception &e) {
	
		cout << e.what() << endl;
	        return -1;
	
	}
	return 0;
}

Thanks.

Wrong Syscall number retrieval in WS2012

  • OS_VERSION: Windows Server 2012 6.2.9200

While enumerating the Service call numbers at ExtractStubs they seem to be offseted by 1.

This is due to NtGetTickCount being stored as the first RVA in 6.2.9200 ntdll.dll and not making use of a syscall nÂş.
image

Thus, creating said offset +1:

image

In recent versions of ntdll.dll this function is, instead, referenced at the end of the EAT.

Bridge between C#

Hey @ElephantSe4l & @jarilaos jarilaos , awesome work!

So I'm trying to create a bridge between FreshyCalls to C# using a DLL, I do not have much experience with C++ and was wondering why the following code does not compile:

// C++ 17 64bit
#include <windows.h>
#include <winternl.h>
#include "syscall/syscall.hpp"

static auto& syscall = freshycalls::Syscall::get_instance();

extern "C" __declspec(dllexport)

HANDLE HelloProcess(uint32_t process_id) {
    HANDLE handle{};
    OBJECT_ATTRIBUTES obj{};

    InitializeObjectAttributes(&obj, nullptr, 0, nullptr, nullptr);
    CLIENT_ID client = { reinterpret_cast<HANDLE>(static_cast<DWORD_PTR>(process_id)), nullptr };

    syscall.CallSyscall("NtOpenProcess",
        &handle,
        PROCESS_ALL_ACCESS,
        &obj,
        &client)
        .OrDie("[OpenProcess] An error happened while opening the target process: \"{{result_msg}}\" (Error Code: {{result_as_hex}})");

    return handle;
}

image

Any advice or help is more than welcome, thank you!

Kind regards,

Fenny

NtWriteVirtualMemory return STATUS_ACCESS_VIOLATION

NTSTATUS Status;

LPVOID BasePointer = NULL;
SIZE_T BaseSize = 1024;

char Payload[2048];
memset(Payload, 0, 2048);

Status = syscall.CallSyscall("NtAllocateVirtualMemory", NtCurrentProcess,
                            &BasePointer, 0, &BaseSize,
                            MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE)
                            .result;

Status = syscall.CallSyscall("NtWriteVirtualMemory", NtCurrentProcess,
                            BasePointer, Payload, 1024, nullptr)
                            .result;

NtWriteVirtualMemory return code is STATUS_ACCESS_VIOLATION(0xC0000005)
I'm still a beginner, so I don't know why the error occurs and how to debug it...

OS: Windows 11
Arch: x64
Compiler: Visual Studio 2022

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.