Skip to content

Instantly share code, notes, and snippets.

@aeris
Created Sep 12, 2014
Embed
What would you like to do?
W.T.F.
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int main() {
sockaddr_in proxyAddress;
proxyAddress.sin_family = AF_INET;
proxyAddress.sin_port = htons(9050);
inet_aton("127.0.0.1", &proxyAddress.sin_addr);
int proxy = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
connect(proxy, (struct sockaddr *)&proxyAddress, sizeof(proxyAddress));
char buffer[256];
buffer[0] = 5; // Socks5
buffer[1] = 1; // 1 method auth
buffer[2] = 0; // No auth
send(proxy, buffer, 3, 0);
recv(proxy, buffer, 2, 0);
char *address = "google.fr";
u_int16_t port = htons(80);
buffer[0] = 5; // Socks5
buffer[1] = 1; // Connect
buffer[2] = 0;
buffer[3] = 3; // 1- IPv4, 3- domain name, 4- IPv6
ssize_t s = strlen(address);
buffer[4] = s;
memcpy(buffer + 5, address, s);
ssize_t p = sizeof(port);
memcpy(buffer + 5 + s, &port, p);
send(proxy, buffer, 5+s+p, 0);
recv(proxy, buffer, 256, 0);
char *r = "GET / HTTP/1.1\r\n\r\n";
_send(proxy, r, strlen(r), 0);
_recv(proxy, buffer, 256, 0);
shutdown(proxy, SHUT_RDWR);
return 0;
}
#!/usr/bin/env ruby
require 'socket'
def htons(h)
[h].pack("S").unpack("n")[0]
end
socket = TCPSocket.new '127.0.0.1', 9050
socket.write [5, 1, 0].pack('CCC')
socket.recv 2
address = "google.fr"
port = htons 80
socket.write [5, 1, 0, 3, address.size, address, port].pack('CCCCCA*S')
socket.recv 256
socket.write "GET / HTTP/1.1\r\n\r\n"
socket.recv 256
socket.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment