-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Custom responses added for TCP and UDP * Removing unnecessary `fcntl` that bars Windows testing Co-authored-by: Matthew Haigh <[email protected]>
- Loading branch information
1 parent
de6e00e
commit 85da811
Showing
21 changed files
with
1,612 additions
and
1,107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import socket | ||
|
||
# To read about customizing HTTP responses, see docs/CustomResponse.md | ||
def HandleRequest(req, method, post_data=None): | ||
"""Sample dynamic HTTP response handler. | ||
Parameters | ||
---------- | ||
req : BaseHTTPServer.BaseHTTPRequestHandler | ||
The BaseHTTPRequestHandler that recevied the request | ||
method: str | ||
The HTTP method, either 'HEAD', 'GET', 'POST' as of this writing | ||
post_data: str | ||
The HTTP post data received by calling `rfile.read()` against the | ||
BaseHTTPRequestHandler that received the request. | ||
""" | ||
response = 'Ahoy\r\n' | ||
|
||
if method == 'GET': | ||
req.send_response(200) | ||
req.send_header('Content-Length', len(response)) | ||
req.end_headers() | ||
req.wfile.write(response) | ||
|
||
elif method == 'POST': | ||
req.send_response(200) | ||
req.send_header('Content-Length', len(response)) | ||
req.end_headers() | ||
req.wfile.write(response) | ||
|
||
elif method == 'HEAD': | ||
req.send_response(200) | ||
req.end_headers() | ||
|
||
|
||
def HandleTcp(sock): | ||
"""Handle a TCP buffer. | ||
Parameters | ||
---------- | ||
sock : socket | ||
The connected socket with which to recv and send data | ||
""" | ||
while True: | ||
try: | ||
data = None | ||
data = sock.recv(1024) | ||
except socket.timeout: | ||
pass | ||
|
||
if not data: | ||
break | ||
|
||
resp = raw_input('\nEnter a response for the TCP client: ') | ||
sock.sendall(resp) | ||
|
||
|
||
def HandleUdp(sock, data, addr): | ||
"""Handle a UDP buffer. | ||
Parameters | ||
---------- | ||
sock : socket | ||
The connected socket with which to recv and send data | ||
data : str | ||
The data received | ||
addr : tuple | ||
The host and port of the remote peer | ||
""" | ||
if data: | ||
resp = raw_input('\nEnter a response for the UDP client: ') | ||
sock.sendto(resp, addr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# To read about customizing HTTP responses, see docs/CustomResponse.md | ||
[Example0] | ||
InstanceName: HTTPListener80 | ||
HttpURIs: /test.txt | ||
HttpStaticString: Wraps this with normal FakeNet HTTP headers (<RAW-DATE>)\r\n | ||
|
||
[Example1] | ||
InstanceName: HTTPListener80 | ||
ListenerType: HTTP | ||
HttpHosts: some.random.c2.com, other.c2.com | ||
HttpRawFile: sample_raw_response.txt | ||
|
||
[Example2] | ||
ListenerType: HTTP | ||
HttpHosts: both_host.com | ||
HttpURIs: and_uri.txt | ||
HttpDynamic: CustomProviderExample.py | ||
|
||
[ExampleTCP] | ||
InstanceName: RawTCPListener | ||
TcpDynamic: CustomProviderExample.py | ||
|
||
[ExampleUDP] | ||
InstanceName: RawUDPListener | ||
UdpDynamic: CustomProviderExample.py |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.