void ftp_login(int sock,char*u_name,char*u_pass) { char buff[2048]; printf("loggin into system..\n"); snprintf(buff,2047,"USER %s\r\n", u_name); ftp_send(sock, buff,strlen(buff),1,buff,2047); printf(GREEN"USER %s\n"NORM"%s",u_name,buff); snprintf(buff,2047,"PASS %s\r\n",u_pass); printf(GREEN"PASS %s\n"NORM,*u_pass=='\x90'?"<shellcode>":u_pass); ftp_send(sock,buff,strlen(buff),1,buff,2047); while(strstr(buff,"230 ")==NULL){ (void)bzero(buff,2048); ftp_recv(sock,buff,2048,0); } printf("%s",buff); return; }
int ftp_siteexec(int sock,char*buff,int buff_len,int q,char*ans,int ans_len){ ftp_send(sock,buff,buff_len,q,ans,ans_len); if(strncmp(ans,"200-",4)==0) ftp_recv(sock,NULL,0,1); else ftp_recv(sock,ans,ans_len,0); if(strncmp(ans,"200-",4)){ fprintf(stderr,"Cannot find site exec response string\n"); exit(1); } return 0; }
int FTP_PutFile(char *tftpserver, int port, char *username, char *password, char *localfile, char *remotefile) { int fd = -1; int ret = -1; struct hostent *host = NULL; ftp_host_info_t server; unsigned short port1 = 0; FILE *control_stream = NULL; if (tftpserver==NULL || username==NULL || password==NULL || remotefile==NULL || localfile==NULL) { return -1; } if (port<=0 || port>65535) { port = 21; } host = gethostbyname(tftpserver); if (host == NULL) { return -1; } port1 = htons(port); strncpy(server.user, username, 32); strncpy(server.password, password, 32); server.s_in.sin_family = host->h_addrtype; server.s_in.sin_port = port1; memcpy(&server.s_in.sin_addr, (struct in_addr *) host->h_addr, sizeof(server.s_in.sin_addr)); control_stream = ftp_login(&server); if (control_stream == NULL) { printf("ftp_login() Failed!\n"); return -1; } ret = ftp_send(&server, control_stream, localfile, remotefile); return ret; }
int ftp_put(FTP_CON * con, const char *local_name, const char *remote_name) /* put file */ { int fh; int status; char buff[8193]; char str[256]; int count, i = 0; long total = 0; DWORD start, stop; if (ftp_open_write(con, remote_name) >= 0) return con->err_no; if ((fh = open(local_name, O_BINARY)) == -1) return FTP_FILE_ERROR; start = ss_millitime(); while ((count = read(fh, buff, 8192)) > 0) { total += ftp_send(con->data, buff, count); if (ftp_debug_func != NULL) { printf("%c\r", bars[(i++) % 4]); fflush(stdout); } } close(fh); stop = ss_millitime(); status = ftp_close(con); if (ftp_debug_func != NULL) { sprintf(str, "%ld bytes sent in %1.2f seconds (%1.2lf kB/sec).", total, (stop - start) / 1000.0, total / 1024.0 / ((stop - start) / 1000.0)); ftp_debug_func(str); } return status; }
int interface_capture (SDL_Surface *screen, int w, int h) {{{ const char *extension[]={".jpeg",".png",".bmp"}; /* This function is called to take a picure from the cam * and save it to a file */ char *capture_filename; SDL_Surface *tmp_surface; struct stat file_stat; int file_size = -1; /* Get a free filename */ capture_filename = getNewFilename (Dump_Path(), Dump_Prefix(), extension [configuration.dump_mode]); if (NULL == capture_filename) return -1; /* Capture the image*/ tmp_surface = get_ImageSurface(screen, w, h); /* {{{ Write image */ { unsigned char *data; int i; unsigned char tmp; data = (unsigned char*)tmp_surface->pixels; if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError()); free (capture_filename); return -1; } } /* swap Red and blue */ for (i=0; i<tmp_surface->w*tmp_surface->h*3; i+=3) { tmp = data[i]; data[i] = data[i+2]; data[i+2] = tmp; } if ( SDL_MUSTLOCK (screen) ) { SDL_UnlockSurface (screen); } switch (configuration.dump_mode) { case 0: write_file_jpeg (capture_filename, (unsigned char*)tmp_surface->pixels, tmp_surface->w, tmp_surface->h); break; case 1: write_file_png (capture_filename, (unsigned char*)tmp_surface->pixels, (unsigned int)tmp_surface->w, (unsigned int)tmp_surface->h); break; case 2: SDL_SaveBMP(tmp_surface, capture_filename); break; default: fprintf(stderr, "Unsuported capture format.\n"); break; } } /* }}} */ SDL_FreeSurface(tmp_surface); // if (configuration.debug > 0) printf("Saved file: %s\n", capture_filename); /* {{{ FTP-Stuff */ if( configuration.ftp_host !=NULL && configuration.ftp_user !=NULL && configuration.ftp_pass !=NULL && configuration.ftp_file !=NULL ) { if (init_ftp (configuration.ftp_host, configuration.ftp_user, configuration.ftp_pass)) { if (configuration.debug > 0) printf ("Starte FTP Upload\n"); if (configuration.ftp_temp != NULL) { if (configuration.debug > 0) printf ("Using FTP Rename Method\n"); if (ftp_send (capture_filename, configuration.ftp_temp)) ftp_rename (configuration.ftp_temp, configuration.ftp_file); } else ftp_send (capture_filename, configuration.ftp_file); } } /* }}} */ if (!stat (capture_filename, &file_stat)) { file_size = file_stat.st_size; } free (capture_filename); return file_size; }}}
int ftp_putfile(const char *infile, const char *outfile, putmode_t how, transfer_mode_t mode, ftp_transfer_func hookf) { FILE *fp; int r; struct stat statbuf; if(stat(infile, &statbuf) != 0) { perror(infile); return -1; } if(S_ISDIR(statbuf.st_mode)) { ftp_err(_("%s: is a directory\n"), infile); return -1; } fp = fopen(infile, "r"); if(fp == 0) { perror(infile); return -1; } ftp->ti.total_size = statbuf.st_size; free(ftp->ti.remote_name); free(ftp->ti.local_name); ftp->ti.remote_name = xstrdup(infile); /* actually local file, or _target_ */ ftp->ti.local_name = xstrdup(outfile); /* actually remote file, or _source_ */ if(how == putResume) { rfile *f; f = ftp_get_file(outfile); if(f && f->size != (unsigned long long)-1) ftp->restart_offset = f->size; else { ftp->restart_offset = ftp_filesize(outfile); if(ftp->restart_offset == (unsigned long long)-1) { ftp_err(_("unable to get remote filesize of '%s'," " unable to resume\n"), outfile); ftp->restart_offset = 0L; } } } else ftp->restart_offset = 0L; if(ftp->restart_offset > 0L) { if(fseek(fp, ftp->restart_offset, SEEK_SET) != 0) { ftp_err(_("%s: %s, transfer cancelled\n"), outfile, strerror(errno)); fclose(fp); return -1; } } foo_hookf = hookf; #ifdef HAVE_LIBSSH if(ftp->session) r = ssh_send(outfile, fp, how, mode, hookf); else #endif r = ftp_send(outfile, fp, how, mode, hookf); fclose(fp); return r; }
int main(int argc, char* argv[]) { struct sockaddr_in in; struct in_addr s; int fd, localfile, cmd, flag; unsigned long filesize = 0; struct stat st_buf; char path[MAX_LINE]; if (argc != 3) { printf("client ip port\n"); return 0; } in.sin_family = AF_INET; inet_pton(AF_INET, argv[1], &s); in.sin_addr = s; in.sin_port = htons(atoi(argv[2])); fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { perror("socket"); exit(-1); } if (connect(fd, (struct sockaddr*)&in, sizeof(struct sockaddr)) < 0) { perror("connect"); exit(-1); } printf("connect to server...\n"); cmd = ftp_cmd(fd, RECV_CMD, &cmd, &filesize, path); if (cmd == REQUEST_SEND) { stat(path, &st_buf); filesize = st_buf.st_size; } cmd = ftp_cmd(fd, SEND_CMD, &cmd, &filesize, path); if (cmd == REQUEST_SEND) flag = O_RDONLY; else if (cmd == REQUEST_RECV) flag = O_RDWR|O_CREAT|O_TRUNC; else if (cmd == REQUEST_RM) { printf("remove[%s]:",path); fprintf(stderr, "remove file %s\n", path); unlink(path); goto end; }else flag = O_RDWR; localfile = open(path, flag, 0666); if (localfile == -1) { perror("open"); exit(-1); } if (cmd == REQUEST_SEND) { printf("send[%s]:",path); if (ftp_send(fd, localfile, filesize) == -1) perror("ftp_send"); }else if (cmd == REQUEST_RECV) { printf("recv[%s]:",path); if (ftp_recv(fd, localfile, filesize) == -1) perror("ftp_recv"); }else { fprintf(stderr, "unknow command\n"); } end: close(fd); close(localfile); }