hacking contest

hacking exploits security forum
hacking
compliance articles
upgrade backup exec
information security consultant

Full Version: Net_client
gsicht
hi, i have coded a little net client. it can be used as telnet or netcat client. for windows compilation take cygnus as compiler.
CODE

/***************** net_client 1.0 **********************
* net_client is a lame alternative to netcat or telnet
* coded by done (23.12.03)
******************************************************/


#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>

#define TOPIC "\nnet_client by gsicht\nversion: 1.0 23.12.03\n"

void usage(char *prog)
{
printf("USAGE:\n");
printf("%s -d HOST -p PORT\n",prog);
printf(" -d [host]\tdest host\n");
printf(" -p [port]\tport to connect\n");
printf("example: %s -d www.google.com -p 80\n\n",prog);
}


void connected(int sock)
{
char rb[1500];
fd_set  fdreadme;
int i;
FD_ZERO(&fdreadme);
FD_SET(sock, &fdreadme);
FD_SET(0, &fdreadme);

while(1)
{
 FD_SET(sock, &fdreadme);
 FD_SET(0, &fdreadme);
 if(select(FD_SETSIZE, &fdreadme, NULL, NULL, NULL) < 0 ) break;
 if(FD_ISSET(sock, &fdreadme))
 {
  if((i = recv(sock, rb, sizeof(rb), 0)) < 0)
  {
   printf("[-] Connection lost..\n");
   exit(1);
  }
  if(write(1, rb, i) < 0) break;
 }

 if(FD_ISSET(0, &fdreadme))
 {
  if((i = read(0, rb, sizeof(rb))) < 0)
  {
   printf("[-] Connection lost..\n");
   exit(1);
  }
  if (send(sock, rb, i, 0) < 0) break;
 }
 sleep(1);
}
printf("[-] Connection closed by foreign host..\n");
exit(0);
}


int main(int argc, char *argv[])
{

int port,sock,c;
struct sockaddr_in addr;
struct hostent *host;
static char *hostname=NULL;

puts(TOPIC);

if(argc < 2)
{
 usage(argv[0]);
 return 0;
}

while((c = getopt(argc, argv, "d:p:"))!= EOF)
{
 switch (c)
 {
  case 'd':
  hostname = optarg;
  if(hostname == NULL)
  {
   printf("do this: -d host\n");
   exit(0);
  }
  break;

  case 'p':
  port = atoi(optarg);
 
  if((port > 65535) || (port < 1))
  {
   printf("select a port between 1-65535\n");
   exit(0);
  }
  break;
   
  default:
  usage(argv[0]);
  return 1;
 }
}

sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock == -1)
{
 printf("socket() failed\n");
 exit(0);
}

if((host = gethostbyname(hostname)) == NULL)
{
 printf("gethostbyname() failed\n");
 exit(1);
}

addr.sin_addr = *((struct in_addr *)host->h_addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);

printf("\n[+] connecting to %s:%d...\n",hostname,port);

if(connect(sock,(struct sockaddr *)&addr, sizeof(struct sockaddr)) == -1)
{
 printf("[-] couldn't connect to server\n");
 exit(0);
}

printf("[~] connected\n");
connected(sock);
close(sock);
return 0;
}
// EOF
liquidSilver
Not bad smile.gif Oh, well, I will compile this now.. wink.gif
virus
For once we can see some good constructive work going on here .... wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.

 
Invision Power Board © 2001-2005 Invision Power Services, Inc.