Programming HandBook part 153 pptx

6 158 0
Programming HandBook part 153 pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Hình 3.13. Biểu đồ luồng dữ liệu mức dưới đỉnh giải thích chức năng 2 (Thu nợ) Mã bảo vệ chương trình không bị End Task trong Windows Đoạn code sau đây sử dụng các tính năng sercurity object trên Win2K/XP. Một process cần được bảo vệ sẽ được tạo ra với quyền truy cập được hạn chế bằng cách đặt thuộc tính SECURITY_ATTRIBUTES trong khi gọi hàn CreateProcess để tạo process được bảo vệ! <Tham khảo trong MSDN Platform SDK: Access Control 8) > Code: // SecurityObj.cpp : Defines the entry point for the application. // #include "stdafx.h" #include <windows.h> #include <stdio.h> #include <aclapi.h> BOOL CreateProtectedProcess( LPCTSTR lpApplicationName, // name of executable module LPTSTR lpCommandLine, // command line string DWORD dwCreationFlags // creation flags ); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CreateProtectedProcess("c:\winnt\system32\calc.exe", NULL, 0 ); return 0; } BOOL CreateProtectedProcess( LPCTSTR lpApplicationName, // name of executable module LPTSTR lpCommandLine, // command line string DWORD dwCreationFlags // creation flags ) { DWORD dwRes; PSID pEveryoneSID = NULL, pAdminSID = NULL; PACL pACL = NULL; PSECURITY_DESCRIPTOR pSD = NULL; EXPLICIT_ACCESS ea[2]; SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY; SID_IDENTIFIER_AUTHORITY SIDAuthNT = SECURITY_NT_AUTHORITY; SECURITY_ATTRIBUTES sa; // Create a well-known SID for the Everyone group. if(! AllocateAndInitializeSid( &SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID) ) { return FALSE; } // Initialize an EXPLICIT_ACCESS structure for an ACE. // The ACE will allow Everyone read access to the object. ZeroMemory(&ea, 2 * sizeof(EXPLICIT_ACCESS)); ea[0].grfAccessPermissions = GENERIC_READ; ea[0].grfAccessMode = DENY_ACCESS; ea[0].grfInheritance= NO_INHERITANCE; ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID; ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP; ea[0].Trustee.ptstrName = (LPTSTR) pEveryoneSID; // Create a SID for the BUILTIN\Administrators group. if(! AllocateAndInitializeSid( &SIDAuthNT, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pAdminSID) ) { goto Cleanup; } // Initialize an EXPLICIT_ACCESS structure for an ACE. // The ACE will allow the Administrators group full access to the key. ea[1].grfAccessPermissions = GENERIC_READ; ea[1].grfAccessMode = DENY_ACCESS; ea[1].grfInheritance= NO_INHERITANCE; ea[1].Trustee.TrusteeForm = TRUSTEE_IS_SID; ea[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP; ea[1].Trustee.ptstrName = (LPTSTR) pAdminSID; // Create a new ACL that contains the new ACEs. dwRes = SetEntriesInAcl(2, ea, NULL, &pACL); if (ERROR_SUCCESS != dwRes) { goto Cleanup; } // Initialize a security descriptor. pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); if (pSD == NULL) { goto Cleanup; } if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) { goto Cleanup; } // Add the ACL to the security descriptor. if (!SetSecurityDescriptorDacl(pSD, TRUE, // fDaclPresent flag pACL, FALSE)) // not a default DACL { goto Cleanup; } // Initialize a security attributes structure. sa.nLength = sizeof (SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = pSD; sa.bInheritHandle = FALSE; // Use the security attributes to set the security descriptor // when you create a key. PROCESS_INFORMATION pi; STARTUPINFO si; memset(π,0,sizeof(pi)); memset(&si,0,sizeof(si)); si.cb = sizeof(si); si.wShowWindow = SW_SHOW; CreateProcess(lpApplicationName,lpCommandLine, &sa, &sa,dwCreationFlags,0,0,0,&si,π); // clean up data Cleanup: if (pEveryoneSID) FreeSid(pEveryoneSID); if (pAdminSID) FreeSid(pAdminSID); if (pACL) LocalFree(pACL); if (pSD) LocalFree(pSD); return TRUE; } ngoalong(HVA) Protect Access Database Tác giả: (someone) 1. Bảo vệ mã lệnh VBA (Visual Basic for Application) bằng cách chọn mục Properties trên trình đơn Tools của cửa sổ soạn thảo Microsoft Visual Basic rồi chọn trang Protection trên hộp thoại Project Properties. Cuối cùng, chọn Lock project for viewing, kèm theo là mật khẩu bảo vệ. Với cách này, cấu trúc và dữ liệu các bảng (table) vẫn có thể được xem và sửa đổi. 2. Dùng chức năng Make MDE file để ngăn không cho sửa đổi mã lệnh, thiết kế biểu mẫu (form) và thiết kế báo biểu (report). Với cách này, cấu trúc và dữ liệu các bảng (table) vẫn có thể được lấy đi để chuyển vào tập tin .MDB khác mà xem và sửa đổi. 3. Dùng chức năng Encrypt / Decrypt database… để mã hóa CSDL, ngăn không cho các chương trình tiện ích hay xử lý văn bản giải mã nhưng vẫn có thể dùng Access để mở. 4. Dùng chức năng Set database password để quy định mật khẩu cho CSDL. Cách này hơi phiền nếu có một bảng trong CSDL khác liên kết (link) với nó. Nếu quên mật khẩu thì … khóc luôn chứ sao! 5. Thiết kế một biểu mẫu khởi động, trong đó yêu cầu cho biết tên và mật khẩu, dùng hộp thoại Startup (từ danh sách Display Form/Page) để quy định phải mở biểu mẫu này trước tiên mỗi lần mở CSDL. Nhờ cách này, ta có thể giấu luôn cửa sổ Database, nơi có thể xem và chọn các thành phần của CSDL để sửa chữa. Trong những cách trên, cách thứ 5 vẫn có thể bị vượt qua bằng cách nhấn và giữ phím Shift trong lúc mở CSDL. Để khắc phục, ta có thể dùng Visual Basic gán trị False cho thuộc tính AllowBypassKey để vô hiệu hóa phím Shift khi mở CSDL. Giả sử bạn có một CSDL tên dbLock.MDB. Mỗi lần người ta mở nó, bạn muốn

Ngày đăng: 03/07/2014, 09:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan