implement shellcode spawn for python API

This commit is contained in:
char
2023-12-04 11:36:04 -07:00
parent e8782ce441
commit e1f150ecbd
2 changed files with 42 additions and 0 deletions
@@ -51,6 +51,7 @@ PyObject* DemonClass_DotnetInlineExecute( PPyDemonClass self, PyObject *args )
PyObject* DemonClass_RegisterCallback( PPyDemonClass self, PyObject *args );
PyObject* DemonClass_Command( PPyDemonClass self, PyObject *args );
PyObject* DemonClass_CommandGetOutput( PPyDemonClass self, PyObject *args );
PyObject* DemonClass_ShellcodeSpawn( PPyDemonClass self, PyObject *args );
// Utils
PyObject* DemonClass_ConsoleWrite( PPyDemonClass self, PyObject *args );
@@ -42,6 +42,7 @@ PyMethodDef PyDemonClass_methods[] = {
{ "DotnetInlineExecute", ( PyCFunction ) DemonClass_DotnetInlineExecute, METH_VARARGS, "Executes a dotnet assembly in the context of the demon sessions" },
{ "Command", ( PyCFunction ) DemonClass_Command, METH_VARARGS, "Run a command" },
{ "CommandGetOutput", ( PyCFunction ) DemonClass_CommandGetOutput, METH_VARARGS, "Run a command and retreive the output" },
{ "ShellcodeSpawn", ( PyCFunction ) DemonClass_ShellcodeSpawn, METH_VARARGS, "Executes shellcode spawning a new process" },
{ NULL },
};
@@ -384,6 +385,46 @@ PyObject* DemonClass_CommandGetOutput( PPyDemonClass self, PyObject *args )
Py_RETURN_NONE;
}
// ShellcodeSpawn( QString TaskID, QString InjectionTechnique, QString TargetArch, QString Path, QString Arguments )
PyObject* DemonClass_ShellcodeSpawn( PPyDemonClass self, PyObject *args )
{
char* TaskID = NULL;
char* InjectTechnique = NULL;
char* TargetArch = NULL;
char* ShellcodePath = NULL;
char* ShellcodeArgs = NULL;
int ArgSize = 0;
auto ArgsByteArray = QByteArray();
spdlog::debug( "Running ShellcodeSpawn from python API" );
if ( ! PyArg_ParseTuple( args, "ssssO", &TaskID, &InjectTechnique, &TargetArch, &ShellcodePath, &ShellcodeArgs ) )
return NULL;
ArgSize = PyBytes_GET_SIZE( ShellcodeArgs );
ShellcodeArgs = PyBytes_AS_STRING( ShellcodeArgs );
ArgsByteArray = QByteArray( ShellcodeArgs, ArgSize );
for ( auto& Sessions : HavocX::Teamserver.Sessions )
{
if ( Sessions.Name.compare( self->DemonID ) == 0 )
{
if ( FileRead( ShellcodePath ) == nullptr )
{
Sessions.InteractedWidget->AppendRaw();
Sessions.InteractedWidget->TaskError( "Failed to open shellcode path: " + QString( ShellcodePath ) );
}
else
{
Sessions.InteractedWidget->DemonCommands->Execute.ShellcodeSpawn( TaskID, InjectTechnique, TargetArch, ShellcodePath, ArgsByteArray );
}
break;
}
}
Py_RETURN_NONE;
}
// Demon.DllInject( TaskID: str, Pid: str, DllPath: str, DllArgs: str )
PyObject* DemonClass_DllInject( PPyDemonClass self, PyObject *args )