int ntlm_convert_password_hash(NTLM_CONTEXT* context, BYTE* hash) { int status; int i, hn, ln; char* PasswordHash = NULL; UINT32 PasswordHashLength = 0; SSPI_CREDENTIALS* credentials = context->credentials; /* Password contains a password hash of length (PasswordLength / SSPI_CREDENTIALS_HASH_LENGTH_FACTOR) */ PasswordHashLength = credentials->identity.PasswordLength / SSPI_CREDENTIALS_HASH_LENGTH_FACTOR; status = ConvertFromUnicode(CP_UTF8, 0, (LPCWSTR) credentials->identity.Password, PasswordHashLength, &PasswordHash, 0, NULL, NULL); if (status <= 0) return -1; CharUpperBuffA(PasswordHash, PasswordHashLength); for (i = 0; i < 32; i += 2) { hn = PasswordHash[i] > '9' ? PasswordHash[i] - 'A' + 10 : PasswordHash[i] - '0'; ln = PasswordHash[i + 1] > '9' ? PasswordHash[i + 1] - 'A' + 10 : PasswordHash[i + 1] - '0'; hash[i / 2] = (hn << 4) | ln; } free(PasswordHash); return 1; }
netbios_name::netbios_name(LPCTSTR n, UCHAR type, bool group, UCHAR lana) : m_managed (false), m_registered (false), m_duplicated (false), m_error (false), m_lana (lana), m_listener (NULL), m_dgreceiver (NULL), m_term (NULL) { // Преобразование имени в NetBIOS-имя int len = NCBNAMSZ - 1; CT2A nA( n ); LPCSTR src = (LPCSTR)nA; LPSTR dst = (LPSTR)netbiosed.name; for ( ; len && *src; --len, ++dst, ++src ) *dst = *src; for ( ; len; --len ) *dst++ = ' '; *dst = (CHAR)type; CharUpperBuffA( (LPSTR)netbiosed.name, NCBNAMSZ - 1 ); CharToOemBuffA( (LPSTR)netbiosed.name, (LPSTR)netbiosed.name, NCBNAMSZ - 1 ); netbiosed.name_num = 0; netbiosed.name_flags = (UCHAR)( group ? GROUP_NAME : UNIQUE_NAME ); original = GetANSIName(); }
/*********************************************************************** * CharUpperA (USER32.@) */ LPSTR WINAPI CharUpperA(LPSTR str) { if (!HIWORD(str)) { char ch = LOWORD(str); CharUpperBuffA( &ch, 1 ); return (LPSTR)(UINT_PTR)(BYTE)ch; } __TRY { CharUpperBuffA( str, strlen(str) ); } __EXCEPT_PAGE_FAULT { SetLastError( ERROR_INVALID_PARAMETER ); return NULL; } __ENDTRY return str; }
/* * @implemented */ LPSTR WINAPI CharUpperA(LPSTR str) { if (!HIWORD(str)) { char ch = LOWORD(str); CharUpperBuffA( &ch, 1 ); return (LPSTR)(UINT_PTR)(BYTE)ch; } _SEH2_TRY { CharUpperBuffA( str, strlen(str) ); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { SetLastError( ERROR_INVALID_PARAMETER ); _SEH2_YIELD(return NULL); } _SEH2_END; return str; }
static void HexStrToBin(char* str, BYTE* bin, int length) { int i; CharUpperBuffA(str, length * 2); for (i = 0; i < length; i++) { bin[i] = 0; if ((str[i * 2] >= '0') && (str[i * 2] <= '9')) bin[i] |= (str[i * 2] - '0') << 4; if ((str[i * 2] >= 'A') && (str[i * 2] <= 'F')) bin[i] |= (str[i * 2] - 'A' + 10) << 4; if ((str[i * 2 + 1] >= '0') && (str[i * 2 + 1] <= '9')) bin[i] |= (str[i * 2 + 1] - '0'); if ((str[i * 2 + 1] >= 'A') && (str[i * 2 + 1] <= 'F')) bin[i] |= (str[i * 2 + 1] - 'A' + 10); } }
BOOL rdp_client_connect(rdpRdp* rdp) { rdpSettings* settings = rdp->settings; if (rdp->settingsCopy) { freerdp_settings_free(rdp->settingsCopy); rdp->settingsCopy = NULL; } rdp->settingsCopy = freerdp_settings_clone(settings); nego_init(rdp->nego); nego_set_target(rdp->nego, settings->ServerHostname, settings->ServerPort); if (settings->GatewayEnabled) { char* user = NULL; char* domain = NULL; char* cookie = NULL; int user_length = 0; int domain_length = 0; int cookie_length = 0; if (settings->Username) { user = settings->Username; user_length = strlen(settings->Username); } if (settings->Domain) domain = settings->Domain; else domain = settings->ComputerName; domain_length = strlen(domain); cookie_length = domain_length + 1 + user_length; cookie = (char*) malloc(cookie_length + 1); CopyMemory(cookie, domain, domain_length); CharUpperBuffA(cookie, domain_length); cookie[domain_length] = '\\'; if (settings->Username) CopyMemory(&cookie[domain_length + 1], user, user_length); cookie[cookie_length] = '\0'; nego_set_cookie(rdp->nego, cookie); free(cookie); } else { nego_set_cookie(rdp->nego, settings->Username); } nego_set_send_preconnection_pdu(rdp->nego, settings->SendPreconnectionPdu); nego_set_preconnection_id(rdp->nego, settings->PreconnectionId); nego_set_preconnection_blob(rdp->nego, settings->PreconnectionBlob); nego_set_negotiation_enabled(rdp->nego, settings->NegotiateSecurityLayer); nego_set_restricted_admin_mode_required(rdp->nego, settings->RestrictedAdminModeRequired); nego_enable_rdp(rdp->nego, settings->RdpSecurity); nego_enable_tls(rdp->nego, settings->TlsSecurity); nego_enable_nla(rdp->nego, settings->NlaSecurity); nego_enable_ext(rdp->nego, settings->ExtSecurity); if (settings->MstscCookieMode) settings->CookieMaxLength = MSTSC_COOKIE_MAX_LENGTH; nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength); if (settings->LoadBalanceInfo) nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength); if (!nego_connect(rdp->nego)) { fprintf(stderr, "Error: protocol security negotiation or connection failure\n"); return FALSE; } if ((rdp->nego->selected_protocol & PROTOCOL_TLS) || (rdp->nego->selected_protocol == PROTOCOL_RDP)) { if ((settings->Username != NULL) && ((settings->Password != NULL) || (settings->RedirectionPassword != NULL && settings->RedirectionPasswordLength > 0))) settings->AutoLogonEnabled = TRUE; } rdp_set_blocking_mode(rdp, FALSE); rdp_client_transition_to_state(rdp, CONNECTION_STATE_NEGO); rdp->finalize_sc_pdus = 0; if (!mcs_send_connect_initial(rdp->mcs)) { if (!connectErrorCode) { connectErrorCode = MCSCONNECTINITIALERROR; } fprintf(stderr, "Error: unable to send MCS Connect Initial\n"); return FALSE; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return FALSE; } return TRUE; }
BOOL rdp_client_connect(rdpRdp* rdp) { BOOL status; rdpSettings* settings = rdp->settings; if (rdp->settingsCopy) { freerdp_settings_free(rdp->settingsCopy); rdp->settingsCopy = NULL; } rdp->settingsCopy = freerdp_settings_clone(settings); if (!rdp->settingsCopy) return FALSE; nego_init(rdp->nego); nego_set_target(rdp->nego, settings->ServerHostname, settings->ServerPort); if (settings->GatewayEnabled) { char* user = NULL; char* domain = NULL; char* cookie = NULL; int user_length = 0; int domain_length = 0; int cookie_length = 0; if (settings->Username) { user = settings->Username; user_length = strlen(settings->Username); } if (settings->Domain) domain = settings->Domain; else domain = settings->ComputerName; domain_length = strlen(domain); cookie_length = domain_length + 1 + user_length; cookie = (char*) malloc(cookie_length + 1); if (!cookie) return FALSE; CopyMemory(cookie, domain, domain_length); CharUpperBuffA(cookie, domain_length); cookie[domain_length] = '\\'; if (settings->Username) CopyMemory(&cookie[domain_length + 1], user, user_length); cookie[cookie_length] = '\0'; status = nego_set_cookie(rdp->nego, cookie); free(cookie); } else { status = nego_set_cookie(rdp->nego, settings->Username); } if (!status) return FALSE; nego_set_send_preconnection_pdu(rdp->nego, settings->SendPreconnectionPdu); nego_set_preconnection_id(rdp->nego, settings->PreconnectionId); nego_set_preconnection_blob(rdp->nego, settings->PreconnectionBlob); nego_set_negotiation_enabled(rdp->nego, settings->NegotiateSecurityLayer); nego_set_restricted_admin_mode_required(rdp->nego, settings->RestrictedAdminModeRequired); nego_set_gateway_enabled(rdp->nego, settings->GatewayEnabled); nego_set_gateway_bypass_local(rdp->nego, settings->GatewayBypassLocal); nego_enable_rdp(rdp->nego, settings->RdpSecurity); nego_enable_tls(rdp->nego, settings->TlsSecurity); nego_enable_nla(rdp->nego, settings->NlaSecurity); nego_enable_ext(rdp->nego, settings->ExtSecurity); if (settings->MstscCookieMode) settings->CookieMaxLength = MSTSC_COOKIE_MAX_LENGTH; nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength); if (settings->LoadBalanceInfo) { if (!nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength)) return FALSE; } rdp_client_transition_to_state(rdp, CONNECTION_STATE_NEGO); if (!nego_connect(rdp->nego)) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED); WLog_ERR(TAG, "Error: protocol security negotiation or connection failure"); return FALSE; } if ((rdp->nego->SelectedProtocol & PROTOCOL_TLS) || (rdp->nego->SelectedProtocol == PROTOCOL_RDP)) { if ((settings->Username != NULL) && ((settings->Password != NULL) || (settings->RedirectionPassword != NULL && settings->RedirectionPasswordLength > 0))) settings->AutoLogonEnabled = TRUE; } /* everything beyond this point is event-driven and non blocking */ rdp->transport->ReceiveCallback = rdp_recv_callback; rdp->transport->ReceiveExtra = rdp; transport_set_blocking_mode(rdp->transport, FALSE); if (rdp->state != CONNECTION_STATE_NLA) { if (!mcs_client_begin(rdp->mcs)) return FALSE; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); return FALSE; } } return TRUE; }
void str_wrap_text_uppercase(char *out, aint maxlen) { CharUpperBuffA(out, maxlen); }
INT_PTR CALLBACK DlgProcFind(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static char Searchstr[128]; static int loc; static int oldloc; static int startposition; static int OLDstartposition; HWND ParentHwnd = GetParent(hwndDlg); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); SetWindowText(hwndDlg, TranslateT("Find")); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hInst, MAKEINTRESOURCE(IDI_FIND))); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_OK: // find Next { char NewSearchstr[128]; int location = 0; int startsel = 0, endsel = 0; char buff[MAXSIZE1]; memset(&NewSearchstr, 0, sizeof(NewSearchstr)); int len = GetWindowTextLength(GetDlgItem(ParentHwnd, IDC_DATA)); char *tempbuffer = (char*)malloc(len + 2); GetDlgItemTextA(ParentHwnd, IDC_DATA, tempbuffer, len); strncpy(buff, tempbuffer, _countof(buff)); free(tempbuffer); Filter(buff); CharUpperBuffA(buff, (int)mir_strlen(buff)); GetDlgItemTextA(hwndDlg, IDC_FINDWHAT, NewSearchstr, _countof(NewSearchstr)); CharUpperBuffA(NewSearchstr, (int)mir_strlen(NewSearchstr)); OLDstartposition = startposition; if ((strstr(Searchstr, NewSearchstr)) != 0) startposition = loc + (int)mir_strlen(Searchstr); else { oldloc = 0; startposition = 0; } mir_strcpy(Searchstr, NewSearchstr); if (!(startposition > mir_strlen(buff))) location = (strstr(buff + startposition, NewSearchstr)) - buff; oldloc = loc; loc = location; if (loc == 0) { ShowWindow(GetDlgItem(hwndDlg, IDC_SEARCH_COMPLETE), SW_SHOW); loc = (strstr(buff, NewSearchstr)) - buff; startsel = loc; endsel = loc + (int)mir_strlen(NewSearchstr); oldloc = 0; startposition = 0; } else { ShowWindow(GetDlgItem(hwndDlg, IDC_SEARCH_COMPLETE), SW_HIDE); startsel = loc; endsel = loc + (int)mir_strlen(NewSearchstr); } CHARRANGE sel2 = {startsel, endsel}; SendDlgItemMessage(ParentHwnd, IDC_DATA, EM_EXSETSEL, 0, (LPARAM)&sel2); SetFocus(GetDlgItem(ParentHwnd, IDC_DATA)); } return TRUE; case WM_DESTROY: case IDC_CANCEL: EnableWindow(GetDlgItem(ParentHwnd, IDC_FIND_BUTTON), 1); EnableWindow(ParentHwnd, 1); DestroyWindow(hwndDlg); } break; } return FALSE; }
void str_wrap_text_uppercase(char *out, ZSTRINGS_SIGNED maxlen) { CharUpperBuffA(out, maxlen); }
BOOL rdp_client_connect(rdpRdp* rdp) { BOOL status; rdpSettings* settings = rdp->settings; /* make sure SSL is initialize for earlier enough for crypto, by taking advantage of winpr SSL FIPS flag for openssl initialization */ DWORD flags = WINPR_SSL_INIT_DEFAULT; if (settings->FIPSMode) flags |= WINPR_SSL_INIT_ENABLE_FIPS; winpr_InitializeSSL(flags); /* FIPS Mode forces the following and overrides the following(by happening later */ /* in the command line processing): */ /* 1. Disables NLA Security since NLA in freerdp uses NTLM(no Kerberos support yet) which uses algorithms */ /* not allowed in FIPS for sensitive data. So, we disallow NLA when FIPS is required. */ /* 2. Forces the only supported RDP encryption method to be FIPS. */ if (settings->FIPSMode || winpr_FIPSMode()) { settings->NlaSecurity = FALSE; settings->EncryptionMethods = ENCRYPTION_METHOD_FIPS; } nego_init(rdp->nego); nego_set_target(rdp->nego, settings->ServerHostname, settings->ServerPort); if (settings->GatewayEnabled) { char* user = NULL; char* domain = NULL; char* cookie = NULL; int user_length = 0; int domain_length = 0; int cookie_length = 0; if (settings->Username) { user = settings->Username; user_length = strlen(settings->Username); } if (settings->Domain) domain = settings->Domain; else domain = settings->ComputerName; domain_length = strlen(domain); cookie_length = domain_length + 1 + user_length; cookie = (char*) malloc(cookie_length + 1); if (!cookie) return FALSE; CopyMemory(cookie, domain, domain_length); CharUpperBuffA(cookie, domain_length); cookie[domain_length] = '\\'; if (settings->Username) CopyMemory(&cookie[domain_length + 1], user, user_length); cookie[cookie_length] = '\0'; status = nego_set_cookie(rdp->nego, cookie); free(cookie); } else { status = nego_set_cookie(rdp->nego, settings->Username); } if (!status) return FALSE; nego_set_send_preconnection_pdu(rdp->nego, settings->SendPreconnectionPdu); nego_set_preconnection_id(rdp->nego, settings->PreconnectionId); nego_set_preconnection_blob(rdp->nego, settings->PreconnectionBlob); nego_set_negotiation_enabled(rdp->nego, settings->NegotiateSecurityLayer); nego_set_restricted_admin_mode_required(rdp->nego, settings->RestrictedAdminModeRequired); nego_set_gateway_enabled(rdp->nego, settings->GatewayEnabled); nego_set_gateway_bypass_local(rdp->nego, settings->GatewayBypassLocal); nego_enable_rdp(rdp->nego, settings->RdpSecurity); nego_enable_tls(rdp->nego, settings->TlsSecurity); nego_enable_nla(rdp->nego, settings->NlaSecurity); nego_enable_ext(rdp->nego, settings->ExtSecurity); if (settings->MstscCookieMode) settings->CookieMaxLength = MSTSC_COOKIE_MAX_LENGTH; nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength); if (settings->LoadBalanceInfo) { if (!nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength)) return FALSE; } rdp_client_transition_to_state(rdp, CONNECTION_STATE_NEGO); if (!nego_connect(rdp->nego)) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED); WLog_ERR(TAG, "Error: protocol security negotiation or connection failure"); return FALSE; } if ((rdp->nego->SelectedProtocol & PROTOCOL_TLS) || (rdp->nego->SelectedProtocol == PROTOCOL_RDP)) { if ((settings->Username != NULL) && ((settings->Password != NULL) || (settings->RedirectionPassword != NULL && settings->RedirectionPasswordLength > 0))) settings->AutoLogonEnabled = TRUE; } /* everything beyond this point is event-driven and non blocking */ rdp->transport->ReceiveCallback = rdp_recv_callback; rdp->transport->ReceiveExtra = rdp; transport_set_blocking_mode(rdp->transport, FALSE); if (rdp->state != CONNECTION_STATE_NLA) { if (!mcs_client_begin(rdp->mcs)) return FALSE; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); return FALSE; } } return TRUE; }
//----------------------------------------------------------------------------- // Name: DoesItemMatch // Object: check if item with index ItemIndex in main dialog list view match the filters // and if item match, select it // Parameters : // in : int ItemIndex : item index of dialog main this->pListview // out : // return : TRUE if item match, FALSE else //----------------------------------------------------------------------------- BOOL CSearch::DoesItemMatch(int ItemIndex) { HEAP_CONTENT* pHeapContent; // get Heap content if(!this->pListview->GetItemUserData(ItemIndex,(LPVOID*)(&pHeapContent))) return FALSE; if (pHeapContent==0) return FALSE; if (IsBadReadPtr(pHeapContent,sizeof(HEAP_CONTENT))) return FALSE; if ((pHeapContent->HeapEntry.dwBlockSize==0)||(pHeapContent->pData==NULL)) return FALSE; if (IsBadReadPtr(pHeapContent->pData,pHeapContent->HeapEntry.dwBlockSize)) return FALSE; // if hex search if (this->SearchHex) { // search HexData into pHeapContent->pData return this->FindBufferInBuffer(this->HexData, this->HexDataSize, pHeapContent->pData, pHeapContent->HeapEntry.dwBlockSize ); } else // if text search { if (this->SearchAscii) { char* pc; if (this->SearchMatchCase) { pc=(char*)pHeapContent->pData; } // if insensitive search else { // convert buffer to upper case pc=new char[pHeapContent->HeapEntry.dwBlockSize+1]; if (!pc) return FALSE; pc[pHeapContent->HeapEntry.dwBlockSize]=0; memcpy(pc,pHeapContent->pData,pHeapContent->HeapEntry.dwBlockSize); CharUpperBuffA(pc,pHeapContent->HeapEntry.dwBlockSize); } // search buffer if (this->FindBufferInBuffer((PBYTE)this->AsciiSearchContent, this->AsciiSearchContentSize, (PBYTE)pc, pHeapContent->HeapEntry.dwBlockSize ) ) { if (!this->SearchMatchCase) delete pc; return TRUE; } if (!this->SearchMatchCase) delete pc; } if (this->SearchUnicode) { wchar_t* pc; if (this->SearchMatchCase) { pc=(wchar_t*)pHeapContent->pData; } // if insensitive search else { // convert buffer to upper case pc=new wchar_t[pHeapContent->HeapEntry.dwBlockSize/sizeof(wchar_t)+1]; if (!pc) return FALSE; pc[pHeapContent->HeapEntry.dwBlockSize/sizeof(wchar_t)]=0; memcpy(pc,pHeapContent->pData,pHeapContent->HeapEntry.dwBlockSize/sizeof(wchar_t)); CharUpperBuffW(pc,pHeapContent->HeapEntry.dwBlockSize/sizeof(wchar_t)); } // search buffer if (this->FindBufferInBuffer((PBYTE)this->UnicodeSearchContent, this->UnicodeSearchContentSize, (PBYTE)pc, pHeapContent->HeapEntry.dwBlockSize ) ) { if (!this->SearchMatchCase) delete pc; return TRUE; } if (!this->SearchMatchCase) delete pc; } return FALSE; } }