-
Notifications
You must be signed in to change notification settings - Fork 0
/
wterm.c
148 lines (117 loc) · 3.04 KB
/
wterm.c
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
/* wterm.c
* truefinder, [email protected]
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <sys/socket.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <getopt.h>
#include "kbhit.h"
void print_banner(void);
void print_usage( char *argv[]);
#define BUFSIZE 4096
#define HTTP_METHOD "POST"
#define HTTP_PROTO "HTTP/1.0\r\nContent-Length: 1\r\n\r\n"
int
main( int argc, char *argv[] )
{
char cmd[1024];
char *msg_h = HTTP_METHOD;
char *msg_t = HTTP_PROTO;
char ch ;
int len, i, j ;
struct sockaddr_in s ;
int sock; int n;
char buf[BUFSIZE];
char *needle;
static char *optstr = "h:p:l:";
char oc;
char *host;
char *location;
char *port;
fd_set fds ;
if ( argc < 3 ) {
print_usage(argv);
exit(0);
}
while( (oc = getopt( argc, argv, optstr)) != -1 ) {
switch (oc) {
case 'h':
host = optarg;
break;
case 'p':
port = optarg;
break;
case 'l':
location= optarg;
break;
default:
exit(-1);
}
}
printf("%s %s %s \n", host ,port, location);
print_banner();
init_keyboard();
do {
if ( kbhit()) {
ch = readch();
if (ch == '\n') ch = '\r';
} else continue;
sprintf( cmd , "%s %s %s%c", msg_h, location, msg_t, ch);
len = strlen(cmd);
sock = socket( PF_INET, SOCK_STREAM, 0 );
if ( sock < 0 ){
perror("socket");
exit(0);
}
bzero( &s, sizeof(s) );
s.sin_family = PF_INET ;
s.sin_port = htons(atoi(port));
s.sin_addr.s_addr = inet_addr(host);
if ( connect( sock , (struct sockaddr*)&s, sizeof(s) ) <0 ) {
perror("connect");
exit(0);
}
write( sock, cmd , len );
bzero( buf, sizeof(buf) );
i = read( sock, buf, sizeof(buf) );
needle = strstr(buf, "\r\n\r\n" );
needle += 4;
j = strlen( needle);
write( STDOUT_FILENO, needle, j );
close(sock);
} while(1);
close_keyboard();
// Author : Seunghyun Seo
// Last update : at Aug 24 03:20:31 KST 2002
}
void
print_usage(char* argv[])
{
fprintf(stderr, "Usage : %s -h [ip] -p [port] -l [location]\n", argv[0] );
fprintf(stderr, "Options:\n");
fprintf(stderr, "\t[ip] host ip\n" );
fprintf(stderr, "\t[port] port of webserver\n" );
fprintf(stderr, "\t[location] location of wtcgi.cgi\n\n" );
fprintf(stderr, "\tex)\n" );
fprintf(stderr, "\t%s -h 192.168.1.1 -p 80 -l /cgi-bin/wtcgi.cgi\n", argv[0] );
}
void
print_banner(void)
{
printf("+-----------------------------------------------------------+\n");
printf("| |\n");
printf("| Welcome to Web Terminal |\n");
printf("| |\n");
printf("| by truefinder |\n");
printf("| [email protected], [email protected]|\n");
printf("| |\n");
printf("+-----------------------------------------------------------+\n");
}