dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

decode_ldap.c
Go to the documentation of this file.
1 /*
2  * decode_ldap.c
3  *
4  * Lightweight Directory Access Protocol.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: decode_ldap.c,v 1.5 2001/03/15 08:33:01 dugsong Exp $
9  */
10 
11 #include "config.h"
12 
13 #include <sys/types.h>
14 
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include "buf.h"
19 #include "asn1.h"
20 #include "decode.h"
21 
22 int
23 decode_ldap(u_char *buf, int len, u_char *obuf, int olen)
24 {
25  struct buf *msg, inbuf, outbuf;
26  int i, type;
27  u_char *p;
28 
29  buf_init(&inbuf, buf, len);
30  buf_init(&outbuf, obuf, olen);
31 
32  while (buf_len(&inbuf) > 10) {
33  /* LDAPMessage */
34  type = asn1_type(&inbuf);
35  i = asn1_len(&inbuf);
36 
37  if (i <= 0 || (msg = buf_tok(&inbuf, NULL, i)) == NULL)
38  break;
39 
40  if (type != ASN1_SEQUENCE)
41  continue;
42 
43  /* messageID */
44  type = asn1_type(msg);
45  i = asn1_len(msg);
46  if (type != ASN1_INTEGER || i <= 0 || buf_skip(msg, i) < 0)
47  continue;
48 
49  /* bindRequest op - APPLICATION[0] SEQUENCE */
50  if (buf_cmp(msg, "\x60", 1) != 0)
51  continue;
52  asn1_type(msg);
53  asn1_len(msg);
54 
55  /* version */
56  type = asn1_type(msg);
57  i = asn1_len(msg);
58  if (type != ASN1_INTEGER || i <= 0 || buf_skip(msg, i) < 0)
59  continue;
60 
61  /* name */
62  type = asn1_type(msg);
63  i = asn1_len(msg);
64  p = buf_ptr(msg);
65  if (type != ASN1_STRING || i <= 0 || buf_skip(msg, i) < 0)
66  continue;
67 
68  /* simple auth [0] */
69  if (buf_cmp(msg, "\x80", 1) != 0)
70  continue;
71  *(buf_ptr(msg)) = '\0';
72  buf_skip(msg, 1);
73 
74  /* passwd */
75  i = asn1_len(msg);
76 
77  if (i <= 0 || i > buf_len(msg))
78  continue;
79 
80  if (buf_tell(&outbuf) > 0)
81  buf_put(&outbuf, "\n", 1);
82  buf_putf(&outbuf, "%s\n", p);
83  buf_put(&outbuf, buf_ptr(msg), i);
84  buf_put(&outbuf, "\n", 1);
85  }
86  buf_end(&outbuf);
87 
88  return (buf_len(&outbuf));
89 }
90 
buf_putf
int buf_putf(buf_t buf, const char *fmt,...)
Definition: buf.c:106
buf_init
void buf_init(buf_t buf, u_char *data, int len)
Definition: buf.c:24
ASN1_STRING
#define ASN1_STRING
Definition: asn1.h:15
buf_end
void buf_end(buf_t buf)
Definition: buf.c:121
buf_tell
#define buf_tell(b)
Definition: buf.h:43
buf_put
int buf_put(buf_t buf, void *src, int len)
Definition: buf.c:93
decode.h
buf.h
ASN1_INTEGER
#define ASN1_INTEGER
Definition: asn1.h:14
asn1_len
int asn1_len(buf_t buf)
Definition: asn1.c:31
buf
Definition: buf.h:14
buf_tok
buf_t buf_tok(buf_t buf, void *sep, int len)
Definition: buf.c:167
buf_ptr
#define buf_ptr(b)
Definition: buf.h:31
asn1_type
int asn1_type(buf_t buf)
Definition: asn1.c:20
buf_cmp
int buf_cmp(buf_t buf, void *ptr, int len)
Definition: buf.c:158
ASN1_SEQUENCE
#define ASN1_SEQUENCE
Definition: asn1.h:16
buf_skip
#define buf_skip(b, l)
Definition: buf.h:47
config.h
decode_ldap
int decode_ldap(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_ldap.c:23
obuf
static char obuf[4096]
Definition: trigger.c:43
buf_len
#define buf_len(b)
Definition: buf.h:34
asn1.h