Welcome to the CC ++ programming Community Forum and interact with 2 million technical staff. The first step is to prevent hackers from stealing PasswordWindows in the Edit box. Although it is a powerful operating system, however, some of its inherent defects left hackers with a lot of opportunities. The famous BO program uses these Windows vulnerabilities to harm computers.
Welcome to the C/C ++ programming Community Forum and interact with 2 million technical staff> enter the first rule: this prevents hackers from stealing the Password in the Edit box. Windows is a powerful operating system, but it has some inherent defects, leaving many opportunities for hackers, the famous BO program uses these Windows vulnerabilities to harm computers.
Welcome to the C/C ++ programming Community Forum and interact with 2 million technical staff> enter
First, hackers cannot steal the Password in the Edit box.
Although Windows is a powerful operating system, some of its inherent defects leave a lot of opportunities for hackers, the famous BO program uses these Windows vulnerabilities to endanger computer security. I recently discovered a very popular tool for getting the Password of the Edit box, and even its source code has been published in a newspaper. This is undoubtedly a complete rejection of the Edit Password function. This article first analyzes the principle of illegal access to the Password, and then provides countermeasures to protect the Password in the Edit box from illegal access using Visual C ++.
(1) Principle of illegal access to Password
Edit is a standard control in Windows. When the Password attribute is set to True, the input content is blocked as an asterisk (*) to protect the content. The content in the Edit box can be obtained by sending WM_GETTEXT and EM_GETLINE messages. Hackers use the Edit feature to enumerate all child windows of the current program. When the enumerated window is found to be EDIT and has the ES_PASSWORD attribute, send the WM_GETTEXT or EM_GETLINE message to this window through SendMessage, so that the content in the Edit box is clear at a glance.
(2) Password protection
The preceding analysis shows that the vulnerability of Edit is that it does not check the identity of the sender of the WM_GETTEXT or EM_GETLINE message. Any process can obtain the content of the Edit window handle. A simple method is provided to verify whether the sender's identity is valid.
1) Create a New CEdit class
Inherit a subclass CPasswordEdit from CEdit and declare that the global variable g_bAuthorIdentity indicates the identity of the message sender:
BOOL g_bAuthorIdentity;
Then, return to the virtual function DefWindowProc of CWnd and perform authentication in the callback function:
LRESULT CPasswordEdit: DefWindowProc (UINT message,
WPARAM wParam, LPARAM lParam)
{
// Obtain the Edit content through one of the following two messages
If (message = WM_GETTEXT) |
(Message = EM_GETLINE ))
{
// Check validity
If (! G_bAuthorIdentity)
{
// Illegal acquisition, display information
AfxMessageBox (_ T ("My password can't be viewed by you! "));
//
Return 0;
}
// Valid access
G_bAuthorIdentity = FALSE;
}
Return CEdit: DefWindowProc (message, wParam, lParam );
} |
2) process the data in the data input dialog box.
In the dialog box, declare a class member m_edtPassword:
CPasswordEdit m_edtPassword; then add the following code to OnInitDialog () in the dialog box:
M_edtPassword.SubclassDlgItem (IDC_EDIT_PASSWORD, this); the objective is to associate the control with the new class.
Then, set the identity to legal in the Data Exchange dialog box:
Void CDlgInput: DoDataExchange (CDataExchange * pDX)
{
// If data is obtained
// Note: this is not required for the CPropertyPage class.
If (pDX-> m_bSaveAndValidate) Condition
If (pDX-> m_bSaveAndValidate)
{
G_bAuthorIdentity = TRUE;
}
CDialog: DoDataExchange (pDX );
// {AFX_DATA_MAP (CDlgInput)
DDX_Text (pDX, IDC_EDIT_PASSWORD, m_sPassword );
//} AFX_DATA_MAP
} |
In this way, the Password input box will be protected.
(3) Notes
The above method is only for VC programs. For vbprograms, you need to use VC to create a Password ActiveX control. The implementation method is similar to above.
[1] [2]