summaryrefslogtreecommitdiff
path: root/other/b-scan/tmp/modules/mod_httpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'other/b-scan/tmp/modules/mod_httpd.c')
-rw-r--r--other/b-scan/tmp/modules/mod_httpd.c188
1 files changed, 188 insertions, 0 deletions
diff --git a/other/b-scan/tmp/modules/mod_httpd.c b/other/b-scan/tmp/modules/mod_httpd.c
new file mode 100644
index 0000000..275125c
--- /dev/null
+++ b/other/b-scan/tmp/modules/mod_httpd.c
@@ -0,0 +1,188 @@
1/*
2 * mod_example.c
3 * Example module for bscan.
4 */
5
6#include <bscan/bscan.h>
7#include <bscan/module.h>
8#include <stdio.h>
9
10
11#ifndef MOD_NAME
12#define MOD_NAME "mod_httpd"
13#endif
14
15#define HEADREQ "HEAD / HTTP/1.0\r\n\r\n"
16
17
18static int isinit=0;
19/*
20 * some variables from the binary-process
21 */
22extern int dlt_len;
23extern u_char *align_buf;
24extern unsigned short ip_options;
25extern struct ip *ip;
26extern struct Ether_header *eth;
27extern u_int plen, pcaplen;
28
29struct _mopt
30{
31 unsigned short int dport; /* dport in NBO */
32 char *request; /* the http-request */
33} static mopt;
34
35/*
36 * static functions prototypes
37 */
38static int mdo_opt(int, char **, struct _opt *);
39static void init_vars(struct _opt *);
40static int process_rcv(struct _opt *);
41
42/*
43 * print out usage informations
44 */
45void
46musage()
47{
48 printf ("\n"MOD_NAME"\n");
49 printf (" -p <port>, default 80\n");
50 printf (" -r <request>, default 'HEAD / HTTP/1.0'\n");
51}
52
53
54/*
55 * return 0 on success, != 0 on failure
56 */
57int
58init(char **modname, int argc, char *argv[], struct _opt *opt)
59{
60#ifdef DEBUG
61 printf("MODULE INIT\n");
62#endif
63 if (isinit)
64 return(-1);
65
66 *modname = MOD_NAME;
67 isinit = 1;
68 init_vars(opt);
69
70 if (mdo_opt(argc, argv, opt) != 0)
71 return(-1);
72
73 return(0);
74}
75
76/*
77 * fini-routine. called on cleanup
78 */
79int
80fini()
81{
82#ifdef DEBUG
83 printf("MODULE FINI\n");
84#endif
85 return(0);
86}
87
88
89/*
90 *
91 */
92int
93callmdl(int entry, struct _opt *opt)
94{
95#ifdef DEBUG
96 printf("MODULE CALLMDL\n");
97#endif
98 if (entry == MOD_FIRSTPKG)
99 return(RMOD_SKIP);
100
101 if (entry == MOD_RCV)
102 process_rcv(opt);
103
104 return(RMOD_OK);
105}
106
107
108/*
109 ***********************************************************
110 * Our OWN/static functions for THIS module *
111 ***********************************************************
112 */
113
114/*
115 * initialize all local variables.
116 * We use some 'unused' variables of the masterprogramm
117 */
118static void
119init_vars(struct _opt *opt)
120{
121 mopt.dport = htons(80);
122 mopt.request = HEADREQ;
123}
124
125
126/*
127 * LOCAL/STATIC function, only available in the module
128 * return 0 on success, != 0 on failure
129 */
130static int
131mdo_opt(int argc, char *argv[], struct _opt *opt)
132{
133 extern char *optarg;
134 /*extern int optind, opterr, optopt;*/
135 int c;
136
137 while ((c = getopt (argc, argv, "p:r:")) != -1)
138 {
139 switch (c)
140 {
141 case 'p':
142 mopt.dport = htons(strtoul (optarg, (char **) NULL, 10));
143 break;
144 case 'r':
145 mopt.request = optarg;
146 fprintf(stderr, MOD_NAME ": requesting \"%s\"\n", optarg);
147 break;
148 case ':':
149 fprintf(stderr, "missing parameter\n");
150 return(-1);
151 default:
152 return(-1);
153 }
154 }
155 return(0);
156}
157
158
159/*
160 * process incoming packets
161 * IP-packet is verified and variables valid (ip_options, *ip)
162 */
163static int
164process_rcv(struct _opt *opt)
165{
166 struct tcphdr *tcp;
167 unsigned short tcp_options = 0;
168 uint iphdr_len = 0;
169
170
171 if (ip->ip_p != IPPROTO_TCP)
172 return(0);
173
174 iphdr_len = sizeof(*ip) + ip_options;
175 tcp = (struct tcphdr *) (align_buf + iphdr_len);
176
177 if (vrfy_tcp(tcp, plen - dlt_len - iphdr_len, &tcp_options) != 0)
178 return(0);
179
180 if (tcp->th_sport != mopt.dport)
181 return(0);
182
183 if ((tcp->th_flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK))
184 answer_tcp (opt->sox, ip, tcp, TH_ACK | TH_PUSH, mopt.request, strlen(mopt.request));
185
186 return(0);
187}
188