[Uncategorized] Web(e.g. HTTPS) fail-over simulation
gnh1201 opened this issue · comments
Summary
Recently, a request came in from a company with prior experience in adopting WelsonJS, expressing the desire to create a tool for web fail-over simulation (e.g., simulating HTTPS connection failures). They mentioned having used the Windivert library alongside WelsonJS before, suggesting that it should be possible to utilize these components to develop a fail-over simulator. I am currently looking into this issue.
Keywords: High Availablity, Disaster Recovery, Emergency Response Training
I queried ChatGPT for details on this issue and was able to obtain the example code using pydivert
as follows:
import pydivert
def is_port_443(packet):
# Implement the logic to check if the destination port is 443
# For example, check the TCP header in the packet
return True
def modify_packet(packet):
# Modify the packet to send a fake "Bad Request" response
fake_response = "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\n\r\nBad Request"
response_bytes = bytes(fake_response, 'utf-8')
# Replace the original payload with the fake response
packet.payload = response_bytes
def main():
with pydivert.WinDivert("tcp.DstPort == 443 or tcp.SrcPort == 443") as w:
print("Intercepting traffic on port 443...")
for packet in w:
if is_port_443(packet):
modify_packet(packet)
w.send(packet)
print("Sent fake 'Bad Request' response to port 443.")
else:
w.send(packet)
if __name__ == "__main__":
main()
I will review this code snippet.