what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

shbnc.c

shbnc.c
Posted Jul 1, 2000
Authored by Wildandi

shbnc.c allows you to use a SQUID bouncer with applications which are configured to use a SOCKS proxy.

tags | tool
systems | unix
SHA-256 | f01eb2b1304f99ba8f00fcffc17ecad885fd78033d57685382285705a434801f

shbnc.c

Change Mirror Download
/* socks->http proxy bouncer 
* Wildandi <andi@void.at>
*
* Use vulnerable SQUID server (= allows CONNECT method) as an SOCKS server for your application
*
* Example: ./shbnc 0 1080 httpproxy 8080
*
* http://void.at:8080
*/
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>

struct socks4 {
char vn;
char cd;
unsigned short dstport;
unsigned int dstip;
char *data;
};

int conn(int *sock, char *server, int port);
int list(char *server, int port);

int main(int argc, char **argv) {
int serversock,
clientsock,
disconnected,
greater;
fd_set fs;
struct socks4 stype, ctype;
char buffer[2048]="";

if (argc>4) {
clientsock = list(argv[1], atoi(argv[2]));
if (clientsock==-1) return 0;
disconnected = 1;
if (!conn(&serversock,argv[3], atoi(argv[4]))) {
/* Data from client */
memset(&stype, 0, sizeof(stype));
recv(clientsock, &stype, sizeof(stype), 0x4);
ctype.vn = 0;
ctype.cd = 90;
ctype.dstport = 0;
ctype.dstip = 0;
ctype.data = NULL;
send(clientsock, &ctype, sizeof(ctype), 0x4);

snprintf(buffer, sizeof(buffer), "CONNECT %s:%d HTTP/1.0\n\n", inet_ntoa(stype.dstip), ntohs(stype.dstport));
send(serversock, buffer, strlen(buffer), 0x4);
recv(serversock, buffer, sizeof(buffer), 0x4);

greater = (serversock > clientsock ? serversock : clientsock);

while (disconnected) {
FD_ZERO(&fs);
FD_SET(clientsock, &fs);
FD_SET(serversock, &fs);
select(greater + 1, &fs, NULL, NULL, NULL);
if (FD_ISSET(serversock, &fs)) {
memset(buffer, 0, sizeof(buffer));
disconnected = recv(serversock, buffer, sizeof(buffer), 0x4);
if (disconnected) send(clientsock, buffer, disconnected, 0x4);
} else if (FD_ISSET(clientsock, &fs)) {
memset(&buffer, 0, sizeof(buffer));
disconnected = recv(clientsock, buffer, sizeof(buffer), 0x4);
if (disconnected) send(serversock, buffer, disconnected, 0x4);
}
}
} else {
stype.vn = 0;
stype.cd = 91;
stype.dstport = 0;
stype.dstip = 0;
stype.data = NULL;
send(clientsock, &stype, sizeof(stype), 0x4);
}
close(clientsock);
close(serversock);
} else {
fprintf(stderr,"%s bindhost bindport httpproxy httpproxyport\n", *argv);
}

return 0;
}

int conn(int *sock, char *server, int port)
{
struct sockaddr_in s_in;
struct hostent *he;
char *ip;

if ((*sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) /* TCP */
{
fprintf(stderr,"Cant create TCP socket\n");
return -1;
}

bzero((char *)&s_in,sizeof(s_in));
s_in.sin_family=AF_INET;
s_in.sin_addr.s_addr=inet_addr(server);
s_in.sin_port=htons(port);

if ((he=gethostbyname(server))!=NULL)
bcopy(he->h_addr,(char *)&s_in.sin_addr,he->h_length);
else if ((s_in.sin_addr.s_addr=inet_addr(server))<0) return 2;

if (connect(*sock,(struct sockaddr *)&s_in,16)==-1)
{
fprintf(stderr,"Cant connect to %s:%d\n",server,port);
close(*sock);
return 3;
}
return 0;
}

int list(char *server, int port) {
struct sockaddr_in s_in;
struct hostent *he;
int sock=0, len=0;

if ((sock=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))==-1) {
fprintf(stderr,"Cant create TCP socket\n");
return -1;
}

bzero((char *)&s_in,sizeof(s_in));
s_in.sin_family=AF_INET;
s_in.sin_addr.s_addr=inet_addr(server);
s_in.sin_port=htons(port);

if ((he=gethostbyname(server))!=NULL)
bcopy(he->h_addr,(char *)&s_in.sin_addr,he->h_length);
else if ((s_in.sin_addr.s_addr=inet_addr(server))<0) return 2;


if (bind(sock, (struct sockaddr *)&s_in, sizeof(s_in))) {
fprintf(stderr,"Cant bind\n");
return -2;
}

if (listen(sock, 1)) {
fprintf(stderr, "listen error\n");
return -3;
}

return accept(sock, (struct sockaddr *)&s_in, &len);
}

Login or Register to add favorites

File Archive:

July 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jul 1st
    27 Files
  • 2
    Jul 2nd
    10 Files
  • 3
    Jul 3rd
    35 Files
  • 4
    Jul 4th
    27 Files
  • 5
    Jul 5th
    18 Files
  • 6
    Jul 6th
    0 Files
  • 7
    Jul 7th
    0 Files
  • 8
    Jul 8th
    28 Files
  • 9
    Jul 9th
    44 Files
  • 10
    Jul 10th
    24 Files
  • 11
    Jul 11th
    25 Files
  • 12
    Jul 12th
    11 Files
  • 13
    Jul 13th
    0 Files
  • 14
    Jul 14th
    0 Files
  • 15
    Jul 15th
    28 Files
  • 16
    Jul 16th
    6 Files
  • 17
    Jul 17th
    34 Files
  • 18
    Jul 18th
    6 Files
  • 19
    Jul 19th
    0 Files
  • 20
    Jul 20th
    0 Files
  • 21
    Jul 21st
    0 Files
  • 22
    Jul 22nd
    0 Files
  • 23
    Jul 23rd
    0 Files
  • 24
    Jul 24th
    0 Files
  • 25
    Jul 25th
    0 Files
  • 26
    Jul 26th
    0 Files
  • 27
    Jul 27th
    0 Files
  • 28
    Jul 28th
    0 Files
  • 29
    Jul 29th
    0 Files
  • 30
    Jul 30th
    0 Files
  • 31
    Jul 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close