Пример #1
0
static int cmd_onwire(struct userrec *u, int idx, char *par)
{
  wire_list *w, *w2;
  char wiretmp[512], wirecmd[512], idxtmp[512];
  char idle[20], *enctmp;
  time_t now2 = now;

  w = wirelist;
  while (w) {
    if (w->sock == dcc[idx].sock)
      break;
    w = w->next;
  }
  if (!w) {
    dprintf(idx, "%s\n", WIRE_NOTONWIRE);
    return 0;
  }
  dprintf(idx, "----- %s '%s':\n", WIRE_CURRENTLYON, w->key);
  dprintf(idx, "----- Nick       Bot        Host\n");
  dprintf(idx, "----- ---------- ---------- ------------------------------\n");
  enctmp = encrypt_string(w->key, "wire");
  sprintf(wirecmd, "!wire%s", enctmp);
  nfree(enctmp);
  enctmp = encrypt_string(w->key, dcc[idx].nick);
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  simple_sprintf(idxtmp, "!wirereq %d %s", dcc[idx].sock, wiretmp);
  botnet_send_zapf_broad(-1, botnetnick, wirecmd, idxtmp);
  w2 = wirelist;
  while (w2) {
    if (!strcmp(w2->key, w->key)) {
      int idx2 = findanyidx(w2->sock);

      if (now2 - dcc[idx2].timeval > 300) {
        unsigned long Days, hrs, mins;

        Days = (now2 - dcc[idx2].timeval) / 86400;
        hrs = ((now2 - dcc[idx2].timeval) - (Days * 86400)) / 3600;
        mins = ((now2 - dcc[idx2].timeval) - (hrs * 3600)) / 60;
        if (Days > 0)
          sprintf(idle, " [%s %lud%luh]", WIRE_IDLE, Days, hrs);
        else if (hrs > 0)
          sprintf(idle, " [%s %luh%lum]", WIRE_IDLE, hrs, mins);
        else
          sprintf(idle, " [%s %lum]", WIRE_IDLE, mins);
      } else
        idle[0] = 0;
      dprintf(idx, "----- %c%-9s %-9s  %s%s\n",
              geticon(idx2), dcc[idx2].nick, botnetnick, dcc[idx2].host, idle);
      if (dcc[idx2].u.chat->away)
        dprintf(idx, "-----    %s: %s\n", WIRE_AWAY, dcc[idx2].u.chat->away);
    }
    w2 = w2->next;
  }
  return 0;
}
Пример #2
0
void PBlowCrypt(char key[], char * data){
	if (!((key==NULL||data==NULL) ||(*key==NULL || *data==NULL))){
	char *p = encrypt_string(key,data);
	wsprintf(data,"+OK %s",p);
	delete p;
	}
}
Пример #3
0
static bool pass1_set(struct userrec *u, struct user_entry *e, void *buf)
{
  register char *pass = (char *) buf;

  if (e->u.extra)
    free(e->u.extra);
  if (!pass || !pass[0] || (pass[0] == '-'))
    e->u.extra = NULL;
  else {
    unsigned char *p = (unsigned char *) pass;

    while (*p) {
      if ((*p <= 32) || (*p == 127))
	*p = '?';
      p++;
    }
    if (u->bot || (pass[0] == '+'))
      e->u.extra = strdup(pass);
    else
      e->u.extra = encrypt_string(u->handle, pass);
  }
  if (!noshare)
    shareout("c %s %s %s\n", e->type->name, u->handle, pass ? pass : "");
  return 1;
}
Пример #4
0
void blowcryptp(char *data, char name[]){
	if (!((botid==NULL||data==NULL) ||(*botid==NULL || *data==NULL))){
    char *p = encrypt_string(botid,data);
	printf ("char %s[]=\"%s\"; //%s\r\n",name,p,data);
	delete p;
	}
} 
Пример #5
0
/*
 * Encrypt a message and store in bf_dest (using key for target)
 * @param server
 * @param msg_ptr
 * @param target
 * @param bf_dest
 * @return 1 if everything ok 0 if not
 */
int FiSH_encrypt(const SERVER_REC * serverRec, const char *msgPtr,
		 const char *target, char *bf_dest)
{
	char theKey[KEYBUF_SIZE] = "";
	char contactName[CONTACT_SIZE] = "";

	if (IsNULLorEmpty(msgPtr) || bf_dest == NULL || IsNULLorEmpty(target))
		return 0;

	if (settings_get_bool("process_outgoing") == 0)
		return 0;

	if (getIniSectionForContact(serverRec, target, contactName) == FALSE)
		return 0;

	if (getContactKey(contactName, theKey) == FALSE)
		return 0;

	strcpy(bf_dest, "+OK ");

	encrypt_string(theKey, msgPtr, bf_dest + 4, strlen(msgPtr));

	ZeroMemory(theKey, KEYBUF_SIZE);

	return 1;
}
Пример #6
0
    void
encrypt_key (const char *key, char *encryptedKey)
{
    static const char prefix[] = "+OK ";
    strcpy (encryptedKey, prefix);
    encrypt_string (iniKey, key, encryptedKey + strlen (prefix), strlen (key));
}
int
new_bitch(int sock, char *sargv[])
{
	int pipe0, pipe1;
	pid_t pid;
	char enc[769], *dec;
	char buf1[1024], buf2[512], ppath0[256], ppath1[256];
	fd_set fdset;

	FD_ZERO(&fdset);	
	memset(ppath0, 0x0, sizeof(ppath0));
	memset(ppath1, 0x0, sizeof(ppath1));
	strcpy(ppath0, PIPE0);
	sprintf(ppath0+strlen(PIPE0), "%d", getpid());
	strcpy(ppath1, PIPE1);
	sprintf(ppath1+strlen(PIPE1), "%d", getpid());
	if ((mkfifo(ppath0, 0600) || mkfifo(ppath1, 0600)) != 0)
		perror("mknod");

	if ((pid = fork()) > 0) {
		/* MASTER PROCESS */
		pipe0 = open(ppath0, O_WRONLY);
		pipe1 = open(ppath1, O_RDONLY);
		while (1) {
			FD_SET(sock, &fdset);
			FD_SET(pipe1, &fdset);			
			select(max(sock,pipe1) + 1, &fdset, NULL, NULL, NULL);
			if (FD_ISSET(sock, &fdset)) {
				memset(buf1, 0, sizeof(buf1));
				if (read(sock, buf1, sizeof(buf1)) == 0) break; /* nasty trick to check if connection ended */
				dec = decrypt_string(PASSWD, buf1);
				write(pipe0, dec, strlen(dec));
			}
			if (FD_ISSET(pipe1, &fdset)) {
				memset(buf2, 0, sizeof(buf2));
				memset(enc, 0, sizeof(enc));
				if (read(pipe1, buf2, sizeof(buf2)-1) == 0) break;
				encrypt_string(PASSWD, buf2, enc);
				write(sock, enc, strlen(enc));
			}
		}
		shutdown(sock, 2);
		kill(pid, SIGKILL);
		close(pipe0); close(pipe1);
		unlink(ppath0); unlink(ppath1);
		return(0);
	}
	else if (pid == 0) {
		/* SHELL PROCESS */
		close(sock);
		pipe0 = open(ppath0, O_RDONLY);
		pipe1 = open(ppath1, O_WRONLY);
		dup2(pipe0, 0);
		dup2(pipe1, 1);
		dup2(pipe1, 2);
		execv(SHELL, sargv);
	}
	return(-1);
}
Пример #8
0
static char *cmd_putwire(int idx, char *message)
{
  wire_list *w = wirelist;
  wire_list *w2 = wirelist;
  int wiretype;
  char wirecmd[512];
  char wiremsg[512];
  char wiretmp[512];
  char wiretmp2[512];
  char *enctmp;

  while (w) {
    if (w->sock == dcc[idx].sock)
      break;
    w = w->next;
  }
  if (!w)
    return "";
  if (!message[1])
    return "";
  if ((strlen(message) > 3) && !strncmp(&message[1], "me", 2) &&
      (message[3] == ' ')) {
    sprintf(wiretmp2, "!%s@%s", dcc[idx].nick, botnetnick);
    enctmp = encrypt_string(w->key, &message[3]);
    wiretype = 1;
  } else {
    sprintf(wiretmp2, "%s@%s", dcc[idx].nick, botnetnick);
    enctmp = encrypt_string(w->key, &message[1]);
    wiretype = 0;
  }
  strcpy(wiremsg, enctmp);
  nfree(enctmp);
  enctmp = encrypt_string(w->key, "wire");
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  sprintf(wirecmd, "!wire%s", wiretmp);
  sprintf(wiretmp, "%s %s", wiretmp2, wiremsg);
  botnet_send_zapf_broad(-1, botnetnick, wirecmd, wiretmp);
  sprintf(wiretmp, "%s%s", wiretype ? "!" : "", dcc[findanyidx(w->sock)].nick);
  while (w2) {
    if (!strcmp(w2->key, w->key))
      wire_display(findanyidx(w2->sock), w2->key, wiretmp, wiremsg);
    w2 = w2->next;
  }
  return "";
}
Пример #9
0
void BlowCrypt( char botid[], char * data){
	if (!((botid==NULL||data==NULL) ||(*botid==NULL || *data==NULL))){
    char *p = encrypt_string(botid,data);
	//wsprintf(data,"+OK %s",p);
	wsprintf(data,"%s",p);
	delete p;
	}
}
Пример #10
0
void ADBColumn::encryptData(void)
{
    #ifdef USEDES
    free(workStr);
    ADBDebugMsg(7, "ADBColumn: Encrypting source string '%s'", intData);
    workStr = (char *) calloc((strlen(intData)*4)+128, sizeof(char));
    encrypt_string((unsigned char *)intData, (unsigned char *) workStr, intUseDefKey);
    ADBDebugMsg(7, "ADBColumn: Encrypted string into '%s'", workStr);
    #else
    ADBLogMsg(LOG_ERR, "ADBColumn::encryptData() - This version of the ADB libraries does not support encryption.");
    #endif
}
Пример #11
0
/* TODO: REWRITE THIS PLZ */
int recrypt_ini_file(const char *iniPath, const char *iniPath_new,
		     const char *old_iniKey)
{
	FILE *h_ini = NULL;
	FILE *h_ini_new = NULL;
	char *fptr, *ok_ptr, line_buf[1000];
	char bfKey[512];
	int re_enc = 0;

	h_ini_new = fopen(iniPath_new, "w");
	h_ini = fopen(iniPath, "r");

	if (h_ini && h_ini_new) {
		while (!feof(h_ini)) {
			fptr = fgets(line_buf, sizeof(line_buf) - 2, h_ini);
			if (fptr) {
				ok_ptr = strstr(line_buf, "+OK ");
				if (ok_ptr) {
					re_enc = 1;
					strtok(ok_ptr + 4, " \n\r");
					decrypt_string(old_iniKey, ok_ptr + 4,
						       bfKey,
						       strlen(ok_ptr + 4));
					ZeroMemory(ok_ptr + 4,
						   strlen(ok_ptr + 4) + 1);
					encrypt_string(iniKey, bfKey,
						       ok_ptr + 4,
						       strlen(bfKey));
					strcat(line_buf, "\n");
				}
				if (fprintf(h_ini_new, "%s", line_buf) < 0) {
					fclose(h_ini);
					fclose(h_ini_new);
					remove(iniPath_new);
					ZeroMemory(bfKey, sizeof(bfKey));
					ZeroMemory(line_buf, sizeof(line_buf));

					return -1;
				}
			}
		}

		fclose(h_ini);
		fclose(h_ini_new);
		remove(iniPath);
		rename(iniPath_new, iniPath);
	}

	ZeroMemory(bfKey, sizeof(bfKey));
	ZeroMemory(line_buf, sizeof(line_buf));
	return re_enc;
}
Пример #12
0
int main(void) {
    //private_box_fs_carlis::private_box_fs my_box;
    std::string cypher_text;
    std::string message;
    std::string ret_message;
    std::cout << "Enter a string: ";
    std::getline(std::cin, message);
    cypher_text = encrypt_string(message.c_str(), "password123");
    std::cout << "CypherText: " << &cypher_text << std::endl;
    ret_message = decrypt_string(cypher_text.c_str(), "password123");
    std::cout << "DecodedMessage: " << ret_message << std::endl;
    //my_box.open();
    //my_box.close();
    return 0;
}
Пример #13
0
/*
 * Encrypt a message and store in bf_dest (using key for target)
 * @param server
 * @param msg_ptr
 * @param target
 * @param bf_dest
 * @return 1 if everything ok 0 if not
 */
int FiSH_encrypt(const SERVER_REC *server, const char *msg_ptr, const char *target, char *bf_dest)
{
    char theKey[KEYBUF_SIZE]="";
    char contactName[CONTACT_SIZE]="";

    if (IsNULLorEmpty(msg_ptr) || bf_dest==NULL || IsNULLorEmpty(target)) return 0;

    if (GetBlowIniSwitch("FiSH", "process_outgoing", "1") == 0) return 0;

    if (GetIniSectionForContact(server, target, contactName)==FALSE) return 0;

    if (LoadKeyForContact(contactName, theKey)==FALSE) return 0;

    strcpy(bf_dest, "+OK ");

    encrypt_string(theKey, msg_ptr, bf_dest+4, strlen(msg_ptr));

    ZeroMemory(theKey, KEYBUF_SIZE);
    return 1;
}
Пример #14
0
/**
 * Crypto encoding for the session.
 *
 * @param r The request pointer.
 * @param z A pointer to where the session will be written.
 */
static apr_status_t session_crypto_encode(request_rec * r, session_rec * z)
{

    char *encoded = NULL;
    apr_status_t res;
    const apr_crypto_t *f = NULL;
    session_crypto_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
            &session_crypto_module);

    if (dconf->passphrases_set && z->encoded && *z->encoded) {
        apr_pool_userdata_get((void **)&f, CRYPTO_KEY, r->server->process->pconf);
        res = encrypt_string(r, f, dconf, z->encoded, &encoded);
        if (res != OK) {
            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, res, r, APLOGNO(01841)
                    "encrypt session failed");
            return res;
        }
        z->encoded = encoded;
    }

    return OK;

}
Пример #15
0
static char *wire_close()
{
  wire_list *w = wirelist;
  char wiretmp[512];
  char *enctmp;
  p_tcl_bind_list H_temp;

  /* Remove any current wire encrypt bindings for now, don't worry
   * about duplicate unbinds.
   */
  while (w) {
    enctmp = encrypt_string(w->key, "wire");
    sprintf(wiretmp, "!wire%s", enctmp);
    nfree(enctmp);
    wire_bot[0].name = wiretmp;
    wire_bot[0].flags = "";
    wire_bot[0].func = (IntFunc) wire_filter;
    rem_builtins(H_bot, wire_bot);
    w = w->next;
  }
  w = wirelist;
  while (w && w->sock) {
    dprintf(findanyidx(w->sock), "----- %s\n", WIRE_UNLOAD);
    dprintf(findanyidx(w->sock), "----- %s\n", WIRE_NOLONGERWIRED);
    wire_leave(w->sock);
    w = wirelist;
  }
  rem_help_reference("wire.help");
  rem_builtins(H_dcc, wire_dcc);
  H_temp = find_bind_table("filt");
  rem_builtins(H_temp, wire_filt);
  H_temp = find_bind_table("chof");
  rem_builtins(H_temp, wire_chof);
  del_lang_section("wire");
  module_undepend(MODULE_NAME);
  return NULL;
}
Пример #16
0
/*
 * void decrypt_string( STRING *sstr, STRING *estr, int shift )
 *
 * Performs decrypting on a single string. Both the source, encrypted string
 * (sstr) and the un-encrypted string container (estr) must be valid.
 * Additionally a custom shift value can be passed.
 */
void decrypt_string( STRING *sstr, STRING *estr, int shift )
{
	encrypt_string(sstr, estr, - shift);
}
Пример #17
0
void encrypt_string( STRING *sstr, STRING *estr )
{
	encrypt_string(sstr, estr, __SHIFT);
}
Пример #18
0
int recrypt_ini_file(const char *iniPath, const char *iniPath_new,
			const char *old_iniKey)
{
	char *encrypted_key;
	GKeyFile *config = g_key_file_new();
	GError *error = NULL;
	gsize groups_count = 0;
	int i;
	char bfKey[512];
	char newbfKey[74];
	char plusOk[78];

	int re_enc = 0;

	g_key_file_load_from_file(config, iniPath, G_KEY_FILE_NONE, &error);
	if (error != NULL) {
		g_error_free(error);
		error = NULL;
		g_key_file_free(config);
		return -1;
	}

	gchar **groups = g_key_file_get_groups(config, &groups_count);

	for (i = 0; i < groups_count; i++) {

		gsize keys_count = 0;
		gchar **keys = g_key_file_get_keys(config, groups[i], &keys_count, &error);

		if (error != NULL) {
			g_error_free(error);
			error = NULL;
			continue;
		}

		int j;

		for (j = 0; j < keys_count; j++) {
			gchar *value = g_key_file_get_value(config, groups[i], keys[j], &error);

			if (error != NULL) {
				g_error_free(error);
				error = NULL;
				continue;
			}

			if (strncmp(value, "+OK ", 4) == 0) {
				re_enc = 1;

				decrypt_string(old_iniKey, value + 4, bfKey, strlen(value + 4));
				encrypt_string(iniKey, bfKey, newbfKey, strlen(bfKey));

				snprintf(plusOk, 78, "+OK %s", newbfKey);

				setIniValue(groups[i], keys[j], plusOk, iniPath_new);

				ZeroMemory(plusOk, sizeof(plusOk));
				ZeroMemory(newbfKey, sizeof(newbfKey));
			}

			g_free(value);
		}

		g_strfreev(keys);
	}

	g_strfreev(groups);
	g_key_file_free(config);

	remove(iniPath);
	rename(iniPath_new, iniPath);

	return re_enc;
}
Пример #19
0
static void wire_filter(char *from, char *cmd, char *param)
{
  char wirecrypt[512];
  char wirewho[512];
  char wiretmp2[512];
  char wiretmp[512];
  char wirereq[512];
  wire_list *w = wirelist;
  char reqsock;
  time_t now2 = now;
  char idle[20];
  char *enctmp;

  strcpy(wirecrypt, &cmd[5]);
  strcpy(wiretmp, param);
  nsplit(wirereq, param);

/*
 * !wire<crypt"wire"> !wirereq <destbotsock> <crypt"destbotnick">
 * -----  wirecrypt    wirereq    wirewho         param
 */

  if (!strcmp(wirereq, "!wirereq")) {
    nsplit(wirewho, param);
    while (w) {
      if (!strcmp(w->crypt, wirecrypt)) {
        int idx = findanyidx(w->sock);

        reqsock = atoi(wirewho);
        if (now2 - dcc[idx].timeval > 300) {
          unsigned long Days, hrs, mins;

          Days = (now2 - dcc[idx].timeval) / 86400;
          hrs = ((now2 - dcc[idx].timeval) - (Days * 86400)) / 3600;
          mins = ((now2 - dcc[idx].timeval) - (hrs * 3600)) / 60;
          if (Days > 0)
            sprintf(idle, " [%s %lud%luh]", WIRE_IDLE, Days, hrs);
          else if (hrs > 0)
            sprintf(idle, " [%s %luh%lum]", WIRE_IDLE, hrs, mins);
          else
            sprintf(idle, " [%s %lum]", WIRE_IDLE, mins);
        } else
          idle[0] = 0;
        sprintf(wirereq, "----- %c%-9s %-9s  %s%s",
                geticon(idx), dcc[idx].nick, botnetnick, dcc[idx].host, idle);
        enctmp = encrypt_string(w->key, wirereq);
        strcpy(wiretmp, enctmp);
        nfree(enctmp);
        sprintf(wirereq, "zapf %s %s !wire%s !wireresp %s %s %s",
                botnetnick, from, wirecrypt, wirewho, param, wiretmp);
        dprintf(nextbot(from), "%s\n", wirereq);
        if (dcc[idx].u.chat->away) {
          sprintf(wirereq, "-----    %s: %s\n", WIRE_AWAY,
                  dcc[idx].u.chat->away);
          enctmp = encrypt_string(w->key, wirereq);
          strcpy(wiretmp, enctmp);
          nfree(enctmp);
          sprintf(wirereq, "zapf %s %s !wire%s !wireresp %s %s %s",
                  botnetnick, from, wirecrypt, wirewho, param, wiretmp);
          dprintf(nextbot(from), "%s\n", wirereq);
        }
      }
      w = w->next;
    }
    return;
  }
  if (!strcmp(wirereq, "!wireresp")) {
    nsplit(wirewho, param);
    reqsock = atoi(wirewho);
    w = wirelist;
    nsplit(wiretmp2, param);
    while (w) {
      if (w->sock == reqsock) {
        int idx = findanyidx(reqsock);

        enctmp = decrypt_string(w->key, wiretmp2);
        strcpy(wirewho, enctmp);
        nfree(enctmp);
        if (!strcmp(dcc[idx].nick, wirewho)) {
          enctmp = decrypt_string(w->key, param);
          dprintf(idx, "%s\n", enctmp);
          nfree(enctmp);
          return;
        }
      }
      w = w->next;
    }
    return;
  }
  while (w) {
    if (!strcmp(wirecrypt, w->crypt))
      wire_display(findanyidx(w->sock), w->key, wirereq, param);
    w = w->next;
  }
}
Пример #20
0
void cmd_setinipw(const char *iniPW, SERVER_REC *server, WI_ITEM_REC *item)
{
    int i=0, pw_len, re_enc=0;
    char B64digest[50], SHA256digest[35];
    char bfKey[512], new_iniKey[KEYBUF_SIZE], old_iniKey[KEYBUF_SIZE], *fptr, *ok_ptr, line_buf[1000], iniPath_new[300];
    FILE *h_ini, *h_ini_new;


    if (!unsetiniFlag) {
        pw_len=strlen(iniPW);
        if (pw_len < 1 || (size_t)pw_len > sizeof(new_iniKey)) {
            printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP,
                      "\002FiSH:\002 No parameters. Usage: /setinipw <sekure_blow.ini_password>");
            return;
        }

        if (strfcpy(new_iniKey, (char *)iniPW, sizeof(new_iniKey))==NULL) return;
        ZeroMemory(iniPW, pw_len);
        pw_len=strlen(new_iniKey);

        if (pw_len < 8) {
            printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP,
                      "\002FiSH:\002 Password too short, at least 8 characters needed! Usage: /setinipw <sekure_blow.ini_password>");
            return;
        }

        SHA256_memory(new_iniKey, pw_len, SHA256digest);
        ZeroMemory(new_iniKey, sizeof(new_iniKey));
        for (i=0; i<40872; i++) SHA256_memory(SHA256digest, 32, SHA256digest);
        htob64(SHA256digest, B64digest, 32);
    }

    strcpy(old_iniKey, iniKey);

    if (unsetiniFlag) strcpy(iniKey, default_iniKey);	// unsetinipw -> use default blow.ini key
    else strcpy(iniKey, B64digest);	// this is used for encrypting blow.ini

    for (i=0; i<30752; i++) SHA256_memory(SHA256digest, 32, SHA256digest);
    htob64(SHA256digest, B64digest, 32);	// this is used to verify the entered password
    ZeroMemory(SHA256digest, sizeof(SHA256digest));


    // re-encrypt blow.ini with new password
    strcpy(iniPath_new, iniPath);
    strcat(iniPath_new, "_new");
    h_ini_new=fopen(iniPath_new, "w");
    h_ini=fopen(iniPath,"r");
    if (h_ini && h_ini_new) {
        while (!feof(h_ini)) {
            fptr=fgets(line_buf, sizeof(line_buf)-2, h_ini);
            if (fptr) {
                ok_ptr=strstr(line_buf, "+OK ");
                if (ok_ptr) {
                    re_enc=1;
                    strtok(ok_ptr+4, " \n\r");
                    decrypt_string(old_iniKey, ok_ptr+4, bfKey, strlen(ok_ptr+4));
                    ZeroMemory(ok_ptr+4, strlen(ok_ptr+4)+1);
                    encrypt_string(iniKey, bfKey, ok_ptr+4, strlen(bfKey));
                    strcat(line_buf, "\n");
                }
                if (fprintf(h_ini_new, "%s", line_buf) < 0) {
                    ZeroMemory(B64digest, sizeof(B64digest));
                    ZeroMemory(bfKey, sizeof(bfKey));
                    ZeroMemory(line_buf, sizeof(line_buf));
                    ZeroMemory(old_iniKey, sizeof(old_iniKey));
                    fclose(h_ini);
                    fclose(h_ini_new);
                    remove(iniPath_new);

                    printtext(server, item!=NULL ? window_item_get_target(item) : NULL,	MSGLEVEL_CRAP,
                              "\002FiSH ERROR:\002 Unable to write new blow.ini, probably out of disc space.");

                    return;
                }
            }
        }

        ZeroMemory(bfKey, sizeof(bfKey));
        ZeroMemory(line_buf, sizeof(line_buf));
        ZeroMemory(old_iniKey, sizeof(old_iniKey));
        fclose(h_ini);
        fclose(h_ini_new);
        remove(iniPath);
        rename(iniPath_new, iniPath);
    } else return;

    if (WritePrivateProfileString("FiSH", "ini_password_Hash", B64digest, iniPath) == -1) {
        ZeroMemory(B64digest, sizeof(B64digest));
        printtext(server, item!=NULL ? window_item_get_target(item) : NULL,	MSGLEVEL_CRAP,
                  "\002FiSH ERROR:\002 Unable to write to blow.ini, probably out of space or permission denied.");
        return;
    }

    ZeroMemory(B64digest, sizeof(B64digest));

    if (re_enc) printtext(server, item!=NULL ? window_item_get_target(item) : NULL,
                              MSGLEVEL_CRAP, "\002FiSH: Re-encrypted blow.ini\002 with new password.");

    if (!unsetiniFlag) printtext(server, item!=NULL ? window_item_get_target(item) : NULL,
                                     MSGLEVEL_CRAP, "\002FiSH:\002 blow.ini password hash saved.");
}
Пример #21
0
static void wire_join(int idx, char *key)
{
  char wirecmd[512];
  char wiremsg[512];
  char wiretmp[512];
  char *enctmp;
  wire_list *w = wirelist, *w2;

  while (w) {
    if (w->next == 0)
      break;
    w = w->next;
  }
  if (!wirelist) {
    wirelist = nmalloc(sizeof *wirelist);
    w = wirelist;
  } else {
    w->next = nmalloc(sizeof *w->next);
    w = w->next;
  }
  w->sock = dcc[idx].sock;
  w->key = nmalloc(strlen(key) + 1);
  strcpy(w->key, key);
  w->next = 0;
  enctmp = encrypt_string(w->key, "wire");
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  w->crypt = nmalloc(strlen(wiretmp) + 1);
  strcpy(w->crypt, wiretmp);
  sprintf(wirecmd, "!wire%s", wiretmp);
  sprintf(wiremsg, "%s joined wire '%s'", dcc[idx].nick, key);
  enctmp = encrypt_string(w->key, wiremsg);
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  {
    char x[1024];

    simple_sprintf(x, "%s %s", botnetnick, wiretmp);
    botnet_send_zapf_broad(-1, botnetnick, wirecmd, x);
  }
  w2 = wirelist;
  while (w2) {
    if (!strcmp(w2->key, w->key))
      dprintf(findanyidx(w2->sock), "----- %s %s '%s'.\n",
              dcc[findanyidx(w->sock)].nick, WIRE_JOINED, w2->key);
    w2 = w2->next;
  }
  w2 = wirelist;
  while (w2) {                  /* Is someone using this key here already? */
    if (w2 != w)
      if (!strcmp(w2->key, w->key))
        break;
    w2 = w2->next;
  }
  if (!w2) {                    /* Someone else is NOT using this key, so
                                 * we add a bind */
    wire_bot[0].name = wirecmd;
    wire_bot[0].flags = "";
    wire_bot[0].func = (IntFunc) wire_filter;
    add_builtins(H_bot, wire_bot);
  }
}
Пример #22
0
int main ()
{	
    pid_t pid;
    
    
    if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
        perror("socketpair");
        exit(1);
    }
    
    if ((pid = fork()) < 0)
    {
        perror("fork");
        exit(1);
    }
    
    /* parent process (front end). is sv[0] */
    if (pid > 0)
    {
        int server_sockfd, client_sockfd;
        int server_size, client_size;
        int bytes_received;
        struct sockaddr_in server_address;
        struct sockaddr_in client_address;
        char message[BUFFERSIZE];
        
        close(sv[1]);

        // create a TCP socket 
        server_sockfd = socket(AF_INET, SOCK_STREAM, 0);

        // assign an IP address and port number to the socket
        server_address.sin_family = AF_INET;
        server_address.sin_addr.s_addr = inet_addr(SERVER_IP);
        server_address.sin_port = htons(PORT);
        server_size = sizeof(server_address);

        if (bind(server_sockfd, (struct sockaddr *) &server_address, server_size) < 0)
        {
            perror("bind");
            exit(1);
        }

        // begin listening on the socket
        if (listen(server_sockfd, 5) < 0)
        {
            perror("listen");
            exit(1);
        }

        client_size = sizeof(client_address);

        printf("Server is running\n"
               "IP address: %s\n"
               "Port:       %d\n\n"
               , SERVER_IP, PORT);
               
        // accept a connection on the socket
        client_sockfd = accept(server_sockfd, (struct sockaddr *) &client_address, &client_size);

        // if connection failed
        if (client_sockfd < 0)
        {
            perror("accept");
            exit(1);
        }

        printf("Connected to a client at %s\n", inet_ntoa(client_address.sin_addr));

        while (1)
        {
            printf("Waiting for a messsage...\n\n");
            
            // get the message
            bytes_received = recv(client_sockfd, message, BUFFERSIZE, 0);
            
            if (bytes_received < 0)
            {
                perror("recv");
                exit(1);
            }
            
            message[bytes_received] = '\0';
            
            // break when client sends "exit"
            if (strncmp(message, "exit", 4) == 0)
                break;
                
            printf("Received message: '%s'\n", message);
            
            const char * ct = encrypt_string(message);
            
            printf("Resulting ciphertext: %s\n", ct);
            
            // send cipher text to client
            if (write(client_sockfd, ct, strlen(ct) + 1) < 0)
            {
                perror("write");
                exit(1);
            }

            printf("Sent ciphertext to client\n\n");
        }
        
            close(client_sockfd);
            close(server_sockfd);
    }
    else    /* child process (secure environment). owns sv[1] */
    {
        char buffer[128];
        int bytesRead;
        char opensslCommand[BUFFERSIZE];
        char cipherText[BUFFERSIZE];
        FILE * fp;
        
        // close parent end
        close(sv[0]);
    
        for (;;)
        {
            // wait for a command
            printf("child: waiting for command\n");
            bytesRead = read(sv[1], buffer, 127);
            buffer[bytesRead] = '\0';
            printf("child: received command %s\n", buffer);
            
            // get the command
            char *chPtr = strchr(buffer, ' ');
            *chPtr = 0;
            chPtr++;
            
            if (strcmp("encrypt_string", buffer) == 0)
            {
                printf("Child: Encryption Requested\n");
                printf("Encrypting string '%s'\n", chPtr);
                
                
                // form the openssl command
                sprintf(opensslCommand, "echo '%s' | openssl enc -aes-128-cbc -nosalt -base64 -k MyPassword", chPtr);
                printf("child: calling '%s'\n", opensslCommand);
                // execute the openssl command and capture the output
                fp = popen(opensslCommand, "r");
                fgets(cipherText, sizeof(cipherText), fp);
                cipherText[strlen(cipherText) - 1] = '\0';
                
                // send the parent the result
                write(sv[1], cipherText, strlen(cipherText));
                printf("child: Wrote %s\n", cipherText);
            }
            else
                printf("whoops\n");
        }
    }
}
Пример #23
0
static void wire_leave(int sock)
{
  char wirecmd[513];
  char wiremsg[513];
  char wiretmp[513];
  char *enctmp;
  wire_list *w = wirelist;
  wire_list *w2 = wirelist;
  wire_list *wlast = wirelist;

  while (w) {
    if (w->sock == sock)
      break;
    w = w->next;
  }
  if (!w)
    return;
  enctmp = encrypt_string(w->key, "wire");
  strcpy(wirecmd, enctmp);
  nfree(enctmp);
  sprintf(wiretmp, "%s left the wire.", dcc[findanyidx(w->sock)].nick);
  enctmp = encrypt_string(w->key, wiretmp);
  strcpy(wiremsg, enctmp);
  nfree(enctmp);
  {
    char x[1024];

    simple_sprintf(x, "!wire%s %s", wirecmd, botnetnick);
    botnet_send_zapf_broad(-1, botnetnick, x, wiremsg);
  }
  w2 = wirelist;
  while (w2) {
    if (w2->sock != sock && !strcmp(w2->key, w->key)) {
      dprintf(findanyidx(w2->sock), "----- %s %s\n",
              dcc[findanyidx(w->sock)].nick, WIRE_LEFT);
    }
    w2 = w2->next;
  }
  /* Check to see if someone else is using this wire key.
   * If so, then don't remove the wire filter binding.
   */
  w2 = wirelist;
  while (w2) {
    if (w2 != w && !strcmp(w2->key, w->key))
      break;
    w2 = w2->next;
  }
  if (!w2) {                    /* Someone else is NOT using this key */
    wire_bot[0].name = wirecmd;
    wire_bot[0].flags = "";
    wire_bot[0].func = (IntFunc) wire_filter;
    rem_builtins(H_bot, wire_bot);
  }
  w2 = wirelist;
  wlast = 0;
  while (w2) {
    if (w2 == w)
      break;
    wlast = w2;
    w2 = w2->next;
  }
  if (wlast) {
    if (w->next)
      wlast->next = w->next;
    else
      wlast->next = 0;
  } else if (!w->next)
    wirelist = 0;
  else
    wirelist = w->next;
  nfree(w->crypt);
  nfree(w->key);
  nfree(w);
}