In 2002, Microsoft began an initiative to identify the common C and C++ functions that were prone to buffer overrun coding errors. These functions are not "bad" by themselves, but to be used securely they require extensive error checking on the part of the programmer. If that error checking is neglected (and it often is), the code will have a security vulnerability. Given the risk of this oversight, it was decided that it would be best to develop and promote a new set of functions to replace those prone to problems with a robust, thoroughly tested, and documented set of new ones.These new functions, called Safe String Functions, are available from Microsoft for the Windows XP SP1 and later versions of the Windows DDK and Platform SDK. Many other commercial and freeware libraries that implement "safe strings" are available for common operating systems, processors, and compilers.The following list (adapted from the article, "Using Safe String Functions," on msdn.microsoft.com/library) explains some of the benefits of using the new functions:Each function receives the size of the destination buffer as input. The function can thus ensure that it does not write past the end of the buffer.The functions null-terminate all output strings, even if the operation truncates the intended result. The code performing an operation on the returned string can safely assume that it will eventually encounter a nulldenoting the string's end. The data prior to the null will be valid and the string won't run on, indefinitely.Tất cả chức năng trả về một giá trị NTSTATUS, với một trong những chỉ có thể thành công mã. Chức năng gọi điện thoại có thể dễ dàng xác định nếu các chức năng thành công trong việc thực hiện các hoạt động.Mỗi chức năng có sẵn trong hai phiên bản. Một trong những hỗ trợ ký tự ASCII đơn-byte và khác, đôi-byte ký tự Unicode. Nhớ từ chương 10, "Ngôn ngữ nước ngoài thử," để hỗ trợ tất cả các chữ cái và các ký hiệu bằng nhiều ngôn ngữ nước ngoài, ký tự cần phải mất nhiều hơn một byte của không gian.Bảng 13.1 cho thấy một danh sách các chức năng không an toàn và các chức năng an toàn thay thế chúng. Khi bạn và nhóm của bạn đang thực hiện mã giá hoặc trắng-hộp kiểm tra, trên lookout cho các chức năng không an toàn và cách họ sử dụng. Rõ ràng, lập trình viên của nhóm của bạn nên sử dụng các phiên bản an toàn, Tuy nhiên, nếu không, nhận xét mã của bạn sẽ cần phải được thực hiện với nhiều hơn nữa sự chặt chẽ để đảm bảo rằng bất kỳ lỗ hổng bảo mật có thể được giải quyết.Bảng 13.1. Cũ "Unsecure" C chuỗi chức năng và của họ mới thay thế "An toàn" cũ "Không an toàn" chức năng Chức năng mới "An toàn" Mục đích strcatwcscat RtlStringCbCatRtlStringCbCatExRtlStringCchCatRtlStringCchCatEx Tiếp nhau hai dây. strncatwcsncat RtlStringCbCatNRtlStringCbCatNExRtlStringCchCatNRtlStringCchCatNEx Tiếp nhau hai tính byte chuỗi, trong khi hạn chế kích thước của chuỗi gắn. Strcpywcscpy RtlStringCbCopyRtlStringCbCopyExRtlStringCchCopyRtlStringCchCopyEx Sao chép một chuỗi thành một bộ đệm. strncpywcsncpy RtlStringCbCopyNRtlStringCbCopyNExRtlStringCchCopyNRtlStringCchCopyNEx Sao chép một chuỗi byte tính vào một bộ đệm, trong khi hạn chế kích thước của chuỗi sao chép. strlenwcslen RtlStringCbLengthRtlStringCchLength Xác định chiều dài của một chuỗi cung cấp. sprintfswprintf_snprintf_snwprintf RtlStringCbPrintfRtlStringCbPrintfExRtlStringCchPrintfRtlStringCchPrintfEx Tạo ra một chuỗi định dạng văn bản mà dựa trên một chuỗi định dạng và một tập hợp các đối số bổ sung chức năng. vsprintfvswprintf_vsnprintf_vsnwprintf RtlStringCbVPrintfRtlStringCbVPrintfExRtlStringCchVPrintfRtlStringCchVPrintfEx Tạo ra một chuỗi định dạng văn bản mà dựa trên một chuỗi định dạng và một bổ sung chức năng lý luận. JPEG VIRUSNhững gì có thể an toàn hơn so với một hình ảnh? Sau khi tất cả, nó là dữ liệu, không thực thi mã. Giả định sai rằng đã bị phá vỡ trong tháng chín năm 2004 khi một virus được khám phá được nhúng trong một vài hình ảnh JPEG khiêu dâm đăng lên một nhóm tin Internet. Khi xem, một loại virus đã được tải xuống máy tính của người dùng. Không ai nghĩ rằng nó là có thể, nhưng nó đã. Vấn đề khi ở một khai thác lỗi tràn bộ đệm.The JPEG file format, besides storing the picture elements, also allows for the storing of embedded comments. Many software packages for editing and organizing pictures use this field for annotating the picture"Our family at the beach," "House for Sale," and so forth. This comment field starts with a hex value of 0xFFFE followed by a two-byte value. This value specifies the length of the comment, plus 2 bytes (for the field length). Using this encoding method, a comment of up to 65,533 bytes would be valid. If there is no comment, then the field is supposed to contain a value of 2. The problem is that if the value is an illegal entry of 0 or 1, a buffer overflow occurs.It turns out that the code used to interpret the JPEG data and turn it into a viewable picture normalized the length by subtracting off the 2 bytes before it read out the actual comment. If the length byte was set to 0, subtracting off 2 yielded a length of -2. The code was written to handle positive integers and interpreted the negative 2 as a positive 4GB. The next 4GB of "comment" data was then loaded, improperly overwriting valid data and program. If that "comment" data was carefully crafted, hand coded, assembly, it could be used to gain access to the viewer's PC. Microsoft had to issue a critical update to all the components that loaded and viewed JPEG images. Software vulnerabilities can occur where you never expect them. For this reason, it's imperative to consider software security in all aspects of a software product or system. From a user perspective, security is measure of quality. They may not ask for it, but they know they want it, and will consider lack of software security a bug (a huge one) if they don't have it. We'll close out this chapter with a brief visit to another aspect of computer security, one that's related to privacy, computer forensics.
đang được dịch, vui lòng đợi..
