./c0de/c/jackal.txt

0.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
/* Jackal - Stealth/FireWall scanner. With the use of halfopen ports
   and sending SYNC (sometimes additional flags like FIN) one can
   scan behind a firewall. And it shouldnt let the site feel we're scanning
   by not doing a 3-way-handshake we hope to avoid any tcp-logging.
   Credits: Halflife, Jeff (Phiji) Fay, Abdullah Marafie.
   Alpha Tester: Walter Kopecky.
   Results:
   Some firewalls did allow SYN | FIN to pass through. No Site has
   been able to log the connections though.. during alpha testing.
   ShadowS [email protected]
   Copyleft (hack it i realy dont care).
   */
 
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <linux/ip.h>
#include <linux/tcp.h>
 
int timeout = 0;
int counter = 0;
void usage(char *name)
{
  printf("usage:%s [-h target_ip] [-i your_ip] [-t timeout] [-s start-port] [-e end-port] [-f FIN] [-a ACK]\n",name);
  exit(-1);
}
 
void handler(int whateva)
{
   alarm(0);
   timeout = 1;
}
/* Checksum Gen */
 
unsigned short in_cksum(unsigned short *ptr, int nbytes)
{
	register long		sum;		/* assumes long == 32 bits */
	u_short			oddbyte;
	register u_short	answer;		/* assumes u_short == 16 bits */
 
	/*
	 * Our algorithm is simple, using a 32-bit accumulator (sum),
	 * we add sequential 16-bit words to it, and at the end, fold back
	 * all the carry bits from the top 16 bits into the lower 16 bits.
	 */
 
	sum = 0;
	while (nbytes > 1)  {
		sum += *ptr++;
		nbytes -= 2;
	}
 
				/* mop up an odd byte, if necessary */
	if (nbytes == 1) {
		oddbyte = 0;		/* make sure top half is zero */
		*((u_char *) &oddbyte) = *(u_char *)ptr;   /* one byte only */
		sum += oddbyte;
	}
 
	/*
	 * Add back carry outs from top 16 bits to low 16 bits.
	 */
 
	sum  = (sum >> 16) + (sum & 0xffff);	/* add high-16 to low-16 */
	sum += (sum >> 16);			/* add carry */
	answer = ~sum;		/* ones-complement, then truncate to 16 bits */
	return(answer);
}
 
/* Generates the tcp header and packet */
 
struct tcphdr packetgen(int fin,int ack,unsigned int src_addr,unsigned int dst_addr, int port)
{
  /* we create both a tcpheader and a ipheader to calculate checksum */
 
  struct tcphdr packet;
 
  struct ipheader
    {
      unsigned int source_address;
      unsigned int dest_address;
      unsigned char placeholder;
      unsigned char protocol;
      unsigned short tcp_length;
      struct tcphdr tcp;
   }
    pseudo_header;
 
 
 
	counter++;
 
	/* Fill the headers with the options and data */
 
	packet.source = getpid() + counter;
	packet.dest = htons(port);
	packet.seq = getpid() + counter;
	packet.ack_seq = 0;
	packet.res1 = 0;
	packet.doff = 5;
	packet.res2 = 0;
	packet.fin = fin;
	packet.syn = 1;
	packet.rst = 0;
	packet.psh = 0;
	packet.ack = ack;
	packet.urg = 0;
	packet.window = htons(512);
	packet.check = 0;
	packet.urg_ptr = 0;               
 
	/* We need this for the checksum */
 
	pseudo_header.source_address = src_addr;
	pseudo_header.dest_address = dst_addr;
	pseudo_header.placeholder = 0;
	pseudo_header.protocol = IPPROTO_TCP;
	pseudo_header.tcp_length = htons(20);
	bcopy(&packet, &pseudo_header.tcp, 20);
 
	/* Get the checksum and viowlla tcphdr is done :) */
 
	packet.check = in_cksum((unsigned short *)&pseudo_header, 32);
 
	return packet;
}
 
int scan(struct tcphdr packet,int port,unsigned int dst_addr)
{
  struct sockaddr_in remote;
  int len;
 
  /* The header we'll receive the info in */
 
  struct rect
  {
      struct iphdr ip;
      struct tcphdr tcp;
      unsigned char blah[65535];
  }
    recv_tcp;
    int sockd;
 
    /* Now we fill the sock struct */
 
  remote.sin_family = AF_INET;
  remote.sin_port = htons(port);
  remote.sin_addr.s_addr = dst_addr;
 
  len=sizeof(remote);
 
  signal(SIGALRM, handler);
 
  sockd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
 
  if(sockd < 0)
    {
      perror("Socket");
      exit(1);
    }
 
 
  /* Blast the packet into ablivion! */
 
  sendto(sockd, &packet, 20, 0, (struct sockaddr *)&remote, len);
 
  timeout = 0;
  alarm(10);
  while(1)
    {
      /* Now we sit and read */
 
      read(sockd, (struct recv_tcp *)&recv_tcp, 65535);
      if(timeout == 1)
	{
	  close(sockd);
	  timeout=0;
	  return -1;
	}
      if(recv_tcp.tcp.dest == (getpid() + counter))
	{
         alarm(0);
         close(sockd);
 
	 /* It shouldnt be 1 */
 
         if(recv_tcp.tcp.rst == 1)
	   return 0;
         else
	   return 1;
	}
    }
}
 
 
main(int argc, char **argv)
{
  int c;
  int start = 0;
  int end = 0;
  int fin = 0;
  int ack = 0;
  int port = 0;
  int retval;
 
  struct tcphdr packet;
  int host = 0;
  int target = 0;
 
  char source[100];
  char destination[100];
 
  if(getuid() != 0)
    {
      printf("Need root to run this I'm afraid .\n");
      exit(-2);
    }
  if(argc < 2)
    usage(argv[0]);
  while ((c = getopt (argc, argv, "s:e:h:i:af")) != EOF) 
    {
      switch (c)
	{
 
	case 's':
	  start = atoi(optarg);
	  break;
	case 'e':
	  end = atoi(optarg);
	  break;
	case 'a':
	  ack = 1;
	  break;
	case 'f':
	  fin = 1;
	  break;
	case 'h':
	  strcpy(destination,optarg);
	  target = 1;
	  break;
	case 'i':
	  strcpy(source,optarg);
	  host = 1;
	  break;
	case 't':
	  timeout = atoi(optarg);
	  break;
	default:
	  usage(argv[0]);
 
	}
    }
  if((host == 0) || (target == 0))
    usage(argv[0]);
  if(start == 0)
    port = start;
  if(end == 0)
    end = 1024;
  for(;port < (end + 1);port++)
    {
 
      packet = packetgen(fin,ack,inet_addr(source),inet_addr(destination),port);
 
      if( (retval = scan(packet,port,inet_addr(source))) ==  1)
      printf("Port:%i is open.\n",port);
    }
 
  exit(0);
}
 
 
 
 
 
 
 
 
 
 
 
==================================================================================
 
 
 
 
 
 
 
 
 
 
 
/**********************************************************************
** This is a real simple half opened connection scanner I
** put together. It scans ports 0 to 1024 for listening
** processes, and writes to stdout the ports that are 
** listening.
**
** [email protected]
**
** NOTE: You have to define MY_IP as your ip. If you have
** a dynamic ip, this is gonna bite :-).
*********************************************************************/
 
/* define the following as your ip address */
#define MY_IP		"193.62.1.250"
 
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <linux/ip.h>
#include <linux/tcp.h>
 
int syn_timeout = 0;
 
unsigned short in_cksum(unsigned short *, int);
int scan_port(unsigned short, unsigned int, unsigned int);
void alarm_handler(int);
 
void alarm_handler(int s)
{
   alarm(0);
   syn_timeout = 1;
}
 
int scan_port(unsigned short port, unsigned int src_addr, unsigned int dst_addr)
{
   struct tcphdr send_tcp;
   struct recv_tcp
   {
      struct iphdr ip;
      struct tcphdr tcp;
      unsigned char blah[65535];
   }recv_tcp;
   struct pseudo_header
   {
      unsigned int source_address;
      unsigned int dest_address;
      unsigned char placeholder;
      unsigned char protocol;
      unsigned short tcp_length;
      struct tcphdr tcp;
   }pseudo_header;
   int tcp_socket;
   struct sockaddr_in sin;
   int sinlen;
   static int blah = 0;
 
   blah++;
   send_tcp.source = getpid() + blah;
   send_tcp.dest = htons(port);
   send_tcp.seq = getpid() + blah;
   send_tcp.ack_seq = 0;
   send_tcp.res1 = 0;
   send_tcp.doff = 5;
   send_tcp.res2 = 0;
   send_tcp.fin = 0;
   send_tcp.syn = 1;
   send_tcp.rst = 0;
   send_tcp.psh = 0;
   send_tcp.ack = 0;
   send_tcp.urg = 0;
   send_tcp.window = htons(512);
   send_tcp.check = 0;
   send_tcp.urg_ptr = 0;               
   pseudo_header.source_address = src_addr;
   pseudo_header.dest_address = dst_addr;
   pseudo_header.placeholder = 0;
   pseudo_header.protocol = IPPROTO_TCP;
   pseudo_header.tcp_length = htons(20);
   bcopy(&send_tcp, &pseudo_header.tcp, 20);
   send_tcp.check = in_cksum((unsigned short *)&pseudo_header, 32);
   sin.sin_family = AF_INET;
   sin.sin_port = htons(port);
   sin.sin_addr.s_addr = dst_addr;
   sinlen=sizeof(sin);
   signal(SIGALRM, alarm_handler);
   tcp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
   if(tcp_socket < 0)
   {
      fprintf(stderr, "couldnt open raw socket\n");
      exit(1);
   }
   sendto(tcp_socket, &send_tcp, 20, 0, (struct sockaddr *)&sin, sinlen);
   syn_timeout = 0;
   alarm(10);
   while(1)
   {
      read(tcp_socket, (struct recv_tcp *)&recv_tcp, 65535);
      if(syn_timeout == 1) {close(tcp_socket);syn_timeout=0;return -1;}
      if(recv_tcp.tcp.dest == (getpid() + blah))
      {
         alarm(0);
         close(tcp_socket);
         if(recv_tcp.tcp.rst == 1) return 0;
         else return 1;
      }
   }
}
 
unsigned short in_cksum(unsigned short *ptr, int nbytes)
{
	register long		sum;		/* assumes long == 32 bits */
	u_short			oddbyte;
	register u_short	answer;		/* assumes u_short == 16 bits */
 
	/*
	 * Our algorithm is simple, using a 32-bit accumulator (sum),
	 * we add sequential 16-bit words to it, and at the end, fold back
	 * all the carry bits from the top 16 bits into the lower 16 bits.
	 */
 
	sum = 0;
	while (nbytes > 1)  {
		sum += *ptr++;
		nbytes -= 2;
	}
 
				/* mop up an odd byte, if necessary */
	if (nbytes == 1) {
		oddbyte = 0;		/* make sure top half is zero */
		*((u_char *) &oddbyte) = *(u_char *)ptr;   /* one byte only */
		sum += oddbyte;
	}
 
	/*
	 * Add back carry outs from top 16 bits to low 16 bits.
	 */
 
	sum  = (sum >> 16) + (sum & 0xffff);	/* add high-16 to low-16 */
	sum += (sum >> 16);			/* add carry */
	answer = ~sum;		/* ones-complement, then truncate to 16 bits */
	return(answer);
}
 
main(int argc, char **argv)
{   
   unsigned short i;
   if(argc < 2)
   {
      fprintf(stderr, "%s target_ip\n", argv[0]);
      exit(0);
   }
   if(geteuid() != 0)
   {
      fprintf(stderr, "this program requires root\n");
      exit(0);
   }
   printf("Scanning %s\n", argv[1]);
   for(i=0;i < 1025;i++)
   {
      if(scan_port(i, inet_addr(MY_IP), inet_addr(argv[1]))==1)
         printf("Port %d active\n", i);
   }
}
 
 

Back