summaryrefslogtreecommitdiff
path: root/other/telnetfp-0.1.2/telnetfp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/telnetfp-0.1.2/telnetfp.cpp')
-rw-r--r--other/telnetfp-0.1.2/telnetfp.cpp267
1 files changed, 267 insertions, 0 deletions
diff --git a/other/telnetfp-0.1.2/telnetfp.cpp b/other/telnetfp-0.1.2/telnetfp.cpp
new file mode 100644
index 0000000..f3bff8a
--- /dev/null
+++ b/other/telnetfp-0.1.2/telnetfp.cpp
@@ -0,0 +1,267 @@
1/*
2 * telnet do/dont negotiation fingerprinting
3 * by Palmers / teso || pa1mers@gmx.de
4 */
5
6#include <telnetfp.hpp>
7
8
9class main_prog
10{
11private:
12tcp_socket con;
13tdfpdb db;
14short verbose,
15 timeout;
16
17
18void
19convert_ascii_to_bin (char *line, unsigned char *bin)
20{
21 char *tmp = NULL;
22
23 line += 6;
24 while (line != NULL)
25 {
26 *bin = atoi (line);
27 bin++;
28 if ((tmp = strstr (line, " ")) == NULL)
29 return ;
30 line = tmp + 1;
31 }
32}
33
34
35public:
36
37void
38interactBin ()
39 {
40 unsigned char do_d[31], dont_d[31];
41
42 db.open ();
43 while (1)
44 {
45 memset (do_d, 0, 31);
46 memset (dont_d, 0, 31);
47 read (STDIN_FILENO, do_d, 30);
48 read (STDIN_FILENO, dont_d, 30);
49 db.find_in_db (do_d, dont_d);
50 db.reset ();
51 }
52 }
53
54
55void
56interactAscii ()
57 {
58 unsigned char line[LINE_LENGTH + 1], do_d[31], dont_d[31];
59
60 db.open ();
61 while (1)
62 {
63 memset (do_d, 0, 31);
64 memset (dont_d, 0, 31);
65 memset (line, 0, LINE_LENGTH + 1);
66 read (STDIN_FILENO, line, LINE_LENGTH);
67 if (strstr ((char *) line, "DO: ") != NULL)
68 {
69 convert_ascii_to_bin ((char *) line, do_d);
70 memset (line, 0, LINE_LENGTH + 1);
71 read (STDIN_FILENO, line, LINE_LENGTH);
72 if (strstr ((char *) line, "DONT: ") != NULL)
73 {
74 convert_ascii_to_bin ((char *) line, dont_d);
75 db.find_in_db (do_d, dont_d);
76 db.reset ();
77 }
78 }
79 }
80 }
81
82
83int
84switch_verbosity ()
85 {
86 return (verbose ^= 1);
87 }
88
89
90/*
91 * void send_will_wont (unsigned char *):
92 * reply to do / dont request with propper will / wont.
93 */
94void
95send_will_wont (unsigned char *a)
96{
97 unsigned char will[] = {IAC, WILL, 0, 0},
98 wont[] = {IAC, WONT, 0, 0};
99 while (strlen ((char *) a) > 0)
100 {
101 if (a[0] == IAC)
102 {
103 if (a[1] == DO)
104 {
105 will[2] = a[2];
106 con.swrite ((char *) will);
107 }
108 else if (a[1] == DONT)
109 {
110 wont[2] = a[2];
111 con.swrite ((char *) wont);
112 }
113 }
114 a += 3;
115 }
116}
117
118
119void
120usage (char *s)
121{
122 printf ("Usage: %s [-v -d <file>] <host>\n", s);
123 printf ("\t-v:\t\t turn off verbose output\n");
124 printf ("\t-t <x>:\t\t set timeout for connect attemps\n");
125 printf ("\t-d <file>:\t define from which file finger prints shall be read (default: %s)\n", DEFAULT_DB);
126 printf ("\t-i (b|a):\t interactive mode. read either (b)inary or (a)scii fingerprints from stdin\n");
127 exit (1);
128}
129
130
131main_prog (int argc, char **argv)
132{
133 int x = 1;
134 printf (PROGRAM VERSION " by "AUTHOR "\n");
135 verbose = 1;
136 timeout = 5;
137
138 db.init ();
139
140 if (argc < 2)
141 usage (argv[0]);
142 while ((argc - 1) > x)
143 {
144 if (argv[x][0] == '-')
145 {
146 switch (argv[x][1])
147 {
148 case 'v':
149 switch_verbosity ();
150 break;
151 case 't':
152 x++;
153 timeout = atoi (argv[x]);
154 break;
155 case 'd':
156 x++;
157 if (!((x) < argc))
158 usage (argv[0]);
159 db.set (argv[x]);
160 break;
161 case 'i':
162 x++;
163 if (argv[x][0] == 'b')
164 {
165 interactBin ();
166 }
167 else if (argv[x][0] == 'a')
168 {
169 interactAscii ();
170 }
171 else
172 usage (argv[0]);
173 break;
174 default:
175 usage (argv[0]);
176 }
177 }
178 else
179 usage (argv[0]);
180 x++;
181 }
182 con.init ();
183 check (argv[argc - 1]);
184}
185
186
187void
188check (char *host)
189{
190 unsigned char *do_d = NULL, *dont_d = NULL;
191 int x = 0;
192
193 db.open ();
194 alarm (timeout);
195 if (con.sopen (host, 23) != 0)
196 {
197 printf ("sopen: can not connect to \"%s\"\n", host);
198 exit (3);
199 }
200/*
201 * 1.: get do's
202 */
203 if ((do_d = (unsigned char *) con.sread (30)) == NULL)
204 {
205 exit (4);
206 }
207 if (verbose)
208 {
209 printf ("DO: ");
210 for (x = 0; x < strlen ((char *) do_d); x++)
211 printf ("%d ", do_d[x]);
212 printf ("\n");
213 }
214
215/*
216 * 2.: reply will's
217 */
218 send_will_wont (do_d);
219
220/*
221 * 3.: get dont's
222 */
223 if ((dont_d = (unsigned char *) con.sread (30)) == NULL)
224 {
225 exit (5);
226 }
227 if (verbose)
228 {
229 printf ("DONT: ");
230 for (x = 0; x < strlen ((char *) dont_d); x++)
231 printf ("%d ", dont_d[x]);
232 printf ("\n");
233 }
234
235/*
236 * 4.: reply wont's
237 */
238 send_will_wont (dont_d);
239
240 con.sclose ();
241
242/*
243 * look up fp, do some output
244 */
245 db.find_in_db (do_d, dont_d);
246 db.close ();
247 exit (0);
248}
249};
250
251
252void alarmHandler (int x)
253{
254 alarm (0);
255 fprintf (stderr, "got timeout\n");
256 return;
257}
258
259
260int
261main (int argc, char **argv)
262{
263 siginterrupt(SIGALRM, 1);
264 signal (SIGALRM, alarmHandler);
265
266 main_prog a(argc, argv);
267}