Skip to content

Commit e408cf9

Browse files
committed
More shellcode formats
1 parent e8f7f7e commit e408cf9

5 files changed

Lines changed: 69 additions & 6 deletions

File tree

Shellcodev/Shellcodev.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<ClCompile Include="command.cpp" />
2828
<ClCompile Include="eval.cpp" />
2929
<ClCompile Include="init.cpp" />
30+
<ClCompile Include="inject.cpp" />
3031
<ClCompile Include="loop.cpp" />
3132
<ClCompile Include="main.cpp" />
3233
<ClCompile Include="print.cpp" />

Shellcodev/Shellcodev.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
<ClCompile Include="str.cpp">
5151
<Filter>Source Files</Filter>
5252
</ClCompile>
53+
<ClCompile Include="inject.cpp">
54+
<Filter>Source Files</Filter>
55+
</ClCompile>
5356
</ItemGroup>
5457
</Project>

Shellcodev/command.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,49 @@ static BOOL shelldev_edit(shell_t* sh, std::vector<asm_t>* assemblies, std::vect
352352

353353
static BOOL shelldev_toshell(std::vector<asm_t>* assemblies, std::vector<std::string> parts)
354354
{
355-
if (parts[0] == "c" || parts[0] == "C")
355+
if (parts[0] == "c")
356356
{
357+
int count = 0;
357358
std::cout << "unsigned char shellcode[] = {" << std::endl;
358-
for (asm_t assembly : *assemblies)
359+
for (int i = 0; i < assemblies->size(); i++)
359360
{
360-
for (unsigned char byte : assembly.bytes)
361-
printf("0x%x, ", byte);
361+
for (int j = 0; j < assemblies->at(i).instruction.size(); j++)
362+
{
363+
if (count % 12 == 0)
364+
printf("\n");
365+
else
366+
printf("0x%x, ", assemblies->at(i).instruction[j]);
367+
368+
count++;
369+
}
362370
}
363371
std::cout << "};" << std::endl;
364372
}
373+
else if (parts[0] == "cs")
374+
{
375+
int count = 0;
376+
std::cout << "byte[] shellcode = {" << std::endl;
377+
for (int i = 0; i < assemblies->size(); i++)
378+
{
379+
for (int j = 0; j < assemblies->at(i).instruction.size(); j++)
380+
{
381+
if (count % 12 == 0)
382+
printf("\n");
383+
else
384+
printf("0x%x, ", assemblies->at(i).instruction[j]);
385+
386+
count++;
387+
}
388+
}
389+
std::cout << "};" << std::endl;
390+
}
391+
else if (parts[0] == "raw")
392+
{
393+
for (int i = 0; i < assemblies->size(); i++)
394+
for (int j = 0; j < assemblies->at(i).instruction.size(); j++)
395+
printf("%X", assemblies->at(i).instruction[j]);
396+
printf("\n");
397+
}
365398

366399
return TRUE;
367400
}
@@ -385,7 +418,8 @@ static BOOL winrepl_command_help()
385418
std::cout << ".del line\t\tDelete specified line from list." << std::endl;
386419
std::cout << ".read addr size\t\tRead from a memory address." << std::endl;
387420
std::cout << ".write addr hexdata\tWrite to a memory address." << std::endl;
388-
std::cout << ".toshell format\t\tConvert list to selected shellcode format. Available formats: c" << std::endl;
421+
std::cout << ".toshell format\t\tConvert list to selected shellcode format. Available formats: c, cs, raw" << std::endl;
422+
//std::cout << ".inject pid\t\tTest shellcode by injecting it into the process." << std::endl;
389423
std::cout << ".allocate size\t\tAllocate a memory buffer." << std::endl;
390424
std::cout << ".loadlibrary path\tLoad a DLL into the process." << std::endl;
391425
std::cout << ".kernel32 func\t\tGet address of a kernel32 export." << std::endl;
@@ -412,6 +446,8 @@ BOOL shelldev_run_command(shell_t* sh, std::string command, std::vector<asm_t>*
412446
return shelldev_edit(sh, assemblies, parts);
413447
else if (mainCmd == ".toshell")
414448
return shelldev_toshell(assemblies, parts);
449+
else if (mainCmd == ".inject")
450+
return shelldev_inject_shellcode(assemblies, parts[0]);
415451
else if (mainCmd == ".read")
416452
return shelldev_command_read(sh, parts);
417453
else if (mainCmd == ".del")

Shellcodev/inject.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "repl.h"
2+
3+
static std::vector<unsigned char> get_shellcode(std::vector<asm_t>* assemblies)
4+
{
5+
std::vector<unsigned char> bytes;
6+
7+
for (asm_t assembly : *assemblies)
8+
bytes.insert(bytes.end(), assembly.bytes.begin(), assembly.bytes.end());
9+
10+
return bytes;
11+
}
12+
13+
BOOL shelldev_inject_shellcode(std::vector<asm_t>* assemblies, std::string pid)
14+
{
15+
DWORD PID = std::stoi(pid);
16+
shelldev_print_good("Injecting shellcode into %d", PID);
17+
18+
std::vector<unsigned char> bytes = get_shellcode(assemblies);
19+
20+
return TRUE;
21+
}

Shellcodev/repl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ void shelldev_print_registers_all(shell_t* sh);
4646
void shelldev_print_assembly(unsigned char* encode, size_t size);
4747
void shelldev_print_bytes(unsigned char* addr, int len, unsigned long long start_addr = 0);
4848
void shelldev_print_good(const char* format, ...);
49-
void shelldev_print_errors(const char* format, ...);
49+
void shelldev_print_errors(const char* format, ...);
50+
51+
BOOL shelldev_inject_shellcode(std::vector<asm_t>* assemblies, std::string pid);

0 commit comments

Comments
 (0)