Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
363f120e
Commit
363f120e
authored
Jul 16, 2015
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify test project
parent
ebe15c59
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
138 deletions
+22
-138
Program.cs
Titanium.Web.Proxy.Test/Program.cs
+2
-7
ProxyTestController.cs
Titanium.Web.Proxy.Test/ProxyTestController.cs
+13
-123
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+7
-8
No files found.
Titanium.Web.Proxy.Test/Program.cs
View file @
363f120e
...
...
@@ -36,9 +36,7 @@ namespace Titanium.Web.Proxy.Test
controller
.
SetAsSystemProxy
=
true
;
}
controller
.
Visited
+=
PageVisited
;
//Start proxy controller
controller
.
StartProxy
();
...
...
@@ -49,10 +47,7 @@ namespace Titanium.Web.Proxy.Test
controller
.
Stop
();
}
private
static
void
PageVisited
(
VisitedEventArgs
e
)
{
Console
.
WriteLine
(
string
.
Concat
(
"Visited: "
,
e
.
URL
));
}
static
bool
ConsoleEventCallback
(
int
eventType
)
{
if
(
eventType
==
2
)
...
...
Titanium.Web.Proxy.Test/ProxyTestController.cs
View file @
363f120e
...
...
@@ -16,8 +16,6 @@ namespace Titanium.Web.Proxy.Test
{
public
partial
class
ProxyTestController
{
private
List
<
string
>
_URLList
=
new
List
<
string
>();
private
string
_lastURL
=
string
.
Empty
;
public
int
ListeningPort
{
get
;
set
;
}
public
bool
EnableSSL
{
get
;
set
;
}
...
...
@@ -26,160 +24,52 @@ namespace Titanium.Web.Proxy.Test
public
void
StartProxy
()
{
if
(
Visited
!=
null
)
{
ProxyServer
.
BeforeRequest
+=
OnRequest
;
ProxyServer
.
BeforeResponse
+=
OnResponse
;
}
ProxyServer
.
EnableSSL
=
EnableSSL
;
ProxyServer
.
BeforeRequest
+=
OnRequest
;
ProxyServer
.
BeforeResponse
+=
OnResponse
;
ProxyServer
.
SetAsSystemProxy
=
SetAsSystemProxy
;
ProxyServer
.
EnableSSL
=
EnableSSL
;
ProxyServer
.
SetAsSystemProxy
=
SetAsSystemProxy
;
ProxyServer
.
Start
();
ListeningPort
=
ProxyServer
.
ListeningPort
;
Console
.
WriteLine
(
String
.
Format
(
"Proxy listening on local machine port: {0} "
,
ProxyServer
.
ListeningPort
));
Console
.
WriteLine
(
String
.
Format
(
"Proxy listening on local machine port: {0} "
,
ProxyServer
.
ListeningPort
));
}
public
void
Stop
()
{
if
(
Visited
!=
null
)
{
ProxyServer
.
BeforeRequest
-=
OnRequest
;
ProxyServer
.
BeforeResponse
-=
OnResponse
;
}
ProxyServer
.
Stop
();
}
ProxyServer
.
BeforeRequest
-=
OnRequest
;
ProxyServer
.
BeforeResponse
-=
OnResponse
;
ProxyServer
.
Stop
();
}
public
delegate
void
SiteVisitedEventHandler
(
VisitedEventArgs
e
);
public
event
SiteVisitedEventHandler
Visited
;
// Invoke the Changed event; called whenever list changes
protected
virtual
void
OnChanged
(
VisitedEventArgs
e
)
{
if
(
Visited
!=
null
)
Visited
(
e
);
}
//Test On Request, intecept requests
//Read browser URL send back to proxy by the injection script in OnResponse event
public
void
OnRequest
(
object
sender
,
SessionEventArgs
e
)
{
string
Random
=
e
.
RequestURL
.
Substring
(
e
.
RequestURL
.
LastIndexOf
(
@"/"
)
+
1
);
int
index
=
_URLList
.
IndexOf
(
Random
);
if
(
index
>=
0
)
{
string
URL
=
e
.
GetRequestHtmlBody
();
if
(
_lastURL
!=
URL
)
{
OnChanged
(
new
VisitedEventArgs
()
{
hostname
=
e
.
RequestHostname
,
URL
=
URL
,
remoteIP
=
e
.
ClientIpAddress
,
remotePort
=
e
.
ClientPort
});
Console
.
WriteLine
(
e
.
RequestURL
);
}
e
.
Ok
(
null
);
_lastURL
=
URL
;
}
}
//Test script injection
//Insert script to read the Browser URL and send it back to proxy
public
void
OnResponse
(
object
sender
,
SessionEventArgs
e
)
{
try
{
if
(
e
.
ProxyRequest
.
Method
==
"GET"
||
e
.
ProxyRequest
.
Method
==
"POST"
)
{
if
(
e
.
ServerResponse
.
StatusCode
==
HttpStatusCode
.
OK
)
{
if
(
e
.
ServerResponse
.
ContentType
.
Trim
().
ToLower
().
Contains
(
"text/html"
))
{
string
c
=
e
.
ServerResponse
.
GetResponseHeader
(
"X-Requested-With"
);
if
(
e
.
ServerResponse
.
GetResponseHeader
(
"X-Requested-With"
)
==
""
)
{
string
responseHtmlBody
=
e
.
GetResponseHtmlBody
();
string
functioname
=
"fr"
+
RandomString
(
10
);
string
VisitedURL
=
RandomString
(
5
);
string
RequestVariable
=
"c"
+
RandomString
(
5
);
string
RandomURLEnding
=
RandomString
(
25
);
string
RandomLastRequest
=
RandomString
(
10
);
string
LocalRequest
;
if
(
e
.
IsSSLRequest
)
LocalRequest
=
"https://"
+
e
.
RequestHostname
+
"/"
+
RandomURLEnding
;
else
LocalRequest
=
"http://"
+
e
.
RequestHostname
+
"/"
+
RandomURLEnding
;
string
script
=
"var "
+
RandomLastRequest
+
" = null;"
+
"if(window.top==self) { "
+
"\n"
+
" "
+
functioname
+
"();"
+
"setInterval("
+
functioname
+
",500); "
+
"\n"
+
"}"
+
"function "
+
functioname
+
"(){ "
+
"\n"
+
"var "
+
RequestVariable
+
" = new XMLHttpRequest(); "
+
"\n"
+
"var "
+
VisitedURL
+
" = null;"
+
"\n"
+
"if(window.top.location.href!=null) "
+
"\n"
+
""
+
VisitedURL
+
" = window.top.location.href; else "
+
"\n"
+
""
+
VisitedURL
+
" = document.referrer; "
+
"if("
+
RandomLastRequest
+
"!= "
+
VisitedURL
+
") {"
+
RequestVariable
+
".open(\"POST\",\""
+
LocalRequest
+
"\", true); "
+
"\n"
+
RequestVariable
+
".send("
+
VisitedURL
+
");} "
+
RandomLastRequest
+
" = "
+
VisitedURL
+
"}"
;
Regex
RE
=
new
Regex
(
"</body>"
,
RegexOptions
.
RightToLeft
|
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Multiline
);
string
modifiedResponseHtmlBody
=
RE
.
Replace
(
responseHtmlBody
,
"<script type =\"text/javascript\">"
+
script
+
"</script></body>"
,
1
);
if
(
modifiedResponseHtmlBody
.
Length
!=
responseHtmlBody
.
Length
)
{
e
.
SetResponseHtmlBody
(
modifiedResponseHtmlBody
);
_URLList
.
Add
(
RandomURLEnding
);
}
}
}
}
}
}
catch
{
}
}
private
Random
random
=
new
Random
((
int
)
DateTime
.
Now
.
Ticks
);
private
string
RandomString
(
int
size
)
{
StringBuilder
builder
=
new
StringBuilder
();
char
ch
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
ch
=
Convert
.
ToChar
(
Convert
.
ToInt32
(
Math
.
Floor
(
26
*
random
.
NextDouble
()
+
65
)));
builder
.
Append
(
ch
);
}
return
builder
.
ToString
();
}
}
public
class
VisitedEventArgs
:
EventArgs
{
public
string
URL
;
public
string
hostname
;
public
IPAddress
remoteIP
{
get
;
set
;
}
public
int
remotePort
{
get
;
set
;
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
363f120e
...
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy
private
static
void
HandleClient
(
TcpClient
Client
)
{
string
connectionGroup
=
null
;
Stream
clientStream
=
null
;
CustomBinaryReader
clientStreamReader
=
null
;
StreamWriter
connectStreamWriter
=
null
;
...
...
@@ -34,8 +34,7 @@ namespace Titanium.Web.Proxy
try
{
//Separate HttpWebRequest connection group for each client
connectionGroup
=
((
IPEndPoint
)
Client
.
Client
.
RemoteEndPoint
).
Address
.
ToString
();
clientStream
=
Client
.
GetStream
();
...
...
@@ -181,7 +180,7 @@ namespace Titanium.Web.Proxy
}
//Now create the request
HandleHttpSessionRequest
(
Client
,
httpCmd
,
c
onnectionGroup
,
c
lientStream
,
tunnelHostName
,
requestLines
,
clientStreamReader
,
securehost
);
HandleHttpSessionRequest
(
Client
,
httpCmd
,
clientStream
,
tunnelHostName
,
requestLines
,
clientStreamReader
,
securehost
);
...
...
@@ -212,7 +211,7 @@ namespace Titanium.Web.Proxy
}
}
private
static
void
HandleHttpSessionRequest
(
TcpClient
Client
,
string
httpCmd
,
string
connectionGroup
,
Stream
clientStream
,
string
tunnelHostName
,
List
<
string
>
requestLines
,
CustomBinaryReader
clientStreamReader
,
string
securehost
)
private
static
void
HandleHttpSessionRequest
(
TcpClient
Client
,
string
httpCmd
,
Stream
clientStream
,
string
tunnelHostName
,
List
<
string
>
requestLines
,
CustomBinaryReader
clientStreamReader
,
string
securehost
)
{
...
...
@@ -324,7 +323,7 @@ namespace Titanium.Web.Proxy
return
;
}
args
.
ProxyRequest
.
ConnectionGroupName
=
connectionGroup
;
args
.
ProxyRequest
.
ConnectionGroupName
=
args
.
RequestHostname
;
args
.
ProxyRequest
.
AllowWriteStreamBuffering
=
true
;
//If request was modified by user
...
...
@@ -361,7 +360,7 @@ namespace Titanium.Web.Proxy
requestLines
.
Add
(
tmpLine
);
}
httpCmd
=
requestLines
.
Count
()
>
0
?
requestLines
[
0
]
:
null
;
HandleHttpSessionRequest
(
Client
,
httpCmd
,
args
.
ProxyRequest
.
ConnectionGroupName
,
args
.
ClientStream
,
args
.
tunnelHostName
,
requestLines
,
args
.
ClientStreamReader
,
args
.
securehost
);
HandleHttpSessionRequest
(
Client
,
httpCmd
,
args
.
ClientStream
,
args
.
tunnelHostName
,
requestLines
,
args
.
ClientStreamReader
,
args
.
securehost
);
}
}
...
...
@@ -634,7 +633,7 @@ namespace Titanium.Web.Proxy
TcpClient
Client
=
args
.
Client
;
//Http request body sent, now wait for next request
HandleHttpSessionRequest
(
Client
,
httpCmd
,
args
.
ProxyRequest
.
ConnectionGroupName
,
args
.
ClientStream
,
args
.
tunnelHostName
,
requestLines
,
args
.
ClientStreamReader
,
args
.
securehost
);
HandleHttpSessionRequest
(
Client
,
httpCmd
,
args
.
ClientStream
,
args
.
tunnelHostName
,
requestLines
,
args
.
ClientStreamReader
,
args
.
securehost
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment