-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (41 loc) · 1.7 KB
/
Program.cs
File metadata and controls
52 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace socks5proxyclient {
class Program {
static void Main(string[] args) {
var proxyAddr = "218.62.97.105:1080";
var proxyIp = proxyAddr.Split(':')[0];
var proxyPort = int.Parse(proxyAddr.Split(':')[1]);
var client = new TcpClient(proxyIp, proxyPort);
Console.WriteLine("Connected to proxy: {0} at port: {1}", proxyIp, proxyPort);
var connection = client.GetStream();
var writer = new BinaryWriter(connection);
var reader = new BinaryReader(connection);
writer.Write(new byte[] { 0x05, 0x01, 0x00 });
var response = reader.ReadBytes(2);
if (response[1] != 0x00)
throw new WebException("Proxy doesn't support connection without authentication.");
writer.Write(new byte[] { 0x05, 0x01, 0x00, 0x01 });
var ip = "173.194.35.152";
foreach (var part in ip.Split('.'))
writer.Write(byte.Parse(part));
var port = 80;
writer.Write(IntToNetworkByteOrder(port));
response = reader.ReadBytes(10);
var errorCode = response[1];
if (errorCode != 0)
throw new WebException("Connection to proxy failed. Errorcode " + errorCode);
Console.WriteLine("Connected to target over proxy.");
}
private static byte[] IntToNetworkByteOrder(int port) {
var hb = port / 256;
var lb = port % 256;
return new byte[] { (byte)hb, (byte)lb };
}
}
}