The Art of Exploitation is the best book for hacking.

Hacking is the art of creative problem solving, whether it means finding an unconventional solution to a difficult problem or tapping holes in sloppy programming. Many people call themselves hackers, but few have the strong technical foundation that is really needed to advance the envelope.

The Art of Exploitation
Instead of just showing how to drive existing adventures, author John Erikson explains how arcane hacking techniques actually work. Sharing the art and science of hacking in a way that is accessible to all, Hacking: The Art of Exploration, the 2D version introduces the fundamentals of C programming from a hacker’s point of view.

Introduction

The Art of Exploitation book’s introduction states that hacking should only be within the purview of the law, and only for productive reasons.
 

 Programming

In the programming chapter of this book, various types of programs are described and shown through examples. The chapter covers control structures and other basic aspects of programming. The live CD provides an environment so that readers can not only follow through with the examples in the book but do some programming themselves.
 

Exploitation

Exploitation is taking the computer’s code or set of rules and changing them so the computer does what you want it to do. Finding ways or holes in the system to change is an important part of exploitation. This chapter specifically covers exploitation techniques such as memory corruption, buffer overflow, and format strings using Perl and Bash shellcodes.