26.07.2018 Views

hacking-the-art-of-exploitation

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Since <strong>the</strong> notesearch exploit allows an optional command-line argument<br />

to define <strong>the</strong> <strong>of</strong>fset, different <strong>of</strong>fsets can quickly be tested.<br />

reader@<strong>hacking</strong>:~/booksrc $ gcc exploit_notesearch.c<br />

reader@<strong>hacking</strong>:~/booksrc $ ./a.out 100<br />

-------[ end <strong>of</strong> note data ]-------<br />

reader@<strong>hacking</strong>:~/booksrc $ ./a.out 200<br />

-------[ end <strong>of</strong> note data ]-------<br />

reader@<strong>hacking</strong>:~/booksrc $<br />

However, doing this manually is tedious and stupid. BASH also has a for<br />

loop that can be used to automate this process. The seq command is a simple<br />

program that generates sequences <strong>of</strong> numbers, which is typically used with<br />

looping.<br />

reader@<strong>hacking</strong>:~/booksrc $ seq 1 10<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

reader@<strong>hacking</strong>:~/booksrc $ seq 1 3 10<br />

1<br />

4<br />

7<br />

10<br />

reader@<strong>hacking</strong>:~/booksrc $<br />

When only two arguments are used, all <strong>the</strong> numbers from <strong>the</strong> first argument<br />

to <strong>the</strong> second are generated. When three arguments are used, <strong>the</strong> middle<br />

argument dictates how much to increment each time. This can be used with<br />

command substitution to drive BASH’s for loop.<br />

reader@<strong>hacking</strong>:~/booksrc $ for i in $(seq 1 3 10)<br />

> do<br />

> echo The value is $i<br />

> done<br />

The value is 1<br />

The value is 4<br />

The value is 7<br />

The value is 10<br />

reader@<strong>hacking</strong>:~/booksrc $<br />

Exploitation 141

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!