Sockets, Shellcode, Porting & Coding: Reverse Engineering Exploits and Tool Coding for Security Professionals

Advanced network programming techniques have historically been one of the most difficult programming theories to grasp. The Sockets section of this book addresses the particulars of proper socket initialization, closing sockets, reading data, and writing. This chapter describes the particulars of writing code that will compile and run on both UNIX/Linux platforms as well as Microsoft Windows, without requiring any modifications.
Using ifdef and endif statements and knowing the different libraries that are required for certain functions to be called within the program, are key when developing platform-independent code. Gaining access to the raw sockets within a program allows programs to potentially manipulate and transmit packets even though they may not conform to all of the Remote Procedure Call (RPC) standards. All of these concepts are discussed and illustrated in this chapter.
The last major section of code that this chapter covers is packet-capturing differentiators on Windows versus UNIX. We look at how to develop code that will capture packets on either system and then prepare such data for analysis or computation.
| Note | All of the example source code in this chapter was written and compiled on OpenBSD 3.2 / x86 using the GNU C compiler version 2.95.3, the tcsh command shell version 6.12.00, and Microsoft Windows XP using Microsoft Visual Studio.NET 2002. |
Berkeley Software Distribution (BSD) sockets and the Microsoft Winsock programming interface are two largely compatible application program interfaces (APIs) used for network programming. With a few minor modifications, most...