Skip to content

Commit 08ee7f5

Browse files
authored
Merge pull request #281 from pwned-17/master
Proxy Listener
2 parents 40942d2 + f2510dd commit 08ee7f5

8 files changed

Lines changed: 247 additions & 1 deletion

File tree

SecureTea.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
os_name = distro.linux_distribution()[0]
2121
os_major_version = distro.linux_distribution()[1].split('.')[0]
2222

23-
if os_name == 'Ubunntu' and int(os_major_version) >= 16:
23+
if os_name == 'Ubuntu' and int(os_major_version) >= 16:
2424
command = 'systemctl suspend'
2525
os.system(command)
2626
if platfom == 'Darwin':

doc/en-US/dev_guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ Currently, the server log monitor supports the following log file types:
483483
- Denial of Service (DoS) attacks
484484
- Cross site scripting (XSS) injection
485485
- SQL injection (SQLi)
486+
- Server Side Request Forgery (SSRF)
486487
- Local file inclusion (LFI)
487488
- Web shell injection
488489
- Reconnaissance attacks

securetea/lib/waf/__init__.py

Whitespace-only changes.

securetea/lib/waf/proxy/__init__.py

Whitespace-only changes.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
u"""WAF Proxy module for SecureTea WAF.
2+
3+
Project:
4+
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐
5+
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤
6+
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴
7+
Author: Shaik Ajmal R <shaikajmal.r2000@gmail.com>
8+
Version:
9+
Module: SecureTea
10+
11+
"""
12+
13+
14+
import asyncio
15+
16+
from requester import Requester
17+
18+
19+
class Http(asyncio.Protocol):
20+
"""
21+
A class that handles incoming HTTP request
22+
Parses the request and sends back the response to the client.
23+
24+
25+
26+
"""
27+
28+
29+
def connection_made(self, transport):
30+
"""
31+
asyncio default method that gets called on every request.
32+
33+
Args:
34+
transport(object): Instance of the current connection.
35+
36+
"""
37+
self.transport = transport
38+
39+
40+
def data_received(self, data):
41+
"""
42+
Clients data ie Http/Https
43+
Args:
44+
data(bytes):Has the request headers and body
45+
46+
47+
"""
48+
49+
requester=Requester(data)
50+
51+
try:
52+
requester.connect()
53+
requester.send_data()
54+
response=requester.receive_data()
55+
self.transport.write(response)
56+
requester.close()
57+
self.close_transport()
58+
59+
except Exception as e:
60+
61+
print("Error",e)
62+
63+
def close_transport(self):
64+
"""
65+
Close the current instance of the transport for every successful session.
66+
"""
67+
self.transport.close();
68+
69+
70+
71+
72+
73+
class Https(asyncio.Protocol):
74+
pass

securetea/lib/waf/proxy/proxy.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
u"""WAF Proxy module for SecureTea WAF.
3+
4+
Project:
5+
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐
6+
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤
7+
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴
8+
Author: Shaik Ajmal R <shaikajmal.r2000@gmail.com>
9+
Version:
10+
Module: SecureTea
11+
12+
"""
13+
14+
import asyncio
15+
from intercept import Http
16+
17+
class RunProxy:
18+
"""
19+
A class that starts the proxy server
20+
21+
22+
"""
23+
def __init__(self):
24+
"""
25+
Initialize host and port for listening
26+
"""
27+
self.host="127.0.0.1"
28+
self.port=2345
29+
30+
31+
def run_server(self):
32+
33+
asyncio.run(self.start())
34+
35+
async def start(self):
36+
37+
self.loop=asyncio.get_event_loop()
38+
self.server = await self.loop.create_server(
39+
lambda:Http(),host=self.host, port=self.port
40+
)
41+
ip, port = self.server.sockets[0].getsockname()
42+
print("Listening on {}:{}".format(ip, port))
43+
44+
await self.server.serve_forever()
45+
46+
47+
48+
c=RunProxy();
49+
c.run_server();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
u"""WAF Proxy module for SecureTea WAF.
2+
3+
Project:
4+
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐
5+
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤
6+
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴
7+
Author: Shaik Ajmal R <shaikajmal.r2000@gmail.com>
8+
Version:
9+
Module: SecureTea
10+
11+
"""
12+
13+
import socket
14+
from utils import RequestParser
15+
16+
class Requester:
17+
"""
18+
This class is responsible for sending the intercepted data to the requested server
19+
and sends back the response to the client.
20+
"""
21+
def __init__(self,data,timeout=5):
22+
"""
23+
Args:
24+
data(bytes): Consists of the raw request.
25+
"""
26+
print("inside requester")
27+
socket.setdefaulttimeout(timeout)
28+
self.socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
29+
self.data=data
30+
31+
def connect(self):
32+
33+
"""
34+
Extracts the host name and connects the socket to the host on port 80
35+
"""
36+
37+
self.host=(RequestParser(self.data).headers["HOST"])
38+
print(self.host)
39+
try :
40+
{
41+
self.socket.connect((self.host,80))
42+
}
43+
except Exception as e:
44+
print(e)
45+
def send_data(self):
46+
"""
47+
Sends the data through the socket to the server
48+
"""
49+
self.socket.send(self.data)
50+
51+
def receive_data(self):
52+
53+
"""
54+
Data from the server (response) is returned to the interceptor.
55+
"""
56+
57+
58+
response = b""
59+
60+
while True:
61+
try:
62+
buf = self.socket.recv(64000)
63+
if not buf:
64+
break
65+
else:
66+
response += buf
67+
except Exception as e:
68+
break
69+
70+
return response
71+
72+
def close(self):
73+
74+
self.socket.close();

securetea/lib/waf/proxy/utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
u"""WAF Proxy module for SecureTea WAF.
2+
3+
Project:
4+
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐
5+
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤
6+
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴
7+
Author: Shaik Ajmal R <shaikajmal.r2000@gmail.com>
8+
Version:
9+
Module: SecureTea
10+
11+
"""
12+
13+
14+
from http.server import BaseHTTPRequestHandler
15+
import io
16+
17+
18+
19+
class RequestParser(BaseHTTPRequestHandler):
20+
"""
21+
Handler to parse the request data from client
22+
23+
"""
24+
def __init__(self,data):
25+
"""
26+
Args:
27+
data(bytes):Data containing the Request From the Client
28+
29+
"""
30+
self.rfile=io.BytesIO(data)
31+
self.raw_requestline=self.rfile.readline()
32+
self.parse_request()
33+
34+
35+
def send_header(self, keyword,value):
36+
print(keyword,value)
37+
38+
39+
def send_error(self, code, message):
40+
"""
41+
Called by the BasseHTTPRequestHandler when there is an error
42+
43+
Args:
44+
code(int): The error code
45+
message(string): The error Messages that should be displayed
46+
"""
47+
self.ecode=code;
48+
self.error_message=message;

0 commit comments

Comments
 (0)