proxyscan

#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string.h>
#define MAX 256
#define SS struct sockaddr

int main(int argc, char *argv[]) {
        int socks, start, stop, i;
        struct hostent *bounce;
        struct sockaddr_in proxey;
        char temp[MAX + 1];
        char buffer[MAX + 1];
        char connected[] = "200";

        char conn[] = "GET http://";

        int port;
        char *target;
        target = argv[3];

        printf("\nProxy Port Scanner v1.2");
        printf("\nby Stuart Manlove [LoG]\n\n");

        if (argc < 5)
                exit(printf("Usage: %s <proxy><port><target><start_port><stop_port>\n",
                                argv[0]));

        bounce = gethostbyname(argv[1]);
        if (!bounce)
                exit(printf("Domain lookup error\n"));

        proxey.sin_family = AF_INET;
        proxey.sin_addr.s_addr = *(long *) (bounce->h_addr);

        start = atoi(argv[4]);
        stop = atoi(argv[5]);

        for (i = start; i <= stop; i++) {
                proxey.sin_port = htons(atoi(argv[2]));
                socks = socket(AF_INET, SOCK_STREAM, 0);
                if (socks < 0)
                        exit(printf("Socket error\n"));
                port = i;
                sprintf(temp, "%s%s:%d HTTP/1.0 \n\n", conn, target, port);
                if ((connect(socks, (struct sockaddr *) &proxey, sizeof(proxey))) < 0)
                        exit(printf("Connection error\n"));
                write(socks, temp, strlen(temp));
                if (read(socks, buffer, sizeof(buffer)) < 0)
                        exit(printf("Read error"));
                if (strcmp(buffer, connected) <= 0)
                        printf("\nPort: %i open", &i);
                printf("%s\n", buffer);
                close(socks);
        }
        printf("\nScan finished\n");

        return 0;
}

通过给向代理服务器,发送http request 然后得到相应

HTTP 请求格式:GET http://www.baidu.com HTTP/1.0


HTTP请求格式:

GET / HTTP/1.1
Host: 
www.baidu.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20050225 Firefox/1.0.1
Connection: Keep-Alive


HTTP响应格式:HTTP/1.1 200 OK
Date: Sat, 31 Dec 2005 23:59:59 GMT
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 122

<html>
<head>
<title>Wrox Homepage</title>
</head>
<body>
<!-- body goes here -->
</body>
</html>

posted on 2012-06-13 16:26  java课程设计  阅读(285)  评论(0编辑  收藏  举报

导航