/*
UHA  Anon Port Scanner v0.1

to compile: gcc aps -o aps.c -w

    to use: ./aps <proxy> <port> <target> <start_port> <stop_port>
            (i.e. ./aps proxy.com 1234 target.com 1 1024 )

This program will alow you to port scan anonymously through the use of a proxy
pretty cool huh. Well not much to say but I put a lot of hard work into this.
Disclaimer:
Please use for scanning a server you own. Do not abuse the power of this
program.Use it for good not evil...........blah..........blah

Greetz
IC3D Inc.,UHA1.com, Pronosisx.com, #webfringe, #linuxhelp, AcidBurn-uha, Pr0gen, and so
on.
*/

#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"; 
/* Some proxys return a diffrent string, but this is the
   generic HTTP 200 OK check */

char conn[]="GET http://";
/* Depending on the type of proxy you connect to, 
   this will be different until the RFC is standardized. 
   It has to be something like GET, or POST or CONNECT 
   depending on the type of proxy box */

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

printf("\n
 Anon Port Scanner v1.2");
printf("\nby iCeR 1999\n\n");

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

/* get IP of proxy */
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);

/* set ports to start and stop at */
start=atoi(argv[4]);
stop=atoi(argv[5]); 

/* loop to scan our ports */
for(i=start;i<=stop;i++)
  {
/* create socket */
  proxey.sin_port=htons(atoi(argv[2]));
  socks=socket(AF_INET,SOCK_STREAM,0);
    if(socks<0) exit(printf("Socket error\n"));
  port=i;

/* format the string we want to send - it takes to returns for it
   to accept it */

sprintf(temp, "%s %s /: %d HTTP/1.0 \n\n",conn,target,port);                          

/* connect, send string and read back reply */
  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);

/* close socket and loop back */
  close(socks);
  }
printf("\nScanning Complete\n");
printf("\nUHA 1999\n");

return 0;
}



