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.

0x475<br />

Proactive Defense (shroud)<br />

Port scans are <strong>of</strong>ten used to pr<strong>of</strong>ile systems before <strong>the</strong>y are attacked. Knowing<br />

what ports are open allows an attacker to determine which services can<br />

be attacked. Many IDSs <strong>of</strong>fer methods to detect port scans, but by <strong>the</strong>n <strong>the</strong><br />

information has already been leaked. While writing this chapter, I wondered<br />

if it is possible to prevent port scans before <strong>the</strong>y actually happen. Hacking,<br />

really, is all about coming up with new ideas, so a newly developed method<br />

for proactive port-scanning defense will be presented here.<br />

First <strong>of</strong> all, <strong>the</strong> FIN, Null, and X-mas scans can be prevented by a simple<br />

kernel modification. If <strong>the</strong> kernel never sends reset packets, <strong>the</strong>se scans will<br />

turn up nothing. The following output uses grep to find <strong>the</strong> kernel code<br />

responsible for sending reset packets.<br />

reader@<strong>hacking</strong>:~/booksrc $ grep -n -A 20 "void.*send_reset" /usr/src/linux/net/ipv4/tcp_ipv4.c<br />

547:static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)<br />

548-{<br />

549- struct tcphdr *th = skb->h.th;<br />

550- struct {<br />

551- struct tcphdr th;<br />

552-#ifdef CONFIG_TCP_MD5SIG<br />

553- __be32 opt[(TCPOLEN_MD5SIG_ALIGNED >> 2)];<br />

554-#endif<br />

555- } rep;<br />

556- struct ip_reply_arg arg;<br />

557-#ifdef CONFIG_TCP_MD5SIG<br />

558- struct tcp_md5sig_key *key;<br />

559-#endif<br />

560-<br />

return; // Modification: Never send RST, always return.<br />

561- /* Never send a reset in response to a reset. */<br />

562- if (th->rst)<br />

563- return;<br />

564-<br />

565- if (((struct rtable *)skb->dst)->rt_type != RTN_LOCAL)<br />

566- return;<br />

567-<br />

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

By adding <strong>the</strong> return command (shown above in bold), <strong>the</strong><br />

tcp_v4_send_reset() kernel function will simply return instead <strong>of</strong> doing<br />

anything. After <strong>the</strong> kernel is recompiled, <strong>the</strong> resulting kernel won’t send<br />

out reset packets, avoiding information leakage.<br />

FIN Scan Before <strong>the</strong> Kernel Modification<br />

matrix@euclid:~ $ sudo nmap -T5 -sF 192.168.42.72<br />

St<strong>art</strong>ing Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2007-03-17 16:58 PDT<br />

Interesting ports on 192.168.42.72:<br />

Not shown: 1678 closed ports<br />

Networking 267

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

Saved successfully!

Ooh no, something went wrong!