File: decode_oracle.c

package info (click to toggle)
dsniff 2.4b1+debian-29
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,020 kB
  • sloc: ansic: 10,803; sh: 152; makefile: 126
file content (71 lines) | stat: -rw-r--r-- 1,440 bytes parent folder | download | duplicates (7)
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
/*
 * decode_oracle.c
 *
 * Oracle SQL*Net v2/Net8.
 *
 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
 *
 * $Id: decode_oracle.c,v 1.6 2001/03/15 08:33:01 dugsong Exp $
 */

#include "config.h"

#include <sys/types.h>

#include <stdio.h>
#include <string.h>

#include "decode.h"

/* XXX - dag nasty. anyone have protocol specs? */
int
decode_oracle(u_char *buf, int len, u_char *obuf, int olen)
{
	u_char *p, *q;
	u_short i, j;
	int gotauth = 0;
	
	p = buf;
	
	i = pntohs(p);
	if (i >= len) return (0);

	if (i < 60) {		/* XXX - skip unknown "empty" packet */
		p += i;
		i = pntohs(p);
		if (p + i > buf + len) return (0);
	}
	/* Save TNS connect string. */
	p[i] = '\0';
	for (q = p + i; q > p && q[-1] != '\0'; q--)
		;
	snprintf(obuf, olen, "%s\n", q);
	p += i;
	
	/* XXX - skip initial username message. */
	if ((p = bufbuf(p, len, "(TNS V", 6)) == NULL) return (0);
	if ((i = len - (p - buf)) <= 0) return (0);
	if ((p = memchr(p, ')', i)) == NULL) return (0);
	
	/* Parse auth messages. */
	for (p++; p - buf < len; p += i) {
		i = pntohs(p);
		if (p + i > buf + len || i < 120)
			break;
		
		if (memcmp(p + 4, "\x06\x00\x00\x00\x00\x00\x03\x3a", 8) != 0)
			continue;
		
		for (q = p + i; q > p && q[-1] != '\0'; q--)
			;
		j = pntohs(p + 19);
		if (q + j > buf + len)
			return (0);
		q[j] = '\0';

		j = strlen(obuf);
		snprintf(obuf + j, olen + j, "%s\n", p + 117);
		gotauth++;
	}
	return (gotauth ? strlen(obuf) : 0);
}